From 8d3c8de51763553b458de5de26e127577dcefe58 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 4 Sep 2014 15:41:17 +0200 Subject: [PATCH 01/21] Enter a log entry when creating new documents. --- code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp | 2 ++ .../src/plugins/georges_editor/georges_treeview_dialog.cpp | 2 ++ code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp | 2 ++ 3 files changed, 6 insertions(+) diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp index d7d329dac..30fa38c7d 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -115,6 +115,8 @@ void GeorgesDFNDialog::newDocument( const QString &fileName ) m_pvt->dfn = new NLGEORGES::CFormDfn(); loadDfn(); + + log( "Created" ); } void GeorgesDFNDialog::onAddClicked() 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 c2aa78005..2b5e67d79 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -423,6 +423,8 @@ namespace GeorgesQt setWindowTitle( info.fileName() + "*" ); setModified( true ); + log( "Created" ); + return true; } diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp index 7e832ba26..d042c6d33 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -115,6 +115,8 @@ void GeorgesTypDialog::newDocument( const QString &fileName ) setModified( true ); loadTyp(); + + log( "Created" ); } void GeorgesTypDialog::onAddClicked() From 12996110fc375b5b57745127a864186b92e753eb Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 5 Sep 2014 15:13:58 +0200 Subject: [PATCH 02/21] Add new array entries with all their children. --- .../georges_editor/georgesform_model.cpp | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index f00e090f2..454e8cdc0 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -494,7 +494,8 @@ void CGeorgesFormModel::arrayResized( const QString &name, int size ) else n = e.Name.c_str(); - item->add( CFormItem::Form, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0, item->form(), false ); + NLGEORGES::CFormElmStruct *s = static_cast< NLGEORGES::CFormElmStruct* >( e.Element ); + addStruct( item, s, s->FormDfn, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0 ); } if( celm->Elements.size() == 0 ) @@ -525,22 +526,22 @@ void CGeorgesFormModel::appendArray( QModelIndex idx ) item->form()->getRootNode().getNodeByName( &elm, item->formName().c_str() ); - const NLGEORGES::CFormDfn *parentDfn; - const NLGEORGES::CFormDfn *nodeDfn; - uint indexDfn; - const NLGEORGES::CType *type; - NLGEORGES::UFormDfn::TEntryType entryType; - NLGEORGES::CFormElm *node; + const NLGEORGES::CFormDfn *parentDfn; + const NLGEORGES::CFormDfn *nodeDfn; + uint indexDfn; + const NLGEORGES::CType *type; + NLGEORGES::UFormDfn::TEntryType entryType; + NLGEORGES::CFormElm *node; bool created; bool isArray; if( elm == NULL ) - { - NLGEORGES::UFormElm *uroot = &item->form()->getRootNode(); - NLGEORGES::CFormElm *croot = static_cast< NLGEORGES::CFormElm* >( uroot ); - - croot->createNodeByName( item->formName().c_str(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created ); - + { + NLGEORGES::UFormElm *uroot = &item->form()->getRootNode(); + NLGEORGES::CFormElm *croot = static_cast< NLGEORGES::CFormElm* >( uroot ); + + croot->createNodeByName( item->formName().c_str(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created ); + if( !created ) return; @@ -566,7 +567,8 @@ void CGeorgesFormModel::appendArray( QModelIndex idx ) std::string formName; node->getFormName( formName ); - item->add( CFormItem::Form, name.c_str(), s, formName.c_str(), 0, item->form(), false ); + NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( node ); + addStruct( item, st, st->FormDfn, name.c_str(), s, formName.c_str(), 0 ); } void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx ) From 2020638e35d4f8e64f5a902973b3d100ba107b43 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 5 Sep 2014 15:20:22 +0200 Subject: [PATCH 03/21] Do the same when readding items after a deletion. --- code/studio/src/plugins/georges_editor/georgesform_model.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index 454e8cdc0..332dbae14 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -610,7 +610,8 @@ void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx ) else n = e.Name.c_str(); - item->add( CFormItem::Form, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0, item->form(), false ); + NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( e.Element ); + addStruct( item, st, st->FormDfn, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0 ); } Q_EMIT endResetModel(); From c4e01eaca61eee64bc3133a408b5449b21a70073 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 5 Sep 2014 18:58:47 +0200 Subject: [PATCH 04/21] 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); From 49f216ca0efd9619883c715aba73af4a69694a29 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 5 Sep 2014 19:41:51 +0200 Subject: [PATCH 05/21] Appending, resizing arrays, deleting array members should now create the proper new nodes. --- .../georges_editor/georgesform_model.cpp | 41 ++++++++++++++++--- .../georges_editor/georgesform_model.h | 2 + 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index 0dc9521db..fac16e86f 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -478,6 +478,31 @@ CFormItem *CGeorgesFormModel::addAtom(CFormItem *parent, NLGEORGES::CFormElm *el } +CFormItem *CGeorgesFormModel::addItem(CFormItem *parent, NLGEORGES::CFormElm *elm, NLGEORGES::CFormDfn *dfn, const char *name, uint id, const char *formName) +{ + CFormItem *item = NULL; + + if( elm->isAtom() ) + item = addAtom(parent, elm, dfn, name, id, formName ); + else + if( elm->isStruct() || elm->isVirtualStruct() ) + { + NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( elm ); + if( st->isVirtualStruct() ) + item = addStruct(parent, st, st->FormDfn, name, id, formName, 0, true); + else + item = addStruct(parent, st, st->FormDfn, name, id, formName, 0, false); + } + else + if( elm->isArray() ) + { + NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( elm ); + item = addArray(parent, arr, arr->FormDfn, name, id, formName, 0 ); + } + + return item; +} + void CGeorgesFormModel::arrayResized( const QString &name, int size ) { CFormItem *item = m_rootItem->findItem( name ); @@ -512,8 +537,9 @@ void CGeorgesFormModel::arrayResized( const QString &name, int size ) else n = e.Name.c_str(); - NLGEORGES::CFormElmStruct *s = static_cast< NLGEORGES::CFormElmStruct* >( e.Element ); - addStruct( item, s, s->FormDfn, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0 ); + NLGEORGES::UFormDfn *udfn = e.Element->getStructDfn(); + NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn ); + addItem( item, e.Element, cdfn, n.toUtf8().constData(), i, formName.toUtf8().constData() ); } if( celm->Elements.size() == 0 ) @@ -585,8 +611,8 @@ void CGeorgesFormModel::appendArray( QModelIndex idx ) std::string formName; node->getFormName( formName ); - NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( node ); - addStruct( item, st, st->FormDfn, name.c_str(), s, formName.c_str(), 0 ); + NLGEORGES::CFormDfn *cdfn = const_cast< NLGEORGES::CFormDfn* >( nodeDfn ); + addItem( item, node, cdfn, name.c_str(), s, formName.c_str() ); } void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx ) @@ -628,8 +654,11 @@ void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx ) else n = e.Name.c_str(); - NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( e.Element ); - addStruct( item, st, st->FormDfn, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0 ); + NLGEORGES::UFormDfn *udfn = e.Element->getStructDfn(); + NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn ); + addItem( item, e.Element, cdfn, n.toUtf8().constData(), i, formName.toUtf8().constData() ); + //NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( e.Element ); + //addStruct( item, st, st->FormDfn, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0 ); } Q_EMIT endResetModel(); diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.h b/code/studio/src/plugins/georges_editor/georgesform_model.h index 154fc3745..716a45178 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.h +++ b/code/studio/src/plugins/georges_editor/georgesform_model.h @@ -72,6 +72,8 @@ namespace GeorgesQt CFormItem *addAtom(CFormItem *parent, NLGEORGES::CFormElm *elm, NLGEORGES::CFormDfn *dfn, const char *name, uint id, const char *formName); + CFormItem *addItem(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); From ca910cf17afef20227272ccede616b3ea3dd3bfe Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 5 Sep 2014 20:28:43 +0200 Subject: [PATCH 06/21] Added support for manipulating atoms. --- code/nel/include/nel/georges/form_elm.h | 1 + code/nel/src/georges/form_elm.cpp | 7 ++++ .../georges_editor/browser_ctrl_pvt.cpp | 38 +++++++++++++++++++ .../plugins/georges_editor/browser_ctrl_pvt.h | 2 + 4 files changed, 48 insertions(+) diff --git a/code/nel/include/nel/georges/form_elm.h b/code/nel/include/nel/georges/form_elm.h index 5453717a2..48118b7d8 100644 --- a/code/nel/include/nel/georges/form_elm.h +++ b/code/nel/include/nel/georges/form_elm.h @@ -454,6 +454,7 @@ public: // Set the value, the elt been used void setValue (const char *value); + std::string getValue() const; private: // The value diff --git a/code/nel/src/georges/form_elm.cpp b/code/nel/src/georges/form_elm.cpp index 518782342..03d39967a 100644 --- a/code/nel/src/georges/form_elm.cpp +++ b/code/nel/src/georges/form_elm.cpp @@ -3056,6 +3056,13 @@ void CFormElmAtom::setValue (const char *value) // *************************************************************************** +std::string CFormElmAtom::getValue() const +{ + return Value; +} + +// *************************************************************************** + void CFormElmAtom::getFormName (std::string &result, const CFormElm *child) const { // Must be NULL 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 fe8a60b28..0b5b464a3 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,29 @@ void BrowserCtrlPvt::setupArray( GeorgesQt::CFormItem *node ) m_browser->addProperty( p ); } +void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node ) +{ + NLGEORGES::UFormElm *n = getGeorgesNode( node ); + + if( n == NULL ) + return; + + NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( n ); + std::string v = atom->getValue(); + + const NLGEORGES::CType *t = atom->getType(); + QVariant::Type tt = QVariant::String; + if( t != NULL ) + { + tt = getValueType( t ); + } + + 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 ) { @@ -159,6 +182,9 @@ void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) else if( node->isStruct() ) setupStruct( node ); + else + if( node->isAtom() ) + setupAtom( node ); m_browser->setFactoryForManager( mgr, factory ); } @@ -283,6 +309,15 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value ) m_currentNode.p = NULL; } +void BrowserCtrlPvt::onAtomValueChanged( QtProperty *p, const QVariant &value ) +{ + NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( m_currentNode.p ); + atom->setValue( value.toString().toUtf8() ); + + Q_EMIT modified(); + Q_EMIT valueChanged( m_currentNode.name, value.toString() ); +} + void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) { if( m_currentNode.p == NULL ) @@ -299,6 +334,9 @@ void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) else if( m_currentNode.p->isArray() ) onArrayValueChanged( p, value ); + else + if( m_currentNode.p->isAtom() ) + 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 bebb65c3e..bcdf773a4 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -65,9 +65,11 @@ private: void setupStruct( GeorgesQt::CFormItem *node ); void setupArray( GeorgesQt::CFormItem *node ); + void setupAtom( GeorgesQt::CFormItem *node ); void onStructValueChanged( QtProperty *p, const QVariant &value ); void onArrayValueChanged( QtProperty *p, const QVariant &value ); + void onAtomValueChanged( QtProperty *p, const QVariant &value ); void createArray(); QtVariantPropertyManager *mgr; From 029ebdc751f0cb544d65c4332cb1a87d3341db32 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 5 Sep 2014 21:42:14 +0200 Subject: [PATCH 07/21] Get type info from DFN. --- .../georges_editor/browser_ctrl_pvt.cpp | 84 +++++++++++++++---- .../plugins/georges_editor/browser_ctrl_pvt.h | 2 +- 2 files changed, 71 insertions(+), 15 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 0b5b464a3..e4b96b7e2 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -26,7 +26,6 @@ namespace { - QVariant::Type getValueType( const NLGEORGES::UType *typ ) { QVariant::Type t = QVariant::String; @@ -47,6 +46,55 @@ namespace return t; } + QVariant::Type getValueTypeFromDfn( NLGEORGES::CFormElmStruct *st, int idx ) + { + NLGEORGES::CFormDfn *cdfn = st->FormDfn; + NLGEORGES::CFormDfn::CEntry entry = cdfn->getEntry( idx ); + return getValueType( entry.getTypePtr() ); + } + + + QVariant::Type getValueTypeFromDfn( NLGEORGES::CFormElmAtom *atom ) + { + QVariant::Type t = QVariant::String; + + NLGEORGES::CFormElm *cparent = static_cast< NLGEORGES::CFormElm* >( atom->getParent() ); + + if( cparent->isArray() ) + { + NLGEORGES::CFormElmStruct *aparent = static_cast< NLGEORGES::CFormElmStruct* >( cparent->getParent() ); + NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( aparent->getStructDfn() ); + + int idx = -1; + for( idx = 0; idx < aparent->Elements.size(); idx++ ) + { + if( aparent->Elements[ idx ].Element == cparent ) + break; + } + + NLGEORGES::CFormDfn::CEntry entry = cdfn->getEntry( idx ); + return getValueType( entry.getTypePtr() ); + } + else + if( cparent->isStruct() ) + { + NLGEORGES::CFormElmStruct *sparent = static_cast< NLGEORGES::CFormElmStruct* >( cparent ); + NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( cparent->getStructDfn() ); + + int idx = -1; + for( idx = 0; idx < sparent->Elements.size(); idx++ ) + { + if( sparent->Elements[ idx ].Element == atom ) + break; + } + + NLGEORGES::CFormDfn::CEntry entry = cdfn->getEntry( idx ); + return getValueType( entry.getTypePtr() ); + } + + return t; + } + NLGEORGES::UFormElm* getGeorgesNode( GeorgesQt::CFormItem *item ) { NLGEORGES::UFormElm *n = NULL; @@ -73,8 +121,19 @@ BrowserCtrlPvt::~BrowserCtrlPvt() m_browser = NULL; } -void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm ) +void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx ) { + NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ idx ]; + if( ( elm.Element != NULL ) && !elm.Element->isAtom() ) + return; + + if( elm.Element == NULL ) + { + NLGEORGES::CFormDfn::CEntry &entry = st->FormDfn->getEntry( idx ); + if( entry.getArrayFlag() ) + return; + } + QString key = elm.Name.c_str(); QString value = ""; QVariant::Type t = QVariant::String; @@ -90,6 +149,10 @@ void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &el m_rootNode->getValueByName( v, formName.c_str(), NLGEORGES::UFormElm::NoEval, NULL, 0 ); value = v.c_str(); } + else + { + t = getValueTypeFromDfn( st, idx ); + } QtVariantProperty *p = mgr->addProperty( t, key ); p->setValue( value ); @@ -102,18 +165,7 @@ void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node ) for( int i = 0; i < st->Elements.size(); i++ ) { - NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ i ]; - if( ( elm.Element != NULL ) && !elm.Element->isAtom() ) - continue; - - if( elm.Element == NULL ) - { - NLGEORGES::CFormDfn::CEntry &entry = st->FormDfn->getEntry( i ); - if( entry.getArrayFlag() ) - continue; - } - - setupAtom( elm ); + setupAtom( st, i ); } } @@ -162,6 +214,10 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node ) { tt = getValueType( t ); } + else + { + tt = getValueTypeFromDfn( atom ); + } QtVariantProperty *p = mgr->addProperty( tt, "value" ); p->setValue( v.c_str() ); 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 bcdf773a4..7c27d3a4f 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -61,7 +61,7 @@ Q_SIGNALS: private: void setupStruct( NLGEORGES::UFormElm *node ); - void setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm ); + void setupAtom( NLGEORGES::CFormElmStruct *st, int idx ); void setupStruct( GeorgesQt::CFormItem *node ); void setupArray( GeorgesQt::CFormItem *node ); From df02d7f7f1988cecbcc0f1b22ed279751a8c999a Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 9 Sep 2014 21:57:30 +0200 Subject: [PATCH 08/21] 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(); From 0c3a1d7b23b59a60b44c6f179a7a07d890e84a2b Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 9 Sep 2014 22:01:52 +0200 Subject: [PATCH 09/21] Don't add Virtual Structs to the property browser! --- code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp | 3 +++ 1 file changed, 3 insertions(+) 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 2461bb218..cdc9950a3 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -132,6 +132,9 @@ void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx ) NLGEORGES::CFormDfn::CEntry &entry = st->FormDfn->getEntry( idx ); if( entry.getArrayFlag() ) return; + + if( entry.getType() == NLGEORGES::UFormDfn::EntryVirtualDfn ) + return; } QString key = elm.Name.c_str(); From bd508d3ef4348b1437d002bb8cbaa0d6aae04a5b Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 00:28:03 +0200 Subject: [PATCH 10/21] 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 ); From 3425c517f58fb2f3dc7d6bf9ef823ff964d7e4a7 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 00:36:55 +0200 Subject: [PATCH 11/21] Create vstruct node when needed. --- .../georges_editor/browser_ctrl_pvt.cpp | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 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 af622633c..723836f67 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -198,16 +198,16 @@ void BrowserCtrlPvt::setupStruct( GeorgesQt::CFormItem *node ) void BrowserCtrlPvt::setupVStruct( GeorgesQt::CFormItem *node ) { NLGEORGES::UFormElm *n = getGeorgesNode( node ); - if( n == NULL ) - return; - - 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 ); + if( n != NULL ) + { + NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( n ); + mgr->setValue( p, vs->DfnFilename.c_str() ); + setupStruct( n ); + } } void BrowserCtrlPvt::setupArray( GeorgesQt::CFormItem *node ) @@ -308,6 +308,25 @@ void BrowserCtrlPvt::onVStructValueChanged( QtProperty *p, const QVariant &value } NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( getCurrentNode() ); + if( vs == NULL ) + { + const NLGEORGES::CFormDfn *parentDfn; + const NLGEORGES::CFormDfn *nodeDfn; + uint indexDfn; + const NLGEORGES::CType *type; + NLGEORGES::UFormDfn::TEntryType entryType; + NLGEORGES::CFormElm *node; + bool created; + bool isArray; + + m_rootNode->createNodeByName( m_currentNode.name.toUtf8().constData(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created ); + + if( !created ) + return; + + vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( node ); + } + vs->DfnFilename = value.toString().toUtf8().constData(); QString key = m_currentNode.name + "." + p->propertyName(); From c4a9db12f9389f2bfe7eecdbe7d9de3df9ed862f Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 16:22:08 +0200 Subject: [PATCH 12/21] Properly support color types. --- .../georges_editor/browser_ctrl_pvt.cpp | 88 +++++++++++++++++-- .../plugins/georges_editor/browser_ctrl_pvt.h | 3 + 2 files changed, 86 insertions(+), 5 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 723836f67..d7ebe35b8 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -102,6 +102,55 @@ namespace return n; } + // Get the data from a string, and pack it into a QVariant properly + // Needed for some special values, like color + // which are represented differently in Nel and Qt + QVariant stringToVariant( const QString &value, QVariant::Type type ) + { + QVariant v; + + if( type == QVariant::Color ) + { + QStringList l = value.split( ',' ); + if( l.size() != 3 ) + v = ""; + else + { + QColor c; + c.setRed( l[ 0 ].toInt() ); + c.setGreen( l[ 1 ].toInt() ); + c.setBlue( l[ 2 ].toInt() ); + v = c; + } + + } + else + v = value; + + return v; + } + + // The inverse function of stringToVariant + // Unpacks the data from a QVariant properly + QString variantToString( const QVariant &value ) + { + QString v; + + if( value.type() == QVariant::Color ) + { + QColor c = value.value< QColor >(); + v += QString::number( c.red() ); + v += ','; + v += QString::number( c.green() ); + v += ','; + v += QString::number( c.blue() ); + } + else + v = value.toString(); + + return v; + } + } @@ -155,23 +204,31 @@ void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx ) QString value = ""; QVariant::Type t = QVariant::String; + // If the atom exists, get the value from it + // Otherwise just get the type so we can set up the proper editor if( elm.Element != NULL ) { - t = getValueType( elm.Element->getType() ); + // Check if there's a type, if not get it from the Dfn + const NLGEORGES::CType *type = elm.Element->getType(); + if( type != NULL ) + t = getValueType( elm.Element->getType() ); + else + t = getValueTypeFromDfn( st, idx ); std::string formName; elm.Element->getFormName( formName, NULL ); std::string v; m_rootNode->getValueByName( v, formName.c_str(), NLGEORGES::UFormElm::NoEval, NULL, 0 ); - value = v.c_str(); + value = stringToVariant( v.c_str(), t ).toString(); } else { t = getValueTypeFromDfn( st, idx ); } - QtVariantProperty *p = mgr->addProperty( t, key ); + QtVariantProperty *p = addProperty( t, key ); + p->setValue( value ); m_browser->addProperty( p ); } @@ -248,7 +305,7 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node ) tt = getValueTypeFromDfn( atom ); } - QtVariantProperty *p = mgr->addProperty( tt, "value" ); + QtVariantProperty *p = addProperty( tt, "value" ); p->setValue( v.c_str() ); m_browser->addProperty( p ); } @@ -286,7 +343,8 @@ void BrowserCtrlPvt::clear() void BrowserCtrlPvt::onStructValueChanged( QtProperty *p, const QVariant &value ) { std::string k = p->propertyName().toUtf8().constData(); - std::string v = value.toString().toUtf8().constData(); + std::string v; + v = variantToString( value ).toUtf8().constData(); NLGEORGES::UFormElm *node = getCurrentNode(); @@ -457,4 +515,24 @@ void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) onAtomValueChanged( p, value ); } +QtVariantProperty* BrowserCtrlPvt::addProperty( QVariant::Type type, const QString &name ) +{ + QtVariantProperty *p = mgr->addProperty( type, name ); + + // Remove the color sub-properties, so they don't get triggered on value change + if( type == QVariant::Color ) + { + QList< QtProperty* > sp = p->subProperties(); + QListIterator< QtProperty* > itr( sp ); + while( itr.hasNext() ) + { + QtProperty *prop = itr.next(); + p->removeSubProperty( prop ); + delete prop; + } + sp.clear(); + } + + return p; +} 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 5dbe1885d..ad2b41307 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -38,6 +38,7 @@ class QtVariantEditorFactory; class QtTreePropertyBrowser; class QVariant; class QtProperty; +class QtVariantProperty; class BrowserCtrlPvt : public QObject { @@ -77,6 +78,8 @@ private: void onArrayValueChanged( QtProperty *p, const QVariant &value ); void onAtomValueChanged( QtProperty *p, const QVariant &value ); void createArray(); + + QtVariantProperty* addProperty( QVariant::Type type, const QString &name ); QtVariantPropertyManager *mgr; QtVariantEditorFactory *factory; From 21da4da0fa8130a3624caaf2ae3b912069b04166 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 16:44:49 +0200 Subject: [PATCH 13/21] Store the filename only in the Dfn value. --- .../src/plugins/georges_editor/dfn_browser_ctrl.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp index 9e2c86a56..c406b549a 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -26,6 +26,8 @@ #include "nel/georges/form_dfn.h" +#include + namespace { enum EntryEnum @@ -248,7 +250,15 @@ void DFNBrowserCtrl::onEnumValueChanged( QtProperty *p, int v ) void DFNBrowserCtrl::onFileValueChanged( QtProperty *p, const QString &v ) { NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx ); - entry.setFilename( v.toUtf8().constData() ); + QFileInfo info( v ); + if( !info.exists() ) + return; + + entry.setFilename( info.fileName().toUtf8().constData() ); + + blockSignals( true ); + m_fileMgr->setValue( p, info.fileName() ); + blockSignals( false ); Q_EMIT valueChanged( p->propertyName(), v ); } From 90b3bd0338f159a05601360d700de560442af3ae Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 17:02:51 +0200 Subject: [PATCH 14/21] A little refactoring --- .../georges_editor/browser_ctrl_pvt.cpp | 24 ++++++++----------- .../plugins/georges_editor/browser_ctrl_pvt.h | 2 +- 2 files changed, 11 insertions(+), 15 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 d7ebe35b8..969e1ce91 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -227,10 +227,7 @@ void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx ) t = getValueTypeFromDfn( st, idx ); } - QtVariantProperty *p = addProperty( t, key ); - - p->setValue( value ); - m_browser->addProperty( p ); + QtVariantProperty *p = addVariantProperty( t, key, value ); } void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node ) @@ -256,8 +253,8 @@ void BrowserCtrlPvt::setupVStruct( GeorgesQt::CFormItem *node ) { NLGEORGES::UFormElm *n = getGeorgesNode( node ); - QtVariantProperty *p = mgr->addProperty( QVariant::String, "Dfn filename" ); - m_browser->addProperty( p ); + QtVariantProperty *p; + p = addVariantProperty( QVariant::String, "Dfn filename", QVariant() ); if( n != NULL ) { @@ -279,9 +276,7 @@ void BrowserCtrlPvt::setupArray( GeorgesQt::CFormItem *node ) } QString key = QObject::tr( "Array size" ); - QtVariantProperty *p = mgr->addProperty( QVariant::Int, key ); - p->setValue( size ); - m_browser->addProperty( p ); + QtVariantProperty *p = addVariantProperty( QVariant::Int, key, size ); } void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node ) @@ -305,9 +300,7 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node ) tt = getValueTypeFromDfn( atom ); } - QtVariantProperty *p = addProperty( tt, "value" ); - p->setValue( v.c_str() ); - m_browser->addProperty( p ); + QtVariantProperty *p = addVariantProperty( tt, "value", v.c_str() ); } void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) @@ -515,9 +508,9 @@ void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) onAtomValueChanged( p, value ); } -QtVariantProperty* BrowserCtrlPvt::addProperty( QVariant::Type type, const QString &name ) +QtVariantProperty* BrowserCtrlPvt::addVariantProperty( QVariant::Type type, const QString &key, const QVariant &value ) { - QtVariantProperty *p = mgr->addProperty( type, name ); + QtVariantProperty *p = mgr->addProperty( type, key ); // Remove the color sub-properties, so they don't get triggered on value change if( type == QVariant::Color ) @@ -533,6 +526,9 @@ QtVariantProperty* BrowserCtrlPvt::addProperty( QVariant::Type type, const QStri sp.clear(); } + p->setValue( value ); + m_browser->addProperty( p ); + return p; } 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 ad2b41307..dd630b962 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -79,7 +79,7 @@ private: void onAtomValueChanged( QtProperty *p, const QVariant &value ); void createArray(); - QtVariantProperty* addProperty( QVariant::Type type, const QString &name ); + QtVariantProperty* addVariantProperty( QVariant::Type type, const QString &key, const QVariant &value ); QtVariantPropertyManager *mgr; QtVariantEditorFactory *factory; From b69169af71c75032a33dfe4c718556bd575abcf8 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 17:59:22 +0200 Subject: [PATCH 15/21] Use a file browser for setting files. --- .../plugins/georges_editor/browser_ctrl.cpp | 12 ++++ .../src/plugins/georges_editor/browser_ctrl.h | 1 + .../georges_editor/browser_ctrl_pvt.cpp | 71 +++++++++++++++++-- .../plugins/georges_editor/browser_ctrl_pvt.h | 9 +++ 4 files changed, 88 insertions(+), 5 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp index 722faf096..ad947edcf 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp @@ -20,6 +20,7 @@ #include "browser_ctrl.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" #include "3rdparty/qtpropertybrowser/qtvariantproperty.h" +#include "filepath_property_manager.h" #include #include "nel/georges/form.h" @@ -69,6 +70,11 @@ void BrowserCtrl::onValueChanged( const QString &key, const QString &value ) Q_EMIT valueChanged( key, value ); } +void BrowserCtrl::onFileValueChanged( QtProperty *p, const QString &value ) +{ + m_pvt->onFileValueChanged( p, value ); +} + void BrowserCtrl::onArrayResized( const QString &name, int size ) { Q_EMIT arrayResized( name, size ); @@ -87,16 +93,22 @@ void BrowserCtrl::onVStructChanged( const QString &name ) void BrowserCtrl::enableMgrConnections() { QtVariantPropertyManager *mgr = m_pvt->manager(); + FileManager *fileMgr = m_pvt->fileManager(); connect( mgr, SIGNAL( valueChanged( QtProperty*, const QVariant & ) ), this, SLOT( onValueChanged( QtProperty*, const QVariant & ) ) ); + connect( fileMgr, SIGNAL( valueChanged( QtProperty*, const QString & ) ), + this, SLOT( onFileValueChanged( QtProperty*, const QString & ) ) ); } void BrowserCtrl::disableMgrConnections() { QtVariantPropertyManager *mgr = m_pvt->manager(); + FileManager *fileMgr = m_pvt->fileManager(); disconnect( mgr, SIGNAL( valueChanged( QtProperty*, const QVariant & ) ), this, SLOT( onValueChanged( QtProperty*, const QVariant & ) ) ); + disconnect( fileMgr, SIGNAL( valueChanged( QtProperty*, const QString & ) ), + this, SLOT( onFileValueChanged( QtProperty*, const QString & ) ) ); } diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.h b/code/studio/src/plugins/georges_editor/browser_ctrl.h index 42ff5d6e7..a70b57356 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.h @@ -53,6 +53,7 @@ Q_SIGNALS: private Q_SLOTS: void onValueChanged( QtProperty *p, const QVariant &value ); void onValueChanged( const QString &key, const QString &value ); + void onFileValueChanged( QtProperty *p, const QString &value ); void onArrayResized( const QString &name, int size ); void onModified(); void onVStructChanged( const QString &name ); 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 969e1ce91..0ce72d39b 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -24,15 +24,31 @@ #include "nel/georges/form.h" +#include "filepath_property_manager.h" namespace { + const unsigned int FILEBROWSER = 9000000; + QVariant::Type getValueType( const NLGEORGES::UType *typ ) { QVariant::Type t = QVariant::String; + bool file = false; + NLGEORGES::UType::TType ttyp = NLGEORGES::UType::String; if( typ != NULL ) + { ttyp = typ->getType(); + + const NLGEORGES::CType *ctyp = static_cast< const NLGEORGES::CType* >( typ ); + if(ctyp->UIType == NLGEORGES::CType::FileBrowser ) + { + file = true; + } + } + + if( file ) + return QVariant::Type( FILEBROWSER ); switch( ttyp ) { @@ -159,6 +175,8 @@ QObject( parent ) { mgr = new QtVariantPropertyManager(); factory = new QtVariantEditorFactory(); + m_fileMgr = new FileManager( this ); + m_fileFactory = new FileEditFactory( this ); m_rootNode = NULL; } @@ -168,6 +186,8 @@ BrowserCtrlPvt::~BrowserCtrlPvt() mgr = NULL; delete factory; factory = NULL; + m_fileMgr = NULL; + m_fileFactory = NULL; m_browser = NULL; } @@ -227,7 +247,10 @@ void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx ) t = getValueTypeFromDfn( st, idx ); } - QtVariantProperty *p = addVariantProperty( t, key, value ); + if( t == QVariant::Type( FILEBROWSER ) ) + addFileProperty( key, value ); + else + addVariantProperty( t, key, value ); } void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node ) @@ -253,13 +276,13 @@ void BrowserCtrlPvt::setupVStruct( GeorgesQt::CFormItem *node ) { NLGEORGES::UFormElm *n = getGeorgesNode( node ); - QtVariantProperty *p; - p = addVariantProperty( QVariant::String, "Dfn filename", QVariant() ); + QtProperty *p = NULL; + p = addFileProperty( "Dfn filename", "" ); if( n != NULL ) { NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( n ); - mgr->setValue( p, vs->DfnFilename.c_str() ); + m_fileMgr->setValue( p, vs->DfnFilename.c_str() ); setupStruct( n ); } } @@ -300,7 +323,10 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node ) tt = getValueTypeFromDfn( atom ); } - QtVariantProperty *p = addVariantProperty( tt, "value", v.c_str() ); + if( tt = QVariant::Type( FILEBROWSER ) ) + addFileProperty( "value", v.c_str() ); + else + addVariantProperty( tt, "value", v.c_str() ); } void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) @@ -324,6 +350,7 @@ void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) setupAtom( node ); m_browser->setFactoryForManager( mgr, factory ); + m_browser->setFactoryForManager( m_fileMgr, m_fileFactory ); } void BrowserCtrlPvt::clear() @@ -508,6 +535,28 @@ void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) onAtomValueChanged( p, value ); } +void BrowserCtrlPvt::onFileValueChanged( QtProperty *p, const QString &value ) +{ + QString v = value; + QFileInfo info( value ); + if( !info.exists() ) + return; + + v = info.fileName(); + blockSignals( true ); + m_fileMgr->setValue( p, v ); + blockSignals( false ); + + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_VSTRUCT ) + onVStructValueChanged( p, v ); + else + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_STRUCT ) + onStructValueChanged( p, v ); + else + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_ATOM ) + onAtomValueChanged( p, v ); +} + QtVariantProperty* BrowserCtrlPvt::addVariantProperty( QVariant::Type type, const QString &key, const QVariant &value ) { QtVariantProperty *p = mgr->addProperty( type, key ); @@ -532,3 +581,15 @@ QtVariantProperty* BrowserCtrlPvt::addVariantProperty( QVariant::Type type, cons return p; } +QtProperty* BrowserCtrlPvt::addFileProperty( const QString &key, const QString &value ) +{ + QtProperty *p = m_fileMgr->addProperty( key ); + + m_fileMgr->setValue( p, value ); + m_browser->addProperty( p ); + + return p; +} + + + 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 dd630b962..2f9785411 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -40,6 +40,9 @@ class QVariant; class QtProperty; class QtVariantProperty; +class FileManager; +class FileEditFactory; + class BrowserCtrlPvt : public QObject { Q_OBJECT @@ -50,8 +53,10 @@ public: void clear(); void setupNode( GeorgesQt::CFormItem *node ); void onValueChanged( QtProperty *p, const QVariant &value ); + void onFileValueChanged( QtProperty *p, const QString &value ); QtVariantPropertyManager* manager() const{ return mgr; } + FileManager* fileManager() const{ return m_fileMgr; } void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; } void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } @@ -80,11 +85,15 @@ private: void createArray(); QtVariantProperty* addVariantProperty( QVariant::Type type, const QString &key, const QVariant &value ); + QtProperty *addFileProperty( const QString &key, const QString &value ); QtVariantPropertyManager *mgr; QtVariantEditorFactory *factory; QtTreePropertyBrowser *m_browser; + FileManager *m_fileMgr; + FileEditFactory *m_fileFactory; + QString m_currentNodeName; NLGEORGES::CFormElm *m_rootNode; From cb0cacf3cc57995425cb21502fde1a4273c7288e Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 18:04:55 +0200 Subject: [PATCH 16/21] oups --- code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0ce72d39b..484649e52 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -323,7 +323,7 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node ) tt = getValueTypeFromDfn( atom ); } - if( tt = QVariant::Type( FILEBROWSER ) ) + if( tt == QVariant::Type( FILEBROWSER ) ) addFileProperty( "value", v.c_str() ); else addVariantProperty( tt, "value", v.c_str() ); From 912248afde11a919a0e41421a8c83061eaf7747a Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 18:49:34 +0200 Subject: [PATCH 17/21] WTF? --- code/studio/src/plugins/georges_editor/georges_dfn_dialog.h | 1 - code/studio/src/plugins/georges_editor/georges_typ_dialog.h | 2 -- 2 files changed, 3 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h index 2d6dc4113..7757779fe 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -53,7 +53,6 @@ private: Ui::GeorgesDFNDialog m_ui; GeorgesDFNDialogPvt *m_pvt; - QString m_fileName; }; #endif diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h index b241c4c8d..6aa7f27f9 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -53,8 +53,6 @@ private: Ui::GeorgesTypDialog m_ui; GeorgesTypDialogPvt *m_pvt; - - QString m_fileName; }; From 6576b3d325de51e575557e67c0992b3d2fab98a6 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 18:50:07 +0200 Subject: [PATCH 18/21] Raise the widget after adding. --- code/studio/src/plugins/georges_editor/georges_editor_form.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp index 54028b5a4..d544d14fd 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -265,6 +265,7 @@ namespace GeorgesQt m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); } + QCoreApplication::processEvents(); w->raise(); } From 26712697c2a885acecad6fc01a45c2ba7f548bee Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 19:14:26 +0200 Subject: [PATCH 19/21] Allow editing of the comment section, and save comments when saving. --- .../src/plugins/georges_editor/georges_dfn_dialog.cpp | 8 ++++++++ .../src/plugins/georges_editor/georges_dfn_dialog.h | 1 + .../src/plugins/georges_editor/georges_dfn_dialog.ui | 2 +- .../plugins/georges_editor/georges_treeview_dialog.cpp | 8 ++++++++ .../src/plugins/georges_editor/georges_treeview_dialog.h | 1 + .../src/plugins/georges_editor/georges_treeview_form.ui | 6 +++++- .../src/plugins/georges_editor/georges_typ_dialog.cpp | 8 ++++++++ .../src/plugins/georges_editor/georges_typ_dialog.h | 1 + .../src/plugins/georges_editor/georges_typ_dialog.ui | 6 +++++- 9 files changed, 38 insertions(+), 3 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp index 30fa38c7d..c7244273e 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -82,6 +82,8 @@ bool GeorgesDFNDialog::load( const QString &fileName ) m_fileName = fileName; + connect(m_ui.commentsEdit, SIGNAL(textChanged()), this, SLOT(onCommentsEdited())); + return true; } @@ -91,6 +93,7 @@ void GeorgesDFNDialog::write() setWindowTitle( windowTitle().remove( "*" ) ); m_pvt->dfn->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); + m_pvt->dfn->Header.Comments = m_ui.commentsEdit->toPlainText().toUtf8().constData(); NLMISC::COFile file; if( !file.open( m_fileName.toUtf8().constData(), false, true, false ) ) @@ -178,6 +181,11 @@ void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value } } +void GeorgesDFNDialog::onCommentsEdited() +{ + onModified(); +} + void GeorgesDFNDialog::loadDfn() { m_pvt->ctrl->setDFN( m_pvt->dfn ); diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h index 7757779fe..edb67144c 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -44,6 +44,7 @@ private Q_SLOTS: void onCurrentRowChanged( int row ); void onValueChanged( const QString& key, const QString &value ); + void onCommentsEdited(); private: void loadDfn(); diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.ui b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.ui index 3cbdb7419..70b5bd265 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.ui +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.ui @@ -98,7 +98,7 @@ - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + Qt::TextEditorInteraction 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 297769b6c..62d5ac653 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -323,6 +323,8 @@ namespace GeorgesQt QFileInfo info( fileName ); setWindowTitle( info.fileName() ); + connect(m_ui.commentEdit, SIGNAL(textChanged()), this, SLOT(onCommentsEdited())); + return true; } @@ -330,6 +332,7 @@ namespace GeorgesQt { NLGEORGES::CForm *form = static_cast< NLGEORGES::CForm* >( m_form ); form->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); + form->Header.Comments = m_ui.commentEdit->toPlainText().toUtf8().constData(); NLMISC::COFile file; std::string s = m_fileName.toUtf8().constData(); @@ -591,6 +594,11 @@ namespace GeorgesQt m_browserCtrl->clicked( idx ); } + void CGeorgesTreeViewDialog::onCommentsEdited() + { + modifiedFile(); + } + 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 4595cc289..87c64ead9 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -103,6 +103,7 @@ namespace GeorgesQt void onValueChanged( const QString &key, const QString &value ); void onVStructChanged( const QString &name ); void onRenameArrayEntry(); + void onCommentsEdited(); private: void log( const QString &msg ); diff --git a/code/studio/src/plugins/georges_editor/georges_treeview_form.ui b/code/studio/src/plugins/georges_editor/georges_treeview_form.ui index 42d9afcf9..43d50e103 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_form.ui +++ b/code/studio/src/plugins/georges_editor/georges_treeview_form.ui @@ -112,7 +112,11 @@ - + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp index d042c6d33..ab4cc0472 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -82,6 +82,8 @@ bool GeorgesTypDialog::load( const QString &fileName ) QFileInfo info( fileName ); setWindowTitle( info.fileName() ); + connect( m_ui.commentEdit, SIGNAL( textChanged() ), this, SLOT( onCommentsEdited() ) ); + return true; } @@ -96,6 +98,7 @@ void GeorgesTypDialog::write() xml.init( &file ); m_pvt->typ->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); + m_pvt->typ->Header.Comments = m_ui.commentEdit->toPlainText().toUtf8().constData(); m_pvt->typ->write( xml.getDocument() ); xml.flush(); @@ -227,6 +230,11 @@ void GeorgesTypDialog::onModified( const QString &k, const QString &v ) onModified(); } +void GeorgesTypDialog::onCommentsEdited() +{ + onModified(); +} + void GeorgesTypDialog::setupConnections() { connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h index 6aa7f27f9..5a6c09e61 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -45,6 +45,7 @@ private Q_SLOTS: void onItemChanged( QTreeWidgetItem *item, int column ); void onModified(); void onModified( const QString &k, const QString &v ); + void onCommentsEdited(); private: void setupConnections(); diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.ui b/code/studio/src/plugins/georges_editor/georges_typ_dialog.ui index 6cd080579..8978fa13b 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.ui +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.ui @@ -118,7 +118,11 @@ - + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + From 54b8bf6aa2a4fd0a525264baff8105dc152e621d Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 19:52:35 +0200 Subject: [PATCH 20/21] When closing a dialog, remove it from the docked dialogs, and delete it. --- .../src/plugins/georges_editor/CMakeLists.txt | 1 + .../georges_editor/georges_dock_widget.cpp | 5 +++++ .../plugins/georges_editor/georges_dock_widget.h | 7 +++++++ .../georges_editor/georges_editor_form.cpp | 16 ++++++++++------ .../plugins/georges_editor/georges_editor_form.h | 2 +- .../georges_editor/georges_treeview_dialog.cpp | 6 ------ .../georges_editor/georges_treeview_dialog.h | 4 ---- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/CMakeLists.txt b/code/studio/src/plugins/georges_editor/CMakeLists.txt index 0f0cbc1e0..bf7e6e0c9 100644 --- a/code/studio/src/plugins/georges_editor/CMakeLists.txt +++ b/code/studio/src/plugins/georges_editor/CMakeLists.txt @@ -23,6 +23,7 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h filepath_property_manager.h typ_browser_ctrl.h georges_typ_dialog.h + georges_dock_widget.h ) SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui diff --git a/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp index 921f59e0b..9602a7678 100644 --- a/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp @@ -29,6 +29,11 @@ GeorgesDockWidget::~GeorgesDockWidget() { } +void GeorgesDockWidget::closeEvent( QCloseEvent *e ) +{ + Q_EMIT closing( this ); +} + QString GeorgesDockWidget::buildLogMsg( const QString &msg ) { QString user = getenv( "USER" ); diff --git a/code/studio/src/plugins/georges_editor/georges_dock_widget.h b/code/studio/src/plugins/georges_editor/georges_dock_widget.h index 53e4f6841..d7f80dff1 100644 --- a/code/studio/src/plugins/georges_editor/georges_dock_widget.h +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.h @@ -25,6 +25,7 @@ class QUndoStack; class GeorgesDockWidget : public QDockWidget { + Q_OBJECT public: GeorgesDockWidget( QWidget *parent = NULL ); ~GeorgesDockWidget(); @@ -39,6 +40,12 @@ public: virtual bool load( const QString &fileName ) = 0; virtual void write() = 0; +protected: + void closeEvent( QCloseEvent *e ); + +Q_SIGNALS: + void closing( GeorgesDockWidget *d ); + protected: QString buildLogMsg( const QString &msg ); virtual void log( const QString &msg ) = 0; diff --git a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp index d544d14fd..4f4b814ec 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -252,7 +252,7 @@ namespace GeorgesQt m_lastActiveDock = w; m_dockedWidgets.append(w); - connect(m_dockedWidgets.last(), SIGNAL(closing()), this, SLOT(closingTreeView())); + connect( w, SIGNAL( closing( GeorgesDockWidget* ) ), this, SLOT( dialogClosing( GeorgesDockWidget* ) ) ); connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)), m_dockedWidgets.last(), SLOT(checkVisibility(bool))); // If there is more than one form open - tabify the new form. If this is the first form open add it to the dock. @@ -337,12 +337,16 @@ namespace GeorgesQt addGeorgesWidget( w ); } - void GeorgesEditorForm::closingTreeView() + void GeorgesEditorForm::dialogClosing( GeorgesDockWidget *d ) { - //qDebug() << "closingTreeView"; - m_dockedWidgets.removeAll(qobject_cast(sender())); - if (qobject_cast(sender()) == m_lastActiveDock) - m_lastActiveDock = 0; + m_dockedWidgets.removeAll( d ); + + if( m_dockedWidgets.size() == 0 ) + m_lastActiveDock = NULL; + else + m_lastActiveDock = m_dockedWidgets.last(); + + delete d; } void GeorgesEditorForm::setModified () diff --git a/code/studio/src/plugins/georges_editor/georges_editor_form.h b/code/studio/src/plugins/georges_editor/georges_editor_form.h index adfaf2e59..031d6e0fc 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.h +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.h @@ -52,7 +52,7 @@ public Q_SLOTS: void save(); void settingsChanged(); - void closingTreeView(); + void dialogClosing( GeorgesDockWidget *d ); void setModified(); void focusChanged(QWidget *old, QWidget *now); 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 62d5ac653..ab5f03924 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -599,12 +599,6 @@ namespace GeorgesQt modifiedFile(); } - void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) - { - Q_EMIT closing(); - deleteLater(); - } - void CGeorgesTreeViewDialog::checkVisibility(bool visible) { // this prevents invisible docks from getting tab focus qDebug() << "checkVisibility" << visible; 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 87c64ead9..37ae55c20 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -77,13 +77,9 @@ namespace GeorgesQt QString loadedForm; - protected: - void closeEvent(QCloseEvent *event); - Q_SIGNALS: void changeFile(QString); void modified(); - void closing(); public Q_SLOTS: void setForm(const CForm*); From af7bff14cf471e3ec9dd1e1f5df29599cc3be5ab Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 19:59:38 +0200 Subject: [PATCH 21/21] Offer to save changes when closing a dialog. --- .../georges_editor/georges_dock_widget.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp index 9602a7678..e031fbc8f 100644 --- a/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp @@ -17,6 +17,7 @@ // along with this program. If not, see . #include "georges_dock_widget.h" +#include GeorgesDockWidget::GeorgesDockWidget( QWidget *parent ) : QDockWidget( parent ) @@ -31,6 +32,26 @@ GeorgesDockWidget::~GeorgesDockWidget() void GeorgesDockWidget::closeEvent( QCloseEvent *e ) { + if( isModified() ) + { + QString title = windowTitle(); + title.remove( '*' ); + + int reply = QMessageBox::question( this, + tr( "Closing dialog" ), + title + tr( " has been modified.\nWould you like to save the changes?" ), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel ); + + if( reply == QMessageBox::Cancel ) + { + e->ignore(); + return; + } + + if( reply == QMessageBox::Yes ) + write(); + } + Q_EMIT closing( this ); }