|
|
@ -32,6 +32,7 @@
|
|
|
|
namespace GUIEditor
|
|
|
|
namespace GUIEditor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QString _lastDir;
|
|
|
|
QString _lastDir;
|
|
|
|
|
|
|
|
std::map< std::string, SWidgetInfo > widgetInfo;
|
|
|
|
|
|
|
|
|
|
|
|
GUIEditorWindow::GUIEditorWindow(QWidget *parent) :
|
|
|
|
GUIEditorWindow::GUIEditorWindow(QWidget *parent) :
|
|
|
|
QMainWindow(parent)
|
|
|
|
QMainWindow(parent)
|
|
|
@ -41,6 +42,8 @@ namespace GUIEditor
|
|
|
|
widgetProps = new CWidgetProperties;
|
|
|
|
widgetProps = new CWidgetProperties;
|
|
|
|
createMenus();
|
|
|
|
createMenus();
|
|
|
|
readSettings();
|
|
|
|
readSettings();
|
|
|
|
|
|
|
|
parseGUIWidgets();
|
|
|
|
|
|
|
|
widgetProps->setupWidgetInfo( &widgetInfo );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GUIEditorWindow::~GUIEditorWindow()
|
|
|
|
GUIEditorWindow::~GUIEditorWindow()
|
|
|
@ -98,4 +101,181 @@ namespace GUIEditor
|
|
|
|
settings->sync();
|
|
|
|
settings->sync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GUIEditorWindow::parseGUIWidgets()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QDir d( "widgets" );
|
|
|
|
|
|
|
|
if( !d.exists() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nlwarning( "GUI widgets directory doesn't exist!" );
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList nameFilters;
|
|
|
|
|
|
|
|
nameFilters.push_back( "*.xml" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList files = d.entryList( nameFilters, QDir::Files );
|
|
|
|
|
|
|
|
if( files.empty() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nlwarning( "GUI widgets directory has no files!" );
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringListIterator itr( files );
|
|
|
|
|
|
|
|
while( itr.hasNext() )
|
|
|
|
|
|
|
|
parseGUIWidget( "widgets/" + itr.next() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GUIEditorWindow::parseGUIWidget( const QString &file )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QFile f( file );
|
|
|
|
|
|
|
|
if( f.open( QIODevice::ReadOnly ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
parseGUIWidgetXML( f );
|
|
|
|
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
nlwarning( QString( "File %1 cannot be opened!" ).arg( file ).toStdString().c_str() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GUIEditorWindow::parseGUIWidgetXML( QFile &file )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QXmlStreamReader reader;
|
|
|
|
|
|
|
|
reader.setDevice( &file );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
if( reader.atEnd() )
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while( !reader.atEnd() && !( reader.isStartElement() && ( reader.name() == "widget" ) ) )
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
if( reader.atEnd() )
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while( !reader.atEnd() && !( reader.isStartElement() && ( reader.name() == "header" ) ) )
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
if( reader.atEnd() )
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString name = parseGUIWidgetHeader( reader );
|
|
|
|
|
|
|
|
if( name.isEmpty() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nlwarning( "malformed XML." );
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while( !reader.atEnd() && !( reader.isStartElement() && ( reader.name() == "properties" ) ) )
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
if( reader.atEnd() )
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parseGUIWidgetProperties( reader, name );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString GUIEditorWindow::parseGUIWidgetHeader( QXmlStreamReader &reader )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
if( reader.atEnd() )
|
|
|
|
|
|
|
|
return QString( "" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SWidgetInfo info;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while( !reader.atEnd() && !( reader.isEndElement() && ( reader.name() == "header" ) ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( reader.isStartElement() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QString key = reader.name().toString();
|
|
|
|
|
|
|
|
QString value = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !reader.hasError() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( key == "name" )
|
|
|
|
|
|
|
|
info.name = value.toStdString();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if( key == "guiname" )
|
|
|
|
|
|
|
|
info.GUIName = value.toStdString();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if( key == "description" )
|
|
|
|
|
|
|
|
info.description = value.toStdString();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if( key == "icon" )
|
|
|
|
|
|
|
|
info.icon == value.toStdString();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if( key == "abstract" )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
info.isAbstract = false;
|
|
|
|
|
|
|
|
if( value == "true" )
|
|
|
|
|
|
|
|
info.isAbstract = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
nlwarning( "Malformed XML." );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.atEnd() )
|
|
|
|
|
|
|
|
return QString( "" );
|
|
|
|
|
|
|
|
if( info.name.empty() )
|
|
|
|
|
|
|
|
return QString( "" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
widgetInfo[ info.name.c_str() ] = info;
|
|
|
|
|
|
|
|
return QString( info.name.c_str() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GUIEditorWindow::parseGUIWidgetProperties( QXmlStreamReader &reader, const QString &widgetName )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
if( reader.atEnd() )
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::map< std::string, SWidgetInfo >::iterator itr =
|
|
|
|
|
|
|
|
widgetInfo.find( widgetName.toStdString() );
|
|
|
|
|
|
|
|
if( itr == widgetInfo.end() )
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector< SPropEntry > &v = itr->second.props;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while( !reader.atEnd() && !( reader.isEndElement() && ( reader.name() == "properties" ) ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( reader.isStartElement() && reader.name() == "property" )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SPropEntry prop;
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while( !reader.atEnd() && !( reader.isEndElement() && ( reader.name() == "property" ) ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( reader.isStartElement() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QString key = reader.name().toString();
|
|
|
|
|
|
|
|
QString value = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !reader.hasError() )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( key == "name" )
|
|
|
|
|
|
|
|
prop.propName = value.toStdString();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if( key == "type" )
|
|
|
|
|
|
|
|
prop.propType = value.toStdString();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if( key == "default" )
|
|
|
|
|
|
|
|
prop.propDefault = value.toStdString();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
nlwarning( QString( "Unknown tag %1 within a property" ).arg( key ).toStdString().c_str() );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
nlwarning( "Malformed XML." );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reader.atEnd() )
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v.push_back( prop );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|