From c4e01eaca61eee64bc3133a408b5449b21a70073 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 5 Sep 2014 18:58:47 +0200 Subject: [PATCH] Added support for adding atoms and virtual structs in the treeview. --- .../georges_editor/browser_ctrl_pvt.cpp | 2 ++ .../src/plugins/georges_editor/formitem.cpp | 35 ++++++++++++++++--- .../src/plugins/georges_editor/formitem.h | 15 ++++++-- .../georges_editor/georgesform_model.cpp | 28 ++++++++++++--- .../georges_editor/georgesform_model.h | 4 ++- 5 files changed, 72 insertions(+), 12 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 492258c71..fe8a60b28 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -146,6 +146,7 @@ void BrowserCtrlPvt::setupArray( GeorgesQt::CFormItem *node ) m_browser->addProperty( p ); } + void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) { m_currentNode.clear(); @@ -156,6 +157,7 @@ void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) if( node->isArray() ) setupArray( node ); else + if( node->isStruct() ) setupStruct( node ); m_browser->setFactoryForManager( mgr, factory ); diff --git a/code/studio/src/plugins/georges_editor/formitem.cpp b/code/studio/src/plugins/georges_editor/formitem.cpp index 8cd479961..c6216ff36 100644 --- a/code/studio/src/plugins/georges_editor/formitem.cpp +++ b/code/studio/src/plugins/georges_editor/formitem.cpp @@ -40,7 +40,7 @@ namespace GeorgesQt _StructId = 0; _Slot = 0; _Type = Null; - _Array = false; + _TType = TYPE_ATOM; } CFormItem::~CFormItem() @@ -113,7 +113,10 @@ namespace GeorgesQt bool CFormItem::isArray() { - return _Array; + if( _TType == TYPE_ARRAY ) + return true; + else + return false; } bool CFormItem::isArrayMember() @@ -124,6 +127,30 @@ namespace GeorgesQt return parentItem->isArray(); } + bool CFormItem::isStruct() + { + if( _TType == TYPE_STRUCT ) + return true; + else + return false; + } + + bool CFormItem::isVStruct() + { + if( _TType == TYPE_VSTRUCT ) + return true; + else + return false; + } + + bool CFormItem::isAtom() + { + if( _TType == TYPE_ATOM ) + return true; + else + return false; + } + QIcon CFormItem::getItemImage(CFormItem *rootItem) { if(_Type == CFormItem::Null) @@ -211,7 +238,7 @@ namespace GeorgesQt childItems.clear(); } - CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, bool isArray) + CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, TType itemType ) { CFormItem *newNode = new CFormItem(); newNode->_Type = type; @@ -221,7 +248,7 @@ namespace GeorgesQt newNode->_FormName = formName; newNode->_Slot = slot; newNode->m_form = formPtr; - newNode->_Array = isArray; + newNode->_TType = itemType; appendChild(newNode); return newNode; diff --git a/code/studio/src/plugins/georges_editor/formitem.h b/code/studio/src/plugins/georges_editor/formitem.h index cd67d1b21..302f62a6c 100644 --- a/code/studio/src/plugins/georges_editor/formitem.h +++ b/code/studio/src/plugins/georges_editor/formitem.h @@ -41,12 +41,20 @@ namespace GeorgesQt Form, // This node is a form }; + enum TType + { + TYPE_ARRAY, + TYPE_STRUCT, + TYPE_VSTRUCT, + TYPE_ATOM + }; + CFormItem(); ~CFormItem(); void appendChild(CFormItem *child); - CFormItem *add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, bool isArray ); + CFormItem *add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, TType itemType ); CFormItem *child(int row); int childCount() const; @@ -69,6 +77,9 @@ namespace GeorgesQt bool isEditable(int column); bool isArray(); bool isArrayMember(); + bool isStruct(); + bool isVStruct(); + bool isAtom(); QIcon getItemImage(CFormItem *rootItem); @@ -95,7 +106,7 @@ namespace GeorgesQt std::string _FormName; TSub _Type; uint _Slot; - bool _Array; + TType _TType; }; // CFormItem diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index 332dbae14..0dc9521db 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -277,13 +277,20 @@ namespace GeorgesQt const char *name, uint structId, const char *formName, - uint slot) + uint slot, + bool isVirtual) { // The form pointer NLGEORGES::CForm *formPtr = static_cast(m_form); // Add the new node - CFormItem *newNode = parent->add(CFormItem::Form, name, structId, formName, slot, m_form, false); + CFormItem::TType ttype; + if( isVirtual ) + ttype = CFormItem::TYPE_VSTRUCT; + else + ttype = CFormItem::TYPE_STRUCT; + + CFormItem *newNode = parent->add(CFormItem::Form, name, structId, formName, slot, m_form, ttype ); // Can be NULL in virtual DFN if (parentDfn) @@ -367,7 +374,10 @@ namespace GeorgesQt NLGEORGES::CFormDfn *tmpDfn = vStruct ? ((NLGEORGES::CFormDfn*)vStruct->FormDfn) : entry.getDfnPtr(); // Add the new struct - addStruct (newNode, nextForm, tmpDfn, entry.getName().c_str(), elm, entryName.c_str(), slot); + if( entry.getType() == NLGEORGES::UFormDfn::EntryVirtualDfn ) + addStruct (newNode, nextForm, tmpDfn, entry.getName().c_str(), elm, entryName.c_str(), slot, true); + else + addStruct (newNode, nextForm, tmpDfn, entry.getName().c_str(), elm, entryName.c_str(), slot); } } // Array of type ? @@ -418,7 +428,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent, uint slot) { // Add the new node - CFormItem *newNode = parent->add (CFormItem::Form, name, structId, formName, slot, m_form, true); + CFormItem *newNode = parent->add (CFormItem::Form, name, structId, formName, slot, m_form, CFormItem::TYPE_ARRAY ); // The array exist if (array) @@ -451,7 +461,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent, else { NLGEORGES::CFormElmArray *elmPtr = array->Elements[elm].Element ? static_cast(array->Elements[elm].Element) : NULL; - newNode->add (CFormItem::Form, formArrayName, elm, formArrayElmName, slot, m_form, false); + addAtom( newNode, elmPtr, rootDfn, formArrayName, elm, formArrayElmName ); } } } @@ -460,6 +470,14 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent, } +CFormItem *CGeorgesFormModel::addAtom(CFormItem *parent, NLGEORGES::CFormElm *elm, NLGEORGES::CFormDfn *dfn, const char *name, uint id, const char *formName) +{ + CFormItem *item = parent->add( CFormItem::Form, name, id, formName, 0, m_form, CFormItem::TYPE_ATOM ); + + return item; +} + + void CGeorgesFormModel::arrayResized( const QString &name, int size ) { CFormItem *item = m_rootItem->findItem( name ); diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.h b/code/studio/src/plugins/georges_editor/georgesform_model.h index 70d602232..154fc3745 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.h +++ b/code/studio/src/plugins/georges_editor/georgesform_model.h @@ -65,11 +65,13 @@ namespace GeorgesQt NLGEORGES::UFormElm *getRootForm() { return m_rootElm; } CFormItem *addStruct (CFormItem *parent, NLGEORGES::CFormElmStruct *_struct, NLGEORGES::CFormDfn *parentDfn, - const char *name, uint structId, const char *formName, uint slot); + const char *name, uint structId, const char *formName, uint slot, bool isVirtual = false ); CFormItem *addArray(CFormItem *parent, NLGEORGES::CFormElmArray *array, NLGEORGES::CFormDfn *rootDfn, const char *name, uint structId, const char *formName, uint slot); + CFormItem *addAtom(CFormItem *parent, NLGEORGES::CFormElm *elm, NLGEORGES::CFormDfn *dfn, const char *name, uint id, const char *formName); + void emitDataChanged(const QModelIndex &index) { Q_EMIT dataChanged(index, index);