mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-28 11:50:53 +00:00
CHANGED: #1471 The GUI widget properties are now read from the GUI XML files ( widget inheritance is not yet supported ).
This commit is contained in:
parent
fafbebf10b
commit
545bb65f06
4 changed files with 237 additions and 53 deletions
|
@ -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()
|
||||||
|
@ -97,5 +100,182 @@ namespace GUIEditor
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include "ui_gui_editor_window.h"
|
#include "ui_gui_editor_window.h"
|
||||||
#include <QtGui/QUndoStack>
|
#include <QtGui/QUndoStack>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
namespace GUIEditor
|
namespace GUIEditor
|
||||||
{
|
{
|
||||||
|
@ -49,6 +51,12 @@ private:
|
||||||
|
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
|
void parseGUIWidgets();
|
||||||
|
void parseGUIWidget( const QString &file );
|
||||||
|
void parseGUIWidgetXML( QFile &file );
|
||||||
|
QString parseGUIWidgetHeader( QXmlStreamReader &reader );
|
||||||
|
void parseGUIWidgetProperties( QXmlStreamReader &reader, const QString &widgetName );
|
||||||
|
|
||||||
QUndoStack *m_undoStack;
|
QUndoStack *m_undoStack;
|
||||||
|
|
||||||
Ui::GUIEditorWindow m_ui;
|
Ui::GUIEditorWindow m_ui;
|
||||||
|
|
|
@ -15,67 +15,30 @@
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "widget_properties.h"
|
#include "widget_properties.h"
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
struct SPropEntry
|
|
||||||
{
|
|
||||||
std::string propName;
|
|
||||||
std::string propType;
|
|
||||||
std::string propDefault;
|
|
||||||
|
|
||||||
static SPropEntry create( const char *propname, const char *proptype, const char *propdefault )
|
|
||||||
{
|
|
||||||
SPropEntry entry;
|
|
||||||
entry.propName = propname;
|
|
||||||
entry.propType = proptype;
|
|
||||||
entry.propDefault = propdefault;
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::map< std::string, std::vector< SPropEntry > > props;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace GUIEditor{
|
namespace GUIEditor{
|
||||||
|
|
||||||
CWidgetProperties::CWidgetProperties( QWidget *parent ) :
|
CWidgetProperties::CWidgetProperties( QWidget *parent ) :
|
||||||
QWidget( parent )
|
QWidget( parent )
|
||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
|
|
||||||
widgetList->addItem( QString( "InterfaceElement" ) );
|
|
||||||
widgetList->addItem( QString( "CtrlBase" ) );
|
|
||||||
|
|
||||||
props[ "InterfaceElement" ] = std::vector< SPropEntry >();
|
|
||||||
props[ "CtrlBase" ] = std::vector< SPropEntry >();
|
|
||||||
|
|
||||||
std::map< std::string, std::vector< SPropEntry > >::iterator itr =
|
|
||||||
props.find( "InterfaceElement" );
|
|
||||||
if( itr != props.end() )
|
|
||||||
{
|
|
||||||
itr->second.push_back( SPropEntry::create( "id", "string", "ie" ) );
|
|
||||||
itr->second.push_back( SPropEntry::create( "active", "bool", "false" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
itr = props.find( "CtrlBase" );
|
|
||||||
if( itr != props.end() )
|
|
||||||
{
|
|
||||||
itr->second.push_back( SPropEntry::create( "on_tooltip", "string", "tooltip" ) );
|
|
||||||
itr->second.push_back( SPropEntry::create( "on_tooltip_params", "string", "params" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
connect( closeButton, SIGNAL( clicked(bool) ), this, SLOT( hide() ) );
|
connect( closeButton, SIGNAL( clicked(bool) ), this, SLOT( hide() ) );
|
||||||
connect( widgetList, SIGNAL( currentRowChanged( int ) ), this, SLOT( onListSelectionChanged( int ) ) );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CWidgetProperties::~CWidgetProperties()
|
CWidgetProperties::~CWidgetProperties()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWidgetProperties::setupWidgetInfo( std::map< std::string, SWidgetInfo > *info )
|
||||||
|
{
|
||||||
|
widgetInfo = info;
|
||||||
|
for( std::map< std::string, SWidgetInfo >::iterator itr = info->begin(); itr != info->end(); ++itr ){
|
||||||
|
widgetList->addItem( itr->first.c_str() );
|
||||||
|
}
|
||||||
|
|
||||||
|
onListSelectionChanged( 0 );
|
||||||
|
connect( widgetList, SIGNAL( currentRowChanged( int ) ), this, SLOT( onListSelectionChanged( int ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
void CWidgetProperties::onListSelectionChanged( int i )
|
void CWidgetProperties::onListSelectionChanged( int i )
|
||||||
{
|
{
|
||||||
if( i >= widgetList->count() )
|
if( i >= widgetList->count() )
|
||||||
|
@ -87,15 +50,15 @@ namespace GUIEditor{
|
||||||
|
|
||||||
void CWidgetProperties::setPropsOf( const char *name )
|
void CWidgetProperties::setPropsOf( const char *name )
|
||||||
{
|
{
|
||||||
std::map< std::string, std::vector< SPropEntry > >::iterator itr =
|
std::map< std::string, SWidgetInfo >::iterator itr =
|
||||||
props.find( name );
|
widgetInfo->find( name );
|
||||||
|
|
||||||
if( itr == props.end() )
|
if( itr == widgetInfo->end() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
widgetPropTree->clear();
|
widgetPropTree->clear();
|
||||||
|
|
||||||
std::vector< SPropEntry > &v = itr->second;
|
std::vector< SPropEntry > &v = itr->second.props;
|
||||||
for( std::vector< SPropEntry >::iterator itr2 = v.begin(); itr2 != v.end(); ++itr2 )
|
for( std::vector< SPropEntry >::iterator itr2 = v.begin(); itr2 != v.end(); ++itr2 )
|
||||||
{
|
{
|
||||||
SPropEntry e = *itr2;
|
SPropEntry e = *itr2;
|
||||||
|
|
|
@ -19,9 +19,40 @@
|
||||||
#define WIDGETPROPS_H
|
#define WIDGETPROPS_H
|
||||||
|
|
||||||
#include "ui_widget_properties.h"
|
#include "ui_widget_properties.h"
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace GUIEditor
|
namespace GUIEditor
|
||||||
{
|
{
|
||||||
|
struct SPropEntry
|
||||||
|
{
|
||||||
|
std::string propName;
|
||||||
|
std::string propType;
|
||||||
|
std::string propDefault;
|
||||||
|
|
||||||
|
static SPropEntry create( const char *propname, const char *proptype, const char *propdefault )
|
||||||
|
{
|
||||||
|
SPropEntry entry;
|
||||||
|
entry.propName = propname;
|
||||||
|
entry.propType = proptype;
|
||||||
|
entry.propDefault = propdefault;
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SWidgetInfo
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
std::string GUIName;
|
||||||
|
std::string description;
|
||||||
|
bool isAbstract;
|
||||||
|
std::string icon;
|
||||||
|
|
||||||
|
std::vector< SPropEntry > props;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class CWidgetProperties : public QWidget, public Ui::WidgetProperties
|
class CWidgetProperties : public QWidget, public Ui::WidgetProperties
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -29,12 +60,14 @@ namespace GUIEditor
|
||||||
public:
|
public:
|
||||||
CWidgetProperties( QWidget *parent = NULL );
|
CWidgetProperties( QWidget *parent = NULL );
|
||||||
~CWidgetProperties();
|
~CWidgetProperties();
|
||||||
|
void setupWidgetInfo( std::map< std::string, SWidgetInfo > *info );
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onListSelectionChanged( int i );
|
void onListSelectionChanged( int i );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setPropsOf( const char *name );
|
void setPropsOf( const char *name );
|
||||||
|
std::map< std::string, SWidgetInfo > *widgetInfo;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue