From 8decd3cb57cc1ca43668ab950c2efa6219b0ea57 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 00:28:03 +0200 Subject: [PATCH] Instead of storing the node, store the name and the node type. --- .../georges_editor/browser_ctrl_pvt.cpp | 61 +++++++++---------- .../plugins/georges_editor/browser_ctrl_pvt.h | 7 ++- .../src/plugins/georges_editor/formitem.h | 2 + 3 files changed, 37 insertions(+), 33 deletions(-) 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 cdc9950a3..af622633c 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -101,6 +101,7 @@ namespace item->form()->getRootNode().getNodeByName( &n, item->formName().c_str() ); return n; } + } @@ -121,6 +122,19 @@ BrowserCtrlPvt::~BrowserCtrlPvt() m_browser = NULL; } +NLGEORGES::UFormElm* BrowserCtrlPvt::getNode( const QString &name ) +{ + NLGEORGES::UFormElm *node = NULL; + m_rootNode->getNodeByName( &node, name.toUtf8().constData(), NULL, true ); + + return node; +} + +NLGEORGES::UFormElm* BrowserCtrlPvt::getCurrentNode() +{ + return getNode( m_currentNode.name ); +} + void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx ) { NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ idx ]; @@ -178,8 +192,6 @@ void BrowserCtrlPvt::setupStruct( GeorgesQt::CFormItem *node ) if( n == NULL ) return; - m_currentNode.p = n; - setupStruct( n ); } @@ -189,8 +201,6 @@ void BrowserCtrlPvt::setupVStruct( GeorgesQt::CFormItem *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" ); @@ -209,7 +219,6 @@ void BrowserCtrlPvt::setupArray( GeorgesQt::CFormItem *node ) { NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( n ); arr->getArraySize( size ); - m_currentNode.p = n; } QString key = QObject::tr( "Array size" ); @@ -242,15 +251,14 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node ) QtVariantProperty *p = mgr->addProperty( tt, "value" ); p->setValue( v.c_str() ); m_browser->addProperty( p ); - - m_currentNode.p = n; } void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) { m_currentNode.clear(); m_currentNode.name = node->formName().c_str(); - + m_currentNode.type = node->type(); + m_rootNode = dynamic_cast< NLGEORGES::CFormElm* >( &(node->form()->getRootNode()) ); if( node->isArray() ) @@ -280,8 +288,10 @@ void BrowserCtrlPvt::onStructValueChanged( QtProperty *p, const QVariant &value std::string k = p->propertyName().toUtf8().constData(); std::string v = value.toString().toUtf8().constData(); + NLGEORGES::UFormElm *node = getCurrentNode(); + bool created = false; - m_currentNode.p->setValueByName( v.c_str(), k.c_str(), &created ); + node->setValueByName( v.c_str(), k.c_str(), &created ); QString key = m_currentNode.name + "." + p->propertyName(); @@ -297,7 +307,7 @@ void BrowserCtrlPvt::onVStructValueChanged( QtProperty *p, const QVariant &value return; } - NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( m_currentNode.p ); + NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( getCurrentNode() ); vs->DfnFilename = value.toString().toUtf8().constData(); QString key = m_currentNode.name + "." + p->propertyName(); @@ -323,8 +333,6 @@ void BrowserCtrlPvt::createArray() if( !created ) return; - m_currentNode.p = node; - NLGEORGES::CFormElmArray *arr = dynamic_cast< NLGEORGES::CFormElmArray* >( node ); QString idx = "[0]"; arr->createNodeByName( idx.toUtf8().constData(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created ); @@ -344,7 +352,10 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value ) if( newSize < 0 ) return; - if( m_currentNode.p == NULL ) + + NLGEORGES::UFormElm *node = getCurrentNode(); + + if( node == NULL ) { if( newSize != 1 ) return; @@ -352,7 +363,7 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value ) return; } - NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode.p ); + NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( node ); std::string formName; arr->getFormName( formName, NULL ); @@ -401,14 +412,11 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value ) QString name = formName.c_str(); Q_EMIT arrayResized( name, newSize ); Q_EMIT modified(); - - if( newSize == 0 ) - m_currentNode.p = NULL; } void BrowserCtrlPvt::onAtomValueChanged( QtProperty *p, const QVariant &value ) { - NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( m_currentNode.p ); + NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( getCurrentNode() ); atom->setValue( value.toString().toUtf8() ); Q_EMIT modified(); @@ -417,25 +425,16 @@ void BrowserCtrlPvt::onAtomValueChanged( QtProperty *p, const QVariant &value ) void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) { - if( m_currentNode.p == NULL ) - { - if( m_currentNode.name.isEmpty() ) - return; - - onArrayValueChanged( p, value ); - return; - } - - if( m_currentNode.p->isVirtualStruct() ) + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_VSTRUCT ) onVStructValueChanged( p, value ); else - if( m_currentNode.p->isStruct() ) + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_STRUCT ) onStructValueChanged( p, value ); else - if( m_currentNode.p->isArray() ) + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_ARRAY ) onArrayValueChanged( p, value ); else - if( m_currentNode.p->isAtom() ) + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_ATOM ) onAtomValueChanged( p, value ); } 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 80c549ff8..5dbe1885d 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -61,6 +61,9 @@ Q_SIGNALS: void vstructChanged( const QString &name ); private: + NLGEORGES::UFormElm* getNode( const QString &name ); + NLGEORGES::UFormElm* getCurrentNode(); + void setupStruct( NLGEORGES::UFormElm *node ); void setupAtom( NLGEORGES::CFormElmStruct *st, int idx ); @@ -91,12 +94,12 @@ private: void clear() { - p = NULL; + type = -1; name = ""; } QString name; - NLGEORGES::UFormElm *p; + int type; }; CurrentNode m_currentNode; diff --git a/code/studio/src/plugins/georges_editor/formitem.h b/code/studio/src/plugins/georges_editor/formitem.h index 81d9e1367..a0aabfc10 100644 --- a/code/studio/src/plugins/georges_editor/formitem.h +++ b/code/studio/src/plugins/georges_editor/formitem.h @@ -81,6 +81,8 @@ namespace GeorgesQt bool isVStruct(); bool isAtom(); + TType type() const{ return _TType; } + QIcon getItemImage(CFormItem *rootItem); CFormItem* findItem( const QString &formName );