1 // Ryzom Core Studio - GUI Editor Plugin
3 // Copyright (C) 2010-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "expression_loader.h"
19 #include "expression_info.h"
22 #include <QXmlStreamReader>
24 class ExpressionLoaderPvt
30 QString text
= reader
.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement
);
31 if( reader
.hasError() )
41 QString text
= reader
.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement
);
42 if( reader
.hasError() )
45 if( text
.toLower() == "true" )
48 m_info
->value
= false;
55 QString text
= reader
.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement
);
56 if( reader
.hasError() )
59 m_info
->category
= text
;
66 QString text
= reader
.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement
);
67 if( reader
.hasError() )
70 if( text
.toLower() == "true" )
71 m_info
->variable
= true;
73 m_info
->variable
= false;
80 QString text
= reader
.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement
);
81 if( reader
.hasError() )
84 m_info
->slotNames
.push_back( text
);
93 while( !reader
.atEnd() )
97 if( reader
.isStartElement() )
99 QString name
= reader
.name().toString();
101 error
= !parseSlot();
104 if( reader
.isEndElement() )
106 if( reader
.name() == "slots" )
117 bool load( QFile
*f
)
120 reader
.setDevice( f
);
134 if( reader
.isStartElement() )
136 // Not an expression file?
137 if( reader
.name() != "expression" )
141 while( !reader
.atEnd() )
145 if( reader
.isStartElement() )
147 QString name
= reader
.name().toString();
150 error
= !parseName();
152 if( name
== "value" )
153 error
= !parseValue();
155 if( name
== "category" )
156 error
= !parseCategory();
158 if( name
== "variable" )
159 error
= !parseVariable();
161 if( name
== "slots" )
162 error
= !parseSlots();
169 if( error
|| reader
.hasError() )
177 void setInfo( ExpressionInfo
*info
){ m_info
= info
; }
180 QXmlStreamReader reader
;
181 ExpressionInfo
*m_info
;
184 ExpressionLoader::ExpressionLoader()
186 m_pvt
= new ExpressionLoaderPvt
;
189 ExpressionLoader::~ExpressionLoader()
195 ExpressionInfo
* ExpressionLoader::load( const QString
&filename
)
197 ExpressionInfo
*info
= NULL
;
201 if( !f
.open( QIODevice::ReadOnly
| QIODevice::Text
) )
204 info
= new ExpressionInfo();
205 m_pvt
->setInfo( info
);
206 ok
= m_pvt
->load( &f
);