From ee76b77160917b3eb7d130da11581033c30484b4 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 9 Sep 2014 21:57:30 +0200 Subject: [PATCH] Added support for Virtual Structs. --- .../plugins/georges_editor/browser_ctrl.cpp | 6 +++ .../src/plugins/georges_editor/browser_ctrl.h | 2 + .../georges_editor/browser_ctrl_pvt.cpp | 41 +++++++++++++++++++ .../plugins/georges_editor/browser_ctrl_pvt.h | 3 ++ .../src/plugins/georges_editor/formitem.cpp | 7 ++++ .../src/plugins/georges_editor/formitem.h | 2 + .../georges_treeview_dialog.cpp | 16 ++++++++ .../georges_editor/georges_treeview_dialog.h | 1 + .../georges_editor/georgesform_model.cpp | 38 +++++++++++++++++ .../georges_editor/georgesform_model.h | 1 + 10 files changed, 117 insertions(+) diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp index 2788bd00a..722faf096 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp @@ -37,6 +37,7 @@ QObject( browser ) connect( m_pvt, SIGNAL( arrayResized( const QString&, int ) ), this, SLOT( onArrayResized( const QString&, int ) ) ); connect( m_pvt, SIGNAL( modified() ), this, SLOT( onModified() ) ); connect( m_pvt, SIGNAL( valueChanged( const QString&, const QString& ) ), this, SLOT( onValueChanged( const QString&, const QString& ) ) ); + connect( m_pvt, SIGNAL( vstructChanged( const QString& ) ), this, SLOT( onVStructChanged( const QString& ) ) ); } BrowserCtrl::~BrowserCtrl() @@ -78,6 +79,11 @@ void BrowserCtrl::onModified() Q_EMIT modified(); } +void BrowserCtrl::onVStructChanged( const QString &name ) +{ + Q_EMIT vstructChanged( name ); +} + void BrowserCtrl::enableMgrConnections() { QtVariantPropertyManager *mgr = m_pvt->manager(); diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.h b/code/studio/src/plugins/georges_editor/browser_ctrl.h index 25aeaf49f..42ff5d6e7 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.h @@ -48,12 +48,14 @@ Q_SIGNALS: void arrayResized( const QString &name, int size ); void modified(); void valueChanged( const QString &key, const QString &value ); + void vstructChanged( const QString &name ); private Q_SLOTS: void onValueChanged( QtProperty *p, const QVariant &value ); void onValueChanged( const QString &key, const QString &value ); void onArrayResized( const QString &name, int size ); void onModified(); + void onVStructChanged( const QString &name ); private: void enableMgrConnections(); diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp index e4b96b7e2..2461bb218 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -180,6 +180,23 @@ void BrowserCtrlPvt::setupStruct( GeorgesQt::CFormItem *node ) setupStruct( n ); } +void BrowserCtrlPvt::setupVStruct( GeorgesQt::CFormItem *node ) +{ + NLGEORGES::UFormElm *n = getGeorgesNode( node ); + if( n == NULL ) + return; + + m_currentNode.p = n; + + NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( n ); + + QtVariantProperty *p = mgr->addProperty( QVariant::String, "Dfn filename" ); + mgr->setValue( p, vs->DfnFilename.c_str() ); + m_browser->addProperty( p ); + + setupStruct( n ); +} + void BrowserCtrlPvt::setupArray( GeorgesQt::CFormItem *node ) { NLGEORGES::UFormElm *n = getGeorgesNode( node ); @@ -239,6 +256,9 @@ void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) if( node->isStruct() ) setupStruct( node ); else + if( node->isVStruct() ) + setupVStruct( node ); + else if( node->isAtom() ) setupAtom( node ); @@ -266,6 +286,24 @@ void BrowserCtrlPvt::onStructValueChanged( QtProperty *p, const QVariant &value Q_EMIT valueChanged( key, value.toString() ); } +void BrowserCtrlPvt::onVStructValueChanged( QtProperty *p, const QVariant &value ) +{ + if( p->propertyName() != "Dfn filename" ) + { + onStructValueChanged( p, value ); + return; + } + + NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( m_currentNode.p ); + vs->DfnFilename = value.toString().toUtf8().constData(); + + QString key = m_currentNode.name + "." + p->propertyName(); + + Q_EMIT modified(); + Q_EMIT valueChanged( key, value.toString() ); + Q_EMIT vstructChanged( m_currentNode.name ); +} + void BrowserCtrlPvt::createArray() { const NLGEORGES::CFormDfn *parentDfn; @@ -385,6 +423,9 @@ void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) return; } + if( m_currentNode.p->isVirtualStruct() ) + onVStructValueChanged( p, value ); + else if( m_currentNode.p->isStruct() ) onStructValueChanged( p, value ); else diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h index 7c27d3a4f..80c549ff8 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -58,16 +58,19 @@ Q_SIGNALS: void arrayResized( const QString &name, int size ); void modified(); void valueChanged( const QString &key, const QString &value ); + void vstructChanged( const QString &name ); private: void setupStruct( NLGEORGES::UFormElm *node ); void setupAtom( NLGEORGES::CFormElmStruct *st, int idx ); void setupStruct( GeorgesQt::CFormItem *node ); + void setupVStruct( GeorgesQt::CFormItem *node ); void setupArray( GeorgesQt::CFormItem *node ); void setupAtom( GeorgesQt::CFormItem *node ); void onStructValueChanged( QtProperty *p, const QVariant &value ); + void onVStructValueChanged( QtProperty *p, const QVariant &value ); void onArrayValueChanged( QtProperty *p, const QVariant &value ); void onAtomValueChanged( QtProperty *p, const QVariant &value ); void createArray(); diff --git a/code/studio/src/plugins/georges_editor/formitem.cpp b/code/studio/src/plugins/georges_editor/formitem.cpp index c6216ff36..939ec4cf4 100644 --- a/code/studio/src/plugins/georges_editor/formitem.cpp +++ b/code/studio/src/plugins/georges_editor/formitem.cpp @@ -238,6 +238,13 @@ namespace GeorgesQt childItems.clear(); } + void CFormItem::removeChild( int idx ) + { + CFormItem *item = childItems[ idx ]; + childItems.removeAt( idx ); + delete item; + } + CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, TType itemType ) { CFormItem *newNode = new CFormItem(); diff --git a/code/studio/src/plugins/georges_editor/formitem.h b/code/studio/src/plugins/georges_editor/formitem.h index 302f62a6c..81d9e1367 100644 --- a/code/studio/src/plugins/georges_editor/formitem.h +++ b/code/studio/src/plugins/georges_editor/formitem.h @@ -87,6 +87,8 @@ namespace GeorgesQt void clearChildren(); + void removeChild( int idx ); + bool rootItem() const{ if( parentItem == NULL ) return true; diff --git a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp index 2b5e67d79..297769b6c 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -90,6 +90,7 @@ namespace GeorgesQt connect(m_browserCtrl, SIGNAL(modified()), this, SLOT(modifiedFile())); connect(m_browserCtrl, SIGNAL(valueChanged(const QString&,const QString&)), this, SLOT(onValueChanged(const QString&,const QString&))); + connect(m_browserCtrl, SIGNAL(vstructChanged(const QString&)), this, SLOT( onVStructChanged(const QString&))); } CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog() @@ -575,6 +576,21 @@ namespace GeorgesQt modifiedFile(); } + void CGeorgesTreeViewDialog::onVStructChanged( const QString &name ) + { + QModelIndex idx = m_ui.treeView->currentIndex(); + QModelIndex parent = idx.parent(); + int row = idx.row(); + + m_model->changeVStructDfn( idx ); + + idx = m_model->index( row, 0, parent ); + + m_ui.treeView->expandAll(); + m_ui.treeView->setCurrentIndex( idx ); + m_browserCtrl->clicked( idx ); + } + void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) { Q_EMIT closing(); diff --git a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h index 459258c3f..4595cc289 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -101,6 +101,7 @@ namespace GeorgesQt void onAppendArray(); void onDeleteArrayEntry(); void onValueChanged( const QString &key, const QString &value ); + void onVStructChanged( const QString &name ); void onRenameArrayEntry(); private: diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index eb940bce6..2579a09f5 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -45,6 +45,8 @@ #include "georges_editor_form.h" #include "actions.h" +#include "georges.h" + using namespace NLGEORGES; namespace GeorgesQt @@ -691,6 +693,42 @@ void CGeorgesFormModel::renameArrayEntry( QModelIndex idx, const QString &name ) item->setName( name.toUtf8().constData() ); } +void CGeorgesFormModel::changeVStructDfn( QModelIndex idx ) +{ + CFormItem *item = static_cast< CFormItem* >( idx.internalPointer() ); + + QString vstruct = item->formName().c_str(); + + NLGEORGES::UFormElm *uelm = NULL; + m_form->getRootNode().getNodeByName( &uelm, vstruct.toUtf8().constData() ); + + if( uelm == NULL ) + return; + + NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( uelm ); + + CGeorges g; + NLGEORGES::UFormDfn *udfn = g.loadFormDfn( vs->DfnFilename ); + if( udfn == NULL ) + return; + + NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn ); + vs->build( cdfn ); + + + beginResetModel(); + + CFormItem *parent = item->parent(); + int row = idx.row(); + QString name = item->name().c_str(); + QString formName = item->formName().c_str(); + parent->removeChild( row ); + + addItem( parent, vs, cdfn, name.toUtf8().constData(), row, formName.toUtf8().constData() ); + + endResetModel(); +} + /******************************************************************************/ void CGeorgesFormModel::loadFormHeader() diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.h b/code/studio/src/plugins/georges_editor/georgesform_model.h index 716a45178..7d6bac3f3 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.h +++ b/code/studio/src/plugins/georges_editor/georgesform_model.h @@ -83,6 +83,7 @@ namespace GeorgesQt void appendArray( QModelIndex idx ); void deleteArrayEntry( QModelIndex idx ); void renameArrayEntry( QModelIndex idx, const QString &name ); + void changeVStructDfn( QModelIndex idx ); private: void setupModelData();