Parse expression files, and build the expression tree from the expressions parsed from these files.
--HG-- branch : dfighter-toolshg/feature/qt5
parent
5e5fb49f12
commit
af74411104
@ -0,0 +1,34 @@
|
|||||||
|
// Ryzom Core Studio - GUI Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef EXPRESSION_INFO
|
||||||
|
#define EXPRESSION_INFO
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
struct ExpressionInfo
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
QString category;
|
||||||
|
bool variable;
|
||||||
|
QStringList slotNames;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,203 @@
|
|||||||
|
// Ryzom Core Studio - GUI Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "expression_loader.h"
|
||||||
|
#include "expression_info.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
|
class ExpressionLoaderPvt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
bool parseName()
|
||||||
|
{
|
||||||
|
QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||||
|
if( reader.hasError() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_info->name = text;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseCategory()
|
||||||
|
{
|
||||||
|
QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||||
|
if( reader.hasError() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_info->category = text;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseVariable()
|
||||||
|
{
|
||||||
|
QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||||
|
if( reader.hasError() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( text.toLower() == "true" )
|
||||||
|
m_info->variable = true;
|
||||||
|
else
|
||||||
|
m_info->variable = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseSlot()
|
||||||
|
{
|
||||||
|
QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||||
|
if( reader.hasError() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_info->slotNames.push_back( text );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseSlots()
|
||||||
|
{
|
||||||
|
bool error = false;
|
||||||
|
|
||||||
|
while( !reader.atEnd() )
|
||||||
|
{
|
||||||
|
reader.readNext();
|
||||||
|
|
||||||
|
if( reader.isStartElement() )
|
||||||
|
{
|
||||||
|
QString name = reader.name().toString();
|
||||||
|
if( name == "slot" )
|
||||||
|
error = !parseSlot();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( reader.isEndElement() )
|
||||||
|
{
|
||||||
|
if( reader.name() == "slots" )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( reader.atEnd() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool load( QFile *f )
|
||||||
|
{
|
||||||
|
reader.clear();
|
||||||
|
reader.setDevice( f );
|
||||||
|
|
||||||
|
bool error = false;
|
||||||
|
|
||||||
|
// start of document
|
||||||
|
reader.readNext();
|
||||||
|
if( reader.atEnd() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// root node
|
||||||
|
reader.readNext();
|
||||||
|
if( reader.atEnd() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( reader.isStartElement() )
|
||||||
|
{
|
||||||
|
// Not an expression file?
|
||||||
|
if( reader.name() != "expression" )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while( !reader.atEnd() )
|
||||||
|
{
|
||||||
|
reader.readNext();
|
||||||
|
|
||||||
|
if( reader.isStartElement() )
|
||||||
|
{
|
||||||
|
QString name = reader.name().toString();
|
||||||
|
|
||||||
|
if( name == "name" )
|
||||||
|
error = !parseName();
|
||||||
|
else
|
||||||
|
if( name == "category" )
|
||||||
|
error = !parseCategory();
|
||||||
|
else
|
||||||
|
if( name == "variable" )
|
||||||
|
error = !parseVariable();
|
||||||
|
else
|
||||||
|
if( name == "slots" )
|
||||||
|
error = !parseSlots();
|
||||||
|
}
|
||||||
|
|
||||||
|
if( error )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( error || reader.hasError() )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setInfo( ExpressionInfo *info ){ m_info = info; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QXmlStreamReader reader;
|
||||||
|
ExpressionInfo *m_info;
|
||||||
|
};
|
||||||
|
|
||||||
|
ExpressionLoader::ExpressionLoader()
|
||||||
|
{
|
||||||
|
m_pvt = new ExpressionLoaderPvt;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpressionLoader::~ExpressionLoader()
|
||||||
|
{
|
||||||
|
delete m_pvt;
|
||||||
|
m_pvt = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpressionInfo* ExpressionLoader::load( const QString &filename )
|
||||||
|
{
|
||||||
|
ExpressionInfo *info = NULL;
|
||||||
|
bool ok = false;
|
||||||
|
|
||||||
|
QFile f( filename );
|
||||||
|
if( !f.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
info = new ExpressionInfo();
|
||||||
|
m_pvt->setInfo( info );
|
||||||
|
ok = m_pvt->load( &f );
|
||||||
|
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
if( !ok )
|
||||||
|
{
|
||||||
|
delete info;
|
||||||
|
info = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
|||||||
|
// Ryzom Core Studio - GUI Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef EXPRESSION_LOADER
|
||||||
|
#define EXPRESSION_LOADER
|
||||||
|
|
||||||
|
struct ExpressionInfo;
|
||||||
|
class QString;
|
||||||
|
class ExpressionLoaderPvt;
|
||||||
|
|
||||||
|
class ExpressionLoader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExpressionLoader();
|
||||||
|
~ExpressionLoader();
|
||||||
|
|
||||||
|
ExpressionInfo* load( const QString &filename );
|
||||||
|
|
||||||
|
private:
|
||||||
|
ExpressionLoaderPvt *m_pvt;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,105 @@
|
|||||||
|
// Ryzom Core Studio - GUI Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "expression_store.h"
|
||||||
|
#include "expression_info.h"
|
||||||
|
#include "expression_loader.h"
|
||||||
|
#include <QMap>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
class ExpressionStorePvt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
~ExpressionStorePvt()
|
||||||
|
{
|
||||||
|
qDeleteAll( expressions );
|
||||||
|
expressions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QMap< QString, ExpressionInfo* > expressions;
|
||||||
|
};
|
||||||
|
|
||||||
|
ExpressionStore::ExpressionStore()
|
||||||
|
{
|
||||||
|
m_pvt = new ExpressionStorePvt();
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpressionStore::~ExpressionStore()
|
||||||
|
{
|
||||||
|
delete m_pvt;
|
||||||
|
m_pvt = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ExpressionStore::load()
|
||||||
|
{
|
||||||
|
QDir d( "expressions" );
|
||||||
|
if( !d.exists() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QFileInfoList l = d.entryInfoList();
|
||||||
|
QListIterator< QFileInfo > itr( l );
|
||||||
|
if( !itr.hasNext() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ExpressionLoader loader;
|
||||||
|
|
||||||
|
while( itr.hasNext() )
|
||||||
|
{
|
||||||
|
const QFileInfo &info = itr.next();
|
||||||
|
if( !info.isFile() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( info.suffix() != "xml" )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ExpressionInfo *expr = loader.load( info.absoluteFilePath() );
|
||||||
|
if( expr == NULL )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
m_pvt->expressions[ expr->name ] = expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExpressionStore::getExpressions( QList< const ExpressionInfo* > &l ) const
|
||||||
|
{
|
||||||
|
l.clear();
|
||||||
|
|
||||||
|
QMap< QString, ExpressionInfo* >::const_iterator itr = m_pvt->expressions.constBegin();
|
||||||
|
while( itr != m_pvt->expressions.constEnd() )
|
||||||
|
{
|
||||||
|
l.push_back( itr.value() );
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ExpressionInfo* ExpressionStore::getInfo( const QString &name )
|
||||||
|
{
|
||||||
|
QMap< QString, ExpressionInfo* >::const_iterator itr = m_pvt->expressions.find( name );
|
||||||
|
if( itr == m_pvt->expressions.end() )
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return itr.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
|||||||
|
// Ryzom Core Studio - GUI Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef EXPRESSION_STORE
|
||||||
|
#define EXPRESSION_STORE
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QList>
|
||||||
|
#include "expression_info.h"
|
||||||
|
|
||||||
|
//struct ExpressionInfo;
|
||||||
|
class ExpressionStorePvt;
|
||||||
|
|
||||||
|
class ExpressionStore
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExpressionStore();
|
||||||
|
~ExpressionStore();
|
||||||
|
|
||||||
|
bool load();
|
||||||
|
|
||||||
|
void getExpressions( QList< const ExpressionInfo* > &l ) const;
|
||||||
|
|
||||||
|
const ExpressionInfo* getInfo( const QString &name );
|
||||||
|
|
||||||
|
private:
|
||||||
|
ExpressionStorePvt *m_pvt;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue