From 9b6ff808c551b38e2c1d3e3ec7d9ca0650fb582a Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 19 Aug 2014 01:57:20 +0200 Subject: [PATCH 01/50] Save from the file menu too. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/georges_editor_form.cpp | 6 +++++- .../src/plugins/georges_editor/georges_editor_plugin.cpp | 5 +++++ .../src/plugins/georges_editor/georges_editor_plugin.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) 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 dc0ca409d..b05077c0a 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -144,8 +144,12 @@ namespace GeorgesQt void GeorgesEditorForm::save() { m_lastActiveDock->write(); - m_saveAction->setEnabled(false); + + m_saveAction->setEnabled(false); + QAction *saveAction = Core::ICore::instance()->menuManager()->action( Core::Constants::SAVE ); + if( saveAction != NULL ) + saveAction->setEnabled(false); } void GeorgesEditorForm::readSettings() diff --git a/code/studio/src/plugins/georges_editor/georges_editor_plugin.cpp b/code/studio/src/plugins/georges_editor/georges_editor_plugin.cpp index f1b419e4e..e0b29af2f 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_plugin.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_plugin.cpp @@ -94,6 +94,11 @@ void GeorgesEditorContext::open() m_georgesEditorForm->open(); } +void GeorgesEditorContext::save() +{ + m_georgesEditorForm->save(); +} + QWidget *GeorgesEditorContext::widget() { return m_georgesEditorForm; diff --git a/code/studio/src/plugins/georges_editor/georges_editor_plugin.h b/code/studio/src/plugins/georges_editor/georges_editor_plugin.h index e21d8c57a..931e83ddf 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_plugin.h +++ b/code/studio/src/plugins/georges_editor/georges_editor_plugin.h @@ -86,6 +86,8 @@ public: virtual void open(); + void save(); + virtual QUndoStack *undoStack(); virtual QWidget *widget(); From 655d44615144aae8f1b7dfbb1e4650fbfa641f90 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 20 Aug 2014 18:22:20 +0200 Subject: [PATCH 02/50] When reaching 0 array size, delete the array node. --HG-- branch : dfighter-tools --- .../plugins/georges_editor/georgesform_model.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index 90eaaaacd..3de9b7415 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -497,6 +497,22 @@ void CGeorgesFormModel::arrayResized( const QString &name, int size ) item->add( CFormItem::Form, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0, item->form() ); } + if( celm->Elements.size() == 0 ) + { + NLGEORGES::CFormElmStruct *ps = dynamic_cast< NLGEORGES::CFormElmStruct* >( celm->getParent() ); + if( ps != NULL ) + { + const NLGEORGES::CFormDfn *parentDfn; + const NLGEORGES::CFormDfn *nodeDfn; + uint indexDfn; + const NLGEORGES::CType *nodeType; + NLGEORGES::CFormElm *node; + NLGEORGES::CFormDfn::TEntryType type; + bool isArray; + + ps->deleteNodeByName( item->name().c_str(), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, isArray ); + } + } } From d046a970d97a1c41b69eae5a8a30d8f47264f7a6 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 20 Aug 2014 19:57:16 +0200 Subject: [PATCH 03/50] Initialize CFormItem fields... --HG-- branch : dfighter-tools --- code/studio/src/plugins/georges_editor/formitem.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/studio/src/plugins/georges_editor/formitem.cpp b/code/studio/src/plugins/georges_editor/formitem.cpp index 1ca2ecbe1..a18db48bb 100644 --- a/code/studio/src/plugins/georges_editor/formitem.cpp +++ b/code/studio/src/plugins/georges_editor/formitem.cpp @@ -34,6 +34,12 @@ namespace GeorgesQt { CFormItem::CFormItem() { + parentItem = NULL; + formElm = NULL; + m_form = NULL; + _StructId = 0; + _Slot = 0; + _Type = Null; } CFormItem::~CFormItem() From eeac53ebbab9142a4878bf9d4fbf9f17bc93aaea Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 20 Aug 2014 23:18:16 +0200 Subject: [PATCH 04/50] Added support for creating arrays. --HG-- branch : dfighter-tools --- .../plugins/georges_editor/browser_ctrl.cpp | 14 +-- .../georges_editor/browser_ctrl_pvt.cpp | 117 ++++++++++++++---- .../plugins/georges_editor/browser_ctrl_pvt.h | 33 ++++- .../src/plugins/georges_editor/formitem.cpp | 45 ++----- .../src/plugins/georges_editor/formitem.h | 10 +- .../georges_editor/georgesform_model.cpp | 8 +- 6 files changed, 143 insertions(+), 84 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp index aa431b45c..17eb170c4 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp @@ -31,18 +31,8 @@ void BrowserCtrl::clicked( const QModelIndex &idx ) m_pvt->clear(); GeorgesQt::CFormItem *item = static_cast< GeorgesQt::CFormItem* >( idx.internalPointer() ); - NLGEORGES::UFormElm &root = m_form->getRootNode(); - NLGEORGES::CFormElm *rootNode = dynamic_cast< NLGEORGES::CFormElm* >( &root ); - m_pvt->setRootNode( rootNode ); - NLGEORGES::UFormElm *node = NULL; - bool b = false; - - b = m_form->getRootNode().getNodeByName( &node, item->formName().c_str() ); - - if( !b || ( node == NULL ) ) - return; - - m_pvt->setupNode( node ); + + m_pvt->setupNode( item ); 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 0e22765da..297cf04d8 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -2,6 +2,9 @@ #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" #include "3rdparty/qtpropertybrowser/qtvariantproperty.h" #include +#include "formitem.h" + +#include "nel/georges/form.h" namespace { @@ -26,6 +29,12 @@ namespace return t; } + NLGEORGES::UFormElm* getGeorgesNode( GeorgesQt::CFormItem *item ) + { + NLGEORGES::UFormElm *n = NULL; + item->form()->getRootNode().getNodeByName( &n, item->formName().c_str() ); + return n; + } } @@ -34,7 +43,6 @@ QObject( parent ) { mgr = new QtVariantPropertyManager(); factory = new QtVariantEditorFactory(); - m_currentNode = NULL; m_rootNode = NULL; } @@ -70,19 +78,6 @@ void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &el m_browser->addProperty( p ); } -void BrowserCtrlPvt::setupArray( NLGEORGES::UFormElm *node ) -{ - NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( node ); - uint size = 0; - arr->getArraySize( size ); - - QString key = QObject::tr( "Array size" ); - QtVariantProperty *p = mgr->addProperty( QVariant::Int, key ); - p->setValue( size ); - m_browser->addProperty( p ); - -} - void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node ) { NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( node ); @@ -104,24 +99,54 @@ void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node ) } } -void BrowserCtrlPvt::setupNode( NLGEORGES::UFormElm *node ) +void BrowserCtrlPvt::setupStruct( GeorgesQt::CFormItem *node ) { - if( node->isStruct() ) - setupStruct( node ); - else + NLGEORGES::UFormElm *n = getGeorgesNode( node ); + if( n == NULL ) + return; + + m_currentNode.p = n; + + setupStruct( n ); +} + +void BrowserCtrlPvt::setupArray( GeorgesQt::CFormItem *node ) +{ + NLGEORGES::UFormElm *n = getGeorgesNode( node ); + uint size = 0; + + if( n != NULL ) + { + NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( n ); + arr->getArraySize( size ); + m_currentNode.p = n; + } + + QString key = QObject::tr( "Array size" ); + QtVariantProperty *p = mgr->addProperty( QVariant::Int, key ); + p->setValue( size ); + m_browser->addProperty( p ); +} + +void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) +{ + m_currentNode.clear(); + m_currentNode.name = node->formName().c_str(); + + m_rootNode = dynamic_cast< NLGEORGES::CFormElm* >( &(node->form()->getRootNode()) ); + if( node->isArray() ) setupArray( node ); else - return; + setupStruct( node ); - m_currentNode = node; m_browser->setFactoryForManager( mgr, factory ); } void BrowserCtrlPvt::clear() { m_browser->clear(); - m_currentNode = NULL; + m_currentNode.clear(); } @@ -131,14 +156,48 @@ void BrowserCtrlPvt::onStructValueChanged( QtProperty *p, const QVariant &value std::string v = value.toString().toUtf8().constData(); bool created = false; - m_currentNode->setValueByName( v.c_str(), k.c_str(), &created ); + m_currentNode.p->setValueByName( v.c_str(), k.c_str(), &created ); + + Q_EMIT modified(); +} + +void BrowserCtrlPvt::createArray() +{ + 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; + NLGEORGES::CFormElmArray *arr = dynamic_cast< NLGEORGES::CFormElmArray* >( node ); + QString idx = "[0]"; + arr->createNodeByName( idx.toUtf8().constData(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created ); + + std::string formName; + arr->getFormName( formName, NULL ); + + Q_EMIT arrayResized( formName.c_str(), 1 ); Q_EMIT modified(); + } void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value ) { - NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode ); + if( m_currentNode.p == NULL ) + { + createArray(); + return; + } + + NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode.p ); std::string formName; arr->getFormName( formName, NULL ); @@ -192,13 +251,19 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value ) void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) { - if( m_currentNode == NULL ) + if( m_currentNode.p == NULL ) + { + if( m_currentNode.name.isEmpty() ) + return; + + onArrayValueChanged( p, value ); return; + } - if( m_currentNode->isStruct() ) + if( m_currentNode.p->isStruct() ) onStructValueChanged( p, value ); else - if( m_currentNode->isArray() ) + if( m_currentNode.p->isArray() ) onArrayValueChanged( 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 0d0363c1f..69924a308 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -10,6 +10,11 @@ namespace NLGEORGES class CFormElmStruct; } +namespace GeorgesQt +{ + class CFormItem; +} + class QtVariantPropertyManager; class QtVariantEditorFactory; class QtTreePropertyBrowser; @@ -24,7 +29,7 @@ public: ~BrowserCtrlPvt(); void clear(); - void setupNode( NLGEORGES::UFormElm *node ); + void setupNode( GeorgesQt::CFormItem *node ); void onValueChanged( QtProperty *p, const QVariant &value ); QtVariantPropertyManager* manager() const{ return mgr; } @@ -37,18 +42,40 @@ Q_SIGNALS: private: void setupStruct( NLGEORGES::UFormElm *node ); - void setupArray( NLGEORGES::UFormElm *node ); void setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm ); + void setupStruct( GeorgesQt::CFormItem *node ); + void setupArray( GeorgesQt::CFormItem *node ); + void onStructValueChanged( QtProperty *p, const QVariant &value ); void onArrayValueChanged( QtProperty *p, const QVariant &value ); + void createArray(); QtVariantPropertyManager *mgr; QtVariantEditorFactory *factory; QtTreePropertyBrowser *m_browser; - NLGEORGES::UFormElm *m_currentNode; + QString m_currentNodeName; NLGEORGES::CFormElm *m_rootNode; + + struct CurrentNode + { + CurrentNode() + { + clear(); + } + + void clear() + { + p = NULL; + name = ""; + } + + QString name; + NLGEORGES::UFormElm *p; + }; + + CurrentNode m_currentNode; }; #endif diff --git a/code/studio/src/plugins/georges_editor/formitem.cpp b/code/studio/src/plugins/georges_editor/formitem.cpp index a18db48bb..8cd479961 100644 --- a/code/studio/src/plugins/georges_editor/formitem.cpp +++ b/code/studio/src/plugins/georges_editor/formitem.cpp @@ -40,6 +40,7 @@ namespace GeorgesQt _StructId = 0; _Slot = 0; _Type = Null; + _Array = false; } CFormItem::~CFormItem() @@ -112,48 +113,15 @@ namespace GeorgesQt bool CFormItem::isArray() { - // If it wasn't a root node then lets check the node type. - const NLGEORGES::CFormDfn *parentDfn; - uint indexDfn; - const NLGEORGES::CFormDfn *nodeDfn; - const NLGEORGES::CType *nodeType; - NLGEORGES::CFormElm *node; - NLGEORGES::UFormDfn::TEntryType type; - bool array; - bool parentVDfnArray; - NLGEORGES::CForm *form = static_cast(m_form); - NLGEORGES::CFormElm *elm = static_cast(&form->getRootNode()); - nlverify ( elm->getNodeByName (_FormName.c_str(), &parentDfn, indexDfn, - &nodeDfn, &nodeType, &node, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) ); - - if(array && node) - return true; - - return false; + return _Array; } bool CFormItem::isArrayMember() { - CFormItem *parent = this->parent(); - - // If it wasn't a root node then lets check the node type. - const NLGEORGES::CFormDfn *parentDfn; - uint indexDfn; - const NLGEORGES::CFormDfn *nodeDfn; - const NLGEORGES::CType *nodeType; - NLGEORGES::CFormElm *parentNode; - NLGEORGES::UFormDfn::TEntryType type; - bool array; - bool parentVDfnArray; - NLGEORGES::CForm *form = static_cast(m_form); - NLGEORGES::CFormElm *elm = static_cast(&form->getRootNode()); - nlverify ( elm->getNodeByName (parent->formName ().c_str (), &parentDfn, indexDfn, - &nodeDfn, &nodeType, &parentNode, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) ); - - if(array && parentNode) - return true; + if( parentItem == NULL ) + return false; - return false; + return parentItem->isArray(); } QIcon CFormItem::getItemImage(CFormItem *rootItem) @@ -243,7 +211,7 @@ namespace GeorgesQt childItems.clear(); } - CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr) + CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, bool isArray) { CFormItem *newNode = new CFormItem(); newNode->_Type = type; @@ -253,6 +221,7 @@ namespace GeorgesQt newNode->_FormName = formName; newNode->_Slot = slot; newNode->m_form = formPtr; + newNode->_Array = isArray; 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 d29dfce0c..cd67d1b21 100644 --- a/code/studio/src/plugins/georges_editor/formitem.h +++ b/code/studio/src/plugins/georges_editor/formitem.h @@ -46,7 +46,7 @@ namespace GeorgesQt void appendChild(CFormItem *child); - CFormItem *add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr); + CFormItem *add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr, bool isArray ); CFormItem *child(int row); int childCount() const; @@ -76,6 +76,13 @@ namespace GeorgesQt void clearChildren(); + bool rootItem() const{ + if( parentItem == NULL ) + return true; + else + return false; + } + private: QList childItems; QList itemData; @@ -88,6 +95,7 @@ namespace GeorgesQt std::string _FormName; TSub _Type; uint _Slot; + bool _Array; }; // CFormItem diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index 3de9b7415..f533970fa 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -283,7 +283,7 @@ namespace GeorgesQt NLGEORGES::CForm *formPtr = static_cast(m_form); // Add the new node - CFormItem *newNode = parent->add(CFormItem::Form, name, structId, formName, slot, m_form); + CFormItem *newNode = parent->add(CFormItem::Form, name, structId, formName, slot, m_form, false); // Can be NULL in virtual DFN if (parentDfn) @@ -418,7 +418,7 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent, uint slot) { // Add the new node - CFormItem *newNode = parent->add (CFormItem::Form, name, structId, formName, slot, m_form); + CFormItem *newNode = parent->add (CFormItem::Form, name, structId, formName, slot, m_form, true); // The array exist if (array) @@ -451,7 +451,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); + newNode->add (CFormItem::Form, formArrayName, elm, formArrayElmName, slot, m_form, false); } } } @@ -494,7 +494,7 @@ 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() ); + item->add( CFormItem::Form, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0, item->form(), false ); } if( celm->Elements.size() == 0 ) From d593ef5d17f75add4ad3d14eeedb34637df9ee9c Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 20 Aug 2014 23:36:53 +0200 Subject: [PATCH 05/50] Crash fixes related to Georges array size changing. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/browser_ctrl_pvt.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 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 297cf04d8..df4168a78 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -177,6 +177,8 @@ 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 ); @@ -191,8 +193,15 @@ void BrowserCtrlPvt::createArray() void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value ) { + // Newsize checks hacked in, because setting unsigned value type in QVariant crashes the property browser! + int newSize = value.toInt(); + if( newSize < 0 ) + return; + if( m_currentNode.p == NULL ) { + if( newSize != 1 ) + return; createArray(); return; } @@ -201,7 +210,6 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value ) std::string formName; arr->getFormName( formName, NULL ); - int newSize = value.toInt(); int oldSize = arr->Elements.size(); if( newSize == oldSize ) @@ -247,6 +255,9 @@ 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::onValueChanged( QtProperty *p, const QVariant &value ) From 6fb9c35d84ff478a83eb75bbfd4cb87f3488ec28 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 27 Aug 2014 01:14:49 +0200 Subject: [PATCH 06/50] Implemented 'append array entry' context menu --HG-- branch : dfighter-tools --- .../georges_treeview_dialog.cpp | 35 ++++++------ .../georges_editor/georges_treeview_dialog.h | 1 + .../georges_editor/georgesform_model.cpp | 54 +++++++++++++++++++ .../georges_editor/georgesform_model.h | 1 + 4 files changed, 74 insertions(+), 17 deletions(-) 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 3ecc73045..1114d339b 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -470,6 +470,19 @@ namespace GeorgesQt m_ui.treeView->setCurrentIndex( idx ); } + void CGeorgesTreeViewDialog::onAppendArray() + { + QModelIndex idx = m_ui.treeView->currentIndex(); + + m_model->appendArray( idx ); + + m_ui.treeView->reset(); + m_ui.treeView->expandAll(); + + m_ui.treeView->setCurrentIndex( idx ); + m_browserCtrl->clicked( idx ); + } + void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) { Q_EMIT closing(); @@ -523,7 +536,8 @@ namespace GeorgesQt // } if(item->isArray()) { - contextMenu.addAction("Append array entry..."); + QAction *appendAction = contextMenu.addAction("Append array entry..."); + connect( appendAction, SIGNAL( triggered( bool ) ), this, SLOT( onAppendArray() ) ); } else if(item->isArrayMember()) { @@ -558,24 +572,10 @@ namespace GeorgesQt // else if(item->getFormElm()->isAtom() && item->valueFrom() == NLGEORGES::UFormElm::ValueForm) // contextMenu.addAction("Revert to parent/default..."); - QAction *selectedItem = contextMenu.exec(QCursor::pos()); + contextMenu.exec(QCursor::pos()); + /* if(selectedItem) { - if(selectedItem->text() == "Append array entry...") - { - - - } // Append an array entry... - else if(selectedItem->text() == "Delete array entry...") - { - - } - else if(selectedItem->text() == "Insert after array entry...") - { - - } - - // if(selectedItem->text() == "Add parent...") // { // // Get the file extension of the form so we can build a dialog pattern. @@ -624,6 +624,7 @@ namespace GeorgesQt // } } // if selected context menu item is valid. + */ } // if 'm' model valid. //if(structContext) 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 7b40fc3ef..739fa0e28 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -104,6 +104,7 @@ namespace GeorgesQt void headerClicked(int); void onArrayResized( const QString &name, int size ); + void onAppendArray(); private: Ui::CGeorgesTreeViewDialog m_ui; diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index f533970fa..f0f70b642 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -515,6 +515,60 @@ void CGeorgesFormModel::arrayResized( const QString &name, int size ) } } +void CGeorgesFormModel::appendArray( QModelIndex idx ) +{ + if( !idx.isValid() ) + return; + + CFormItem *item = reinterpret_cast< CFormItem* >( idx.internalPointer() ); + NLGEORGES::UFormElm *elm = NULL; + + 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; + 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 ); + + if( !created ) + return; + + elm = node; + } + + NLGEORGES::CFormElmArray *celm = dynamic_cast< NLGEORGES::CFormElmArray* >( elm ); + if( celm == NULL ) + return; + + unsigned long s = celm->Elements.size(); + std::string nodeIdx = "["; + nodeIdx += QString::number( s ).toUtf8().constData(); + nodeIdx += "]"; + + celm->createNodeByName( nodeIdx.c_str(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created ); + if( !created ) + return; + + std::string name = "#"; + name += QString::number( s ).toUtf8().constData(); + + std::string formName; + node->getFormName( formName ); + + item->add( CFormItem::Form, name.c_str(), s, formName.c_str(), 0, item->form(), false ); +} + /******************************************************************************/ diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.h b/code/studio/src/plugins/georges_editor/georgesform_model.h index 4ca91398b..03c4c592a 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.h +++ b/code/studio/src/plugins/georges_editor/georgesform_model.h @@ -76,6 +76,7 @@ namespace GeorgesQt } void arrayResized( const QString &name, int size ); + void appendArray( QModelIndex idx ); private: void setupModelData(); From 5bb3e16ca4fcedb7dadbd85831f814cccf100aee Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 27 Aug 2014 16:23:16 +0200 Subject: [PATCH 07/50] Implement 'delete array entry' context menu command. --HG-- branch : dfighter-tools --- .../georges_treeview_dialog.cpp | 17 +++++++- .../georges_editor/georges_treeview_dialog.h | 1 + .../georges_editor/georgesform_model.cpp | 43 +++++++++++++++++++ .../georges_editor/georgesform_model.h | 1 + 4 files changed, 60 insertions(+), 2 deletions(-) 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 1114d339b..f0dd0aabf 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -483,6 +483,18 @@ namespace GeorgesQt m_browserCtrl->clicked( idx ); } + void CGeorgesTreeViewDialog::onDeleteArrayEntry() + { + QModelIndex current = m_ui.treeView->currentIndex(); + QModelIndex parent = current.parent(); + + m_model->deleteArrayEntry( current ); + + m_ui.treeView->expandAll(); + m_ui.treeView->setCurrentIndex( parent ); + m_browserCtrl->clicked( parent ); + } + void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) { Q_EMIT closing(); @@ -541,8 +553,9 @@ namespace GeorgesQt } else if(item->isArrayMember()) { - contextMenu.addAction("Delete array entry..."); - contextMenu.addAction("Insert after array entry..."); + QAction *deleteAction = contextMenu.addAction("Delete array entry..."); + connect( deleteAction, SIGNAL( triggered( bool ) ), this, SLOT( onDeleteArrayEntry() ) ); + //contextMenu.addAction("Insert after array entry..."); } // else if(item->getFormElm()->isStruct()) // { 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 739fa0e28..5e3e30ed8 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -105,6 +105,7 @@ namespace GeorgesQt void onArrayResized( const QString &name, int size ); void onAppendArray(); + void onDeleteArrayEntry(); private: Ui::CGeorgesTreeViewDialog m_ui; diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index f0f70b642..dfe581ed2 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -569,7 +569,50 @@ void CGeorgesFormModel::appendArray( QModelIndex idx ) item->add( CFormItem::Form, name.c_str(), s, formName.c_str(), 0, item->form(), false ); } +void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx ) +{ + CFormItem *item = reinterpret_cast< CFormItem* >( idx.internalPointer() ); + NLGEORGES::UFormElm &uroot = item->form()->getRootNode(); + NLGEORGES::CFormElm *root = static_cast< NLGEORGES::CFormElm* >( &item->form()->getRootNode() ); + NLGEORGES::UFormElm *unode; + uroot.getNodeByName( &unode, item->formName().c_str() ); + NLGEORGES::CFormElm *cnode = static_cast< NLGEORGES::CFormElm* >( unode ); + NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( cnode->getParent() ); + + NLGEORGES::CFormElm *elm = arr->Elements[ idx.row() ].Element; + + Q_EMIT beginResetModel(); + + std::vector< NLGEORGES::CFormElmArray::CElement >::iterator itr = arr->Elements.begin() + idx.row(); + arr->Elements.erase( itr ); + + delete elm; + + item = item->parent(); + item->clearChildren(); + + NLGEORGES::CFormElmArray *celm = arr; + + for( int i = 0; i < celm->Elements.size(); i++ ) + { + NLGEORGES::CFormElmArray::CElement &e = celm->Elements[ i ]; + + QString formName = item->formName().c_str(); + formName += '['; + formName += QString::number( i ); + formName += ']'; + QString n; + if( e.Name.empty() ) + n = "#" + QString::number( i ); + else + n = e.Name.c_str(); + + item->add( CFormItem::Form, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0, item->form(), false ); + } + + 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 03c4c592a..18b98735f 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.h +++ b/code/studio/src/plugins/georges_editor/georgesform_model.h @@ -77,6 +77,7 @@ namespace GeorgesQt void arrayResized( const QString &name, int size ); void appendArray( QModelIndex idx ); + void deleteArrayEntry( QModelIndex idx ); private: void setupModelData(); From f0fdd4167511f0fc2f3c99fd91b195065b579523 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 27 Aug 2014 17:34:26 +0200 Subject: [PATCH 08/50] Don't disable the log tab! --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/georges_treeview_dialog.cpp | 1 - 1 file changed, 1 deletion(-) 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 f0dd0aabf..f66b00bbf 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -71,7 +71,6 @@ namespace GeorgesQt m_ui.treeView->setHeader(m_header); m_ui.treeView->header()->setResizeMode(QHeaderView::ResizeToContents); m_ui.treeView->header()->setStretchLastSection(true); - m_ui.treeViewTabWidget->setTabEnabled (2,false); m_form = 0; m_model = NULL; From 3c0e76e78bcb114e4a84920f6ff53cfe50dfda14 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 27 Aug 2014 17:37:53 +0200 Subject: [PATCH 09/50] Load log into the log tab. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/georges_treeview_dialog.cpp | 3 +++ 1 file changed, 3 insertions(+) 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 f66b00bbf..3222cab5f 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -219,6 +219,9 @@ namespace GeorgesQt else return; + m_ui.logEdit->setPlainText( form->Header.Log.c_str() ); + m_ui.logEdit->setReadOnly( true ); + UFormElm *root = 0; root = &m_form->getRootNode(); From 77a21cfc996e3be933db1a0bb11f383174478f3c Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 27 Aug 2014 19:22:10 +0200 Subject: [PATCH 10/50] Now logging changes. --HG-- branch : dfighter-tools --- .../plugins/georges_editor/browser_ctrl.cpp | 6 +++ .../src/plugins/georges_editor/browser_ctrl.h | 2 + .../georges_editor/browser_ctrl_pvt.cpp | 3 ++ .../plugins/georges_editor/browser_ctrl_pvt.h | 1 + .../georges_treeview_dialog.cpp | 49 +++++++++++++++++++ .../georges_editor/georges_treeview_dialog.h | 3 ++ 6 files changed, 64 insertions(+) diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp index 17eb170c4..d4bd8daaa 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp @@ -17,6 +17,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& ) ) ); } BrowserCtrl::~BrowserCtrl() @@ -43,6 +44,11 @@ void BrowserCtrl::onValueChanged( QtProperty *p, const QVariant &value ) m_pvt->onValueChanged( p, value ); } +void BrowserCtrl::onValueChanged( const QString &key, const QString &value ) +{ + Q_EMIT valueChanged( key, value ); +} + void BrowserCtrl::onArrayResized( const QString &name, int size ) { Q_EMIT arrayResized( name, size ); diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.h b/code/studio/src/plugins/georges_editor/browser_ctrl.h index 9c70f51bb..daf77cc87 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.h @@ -29,9 +29,11 @@ public Q_SLOTS: Q_SIGNALS: void arrayResized( const QString &name, int size ); void modified(); + void valueChanged( const QString &key, const QString &value ); 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(); 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 df4168a78..0a62aa5a8 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -158,7 +158,10 @@ void BrowserCtrlPvt::onStructValueChanged( QtProperty *p, const QVariant &value bool created = false; m_currentNode.p->setValueByName( v.c_str(), k.c_str(), &created ); + QString key = m_currentNode.name + "." + p->propertyName(); + Q_EMIT modified(); + Q_EMIT valueChanged( key, value.toString() ); } void BrowserCtrlPvt::createArray() 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 69924a308..2aabd5ecb 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -39,6 +39,7 @@ public: Q_SIGNALS: void arrayResized( const QString &name, int size ); void modified(); + void valueChanged( const QString &key, const QString &value ); private: void setupStruct( NLGEORGES::UFormElm *node ); 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 3222cab5f..6dbbe4899 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(arrayResized(const QString&,int)), this, SLOT(onArrayResized(const QString&,int))); connect(m_browserCtrl, SIGNAL(modified()), this, SLOT(modifiedFile())); + connect(m_browserCtrl, SIGNAL(valueChanged(const QString&,const QString&)), this, SLOT(onValueChanged(const QString&,const QString&))); } CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog() @@ -470,12 +471,18 @@ namespace GeorgesQt if( !idx.isValid() ) return; m_ui.treeView->setCurrentIndex( idx ); + + log( name + " resized = " + QString::number( size ) ); } void CGeorgesTreeViewDialog::onAppendArray() { QModelIndex idx = m_ui.treeView->currentIndex(); + CFormItem *item = reinterpret_cast< CFormItem* >( idx.internalPointer() ); + QString formName = item->formName().c_str(); + int size = item->childCount(); + m_model->appendArray( idx ); m_ui.treeView->reset(); @@ -483,6 +490,8 @@ namespace GeorgesQt m_ui.treeView->setCurrentIndex( idx ); m_browserCtrl->clicked( idx ); + + log( formName + " resized = " + QString::number( size + 1 ) ); } void CGeorgesTreeViewDialog::onDeleteArrayEntry() @@ -490,11 +499,21 @@ namespace GeorgesQt QModelIndex current = m_ui.treeView->currentIndex(); QModelIndex parent = current.parent(); + CFormItem *item = reinterpret_cast< CFormItem* >( current.internalPointer() ); + QString formName = item->formName().c_str(); + m_model->deleteArrayEntry( current ); m_ui.treeView->expandAll(); m_ui.treeView->setCurrentIndex( parent ); m_browserCtrl->clicked( parent ); + + log( "deleted " + formName ); + } + + void CGeorgesTreeViewDialog::onValueChanged( const QString &key, const QString &value ) + { + log( key + " = " + value ); } void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) @@ -646,4 +665,34 @@ namespace GeorgesQt // delete structContext; } + void CGeorgesTreeViewDialog::log( const QString &msg ) + { + QString user = getenv( "USER" ); + if( user.isEmpty() ) + user = getenv( "USERNAME" ); + if( user.isEmpty() ) + user = "anonymous"; + + QTime time = QTime::currentTime(); + QDate date = QDate::currentDate(); + + QString dateString = date.toString( "ddd MMM dd" ); + QString timeString = time.toString( "HH:mm:ss" ); + + QString logMsg; + logMsg += dateString; + logMsg += ' '; + logMsg += timeString; + logMsg += ' '; + logMsg += QString::number( date.year() ); + logMsg += ' '; + logMsg += "("; + logMsg += user; + logMsg += ")"; + logMsg += ' '; + logMsg += msg; + + m_ui.logEdit->appendPlainText( logMsg ); + } + } /* namespace GeorgesQt */ 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 5e3e30ed8..17923e429 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -106,8 +106,11 @@ namespace GeorgesQt void onArrayResized( const QString &name, int size ); void onAppendArray(); void onDeleteArrayEntry(); + void onValueChanged( const QString &key, const QString &value ); private: + void log( const QString &msg ); + Ui::CGeorgesTreeViewDialog m_ui; ExpandableHeaderView *m_header; UForm *m_form; From 0ae8fbde29006c433e77ff436877add173ddb2c2 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 27 Aug 2014 20:24:05 +0200 Subject: [PATCH 11/50] Implemented rename context menu. --HG-- branch : dfighter-tools --- .../georges_treeview_dialog.cpp | 22 +++++++++++++++ .../georges_editor/georges_treeview_dialog.h | 1 + .../georges_editor/georgesform_model.cpp | 28 +++++++++++++++++++ .../georges_editor/georgesform_model.h | 1 + 4 files changed, 52 insertions(+) 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 6dbbe4899..9450eeec2 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -516,6 +516,25 @@ namespace GeorgesQt log( key + " = " + value ); } + void CGeorgesTreeViewDialog::onRenameArrayEntry() + { + QModelIndex idx = m_ui.treeView->currentIndex(); + + CFormItem *item = static_cast< CFormItem* >( idx.internalPointer() ); + + QString newName = QInputDialog::getText( this, + tr( "Rename" ), + tr( "Enter new name" ), + QLineEdit::Normal, + item->name().c_str() ); + + m_model->renameArrayEntry( idx, newName ); + + QString formName = item->formName().c_str(); + + log( formName + " renamed = " + newName ); + } + void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) { Q_EMIT closing(); @@ -576,6 +595,9 @@ namespace GeorgesQt { QAction *deleteAction = contextMenu.addAction("Delete array entry..."); connect( deleteAction, SIGNAL( triggered( bool ) ), this, SLOT( onDeleteArrayEntry() ) ); + + QAction *renameAction = contextMenu.addAction("Rename"); + connect( renameAction, SIGNAL( triggered( bool ) ), this, SLOT( onRenameArrayEntry() ) ); //contextMenu.addAction("Insert after array entry..."); } // else if(item->getFormElm()->isStruct()) 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 17923e429..c3e9937ef 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -107,6 +107,7 @@ namespace GeorgesQt void onAppendArray(); void onDeleteArrayEntry(); void onValueChanged( const QString &key, const QString &value ); + void onRenameArrayEntry(); private: void log( const QString &msg ); diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index dfe581ed2..f00e090f2 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -614,6 +614,34 @@ void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx ) Q_EMIT endResetModel(); } +void CGeorgesFormModel::renameArrayEntry( QModelIndex idx, const QString &name ) +{ + CFormItem *item = static_cast< CFormItem* >( idx.internalPointer() ); + + NLGEORGES::UFormElm *elm; + + item->form()->getRootNode().getNodeByName( &elm, item->formName().c_str() ); + + NLGEORGES::CFormElm *celm = dynamic_cast< NLGEORGES::CFormElm* >( elm ); + if( celm == NULL ) + return; + + NLGEORGES::UFormElm *uparent = celm->getParent(); + NLGEORGES::CFormElmArray *cparent = dynamic_cast< NLGEORGES::CFormElmArray* >( uparent ); + if( cparent == NULL ) + return; + + int i = 0; + for( i = 0; i < cparent->Elements.size(); i++ ) + { + if( cparent->Elements[ i ].Element == celm ) + break; + } + + cparent->Elements[ i ].Name = name.toUtf8().constData(); + item->setName( name.toUtf8().constData() ); +} + /******************************************************************************/ 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 18b98735f..dc4b67a62 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.h +++ b/code/studio/src/plugins/georges_editor/georgesform_model.h @@ -78,6 +78,7 @@ namespace GeorgesQt void arrayResized( const QString &name, int size ); void appendArray( QModelIndex idx ); void deleteArrayEntry( QModelIndex idx ); + void renameArrayEntry( QModelIndex idx, const QString &name ); private: void setupModelData(); From e6aa34584a9127383438bcc610c43f07f4594da5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 27 Aug 2014 20:25:30 +0200 Subject: [PATCH 12/50] Mark file modified even when using the context menu. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/georges_treeview_dialog.cpp | 6 ++++++ 1 file changed, 6 insertions(+) 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 9450eeec2..4fd7e10c7 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -492,6 +492,8 @@ namespace GeorgesQt m_browserCtrl->clicked( idx ); log( formName + " resized = " + QString::number( size + 1 ) ); + + modifiedFile(); } void CGeorgesTreeViewDialog::onDeleteArrayEntry() @@ -509,6 +511,8 @@ namespace GeorgesQt m_browserCtrl->clicked( parent ); log( "deleted " + formName ); + + modifiedFile(); } void CGeorgesTreeViewDialog::onValueChanged( const QString &key, const QString &value ) @@ -533,6 +537,8 @@ namespace GeorgesQt QString formName = item->formName().c_str(); log( formName + " renamed = " + newName ); + + modifiedFile(); } void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) From 58b50e7d7e051e69cd2afc8d3a3af6ea2bddd738 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 27 Aug 2014 20:30:16 +0200 Subject: [PATCH 13/50] Save the log too, when saving.. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/georges_treeview_dialog.cpp | 2 ++ 1 file changed, 2 insertions(+) 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 4fd7e10c7..9def10065 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -319,6 +319,8 @@ namespace GeorgesQt void CGeorgesTreeViewDialog::write( ) { + NLGEORGES::CForm *form = static_cast< NLGEORGES::CForm* >( m_form ); + form->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); NLMISC::COFile file; std::string s = NLMISC::CPath::lookup(loadedForm.toAscii().data(), false); From 0d530f15f6809f95bf7d6759115c368762b46448 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 30 Aug 2014 21:32:28 +0200 Subject: [PATCH 14/50] Renamed signal. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/georges_dirtree_dialog.cpp | 2 +- .../src/plugins/georges_editor/georges_dirtree_dialog.h | 2 +- .../src/plugins/georges_editor/georges_editor_form.cpp | 8 ++++---- .../src/plugins/georges_editor/georges_editor_form.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/georges_dirtree_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_dirtree_dialog.cpp index 0a467aac5..c1853233c 100644 --- a/code/studio/src/plugins/georges_editor/georges_dirtree_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dirtree_dialog.cpp @@ -74,7 +74,7 @@ void CGeorgesDirTreeDialog::fileSelected(QModelIndex index) { if (index.isValid() && !m_dirModel->isDir(index)) { - Q_EMIT selectedForm(m_dirModel->fileName(index)); + Q_EMIT fileSelected(m_dirModel->fileName(index)); } } diff --git a/code/studio/src/plugins/georges_editor/georges_dirtree_dialog.h b/code/studio/src/plugins/georges_editor/georges_dirtree_dialog.h index 3654783f3..0a8fc682b 100644 --- a/code/studio/src/plugins/georges_editor/georges_dirtree_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dirtree_dialog.h @@ -49,7 +49,7 @@ private: QString m_ldPath; Q_SIGNALS: - void selectedForm(const QString); + void fileSelected(const QString&); private Q_SLOTS: void fileSelected(QModelIndex index); 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 b05077c0a..e4244673b 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -103,8 +103,8 @@ namespace GeorgesQt connect(Core::ICore::instance(), SIGNAL(changeSettings()), this, SLOT(settingsChanged())); - connect(m_georgesDirTreeDialog, SIGNAL(selectedForm(const QString)), - this, SLOT(loadFile(const QString))); + connect(m_georgesDirTreeDialog, SIGNAL(fileSelected(const QString&)), + this, SLOT(loadFile(const QString&))); connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(focusChanged(QWidget*, QWidget*))); } @@ -194,12 +194,12 @@ namespace GeorgesQt } } - void GeorgesEditorForm::loadFile(const QString fileName) + void GeorgesEditorForm::loadFile(const QString &fileName) { loadFile(fileName, false); } - void GeorgesEditorForm::loadFile(const QString fileName, bool loadFromDfn) + void GeorgesEditorForm::loadFile(const QString &fileName, bool loadFromDfn) { QFileInfo info(fileName); 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 c9cef964c..6b4e33fcd 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.h +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.h @@ -42,8 +42,8 @@ public: public Q_SLOTS: void open(); - void loadFile(const QString fileName); - void loadFile(const QString fileName, bool loadFromDfn); + void loadFile(const QString &fileName); + void loadFile(const QString &fileName, bool loadFromDfn); void newFile(); void save(); void settingsChanged(); From ad4771e3d16684e2c64912fac0763ceecf11a613 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 30 Aug 2014 21:37:11 +0200 Subject: [PATCH 15/50] Show an error message when form loading fails. --HG-- branch : dfighter-tools --- .../studio/src/plugins/georges_editor/georges_editor_form.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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 e4244673b..166243adf 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -261,6 +261,10 @@ namespace GeorgesQt { nlwarning("Failed to load form: %s", info.fileName().toUtf8().constData()); m_dockedWidgets.last()->close(); + + QMessageBox::information( this, + tr( "Failed to load form..." ), + tr( "Failed to load form '%1'" ).arg( info.fileName() ) ); } } From cfabc13ffd89975a70249c895b5583d76ee55f71 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 30 Aug 2014 22:23:21 +0200 Subject: [PATCH 16/50] EOL --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/actions.h | 94 +- .../src/plugins/georges_editor/browser_ctrl.h | 98 +- .../plugins/georges_editor/browser_ctrl_pvt.h | 164 +-- .../src/plugins/gui_editor/action_list.cpp | 98 +- .../src/plugins/gui_editor/action_list.h | 58 +- .../src/plugins/tile_editor/CMakeLists.txt | 100 +- .../plugins/tile_editor/land_edit_dialog.cpp | 210 +-- .../plugins/tile_editor/land_edit_dialog.h | 102 +- .../tile_editor/studio_plugin_tile_editor.xml | 18 +- .../src/plugins/tile_editor/tile_bank.cpp | 1284 ++++++++--------- .../src/plugins/tile_editor/tile_bank.h | 204 +-- .../src/plugins/tile_editor/tile_constants.h | 86 +- .../src/plugins/tile_editor/tile_images.h | 80 +- .../tile_editor/tile_item_delegate.cpp | 242 ++-- .../plugins/tile_editor/tilebank_loader.cpp | 84 +- .../src/plugins/tile_editor/tilebank_loader.h | 70 +- .../plugins/tile_editor/tilebank_saver.cpp | 96 +- .../src/plugins/tile_editor/tilebank_saver.h | 78 +- .../translation_manager/uxt_editor.cpp | 944 ++++++------ code/studio/src/settings_dialog.cpp | 472 +++--- code/studio/src/settings_dialog.h | 124 +- code/studio/src/splash_screen.cpp | 218 +-- code/studio/src/splash_screen.h | 120 +- 23 files changed, 2522 insertions(+), 2522 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/actions.h b/code/studio/src/plugins/georges_editor/actions.h index 0c57b0577..861eaef8e 100644 --- a/code/studio/src/plugins/georges_editor/actions.h +++ b/code/studio/src/plugins/georges_editor/actions.h @@ -1,48 +1,48 @@ -// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework -// Copyright (C) 2011 Adrian Jaekel -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#ifndef ACTIONS_H -#define ACTIONS_H - -#include -#include - -namespace GeorgesQt -{ - class CFormItem; - class CGeorgesFormModel; - - class CUndoFormArrayRenameCommand : public QUndoCommand - { - public: - CUndoFormArrayRenameCommand(CGeorgesFormModel *model, CFormItem *item, const QVariant &value, QUndoCommand *parent = 0); - ~CUndoFormArrayRenameCommand() {} - - void redo(); - void undo(); - - void update(bool redo); - - protected: - CFormItem *m_item; - CGeorgesFormModel *m_model; - - QString m_newValue; - QString m_oldValue; - }; -} - +// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework +// Copyright (C) 2011 Adrian Jaekel +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef ACTIONS_H +#define ACTIONS_H + +#include +#include + +namespace GeorgesQt +{ + class CFormItem; + class CGeorgesFormModel; + + class CUndoFormArrayRenameCommand : public QUndoCommand + { + public: + CUndoFormArrayRenameCommand(CGeorgesFormModel *model, CFormItem *item, const QVariant &value, QUndoCommand *parent = 0); + ~CUndoFormArrayRenameCommand() {} + + void redo(); + void undo(); + + void update(bool redo); + + protected: + CFormItem *m_item; + CGeorgesFormModel *m_model; + + QString m_newValue; + QString m_oldValue; + }; +} + #endif // ACTIONS_H \ No newline at end of file diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.h b/code/studio/src/plugins/georges_editor/browser_ctrl.h index daf77cc87..7c56deceb 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.h @@ -1,49 +1,49 @@ -#ifndef BROWSER_CTRL_H -#define BROWSER_CTRL_H - -#include - -namespace NLGEORGES -{ - class UForm; -} - -class QtTreePropertyBrowser; -class QModelIndex; -class QVariant; -class QtProperty; - -class BrowserCtrlPvt; - -class BrowserCtrl : public QObject -{ - Q_OBJECT -public: - BrowserCtrl( QtTreePropertyBrowser *browser ); - ~BrowserCtrl(); - void setForm( NLGEORGES::UForm *form ){ m_form = form; } - -public Q_SLOTS: - void clicked( const QModelIndex &idx ); - -Q_SIGNALS: - void arrayResized( const QString &name, int size ); - void modified(); - void valueChanged( const QString &key, const QString &value ); - -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(); - -private: - void enableMgrConnections(); - void disableMgrConnections(); - - - BrowserCtrlPvt *m_pvt; - NLGEORGES::UForm *m_form; -}; - -#endif +#ifndef BROWSER_CTRL_H +#define BROWSER_CTRL_H + +#include + +namespace NLGEORGES +{ + class UForm; +} + +class QtTreePropertyBrowser; +class QModelIndex; +class QVariant; +class QtProperty; + +class BrowserCtrlPvt; + +class BrowserCtrl : public QObject +{ + Q_OBJECT +public: + BrowserCtrl( QtTreePropertyBrowser *browser ); + ~BrowserCtrl(); + void setForm( NLGEORGES::UForm *form ){ m_form = form; } + +public Q_SLOTS: + void clicked( const QModelIndex &idx ); + +Q_SIGNALS: + void arrayResized( const QString &name, int size ); + void modified(); + void valueChanged( const QString &key, const QString &value ); + +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(); + +private: + void enableMgrConnections(); + void disableMgrConnections(); + + + BrowserCtrlPvt *m_pvt; + NLGEORGES::UForm *m_form; +}; + +#endif 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 2aabd5ecb..c3d1cf50e 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -1,82 +1,82 @@ -#ifndef BROWSER_CTRL_PVT_H -#define BROWSER_CTRL_PVT_H - -#include - -namespace NLGEORGES -{ - class CFormElm; - class UFormElm; - class CFormElmStruct; -} - -namespace GeorgesQt -{ - class CFormItem; -} - -class QtVariantPropertyManager; -class QtVariantEditorFactory; -class QtTreePropertyBrowser; -class QVariant; -class QtProperty; - -class BrowserCtrlPvt : public QObject -{ - Q_OBJECT -public: - BrowserCtrlPvt( QObject *parent = NULL ); - ~BrowserCtrlPvt(); - - void clear(); - void setupNode( GeorgesQt::CFormItem *node ); - void onValueChanged( QtProperty *p, const QVariant &value ); - - QtVariantPropertyManager* manager() const{ return mgr; } - void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; } - void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } - -Q_SIGNALS: - void arrayResized( const QString &name, int size ); - void modified(); - void valueChanged( const QString &key, const QString &value ); - -private: - void setupStruct( NLGEORGES::UFormElm *node ); - void setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm ); - - void setupStruct( GeorgesQt::CFormItem *node ); - void setupArray( GeorgesQt::CFormItem *node ); - - void onStructValueChanged( QtProperty *p, const QVariant &value ); - void onArrayValueChanged( QtProperty *p, const QVariant &value ); - void createArray(); - - QtVariantPropertyManager *mgr; - QtVariantEditorFactory *factory; - QtTreePropertyBrowser *m_browser; - - QString m_currentNodeName; - NLGEORGES::CFormElm *m_rootNode; - - struct CurrentNode - { - CurrentNode() - { - clear(); - } - - void clear() - { - p = NULL; - name = ""; - } - - QString name; - NLGEORGES::UFormElm *p; - }; - - CurrentNode m_currentNode; -}; - -#endif +#ifndef BROWSER_CTRL_PVT_H +#define BROWSER_CTRL_PVT_H + +#include + +namespace NLGEORGES +{ + class CFormElm; + class UFormElm; + class CFormElmStruct; +} + +namespace GeorgesQt +{ + class CFormItem; +} + +class QtVariantPropertyManager; +class QtVariantEditorFactory; +class QtTreePropertyBrowser; +class QVariant; +class QtProperty; + +class BrowserCtrlPvt : public QObject +{ + Q_OBJECT +public: + BrowserCtrlPvt( QObject *parent = NULL ); + ~BrowserCtrlPvt(); + + void clear(); + void setupNode( GeorgesQt::CFormItem *node ); + void onValueChanged( QtProperty *p, const QVariant &value ); + + QtVariantPropertyManager* manager() const{ return mgr; } + void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; } + void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } + +Q_SIGNALS: + void arrayResized( const QString &name, int size ); + void modified(); + void valueChanged( const QString &key, const QString &value ); + +private: + void setupStruct( NLGEORGES::UFormElm *node ); + void setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm ); + + void setupStruct( GeorgesQt::CFormItem *node ); + void setupArray( GeorgesQt::CFormItem *node ); + + void onStructValueChanged( QtProperty *p, const QVariant &value ); + void onArrayValueChanged( QtProperty *p, const QVariant &value ); + void createArray(); + + QtVariantPropertyManager *mgr; + QtVariantEditorFactory *factory; + QtTreePropertyBrowser *m_browser; + + QString m_currentNodeName; + NLGEORGES::CFormElm *m_rootNode; + + struct CurrentNode + { + CurrentNode() + { + clear(); + } + + void clear() + { + p = NULL; + name = ""; + } + + QString name; + NLGEORGES::UFormElm *p; + }; + + CurrentNode m_currentNode; +}; + +#endif diff --git a/code/studio/src/plugins/gui_editor/action_list.cpp b/code/studio/src/plugins/gui_editor/action_list.cpp index 8925e6d04..4cc30aecb 100644 --- a/code/studio/src/plugins/gui_editor/action_list.cpp +++ b/code/studio/src/plugins/gui_editor/action_list.cpp @@ -1,49 +1,49 @@ -#include "action_list.h" -#include "nel/gui/action_handler.h" -#include -#include - -ActionList::ActionList( QDialog *parent ) : -QDialog( parent ) -{ - setupUi( this ); -} - -ActionList::~ActionList() -{ -} - -void ActionList::load() -{ - actionList->clear(); - - NLGUI::CAHManager *am = NLGUI::CAHManager::getInstance(); - std::vector< std::string > handlers; - am->getActionHandlers( handlers ); - - std::vector< std::string >::const_iterator itr = handlers.begin(); - while( itr != handlers.end() ) - { - actionList->addItem( itr->c_str() ); - ++itr; - } -} - -void ActionList::accept() -{ - QListWidgetItem *item = actionList->currentItem(); - if( item == NULL ) - return; - - selectedAction = item->text(); - - QDialog::accept(); -} - -void ActionList::reject() -{ - selectedAction = ""; - - QDialog::reject(); -} - +#include "action_list.h" +#include "nel/gui/action_handler.h" +#include +#include + +ActionList::ActionList( QDialog *parent ) : +QDialog( parent ) +{ + setupUi( this ); +} + +ActionList::~ActionList() +{ +} + +void ActionList::load() +{ + actionList->clear(); + + NLGUI::CAHManager *am = NLGUI::CAHManager::getInstance(); + std::vector< std::string > handlers; + am->getActionHandlers( handlers ); + + std::vector< std::string >::const_iterator itr = handlers.begin(); + while( itr != handlers.end() ) + { + actionList->addItem( itr->c_str() ); + ++itr; + } +} + +void ActionList::accept() +{ + QListWidgetItem *item = actionList->currentItem(); + if( item == NULL ) + return; + + selectedAction = item->text(); + + QDialog::accept(); +} + +void ActionList::reject() +{ + selectedAction = ""; + + QDialog::reject(); +} + diff --git a/code/studio/src/plugins/gui_editor/action_list.h b/code/studio/src/plugins/gui_editor/action_list.h index 752d66467..f61e0d239 100644 --- a/code/studio/src/plugins/gui_editor/action_list.h +++ b/code/studio/src/plugins/gui_editor/action_list.h @@ -1,29 +1,29 @@ -#ifndef ACTION_LIST_H -#define ACTION_LIST_H - - -#include "ui_action_list.h" -#include - - -class ActionList : public QDialog, public Ui::ActionListDialog -{ - Q_OBJECT - -public: - ActionList( QDialog *parent = NULL ); - ~ActionList(); - void load(); - - QString getSelectedAction(){ return selectedAction; } - - -public Q_SLOTS: - void accept(); - void reject(); - -private: - QString selectedAction; -}; - -#endif +#ifndef ACTION_LIST_H +#define ACTION_LIST_H + + +#include "ui_action_list.h" +#include + + +class ActionList : public QDialog, public Ui::ActionListDialog +{ + Q_OBJECT + +public: + ActionList( QDialog *parent = NULL ); + ~ActionList(); + void load(); + + QString getSelectedAction(){ return selectedAction; } + + +public Q_SLOTS: + void accept(); + void reject(); + +private: + QString selectedAction; +}; + +#endif diff --git a/code/studio/src/plugins/tile_editor/CMakeLists.txt b/code/studio/src/plugins/tile_editor/CMakeLists.txt index 396522235..78cc5ef49 100644 --- a/code/studio/src/plugins/tile_editor/CMakeLists.txt +++ b/code/studio/src/plugins/tile_editor/CMakeLists.txt @@ -1,50 +1,50 @@ -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} - ${LIBXML2_INCLUDE_DIR} - ${QT_INCLUDES}) - -FILE(GLOB SRC *.cpp *.h) -SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.h - ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_manager.h - ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) - -SET(OVQT_TILE_EDITOR_PLUGIN_HDR - tile_model.h - tile_editor_main_window.h - tile_editor_plugin.h - land_edit_dialog.h) - -SET(OVQT_TILE_EDITOR_PLUGIN_UIS - tile_editor_main_window.ui - land_edit_dialog.ui) - -SET(OVQT_PLUG_TILE_EDITOR_RCS tile_editor.qrc) - -SET(QT_USE_QTGUI TRUE) -SET(QT_USE_QTOPENGL TRUE) - -QT4_WRAP_CPP(OVQT_TILE_EDITOR_PLUGIN_MOC_SRC ${OVQT_TILE_EDITOR_PLUGIN_HDR}) -QT4_ADD_RESOURCES( OVQT_PLUG_TILE_EDITOR_RC_SRCS ${OVQT_PLUG_TILE_EDITOR_RCS}) -QT4_WRAP_UI(OVQT_TILE_EDITOR_PLUGIN_UI_HDRS ${OVQT_TILE_EDITOR_PLUGIN_UIS}) - -SOURCE_GROUP(QtGeneratedUiHdr FILES ${OVQT_TILE_EDITOR_PLUGIN_UI_HDRS}) -SOURCE_GROUP(QtGeneratedMocSrc FILES ${OVQT_TILE_EDITOR_PLUGIN_MOC_SRC} ${OVQT_PLUG_TILE_EDITOR_RC_SRCS}) -SOURCE_GROUP("Tile Editor Plugin" FILES ${SRC}) -SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) - -ADD_LIBRARY(studio_plugin_tile_editor MODULE ${SRC} ${OVQT_TILE_EDITOR_PLUGIN_MOC_SRC} ${OVQT_PLUG_TILE_EDITOR_RC_SRCS} ${OVQT_EXT_SYS_SRC} ${OVQT_TILE_EDITOR_PLUGIN_UI_HDRS}) - -TARGET_LINK_LIBRARIES(studio_plugin_tile_editor studio_plugin_core nelmisc ${QT_LIBRARIES}) - -IF(WITH_STLPORT) - TARGET_LINK_LIBRARIES(studio_plugin_tile_editor ${CMAKE_THREAD_LIBS_INIT}) -ENDIF(WITH_STLPORT) - -NL_DEFAULT_PROPS(studio_plugin_tile_editor "Tools: Studio Plugin: Tile Editor") -NL_ADD_RUNTIME_FLAGS(studio_plugin_tile_editor) -NL_ADD_LIB_SUFFIX(studio_plugin_tile_editor) - -ADD_DEFINITIONS(${LIBXML2_DEFINITIONS} -DQT_PLUGIN -DQT_SHARED ${QT_DEFINITIONS}) - -INSTALL(TARGETS studio_plugin_tile_editor LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib COMPONENT tools3d) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/studio_plugin_tile_editor.xml DESTINATION ${OVQT_PLUGIN_SPECS_DIR} COMPONENT tools3d) +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${LIBXML2_INCLUDE_DIR} + ${QT_INCLUDES}) + +FILE(GLOB SRC *.cpp *.h) +SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_manager.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) + +SET(OVQT_TILE_EDITOR_PLUGIN_HDR + tile_model.h + tile_editor_main_window.h + tile_editor_plugin.h + land_edit_dialog.h) + +SET(OVQT_TILE_EDITOR_PLUGIN_UIS + tile_editor_main_window.ui + land_edit_dialog.ui) + +SET(OVQT_PLUG_TILE_EDITOR_RCS tile_editor.qrc) + +SET(QT_USE_QTGUI TRUE) +SET(QT_USE_QTOPENGL TRUE) + +QT4_WRAP_CPP(OVQT_TILE_EDITOR_PLUGIN_MOC_SRC ${OVQT_TILE_EDITOR_PLUGIN_HDR}) +QT4_ADD_RESOURCES( OVQT_PLUG_TILE_EDITOR_RC_SRCS ${OVQT_PLUG_TILE_EDITOR_RCS}) +QT4_WRAP_UI(OVQT_TILE_EDITOR_PLUGIN_UI_HDRS ${OVQT_TILE_EDITOR_PLUGIN_UIS}) + +SOURCE_GROUP(QtGeneratedUiHdr FILES ${OVQT_TILE_EDITOR_PLUGIN_UI_HDRS}) +SOURCE_GROUP(QtGeneratedMocSrc FILES ${OVQT_TILE_EDITOR_PLUGIN_MOC_SRC} ${OVQT_PLUG_TILE_EDITOR_RC_SRCS}) +SOURCE_GROUP("Tile Editor Plugin" FILES ${SRC}) +SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) + +ADD_LIBRARY(studio_plugin_tile_editor MODULE ${SRC} ${OVQT_TILE_EDITOR_PLUGIN_MOC_SRC} ${OVQT_PLUG_TILE_EDITOR_RC_SRCS} ${OVQT_EXT_SYS_SRC} ${OVQT_TILE_EDITOR_PLUGIN_UI_HDRS}) + +TARGET_LINK_LIBRARIES(studio_plugin_tile_editor studio_plugin_core nelmisc ${QT_LIBRARIES}) + +IF(WITH_STLPORT) + TARGET_LINK_LIBRARIES(studio_plugin_tile_editor ${CMAKE_THREAD_LIBS_INIT}) +ENDIF(WITH_STLPORT) + +NL_DEFAULT_PROPS(studio_plugin_tile_editor "Tools: Studio Plugin: Tile Editor") +NL_ADD_RUNTIME_FLAGS(studio_plugin_tile_editor) +NL_ADD_LIB_SUFFIX(studio_plugin_tile_editor) + +ADD_DEFINITIONS(${LIBXML2_DEFINITIONS} -DQT_PLUGIN -DQT_SHARED ${QT_DEFINITIONS}) + +INSTALL(TARGETS studio_plugin_tile_editor LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib COMPONENT tools3d) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/studio_plugin_tile_editor.xml DESTINATION ${OVQT_PLUGIN_SPECS_DIR} COMPONENT tools3d) diff --git a/code/studio/src/plugins/tile_editor/land_edit_dialog.cpp b/code/studio/src/plugins/tile_editor/land_edit_dialog.cpp index 40fbf3024..025e55730 100644 --- a/code/studio/src/plugins/tile_editor/land_edit_dialog.cpp +++ b/code/studio/src/plugins/tile_editor/land_edit_dialog.cpp @@ -1,105 +1,105 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#include "land_edit_dialog.h" - -LandEditDialog::LandEditDialog( QWidget *parent ) : -QDialog( parent ) -{ - setupUi( this ); - setupConnections(); -} - -LandEditDialog::~LandEditDialog() -{ -} - -void LandEditDialog::getSelectedTileSets( QStringList &l ) const -{ - int c = tilesetLV->count(); - for( int i = 0; i < c; i++ ) - { - l.push_back( tilesetLV->item( i )->text() ); - } -} - -void LandEditDialog::setSelectedTileSets( QStringList &l ) -{ - tilesetLV->clear(); - - QStringListIterator itr( l ); - while( itr.hasNext() ) - { - tilesetLV->addItem( itr.next() ); - } -} - -void LandEditDialog::setTileSets( const QStringList &l ) -{ - tilesetCB->clear(); - - QStringListIterator itr( l ); - while( itr.hasNext() ) - { - tilesetCB->addItem( itr.next() ); - } -} - -void LandEditDialog::setupConnections() -{ - connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOkClicked() ) ); - connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) ); - connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); - connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); -} - -void LandEditDialog::onOkClicked() -{ - accept(); -} - -void LandEditDialog::onCancelClicked() -{ - reject(); -} - -void LandEditDialog::onAddClicked() -{ - if( tilesetCB->currentIndex() < 0 ) - return; - - QString text = tilesetCB->currentText(); - - int c = tilesetLV->count(); - for( int i = 0; i < c; i++ ) - { - if( text == tilesetLV->item( i )->text() ) - return; - } - - tilesetLV->addItem( text ); -} - -void LandEditDialog::onRemoveClicked() -{ - if( tilesetLV->currentItem() == NULL ) - return; - - QListWidgetItem *item = tilesetLV->currentItem(); - delete item; -} - +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "land_edit_dialog.h" + +LandEditDialog::LandEditDialog( QWidget *parent ) : +QDialog( parent ) +{ + setupUi( this ); + setupConnections(); +} + +LandEditDialog::~LandEditDialog() +{ +} + +void LandEditDialog::getSelectedTileSets( QStringList &l ) const +{ + int c = tilesetLV->count(); + for( int i = 0; i < c; i++ ) + { + l.push_back( tilesetLV->item( i )->text() ); + } +} + +void LandEditDialog::setSelectedTileSets( QStringList &l ) +{ + tilesetLV->clear(); + + QStringListIterator itr( l ); + while( itr.hasNext() ) + { + tilesetLV->addItem( itr.next() ); + } +} + +void LandEditDialog::setTileSets( const QStringList &l ) +{ + tilesetCB->clear(); + + QStringListIterator itr( l ); + while( itr.hasNext() ) + { + tilesetCB->addItem( itr.next() ); + } +} + +void LandEditDialog::setupConnections() +{ + connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOkClicked() ) ); + connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) ); + connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); + connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); +} + +void LandEditDialog::onOkClicked() +{ + accept(); +} + +void LandEditDialog::onCancelClicked() +{ + reject(); +} + +void LandEditDialog::onAddClicked() +{ + if( tilesetCB->currentIndex() < 0 ) + return; + + QString text = tilesetCB->currentText(); + + int c = tilesetLV->count(); + for( int i = 0; i < c; i++ ) + { + if( text == tilesetLV->item( i )->text() ) + return; + } + + tilesetLV->addItem( text ); +} + +void LandEditDialog::onRemoveClicked() +{ + if( tilesetLV->currentItem() == NULL ) + return; + + QListWidgetItem *item = tilesetLV->currentItem(); + delete item; +} + diff --git a/code/studio/src/plugins/tile_editor/land_edit_dialog.h b/code/studio/src/plugins/tile_editor/land_edit_dialog.h index ac3762b46..3873c6df5 100644 --- a/code/studio/src/plugins/tile_editor/land_edit_dialog.h +++ b/code/studio/src/plugins/tile_editor/land_edit_dialog.h @@ -1,51 +1,51 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#ifndef LAND_EDIT_DLG_H -#define LAND_EDIT_DLG_H - - -#include "ui_land_edit_dialog.h" -#include - -class LandEditDialog : public QDialog, public Ui::LandEditDialog -{ - Q_OBJECT -public: - LandEditDialog( QWidget *parent = NULL ); - ~LandEditDialog(); - - void getSelectedTileSets( QStringList &l ) const; - void setSelectedTileSets( QStringList &l ); - - void setTileSets( const QStringList &l ); - -private: - void setupConnections(); - - -private Q_SLOTS: - void onOkClicked(); - void onCancelClicked(); - void onAddClicked(); - void onRemoveClicked(); - -}; - - -#endif - +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef LAND_EDIT_DLG_H +#define LAND_EDIT_DLG_H + + +#include "ui_land_edit_dialog.h" +#include + +class LandEditDialog : public QDialog, public Ui::LandEditDialog +{ + Q_OBJECT +public: + LandEditDialog( QWidget *parent = NULL ); + ~LandEditDialog(); + + void getSelectedTileSets( QStringList &l ) const; + void setSelectedTileSets( QStringList &l ); + + void setTileSets( const QStringList &l ); + +private: + void setupConnections(); + + +private Q_SLOTS: + void onOkClicked(); + void onCancelClicked(); + void onAddClicked(); + void onRemoveClicked(); + +}; + + +#endif + diff --git a/code/studio/src/plugins/tile_editor/studio_plugin_tile_editor.xml b/code/studio/src/plugins/tile_editor/studio_plugin_tile_editor.xml index d69201f9b..0e5727896 100644 --- a/code/studio/src/plugins/tile_editor/studio_plugin_tile_editor.xml +++ b/code/studio/src/plugins/tile_editor/studio_plugin_tile_editor.xml @@ -1,10 +1,10 @@ - - studio_plugin_tile_editor - TileEditor - 1.0 - Ryzom Core - Tile bank editing plugin. - - - + + studio_plugin_tile_editor + TileEditor + 1.0 + Ryzom Core + Tile bank editing plugin. + + + \ No newline at end of file diff --git a/code/studio/src/plugins/tile_editor/tile_bank.cpp b/code/studio/src/plugins/tile_editor/tile_bank.cpp index 8e4d8f511..8e3578eeb 100644 --- a/code/studio/src/plugins/tile_editor/tile_bank.cpp +++ b/code/studio/src/plugins/tile_editor/tile_bank.cpp @@ -1,642 +1,642 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#include "tile_bank.h" -#include "nel/3d/tile_bank.h" - -#include - -namespace{ - - bool pixmapToCBGRA( QPixmap &pixmap, std::vector< NLMISC::CBGRA >& pixels ) - { - QImage img = pixmap.toImage(); - if( img.format() != QImage::Format_ARGB32 ) - img = img.convertToFormat( QImage::Format_ARGB32 ); - - if( img.format() != QImage::Format_ARGB32 ) - return false; - - int c = img.width() * img.height(); - - const unsigned char *data = img.bits(); - const unsigned int *idata = reinterpret_cast< const unsigned int* >( data ); - - NLMISC::CBGRA bgra; - pixels.clear(); - - int i = 0; - while( i < c ) - { - bgra.A = ( idata[ i ] & 0xFF000000 ) >> 24; - bgra.R = ( idata[ i ] & 0x00FF0000 ) >> 16; - bgra.G = ( idata[ i ] & 0x0000FF00 ) >> 8; - bgra.B = ( idata[ i ] & 0x000000FF ); - pixels.push_back( bgra ); - - i++; - } - - return true; - } - - - NL3D::CTile::TBitmap channelToTBitmap( TileConstants::TTileChannel channel ) - { - return NL3D::CTile::TBitmap( int( channel ) ); - } - - -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -class TileBankPvt -{ -public: - - bool checkSize( TileConstants::TNodeTileType type, TileConstants::TTileChannel channel, int w, int h ) - { - int width = -1; - - switch( type ) - { - case TileConstants::Tile128: - width = 128; - break; - - case TileConstants::Tile256: - width = 256; - break; - - case TileConstants::TileTransition: - { - if( channel == TileConstants::TileAlpha ) - width = 64; - else - width = 128; - - } - break; - - case TileConstants::TileDisplacement: - width = 32; - break; - } - - if( width == w ) - return true; - - return false; - } - - NL3D::CTileSet::TError checkTile( NL3D::CTileSet *set, int tile, TileConstants::TNodeTileType type, NL3D::CTileBorder &border, NL3D::CTile::TBitmap bitmap, QString &msg ) - { - NL3D::CTileSet::TError error; - - if( bitmap == NL3D::CTile::additive ) - return NL3D::CTileSet::ok; - - if( type == TileConstants::TileDisplacement ) - return NL3D::CTileSet::ok; - - int component; - int pixel; - int idx; - - switch( type ) - { - case TileConstants::Tile128: - error = set->checkTile128( bitmap, border, pixel, component ); - break; - - case TileConstants::Tile256: - error = set->checkTile256( bitmap, border, pixel, component ); - break; - - case TileConstants::TileTransition: - { - if( bitmap != NL3D::CTile::alpha ) - error = set->checkTile128( bitmap, border, pixel, component ); - else - error = set->checkTileTransition( NL3D::CTileSet::TTransition( tile ), bitmap, border, idx, pixel, component ); - - break; - } - } - - if( ( error != NL3D::CTileSet::ok ) && ( error != NL3D::CTileSet::addFirstA128128 ) ) - { - static const char* comp[]={"Red", "Green", "Blue", "Alpha", ""}; - - msg = NL3D::CTileSet::getErrorMessage( error ); - msg += "\n"; - msg += " pixel %1 component %2"; - msg = msg.arg( pixel ); - msg = msg.arg( comp[ component ] ); - } - - return error; - } - - void setTile( NL3D::CTileSet *set, int tile, int rotation, const QString &name, NL3D::CTile::TBitmap bm, TileConstants::TNodeTileType type, NL3D::CTileBorder &border ) - { - switch( type ) - { - case TileConstants::Tile128: - set->setTile128( tile, name.toUtf8().constData(), bm, m_bank ); - break; - - case TileConstants::Tile256: - set->setTile256( tile, name.toUtf8().constData(), bm, m_bank ); - break; - - case TileConstants::TileTransition: - if( bm != NL3D::CTile::alpha ) - set->setTileTransition( NL3D::CTileSet::TTransition( tile ), name.toUtf8().constData(), bm, m_bank, border ); - else - set->setTileTransitionAlpha( NL3D::CTileSet::TTransition( tile ), name.toUtf8().constData(), m_bank, border, rotation ); - break; - - case TileConstants::TileDisplacement: - set->setDisplacement( NL3D::CTileSet::TDisplacement( tile ), name.toUtf8().constData(), m_bank ); - break; - } - - } - - void buildBorder( QPixmap &pm, NL3D::CTileBorder &border ) - { - std::vector< NLMISC::CBGRA > pixels; - pixmapToCBGRA( pm, pixels ); - border.set( pm.width(), pm.height(), pixels ); - } - - NL3D::CTileBank m_bank; -}; - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -TileBank::TileBank() -{ - m_pvt = new TileBankPvt(); - resetError(); - m_rotation = 0; -} - -TileBank::~TileBank() -{ - delete m_pvt; -} - -void TileBank::addTileSet( const QString &name ) -{ - m_pvt->m_bank.addTileSet( name.toUtf8().constData() ); - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( 0 ); -} - -void TileBank::removeTileSet( int idx ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( idx ); - if( set == NULL ) - return; - - int c = m_pvt->m_bank.getLandCount(); - for( int i = 0; i < c; i++ ) - { - NL3D::CTileLand *land = m_pvt->m_bank.getLand( i ); - land->removeTileSet( set->getName() ); - } - - m_pvt->m_bank.removeTileSet( idx ); -} - -void TileBank::renameTileSet( int idx, const QString &newName ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( idx ); - if( set == NULL ) - return; - - std::string oldName = set->getName(); - set->setName( newName.toUtf8().constData() ); - - int c = m_pvt->m_bank.getLandCount(); - for( int i = 0; i < c; i++ ) - { - NL3D::CTileLand *land = m_pvt->m_bank.getLand( i ); - land->removeTileSet( oldName ); - land->addTileSet( newName.toUtf8().constData() ); - } - -} - -void TileBank::getTileSets( QStringList &l ) -{ - int c = m_pvt->m_bank.getTileSetCount(); - for( int i = 0; i < c; i++ ) - { - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( i ); - l.push_back( set->getName().c_str() ); - } -} - -void TileBank::addLand( const QString &name ) -{ - m_pvt->m_bank.addLand( name.toUtf8().constData() ); -} - -void TileBank::removeLand( int idx ) -{ - m_pvt->m_bank.removeLand( idx ); -} - -void TileBank::getLands( QStringList &l ) -{ - l.clear(); - - int c = m_pvt->m_bank.getLandCount(); - for( int i = 0; i < c; i++ ) - { - NL3D::CTileLand *land = m_pvt->m_bank.getLand( i ); - l.push_back( land->getName().c_str() ); - } -} - -void TileBank::setLandSets( int idx, const QStringList &l ) -{ - NL3D::CTileLand *land = m_pvt->m_bank.getLand( idx ); - land->clear(); - - QStringListIterator itr( l ); - while( itr.hasNext() ) - { - land->addTileSet( itr.next().toUtf8().constData() ); - } -} - -void TileBank::getLandSets( int idx, QStringList &l ) -{ - NL3D::CTileLand *land = m_pvt->m_bank.getLand( idx ); - if( land == NULL ) - return; - - l.clear(); - - std::set< std::string> sets = land->getTileSets(); - std::set< std::string >::const_iterator itr = sets.begin(); - while( itr != sets.end() ) - { - l.push_back( itr->c_str() ); - ++itr; - } -} - -bool TileBank::addTile( int setIdx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type ) -{ - resetError(); - - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( setIdx ); - - int tile; - switch( type ) - { - case TileConstants::Tile128: set->addTile128( tile, m_pvt->m_bank ); break; - case TileConstants::Tile256: set->addTile256( tile, m_pvt->m_bank ); break; - } - - bool b = setTile( setIdx, tile, name, pixmap, channel, type ); - if( b ) - return true; - - // There was an error, roll back - switch( type ) - { - case TileConstants::Tile128: set->removeTile128( tile, m_pvt->m_bank ); break; - case TileConstants::Tile256: set->removeTile256( tile, m_pvt->m_bank ); break; - } - - return false; -} - -void TileBank::removeTile( int ts, int type, int tile ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( ts ); - - switch( type ) - { - case TileConstants::Tile128: set->removeTile128( tile, m_pvt->m_bank ); break; - case TileConstants::Tile256: set->removeTile256( tile, m_pvt->m_bank ); break; - } -} - -bool TileBank::setTile( int tileset, int tile, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type ) -{ - resetError(); - - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileset ); - if( set == NULL ) - return false; - - QPixmap pm = pixmap.value< QPixmap >(); - if( pm.isNull() ) - { - m_hasError = true; - m_lastError = "Failed to load image."; - return false; - } - - if( pm.width() != pm.height() ) - { - m_hasError = true; - m_lastError = "Image isn't square."; - return false; - } - - if( !m_pvt->checkSize( type, channel, pm.width(), pm.height() ) ) - { - m_hasError = true; - m_lastError = "Invalid image size."; - return false; - } - - NL3D::CTileBorder border; - m_pvt->buildBorder( pm, border ); - - if( ( type == TileConstants::TileTransition ) && ( channel == TileConstants::TileAlpha ) ) - { - int rotBits = m_rotation; - while( rotBits > 0 ) - { - border.rotate(); - rotBits--; - } - } - - QString msg; - NL3D::CTileSet::TError error = m_pvt->checkTile( set, tile, type, border, channelToTBitmap( channel ), msg ); - - // Tile checks out fine, set it - if( ( error == NL3D::CTileSet::ok ) || ( error == NL3D::CTileSet::addFirstA128128 ) ) - { - if( error == NL3D::CTileSet::addFirstA128128 ) - set->setBorder( channelToTBitmap( channel ), border ); - - m_pvt->setTile( set, tile, m_rotation, name, channelToTBitmap( channel ), type, border ); - - return true; - } - - setError( msg ); - - return false; -} - -void TileBank::replaceImage( int ts, int type, int tile, TileConstants::TTileChannel channel, const QString &name, const QVariant &pixmap ) -{ - setTile( ts, tile, name, pixmap, channel, TileConstants::TNodeTileType( type ) ); -} - -void TileBank::clearImage( int ts, int type, int tile, TileConstants::TTileChannel channel ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( ts ); - - int tileId; - - NL3D::CTile::TBitmap bm = channelToTBitmap( channel ); - - switch( type ) - { - case TileConstants::Tile128: - set->clearTile128( tile, bm, m_pvt->m_bank ); - break; - - case TileConstants::Tile256: - set->clearTile256( tile, bm, m_pvt->m_bank ); - break; - - case TileConstants::TileTransition: - set->clearTransition( NL3D::CTileSet::TTransition( tile ), bm, m_pvt->m_bank ); - break; - - case TileConstants::TileDisplacement: - set->clearDisplacement( NL3D::CTileSet::TDisplacement( tile ), m_pvt->m_bank ); - break; - } - -} - -int TileBank::getTileCount( int tileSet, TileConstants::TNodeTileType type ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return -1; - - int c = 0; - - switch( type ) - { - case TileConstants::Tile128: - c = set->getNumTile128(); - break; - - case TileConstants::Tile256: - c = set->getNumTile256(); - break; - - case TileConstants::TileTransition: - c = NL3D::CTileSet::count; - break; - - case TileConstants::TileDisplacement: - c = NL3D::CTileSet::CountDisplace; - break; - } - - return c; -} - -int TileBank::getRealTileId( int tileSet, TileConstants::TNodeTileType type, int tileIdInSet ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return -1; - - int tile = -1; - - switch( type ) - { - case TileConstants::Tile128: - tile = set->getTile128( tileIdInSet ); - break; - - case TileConstants::Tile256: - tile = set->getTile256( tileIdInSet ); - break; - - case TileConstants::TileTransition: - tile = set->getTransition( tileIdInSet )->getTile(); - break; - - case TileConstants::TileDisplacement: - tile = set->getDisplacementTile( NL3D::CTileSet::TDisplacement( tileIdInSet ) ); - break; - } - - return tile; -} - -void TileBank::getTileImages( int tileSet, TileConstants::TNodeTileType type, int tileId, TileImages &images ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return; - - switch( type ) - { - case TileConstants::Tile128: - case TileConstants::Tile256: - case TileConstants::TileTransition: - { - NL3D::CTile *t = m_pvt->m_bank.getTile( tileId ); - if( t == NULL ) - return; - - images.diffuse = t->getFileName( channelToTBitmap( TileConstants::TileDiffuse ) ).c_str(); - images.additive = t->getFileName( channelToTBitmap( TileConstants::TileAdditive ) ).c_str(); - images.alpha = t->getFileName( channelToTBitmap( TileConstants::TileAlpha ) ).c_str(); - } - break; - - case TileConstants::TileDisplacement: - { - images.diffuse = m_pvt->m_bank.getDisplacementMap( tileId ); - } - break; - } - -} - -void TileBank::getTileImages( int tileSet, TileConstants::TNodeTileType type, QList< TileImages > &l ) -{ - l.clear(); - - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return; - - int c = getTileCount( tileSet, type ); - - TileImages images; - - for( int i = 0; i < c; i++ ) - { - images.clear(); - - int id = getRealTileId( tileSet, type, i ); - if( id < 0 ) - { - l.push_back( images ); - continue; - } - - getTileImages( tileSet, type, id, images ); - - l.push_back( images ); - } - -} - -void TileBank::setVegetation( int tileSet, const QString &vegetation ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return; - - set->setTileVegetableDescFileName( vegetation.toUtf8().constData() ); -} - - -QString TileBank::getVegetation( int tileSet ) const -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return ""; - - return set->getTileVegetableDescFileName().c_str(); -} - -void TileBank::setOriented( int tileSet, bool b ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return; - - set->setOriented( b ); -} - -bool TileBank::getOriented( int tileSet ) const -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return false; - - return set->getOriented(); -} - - -void TileBank::setSurfaceData( int tileSet, unsigned long data ) -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return; - - set->SurfaceData = data; -} - -unsigned long TileBank::getSurfaceData( int tileSet ) const -{ - NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); - if( set == NULL ) - return 0; - - return set->SurfaceData; -} - -void TileBank::setTexturePath( const QString &path ) -{ - m_pvt->m_bank.setAbsPath( path.toUtf8().constData() ); -} - -QString TileBank::getTexturePath() const -{ - return m_pvt->m_bank.getAbsPath().c_str(); -} - -void TileBank::setRotation( int rotation ) -{ - m_rotation = rotation; -} - -void TileBank::serial( NLMISC::IStream &f ) -{ - m_pvt->m_bank.serial( f ); -} - - +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "tile_bank.h" +#include "nel/3d/tile_bank.h" + +#include + +namespace{ + + bool pixmapToCBGRA( QPixmap &pixmap, std::vector< NLMISC::CBGRA >& pixels ) + { + QImage img = pixmap.toImage(); + if( img.format() != QImage::Format_ARGB32 ) + img = img.convertToFormat( QImage::Format_ARGB32 ); + + if( img.format() != QImage::Format_ARGB32 ) + return false; + + int c = img.width() * img.height(); + + const unsigned char *data = img.bits(); + const unsigned int *idata = reinterpret_cast< const unsigned int* >( data ); + + NLMISC::CBGRA bgra; + pixels.clear(); + + int i = 0; + while( i < c ) + { + bgra.A = ( idata[ i ] & 0xFF000000 ) >> 24; + bgra.R = ( idata[ i ] & 0x00FF0000 ) >> 16; + bgra.G = ( idata[ i ] & 0x0000FF00 ) >> 8; + bgra.B = ( idata[ i ] & 0x000000FF ); + pixels.push_back( bgra ); + + i++; + } + + return true; + } + + + NL3D::CTile::TBitmap channelToTBitmap( TileConstants::TTileChannel channel ) + { + return NL3D::CTile::TBitmap( int( channel ) ); + } + + +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +class TileBankPvt +{ +public: + + bool checkSize( TileConstants::TNodeTileType type, TileConstants::TTileChannel channel, int w, int h ) + { + int width = -1; + + switch( type ) + { + case TileConstants::Tile128: + width = 128; + break; + + case TileConstants::Tile256: + width = 256; + break; + + case TileConstants::TileTransition: + { + if( channel == TileConstants::TileAlpha ) + width = 64; + else + width = 128; + + } + break; + + case TileConstants::TileDisplacement: + width = 32; + break; + } + + if( width == w ) + return true; + + return false; + } + + NL3D::CTileSet::TError checkTile( NL3D::CTileSet *set, int tile, TileConstants::TNodeTileType type, NL3D::CTileBorder &border, NL3D::CTile::TBitmap bitmap, QString &msg ) + { + NL3D::CTileSet::TError error; + + if( bitmap == NL3D::CTile::additive ) + return NL3D::CTileSet::ok; + + if( type == TileConstants::TileDisplacement ) + return NL3D::CTileSet::ok; + + int component; + int pixel; + int idx; + + switch( type ) + { + case TileConstants::Tile128: + error = set->checkTile128( bitmap, border, pixel, component ); + break; + + case TileConstants::Tile256: + error = set->checkTile256( bitmap, border, pixel, component ); + break; + + case TileConstants::TileTransition: + { + if( bitmap != NL3D::CTile::alpha ) + error = set->checkTile128( bitmap, border, pixel, component ); + else + error = set->checkTileTransition( NL3D::CTileSet::TTransition( tile ), bitmap, border, idx, pixel, component ); + + break; + } + } + + if( ( error != NL3D::CTileSet::ok ) && ( error != NL3D::CTileSet::addFirstA128128 ) ) + { + static const char* comp[]={"Red", "Green", "Blue", "Alpha", ""}; + + msg = NL3D::CTileSet::getErrorMessage( error ); + msg += "\n"; + msg += " pixel %1 component %2"; + msg = msg.arg( pixel ); + msg = msg.arg( comp[ component ] ); + } + + return error; + } + + void setTile( NL3D::CTileSet *set, int tile, int rotation, const QString &name, NL3D::CTile::TBitmap bm, TileConstants::TNodeTileType type, NL3D::CTileBorder &border ) + { + switch( type ) + { + case TileConstants::Tile128: + set->setTile128( tile, name.toUtf8().constData(), bm, m_bank ); + break; + + case TileConstants::Tile256: + set->setTile256( tile, name.toUtf8().constData(), bm, m_bank ); + break; + + case TileConstants::TileTransition: + if( bm != NL3D::CTile::alpha ) + set->setTileTransition( NL3D::CTileSet::TTransition( tile ), name.toUtf8().constData(), bm, m_bank, border ); + else + set->setTileTransitionAlpha( NL3D::CTileSet::TTransition( tile ), name.toUtf8().constData(), m_bank, border, rotation ); + break; + + case TileConstants::TileDisplacement: + set->setDisplacement( NL3D::CTileSet::TDisplacement( tile ), name.toUtf8().constData(), m_bank ); + break; + } + + } + + void buildBorder( QPixmap &pm, NL3D::CTileBorder &border ) + { + std::vector< NLMISC::CBGRA > pixels; + pixmapToCBGRA( pm, pixels ); + border.set( pm.width(), pm.height(), pixels ); + } + + NL3D::CTileBank m_bank; +}; + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +TileBank::TileBank() +{ + m_pvt = new TileBankPvt(); + resetError(); + m_rotation = 0; +} + +TileBank::~TileBank() +{ + delete m_pvt; +} + +void TileBank::addTileSet( const QString &name ) +{ + m_pvt->m_bank.addTileSet( name.toUtf8().constData() ); + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( 0 ); +} + +void TileBank::removeTileSet( int idx ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( idx ); + if( set == NULL ) + return; + + int c = m_pvt->m_bank.getLandCount(); + for( int i = 0; i < c; i++ ) + { + NL3D::CTileLand *land = m_pvt->m_bank.getLand( i ); + land->removeTileSet( set->getName() ); + } + + m_pvt->m_bank.removeTileSet( idx ); +} + +void TileBank::renameTileSet( int idx, const QString &newName ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( idx ); + if( set == NULL ) + return; + + std::string oldName = set->getName(); + set->setName( newName.toUtf8().constData() ); + + int c = m_pvt->m_bank.getLandCount(); + for( int i = 0; i < c; i++ ) + { + NL3D::CTileLand *land = m_pvt->m_bank.getLand( i ); + land->removeTileSet( oldName ); + land->addTileSet( newName.toUtf8().constData() ); + } + +} + +void TileBank::getTileSets( QStringList &l ) +{ + int c = m_pvt->m_bank.getTileSetCount(); + for( int i = 0; i < c; i++ ) + { + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( i ); + l.push_back( set->getName().c_str() ); + } +} + +void TileBank::addLand( const QString &name ) +{ + m_pvt->m_bank.addLand( name.toUtf8().constData() ); +} + +void TileBank::removeLand( int idx ) +{ + m_pvt->m_bank.removeLand( idx ); +} + +void TileBank::getLands( QStringList &l ) +{ + l.clear(); + + int c = m_pvt->m_bank.getLandCount(); + for( int i = 0; i < c; i++ ) + { + NL3D::CTileLand *land = m_pvt->m_bank.getLand( i ); + l.push_back( land->getName().c_str() ); + } +} + +void TileBank::setLandSets( int idx, const QStringList &l ) +{ + NL3D::CTileLand *land = m_pvt->m_bank.getLand( idx ); + land->clear(); + + QStringListIterator itr( l ); + while( itr.hasNext() ) + { + land->addTileSet( itr.next().toUtf8().constData() ); + } +} + +void TileBank::getLandSets( int idx, QStringList &l ) +{ + NL3D::CTileLand *land = m_pvt->m_bank.getLand( idx ); + if( land == NULL ) + return; + + l.clear(); + + std::set< std::string> sets = land->getTileSets(); + std::set< std::string >::const_iterator itr = sets.begin(); + while( itr != sets.end() ) + { + l.push_back( itr->c_str() ); + ++itr; + } +} + +bool TileBank::addTile( int setIdx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type ) +{ + resetError(); + + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( setIdx ); + + int tile; + switch( type ) + { + case TileConstants::Tile128: set->addTile128( tile, m_pvt->m_bank ); break; + case TileConstants::Tile256: set->addTile256( tile, m_pvt->m_bank ); break; + } + + bool b = setTile( setIdx, tile, name, pixmap, channel, type ); + if( b ) + return true; + + // There was an error, roll back + switch( type ) + { + case TileConstants::Tile128: set->removeTile128( tile, m_pvt->m_bank ); break; + case TileConstants::Tile256: set->removeTile256( tile, m_pvt->m_bank ); break; + } + + return false; +} + +void TileBank::removeTile( int ts, int type, int tile ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( ts ); + + switch( type ) + { + case TileConstants::Tile128: set->removeTile128( tile, m_pvt->m_bank ); break; + case TileConstants::Tile256: set->removeTile256( tile, m_pvt->m_bank ); break; + } +} + +bool TileBank::setTile( int tileset, int tile, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type ) +{ + resetError(); + + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileset ); + if( set == NULL ) + return false; + + QPixmap pm = pixmap.value< QPixmap >(); + if( pm.isNull() ) + { + m_hasError = true; + m_lastError = "Failed to load image."; + return false; + } + + if( pm.width() != pm.height() ) + { + m_hasError = true; + m_lastError = "Image isn't square."; + return false; + } + + if( !m_pvt->checkSize( type, channel, pm.width(), pm.height() ) ) + { + m_hasError = true; + m_lastError = "Invalid image size."; + return false; + } + + NL3D::CTileBorder border; + m_pvt->buildBorder( pm, border ); + + if( ( type == TileConstants::TileTransition ) && ( channel == TileConstants::TileAlpha ) ) + { + int rotBits = m_rotation; + while( rotBits > 0 ) + { + border.rotate(); + rotBits--; + } + } + + QString msg; + NL3D::CTileSet::TError error = m_pvt->checkTile( set, tile, type, border, channelToTBitmap( channel ), msg ); + + // Tile checks out fine, set it + if( ( error == NL3D::CTileSet::ok ) || ( error == NL3D::CTileSet::addFirstA128128 ) ) + { + if( error == NL3D::CTileSet::addFirstA128128 ) + set->setBorder( channelToTBitmap( channel ), border ); + + m_pvt->setTile( set, tile, m_rotation, name, channelToTBitmap( channel ), type, border ); + + return true; + } + + setError( msg ); + + return false; +} + +void TileBank::replaceImage( int ts, int type, int tile, TileConstants::TTileChannel channel, const QString &name, const QVariant &pixmap ) +{ + setTile( ts, tile, name, pixmap, channel, TileConstants::TNodeTileType( type ) ); +} + +void TileBank::clearImage( int ts, int type, int tile, TileConstants::TTileChannel channel ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( ts ); + + int tileId; + + NL3D::CTile::TBitmap bm = channelToTBitmap( channel ); + + switch( type ) + { + case TileConstants::Tile128: + set->clearTile128( tile, bm, m_pvt->m_bank ); + break; + + case TileConstants::Tile256: + set->clearTile256( tile, bm, m_pvt->m_bank ); + break; + + case TileConstants::TileTransition: + set->clearTransition( NL3D::CTileSet::TTransition( tile ), bm, m_pvt->m_bank ); + break; + + case TileConstants::TileDisplacement: + set->clearDisplacement( NL3D::CTileSet::TDisplacement( tile ), m_pvt->m_bank ); + break; + } + +} + +int TileBank::getTileCount( int tileSet, TileConstants::TNodeTileType type ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return -1; + + int c = 0; + + switch( type ) + { + case TileConstants::Tile128: + c = set->getNumTile128(); + break; + + case TileConstants::Tile256: + c = set->getNumTile256(); + break; + + case TileConstants::TileTransition: + c = NL3D::CTileSet::count; + break; + + case TileConstants::TileDisplacement: + c = NL3D::CTileSet::CountDisplace; + break; + } + + return c; +} + +int TileBank::getRealTileId( int tileSet, TileConstants::TNodeTileType type, int tileIdInSet ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return -1; + + int tile = -1; + + switch( type ) + { + case TileConstants::Tile128: + tile = set->getTile128( tileIdInSet ); + break; + + case TileConstants::Tile256: + tile = set->getTile256( tileIdInSet ); + break; + + case TileConstants::TileTransition: + tile = set->getTransition( tileIdInSet )->getTile(); + break; + + case TileConstants::TileDisplacement: + tile = set->getDisplacementTile( NL3D::CTileSet::TDisplacement( tileIdInSet ) ); + break; + } + + return tile; +} + +void TileBank::getTileImages( int tileSet, TileConstants::TNodeTileType type, int tileId, TileImages &images ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return; + + switch( type ) + { + case TileConstants::Tile128: + case TileConstants::Tile256: + case TileConstants::TileTransition: + { + NL3D::CTile *t = m_pvt->m_bank.getTile( tileId ); + if( t == NULL ) + return; + + images.diffuse = t->getFileName( channelToTBitmap( TileConstants::TileDiffuse ) ).c_str(); + images.additive = t->getFileName( channelToTBitmap( TileConstants::TileAdditive ) ).c_str(); + images.alpha = t->getFileName( channelToTBitmap( TileConstants::TileAlpha ) ).c_str(); + } + break; + + case TileConstants::TileDisplacement: + { + images.diffuse = m_pvt->m_bank.getDisplacementMap( tileId ); + } + break; + } + +} + +void TileBank::getTileImages( int tileSet, TileConstants::TNodeTileType type, QList< TileImages > &l ) +{ + l.clear(); + + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return; + + int c = getTileCount( tileSet, type ); + + TileImages images; + + for( int i = 0; i < c; i++ ) + { + images.clear(); + + int id = getRealTileId( tileSet, type, i ); + if( id < 0 ) + { + l.push_back( images ); + continue; + } + + getTileImages( tileSet, type, id, images ); + + l.push_back( images ); + } + +} + +void TileBank::setVegetation( int tileSet, const QString &vegetation ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return; + + set->setTileVegetableDescFileName( vegetation.toUtf8().constData() ); +} + + +QString TileBank::getVegetation( int tileSet ) const +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return ""; + + return set->getTileVegetableDescFileName().c_str(); +} + +void TileBank::setOriented( int tileSet, bool b ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return; + + set->setOriented( b ); +} + +bool TileBank::getOriented( int tileSet ) const +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return false; + + return set->getOriented(); +} + + +void TileBank::setSurfaceData( int tileSet, unsigned long data ) +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return; + + set->SurfaceData = data; +} + +unsigned long TileBank::getSurfaceData( int tileSet ) const +{ + NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileSet ); + if( set == NULL ) + return 0; + + return set->SurfaceData; +} + +void TileBank::setTexturePath( const QString &path ) +{ + m_pvt->m_bank.setAbsPath( path.toUtf8().constData() ); +} + +QString TileBank::getTexturePath() const +{ + return m_pvt->m_bank.getAbsPath().c_str(); +} + +void TileBank::setRotation( int rotation ) +{ + m_rotation = rotation; +} + +void TileBank::serial( NLMISC::IStream &f ) +{ + m_pvt->m_bank.serial( f ); +} + + diff --git a/code/studio/src/plugins/tile_editor/tile_bank.h b/code/studio/src/plugins/tile_editor/tile_bank.h index a4620ad41..9d765b8ae 100644 --- a/code/studio/src/plugins/tile_editor/tile_bank.h +++ b/code/studio/src/plugins/tile_editor/tile_bank.h @@ -1,102 +1,102 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#ifndef TILE_BANK_H -#define TILE_BANK_H - -#include -#include -#include -#include - -#include "tile_constants.h" -#include "tile_images.h" - -namespace NLMISC -{ - class IStream; -} - -class TileBankPvt; - -class TileBank -{ -public: - TileBank(); - ~TileBank(); - - void addTileSet( const QString &name ); - void removeTileSet( int idx ); - void renameTileSet( int idx, const QString &newName ); - void getTileSets( QStringList &l ); - - void addLand( const QString &name ); - void removeLand( int idx ); - void getLands( QStringList &l ); - void setLandSets( int idx, const QStringList &l ); - void getLandSets( int idx, QStringList &l ); - - bool addTile( int setIdx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type ); - void removeTile( int ts, int type, int tile ); - bool setTile( int tileset, int tile, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type ); - void replaceImage( int ts, int type, int tile, TileConstants::TTileChannel channel, const QString &name, const QVariant &pixmap ); - void clearImage( int ts, int type, int tile, TileConstants::TTileChannel channel ); - - - int getTileCount( int tileSet, TileConstants::TNodeTileType type ); - int getRealTileId( int tileSet, TileConstants::TNodeTileType type, int tileIdInSet ); - void getTileImages( int tileSet, TileConstants::TNodeTileType type, int tileId, TileImages &images ); - void getTileImages( int tileSet, TileConstants::TNodeTileType type, QList< TileImages > &l ); - - void setVegetation( int tileSet, const QString &vegetation ); - QString getVegetation( int tileSet ) const; - - void setOriented( int tileSet, bool b ); - bool getOriented( int tileSet ) const; - - void setSurfaceData( int tileSet, unsigned long data ); - unsigned long getSurfaceData( int tileSet ) const; - - void setTexturePath( const QString &path ); - QString getTexturePath() const; - - void setRotation( int rotation ); - - void serial( NLMISC::IStream &f ); - - bool hasError() const{ return m_hasError; } - QString getLastError() const{ return m_lastError; } - void resetError(){ - m_hasError = false; - m_lastError = ""; - } - - void setError( const QString &msg ) - { - m_hasError = true; - m_lastError = msg; - } - -private: - TileBankPvt *m_pvt; - QString m_lastError; - bool m_hasError; - int m_rotation; -}; - -#endif - +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef TILE_BANK_H +#define TILE_BANK_H + +#include +#include +#include +#include + +#include "tile_constants.h" +#include "tile_images.h" + +namespace NLMISC +{ + class IStream; +} + +class TileBankPvt; + +class TileBank +{ +public: + TileBank(); + ~TileBank(); + + void addTileSet( const QString &name ); + void removeTileSet( int idx ); + void renameTileSet( int idx, const QString &newName ); + void getTileSets( QStringList &l ); + + void addLand( const QString &name ); + void removeLand( int idx ); + void getLands( QStringList &l ); + void setLandSets( int idx, const QStringList &l ); + void getLandSets( int idx, QStringList &l ); + + bool addTile( int setIdx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type ); + void removeTile( int ts, int type, int tile ); + bool setTile( int tileset, int tile, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type ); + void replaceImage( int ts, int type, int tile, TileConstants::TTileChannel channel, const QString &name, const QVariant &pixmap ); + void clearImage( int ts, int type, int tile, TileConstants::TTileChannel channel ); + + + int getTileCount( int tileSet, TileConstants::TNodeTileType type ); + int getRealTileId( int tileSet, TileConstants::TNodeTileType type, int tileIdInSet ); + void getTileImages( int tileSet, TileConstants::TNodeTileType type, int tileId, TileImages &images ); + void getTileImages( int tileSet, TileConstants::TNodeTileType type, QList< TileImages > &l ); + + void setVegetation( int tileSet, const QString &vegetation ); + QString getVegetation( int tileSet ) const; + + void setOriented( int tileSet, bool b ); + bool getOriented( int tileSet ) const; + + void setSurfaceData( int tileSet, unsigned long data ); + unsigned long getSurfaceData( int tileSet ) const; + + void setTexturePath( const QString &path ); + QString getTexturePath() const; + + void setRotation( int rotation ); + + void serial( NLMISC::IStream &f ); + + bool hasError() const{ return m_hasError; } + QString getLastError() const{ return m_lastError; } + void resetError(){ + m_hasError = false; + m_lastError = ""; + } + + void setError( const QString &msg ) + { + m_hasError = true; + m_lastError = msg; + } + +private: + TileBankPvt *m_pvt; + QString m_lastError; + bool m_hasError; + int m_rotation; +}; + +#endif + diff --git a/code/studio/src/plugins/tile_editor/tile_constants.h b/code/studio/src/plugins/tile_editor/tile_constants.h index bf09f21a5..56748cb58 100644 --- a/code/studio/src/plugins/tile_editor/tile_constants.h +++ b/code/studio/src/plugins/tile_editor/tile_constants.h @@ -1,43 +1,43 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#ifndef TILE_CONSTANTS_H -#define TILE_CONSTANTS_H - - -namespace TileConstants -{ - enum TTileChannel - { - TileDiffuse = 0, - TileAdditive = 1, - TileAlpha = 2, - TileChannelCount = 3 - }; - - enum TNodeTileType - { - Tile128 = 0, - Tile256 = 1, - TileTransition = 2, - TileDisplacement = 3, - TileNodeTypeCount = 4 - }; -} - - -#endif +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef TILE_CONSTANTS_H +#define TILE_CONSTANTS_H + + +namespace TileConstants +{ + enum TTileChannel + { + TileDiffuse = 0, + TileAdditive = 1, + TileAlpha = 2, + TileChannelCount = 3 + }; + + enum TNodeTileType + { + Tile128 = 0, + Tile256 = 1, + TileTransition = 2, + TileDisplacement = 3, + TileNodeTypeCount = 4 + }; +} + + +#endif diff --git a/code/studio/src/plugins/tile_editor/tile_images.h b/code/studio/src/plugins/tile_editor/tile_images.h index e17267001..280e0a126 100644 --- a/code/studio/src/plugins/tile_editor/tile_images.h +++ b/code/studio/src/plugins/tile_editor/tile_images.h @@ -1,40 +1,40 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#ifndef TILE_IMAGES_H -#define TILE_IMAGES_H - -#include - -struct TileImages -{ - QString diffuse; - QString additive; - QString alpha; - - void clear() - { - diffuse.clear(); - additive.clear(); - alpha.clear(); - } -}; - - - -#endif - +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef TILE_IMAGES_H +#define TILE_IMAGES_H + +#include + +struct TileImages +{ + QString diffuse; + QString additive; + QString alpha; + + void clear() + { + diffuse.clear(); + additive.clear(); + alpha.clear(); + } +}; + + + +#endif + diff --git a/code/studio/src/plugins/tile_editor/tile_item_delegate.cpp b/code/studio/src/plugins/tile_editor/tile_item_delegate.cpp index 43751d612..6f9479354 100644 --- a/code/studio/src/plugins/tile_editor/tile_item_delegate.cpp +++ b/code/studio/src/plugins/tile_editor/tile_item_delegate.cpp @@ -1,122 +1,122 @@ -// Object Viewer Qt - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#include - -#include - -#include "tile_item_delegate.h" - -#include "tile_model.h" - -TileItemDelegate::TileItemDelegate() -{ - m_zoomFactor = ZoomNormal; - m_imageHint = 128; -} - -TileItemDelegate::~TileItemDelegate() -{ -} - -void TileItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - QStyledItemDelegate::paint(painter,option,index); - - painter->save(); - - QFont font = QApplication::font(); - - //font.setBold(true); - //SubFont.setWeight(SubFont.weight()-2); - QFontMetrics fm(font); - - QPixmap tile = qvariant_cast(index.data(TileModel::TilePixmapRole)); - QString tileFileText = qvariant_cast(index.data(TileModel::TileFilenameRole)); - QString tileIdText = qvariant_cast(index.data(TileModel::TileIndexRole)); - - QSize tileSize = tile.size(); - - //QRect headerRect = option.rect; - QRect rect(option.rect); - //QRect tileRect(option.rect); - int textHeight = fm.height(); - int iconPosModX = PIXMAP_MARGIN + (tile.width() / 2); - int iconPosModY = (option.rect.height() - tile.height()) / 2; - - painter->drawPixmap(rect.adjusted(iconPosModX, iconPosModY, iconPosModX, iconPosModY).topLeft(), tile); - - - - //tileRect.setRight(tileSize.width()+30); - //tileRect.setTop(tileRect.top()+5); - //headerRect.setLeft(tileRect.right()); - //subheaderRect.setLeft(tileRect.right()); - //headerRect.setTop(headerRect.top()+5); - //headerRect.setBottom(headerRect.top()+fm.height()); - - //subheaderRect.setTop(headerRect.bottom()+2); - - //painter->drawPixmap(targetrect, pixmap, sourcerect) - - //painter->drawPixmap(QPoint(iconRect.right()/2,iconRect.top()/2),icon.pixmap(iconsize.width(),iconsize.height())); - //painter->drawPixmap(QPoint(tileRect.left()+tileSize.width()/2+2,tileRect.top()+tileSize.height()/2+3),tile); - - //painter->setFont(font); - //painter->drawText(headerRect,headerText); - - - //painter->setFont(SubFont); - //painter->drawText(subheaderRect.left(),subheaderRect.top()+17,subText); - - painter->restore(); -} - -QSize TileItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const -{ - QPixmap tile = qvariant_cast(index.data(TileModel::TilePixmapRole)); - QSize tileSize = tile.size(); - QFont font = QApplication::font(); - QFontMetrics fm(font); - - return(QSize(tileSize.width()+(2*PIXMAP_MARGIN), tileSize.height()+fm.height()+(2*PIXMAP_MARGIN))); -} - -TileItemDelegate::TZoomFactor TileItemDelegate::getZoomFactor() -{ - return m_zoomFactor; -} - -void TileItemDelegate::setZoomFactor(TileItemDelegate::TZoomFactor zoomFactor) -{ - m_zoomFactor = zoomFactor; -} - -// SLOTS - -void TileItemDelegate::currentTab(int index) -{ - if(index == 1) - { - nlinfo("switching delegate to 1 or 256"); - m_imageHint = 256; - } - else - { - nlinfo("switching delegate to 0,2,3 or 128"); - m_imageHint = 128; - } +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include + +#include + +#include "tile_item_delegate.h" + +#include "tile_model.h" + +TileItemDelegate::TileItemDelegate() +{ + m_zoomFactor = ZoomNormal; + m_imageHint = 128; +} + +TileItemDelegate::~TileItemDelegate() +{ +} + +void TileItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QStyledItemDelegate::paint(painter,option,index); + + painter->save(); + + QFont font = QApplication::font(); + + //font.setBold(true); + //SubFont.setWeight(SubFont.weight()-2); + QFontMetrics fm(font); + + QPixmap tile = qvariant_cast(index.data(TileModel::TilePixmapRole)); + QString tileFileText = qvariant_cast(index.data(TileModel::TileFilenameRole)); + QString tileIdText = qvariant_cast(index.data(TileModel::TileIndexRole)); + + QSize tileSize = tile.size(); + + //QRect headerRect = option.rect; + QRect rect(option.rect); + //QRect tileRect(option.rect); + int textHeight = fm.height(); + int iconPosModX = PIXMAP_MARGIN + (tile.width() / 2); + int iconPosModY = (option.rect.height() - tile.height()) / 2; + + painter->drawPixmap(rect.adjusted(iconPosModX, iconPosModY, iconPosModX, iconPosModY).topLeft(), tile); + + + + //tileRect.setRight(tileSize.width()+30); + //tileRect.setTop(tileRect.top()+5); + //headerRect.setLeft(tileRect.right()); + //subheaderRect.setLeft(tileRect.right()); + //headerRect.setTop(headerRect.top()+5); + //headerRect.setBottom(headerRect.top()+fm.height()); + + //subheaderRect.setTop(headerRect.bottom()+2); + + //painter->drawPixmap(targetrect, pixmap, sourcerect) + + //painter->drawPixmap(QPoint(iconRect.right()/2,iconRect.top()/2),icon.pixmap(iconsize.width(),iconsize.height())); + //painter->drawPixmap(QPoint(tileRect.left()+tileSize.width()/2+2,tileRect.top()+tileSize.height()/2+3),tile); + + //painter->setFont(font); + //painter->drawText(headerRect,headerText); + + + //painter->setFont(SubFont); + //painter->drawText(subheaderRect.left(),subheaderRect.top()+17,subText); + + painter->restore(); +} + +QSize TileItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const +{ + QPixmap tile = qvariant_cast(index.data(TileModel::TilePixmapRole)); + QSize tileSize = tile.size(); + QFont font = QApplication::font(); + QFontMetrics fm(font); + + return(QSize(tileSize.width()+(2*PIXMAP_MARGIN), tileSize.height()+fm.height()+(2*PIXMAP_MARGIN))); +} + +TileItemDelegate::TZoomFactor TileItemDelegate::getZoomFactor() +{ + return m_zoomFactor; +} + +void TileItemDelegate::setZoomFactor(TileItemDelegate::TZoomFactor zoomFactor) +{ + m_zoomFactor = zoomFactor; +} + +// SLOTS + +void TileItemDelegate::currentTab(int index) +{ + if(index == 1) + { + nlinfo("switching delegate to 1 or 256"); + m_imageHint = 256; + } + else + { + nlinfo("switching delegate to 0,2,3 or 128"); + m_imageHint = 128; + } } \ No newline at end of file diff --git a/code/studio/src/plugins/tile_editor/tilebank_loader.cpp b/code/studio/src/plugins/tile_editor/tilebank_loader.cpp index 1aaa055f0..ceae137cc 100644 --- a/code/studio/src/plugins/tile_editor/tilebank_loader.cpp +++ b/code/studio/src/plugins/tile_editor/tilebank_loader.cpp @@ -1,42 +1,42 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#include "tilebank_loader.h" - -#include "tile_model.h" -#include "nel/misc/file.h" - -TileBankLoader::TileBankLoader() -{ -} - -TileBankLoader::~TileBankLoader() -{ -} - -bool TileBankLoader::load( const char *filename, TileModel *model ) -{ - NLMISC::CIFile file; - if( !file.open( filename, false ) ) - return false; - - model->serial( file ); - - file.close(); - - return true; -} +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "tilebank_loader.h" + +#include "tile_model.h" +#include "nel/misc/file.h" + +TileBankLoader::TileBankLoader() +{ +} + +TileBankLoader::~TileBankLoader() +{ +} + +bool TileBankLoader::load( const char *filename, TileModel *model ) +{ + NLMISC::CIFile file; + if( !file.open( filename, false ) ) + return false; + + model->serial( file ); + + file.close(); + + return true; +} diff --git a/code/studio/src/plugins/tile_editor/tilebank_loader.h b/code/studio/src/plugins/tile_editor/tilebank_loader.h index 643cab67f..6f41234ba 100644 --- a/code/studio/src/plugins/tile_editor/tilebank_loader.h +++ b/code/studio/src/plugins/tile_editor/tilebank_loader.h @@ -1,35 +1,35 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#ifndef TILEBANK_LOADER_H -#define TILEBANK_LOADER_H - -class TileModel; - -class TileBankLoader -{ -public: - TileBankLoader(); - ~TileBankLoader(); - - bool load( const char *filename, TileModel *model ); - -private: -}; - - -#endif - +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef TILEBANK_LOADER_H +#define TILEBANK_LOADER_H + +class TileModel; + +class TileBankLoader +{ +public: + TileBankLoader(); + ~TileBankLoader(); + + bool load( const char *filename, TileModel *model ); + +private: +}; + + +#endif + diff --git a/code/studio/src/plugins/tile_editor/tilebank_saver.cpp b/code/studio/src/plugins/tile_editor/tilebank_saver.cpp index 3f087c979..85c96ee94 100644 --- a/code/studio/src/plugins/tile_editor/tilebank_saver.cpp +++ b/code/studio/src/plugins/tile_editor/tilebank_saver.cpp @@ -1,48 +1,48 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#include "tilebank_saver.h" -#include "tile_model.h" -#include "tile_item.h" - -#include "nel/3d/tile_bank.h" -#include "nel/misc/file.h" - -TileBankSaver::TileBankSaver() -{ -} - -TileBankSaver::~TileBankSaver() -{ -} - -bool TileBankSaver::save( const char *fileName, TileModel* model ) -{ - // Save to file - NLMISC::COFile f; - bool b = f.open( fileName, false, false, false ); - if( !b ) - return false; - - model->serial( f ); - - f.flush(); - f.close(); - - return true; -} - +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "tilebank_saver.h" +#include "tile_model.h" +#include "tile_item.h" + +#include "nel/3d/tile_bank.h" +#include "nel/misc/file.h" + +TileBankSaver::TileBankSaver() +{ +} + +TileBankSaver::~TileBankSaver() +{ +} + +bool TileBankSaver::save( const char *fileName, TileModel* model ) +{ + // Save to file + NLMISC::COFile f; + bool b = f.open( fileName, false, false, false ); + if( !b ) + return false; + + model->serial( f ); + + f.flush(); + f.close(); + + return true; +} + diff --git a/code/studio/src/plugins/tile_editor/tilebank_saver.h b/code/studio/src/plugins/tile_editor/tilebank_saver.h index 0f8983157..ba9c3c7fd 100644 --- a/code/studio/src/plugins/tile_editor/tilebank_saver.h +++ b/code/studio/src/plugins/tile_editor/tilebank_saver.h @@ -1,39 +1,39 @@ -// Ryzom Core Studio - Tile Editor plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#ifndef TILEBANK_SAVER_H -#define TILEBANK_SAVER_H - -#include -#include - -class TileModel; - -class TileBankSaver -{ -public: - TileBankSaver(); - ~TileBankSaver(); - - bool save( const char *filename, TileModel* model ); - -private: - -}; - -#endif - +// Ryzom Core Studio - Tile Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef TILEBANK_SAVER_H +#define TILEBANK_SAVER_H + +#include +#include + +class TileModel; + +class TileBankSaver +{ +public: + TileBankSaver(); + ~TileBankSaver(); + + bool save( const char *filename, TileModel* model ); + +private: + +}; + +#endif + diff --git a/code/studio/src/plugins/translation_manager/uxt_editor.cpp b/code/studio/src/plugins/translation_manager/uxt_editor.cpp index 99b0b200c..06e6f98b4 100644 --- a/code/studio/src/plugins/translation_manager/uxt_editor.cpp +++ b/code/studio/src/plugins/translation_manager/uxt_editor.cpp @@ -1,472 +1,472 @@ -// Ryzom Core Studio - Translation Manager Plugin -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#include "translation_manager_constants.h" -#include "uxt_editor.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "nel/misc/diff_tool.h" -#include "nel/misc/i18n.h" - -namespace -{ - -QString getLang( const QString &fn ) -{ - QString lang = fn; - int idx = lang.lastIndexOf( '/' ); - if( idx == -1 ) - return ""; - - lang = lang.mid( idx + 1 ); - idx = lang.lastIndexOf( '.' ); - if( idx == -1 ) - return ""; - - lang = lang.left( idx ); - return lang; -} - -} - -namespace TranslationManager -{ - -void markItemTranslated( QTableWidgetItem *item ) -{ - item->setBackground( QColor::fromRgb( 126, 247, 134 ) ); -} - -void markItemUntranslated( QTableWidgetItem *item ) -{ - item->setBackground( QColor::fromRgb( 247, 126, 126 ) ); -} - -class UXTEditorPvt -{ -public: - - UXTEditorPvt() - { - t = new QTableWidget(); - loadedFromWK = false; - } - - QTableWidget *t; - std::vector< STRING_MANAGER::TStringInfo > infos; - bool loadedFromWK; -}; - - -UXTEditor::UXTEditor( QMdiArea *parent ) : -CEditor( parent ) -{ - editor_type = Constants::ED_UXT; - setAttribute( Qt::WA_DeleteOnClose ); - - d_ptr = new UXTEditorPvt(); - - blockTableSignals( false ); -} - -UXTEditor::~UXTEditor() -{ - delete d_ptr; - d_ptr = NULL; -} - -void UXTEditor::open( QString filename ) -{ - std::vector< STRING_MANAGER::TStringInfo > &infos = d_ptr->infos; - QString lang = getLang( filename ); - - infos.clear(); - STRING_MANAGER::loadStringFile( filename.toUtf8().constData(), infos, false ); - - if( d_ptr->infos.size() == 0 ) - { - // The work file cannot be found, cannot proceed - if( filename.endsWith( "wk.uxt" ) ) - { - QMessageBox::critical( this, - tr( "Error opening file.." ), - tr( "There was an error opening wk.uxt" ) ); - return; - } - - int l = filename.lastIndexOf( "/" ); - if( l == -1 ) - return; - - QString fn = filename.left( l ); - fn += "/wk.uxt"; - - // The work file cannot be found, cannot proceed - STRING_MANAGER::loadStringFile( fn.toUtf8().constData(), infos, true ); - if( d_ptr->infos.size() == 0 ) - { - QMessageBox::critical( this, - tr( "Error opening Uxt file" ), - tr( "Neither the specified file nor wk.uxt could be opened." ) ); - return; - } - - d_ptr->loadedFromWK = true; - } - - blockTableSignals( true ); - - d_ptr->t->clear(); - d_ptr->t->setColumnCount( 2 ); - d_ptr->t->setRowCount( infos.size() ); - - setHeaderText( "Id", lang.toUpper() + " Text" ); - - int i = 0; - - std::vector< STRING_MANAGER::TStringInfo >::const_iterator itr = infos.begin(); - while( itr != infos.end() ) - { - const STRING_MANAGER::TStringInfo &info = *itr; - - QTableWidgetItem *name = new QTableWidgetItem( info.Identifier.c_str() ); - QTableWidgetItem *text1 = new QTableWidgetItem( info.Text.toUtf8().c_str() ); - - d_ptr->t->setItem( i, 0, name ); - d_ptr->t->setItem( i, 1, text1 ); - - if( ( info.HashValue != 0 ) && !d_ptr->loadedFromWK ) - { - markItemTranslated( name ); - markItemTranslated( text1 ); - } - else - { - markItemUntranslated( name ); - markItemUntranslated( text1 ); - } - - ++itr; - i++; - } - - d_ptr->t->resizeColumnsToContents(); - - blockTableSignals( false ); - - setWidget( d_ptr->t ); - - current_file = filename; - setWindowTitle( filename + "[*]" ); - setWindowFilePath( filename ); -} - -void UXTEditor::save() -{ - saveAs( current_file ); -} - -void UXTEditor::saveAs( QString filename ) -{ - QFile f( filename ); - if( !f.open( QIODevice::WriteOnly ) ) - return; - - QTextStream out( &f ); - - int idx = 0; - std::vector< STRING_MANAGER::TStringInfo >::const_iterator itr = d_ptr->infos.begin(); - while( itr != d_ptr->infos.end() ) - { - uint64 hash = 0; - - // If text2 is not empty we can assume the string was translated, so we store with the correct hash - // If text2 is empty, it wasn't translated so we can just use the old hash. - // Additionally, if the strings were loaded from the wk.uxt file, we use a hash of 0 so we know it was not translated - if( itr->Text2.empty() ) - { - if( d_ptr->loadedFromWK ) - hash = 0; - else - hash = itr->HashValue; - } - else - { - hash = NLMISC::CI18N::makeHash( itr->Text2 ); - } - - QString hashLine = "// HASH_VALUE "; - hashLine += QString( NLMISC::CI18N::hashToString( hash ).c_str() ).toUpper(); - hashLine += "\r\n"; - - QString idxLine = "// INDEX "; - idxLine += QString::number( idx ); - idxLine += "\r\n"; - - - QString trLine = ""; - trLine += itr->Identifier.c_str(); - trLine += "\t"; - trLine += "["; - - if( itr->Text2.empty() ) - trLine += itr->Text.toUtf8().c_str(); - else - trLine += itr->Text2.toUtf8().c_str(); - - trLine += "]"; - trLine += "\r\n"; - - QString newLine = "\r\n"; - - out << hashLine; - out << idxLine; - out << trLine; - out << newLine; - - ++itr; - idx++; - } - - f.close(); - - setWindowModified( false ); -} - -void UXTEditor::activateWindow() -{ - showMaximized(); -} - - -void UXTEditor::insertRow() -{ - blockTableSignals( true ); - - d_ptr->infos.push_back( STRING_MANAGER::TStringInfo() ); - d_ptr->t->setRowCount( d_ptr->t->rowCount() + 1 ); - int row = d_ptr->t->rowCount() - 1; - - QTableWidgetItem *item1 = new QTableWidgetItem(); - QTableWidgetItem *item2 = new QTableWidgetItem(); - d_ptr->t->setItem( row, 0, item1 ); - d_ptr->t->setItem( row, 1, item2 ); - - markRowUntranslated( row ); - - setWindowModified( true ); - - blockTableSignals( false ); -} - - -void UXTEditor::deleteRow() -{ - int r = d_ptr->t->currentRow(); - if( r < 0 ) - return; - - int answer = QMessageBox::question( this, - tr( "Deleting a row" ), - tr( "Are you sure you want to delete this row?" ), - QMessageBox::Yes, - QMessageBox::Cancel ); - if( QMessageBox::Yes != answer ) - return; - - std::vector< STRING_MANAGER::TStringInfo >::iterator itr = d_ptr->infos.begin(); - itr += r; - d_ptr->infos.erase( itr ); - - d_ptr->t->removeRow( r ); - - setWindowModified( true ); -} - -void UXTEditor::closeEvent( QCloseEvent *e ) -{ - if( isWindowModified() ) - { - int reply = QMessageBox::question( this, - tr( "Table changed" ), - tr( "The table has changed. Would you like to save your changes?" ), - QMessageBox::Yes, - QMessageBox::No - ); - - if( reply == QMessageBox::Yes ) - save(); - - } - - e->accept(); - close(); -} - -void UXTEditor::contextMenuEvent( QContextMenuEvent *e ) -{ - QMenu *menu = new QMenu( this ); - QAction *insertAction = new QAction( "Insert row", menu ); - QAction *deleteAction = new QAction( "Delete row", menu ); - QAction *markAction = new QAction( "Mark translated", menu ); - QAction *unmarkAction = new QAction( "Mark not-translated", menu ); - QAction *saveAction = new QAction( "Save", menu ); - QAction *saveAsAction = new QAction( "Save as..", menu ); - - connect( insertAction, SIGNAL( triggered( bool ) ), this, SLOT( insertRow() ) ); - connect( deleteAction, SIGNAL( triggered( bool ) ), this, SLOT( deleteRow() ) ); - connect( markAction, SIGNAL( triggered( bool ) ), this, SLOT( markTranslated() ) ); - connect( unmarkAction, SIGNAL( triggered( bool ) ), this, SLOT( markUntranslated() ) ); - connect( saveAction, SIGNAL( triggered( bool ) ), this, SLOT( onSaveClicked() ) ); - connect( saveAsAction, SIGNAL( triggered( bool ) ), this, SLOT( onSaveAsClicked() ) ); - - menu->addAction( insertAction ); - menu->addAction( deleteAction ); - menu->addAction( markAction ); - menu->addAction( unmarkAction ); - menu->addAction( saveAction ); - menu->addAction( saveAsAction ); - menu->exec( e->globalPos() ); -} - -void UXTEditor::onCellChanged( int row, int column ) -{ - QTableWidgetItem *item = d_ptr->t->item( row, column ); - STRING_MANAGER::TStringInfo &info = d_ptr->infos[ row ]; - - if( column == 0 ) - info.Identifier = item->text().toUtf8().constData(); - else - if( column == 1 ) - info.Text2 = item->text().toUtf8().constData(); - - setWindowModified( true ); - - markRowTranslated( row ); -} - -void UXTEditor::markTranslated() -{ - int r = d_ptr->t->currentRow(); - if( r < 0 ) - return; - - STRING_MANAGER::TStringInfo &info = d_ptr->infos[ r ]; - if( !info.Text2.empty() ) - return; - - info.Text2 = info.Text; - - setWindowModified( true ); - - markRowTranslated( r ); -} - -void UXTEditor::markUntranslated() -{ - int r = d_ptr->t->currentRow(); - if( r < 0 ) - return; - - STRING_MANAGER::TStringInfo &info = d_ptr->infos[ r ]; - - info.Text2.clear(); - info.HashValue = 0; - - setWindowModified( true ); - - markRowUntranslated( r ); -} - -void UXTEditor::onSaveClicked() -{ - save(); -} - -void UXTEditor::onSaveAsClicked() -{ - QString path = current_file; - int idx = path.lastIndexOf( '/' ); - if( idx < 0 ) - path = ""; - else - path = path.left( idx + 1 ); - - QString file = QFileDialog::getSaveFileName( this, - tr( "Save Uxt as.." ), - path, - tr( "Uxt files ( *.uxt)" ) ); - - if( file.isEmpty() ) - return; - - saveAs( file ); -} - -void UXTEditor::setHeaderText( const QString &id, const QString &text ) -{ - QTableWidgetItem *h1 = new QTableWidgetItem( id ); - QTableWidgetItem *h2 = new QTableWidgetItem( text ); - h1->setTextAlignment( Qt::AlignLeft ); - h2->setTextAlignment( Qt::AlignLeft ); - d_ptr->t->setHorizontalHeaderItem( 0, h1 ); - d_ptr->t->setHorizontalHeaderItem( 1, h2 ); -} - -void UXTEditor::blockTableSignals( bool block ) -{ - if( block ) - disconnect( d_ptr->t, SIGNAL( cellChanged( int, int ) ), this, SLOT( onCellChanged( int, int ) ) ); - else - connect( d_ptr->t, SIGNAL( cellChanged( int, int ) ), this, SLOT( onCellChanged( int, int ) ) ); -} - -void UXTEditor::markRowTranslated( int row ) -{ - blockTableSignals( true ); - - QTableWidgetItem *item1 = d_ptr->t->item( row, 0 ); - QTableWidgetItem *item2 = d_ptr->t->item( row, 1 ); - markItemTranslated( item1 ); - markItemTranslated( item2 ); - - blockTableSignals( false ); -} - -void UXTEditor::markRowUntranslated( int row ) -{ - blockTableSignals( true ); - - QTableWidgetItem *item1 = d_ptr->t->item( row, 0 ); - QTableWidgetItem *item2 = d_ptr->t->item( row, 1 ); - markItemUntranslated( item1 ); - markItemUntranslated( item2 ); - - blockTableSignals( false ); -} - -} +// Ryzom Core Studio - Translation Manager Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "translation_manager_constants.h" +#include "uxt_editor.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "nel/misc/diff_tool.h" +#include "nel/misc/i18n.h" + +namespace +{ + +QString getLang( const QString &fn ) +{ + QString lang = fn; + int idx = lang.lastIndexOf( '/' ); + if( idx == -1 ) + return ""; + + lang = lang.mid( idx + 1 ); + idx = lang.lastIndexOf( '.' ); + if( idx == -1 ) + return ""; + + lang = lang.left( idx ); + return lang; +} + +} + +namespace TranslationManager +{ + +void markItemTranslated( QTableWidgetItem *item ) +{ + item->setBackground( QColor::fromRgb( 126, 247, 134 ) ); +} + +void markItemUntranslated( QTableWidgetItem *item ) +{ + item->setBackground( QColor::fromRgb( 247, 126, 126 ) ); +} + +class UXTEditorPvt +{ +public: + + UXTEditorPvt() + { + t = new QTableWidget(); + loadedFromWK = false; + } + + QTableWidget *t; + std::vector< STRING_MANAGER::TStringInfo > infos; + bool loadedFromWK; +}; + + +UXTEditor::UXTEditor( QMdiArea *parent ) : +CEditor( parent ) +{ + editor_type = Constants::ED_UXT; + setAttribute( Qt::WA_DeleteOnClose ); + + d_ptr = new UXTEditorPvt(); + + blockTableSignals( false ); +} + +UXTEditor::~UXTEditor() +{ + delete d_ptr; + d_ptr = NULL; +} + +void UXTEditor::open( QString filename ) +{ + std::vector< STRING_MANAGER::TStringInfo > &infos = d_ptr->infos; + QString lang = getLang( filename ); + + infos.clear(); + STRING_MANAGER::loadStringFile( filename.toUtf8().constData(), infos, false ); + + if( d_ptr->infos.size() == 0 ) + { + // The work file cannot be found, cannot proceed + if( filename.endsWith( "wk.uxt" ) ) + { + QMessageBox::critical( this, + tr( "Error opening file.." ), + tr( "There was an error opening wk.uxt" ) ); + return; + } + + int l = filename.lastIndexOf( "/" ); + if( l == -1 ) + return; + + QString fn = filename.left( l ); + fn += "/wk.uxt"; + + // The work file cannot be found, cannot proceed + STRING_MANAGER::loadStringFile( fn.toUtf8().constData(), infos, true ); + if( d_ptr->infos.size() == 0 ) + { + QMessageBox::critical( this, + tr( "Error opening Uxt file" ), + tr( "Neither the specified file nor wk.uxt could be opened." ) ); + return; + } + + d_ptr->loadedFromWK = true; + } + + blockTableSignals( true ); + + d_ptr->t->clear(); + d_ptr->t->setColumnCount( 2 ); + d_ptr->t->setRowCount( infos.size() ); + + setHeaderText( "Id", lang.toUpper() + " Text" ); + + int i = 0; + + std::vector< STRING_MANAGER::TStringInfo >::const_iterator itr = infos.begin(); + while( itr != infos.end() ) + { + const STRING_MANAGER::TStringInfo &info = *itr; + + QTableWidgetItem *name = new QTableWidgetItem( info.Identifier.c_str() ); + QTableWidgetItem *text1 = new QTableWidgetItem( info.Text.toUtf8().c_str() ); + + d_ptr->t->setItem( i, 0, name ); + d_ptr->t->setItem( i, 1, text1 ); + + if( ( info.HashValue != 0 ) && !d_ptr->loadedFromWK ) + { + markItemTranslated( name ); + markItemTranslated( text1 ); + } + else + { + markItemUntranslated( name ); + markItemUntranslated( text1 ); + } + + ++itr; + i++; + } + + d_ptr->t->resizeColumnsToContents(); + + blockTableSignals( false ); + + setWidget( d_ptr->t ); + + current_file = filename; + setWindowTitle( filename + "[*]" ); + setWindowFilePath( filename ); +} + +void UXTEditor::save() +{ + saveAs( current_file ); +} + +void UXTEditor::saveAs( QString filename ) +{ + QFile f( filename ); + if( !f.open( QIODevice::WriteOnly ) ) + return; + + QTextStream out( &f ); + + int idx = 0; + std::vector< STRING_MANAGER::TStringInfo >::const_iterator itr = d_ptr->infos.begin(); + while( itr != d_ptr->infos.end() ) + { + uint64 hash = 0; + + // If text2 is not empty we can assume the string was translated, so we store with the correct hash + // If text2 is empty, it wasn't translated so we can just use the old hash. + // Additionally, if the strings were loaded from the wk.uxt file, we use a hash of 0 so we know it was not translated + if( itr->Text2.empty() ) + { + if( d_ptr->loadedFromWK ) + hash = 0; + else + hash = itr->HashValue; + } + else + { + hash = NLMISC::CI18N::makeHash( itr->Text2 ); + } + + QString hashLine = "// HASH_VALUE "; + hashLine += QString( NLMISC::CI18N::hashToString( hash ).c_str() ).toUpper(); + hashLine += "\r\n"; + + QString idxLine = "// INDEX "; + idxLine += QString::number( idx ); + idxLine += "\r\n"; + + + QString trLine = ""; + trLine += itr->Identifier.c_str(); + trLine += "\t"; + trLine += "["; + + if( itr->Text2.empty() ) + trLine += itr->Text.toUtf8().c_str(); + else + trLine += itr->Text2.toUtf8().c_str(); + + trLine += "]"; + trLine += "\r\n"; + + QString newLine = "\r\n"; + + out << hashLine; + out << idxLine; + out << trLine; + out << newLine; + + ++itr; + idx++; + } + + f.close(); + + setWindowModified( false ); +} + +void UXTEditor::activateWindow() +{ + showMaximized(); +} + + +void UXTEditor::insertRow() +{ + blockTableSignals( true ); + + d_ptr->infos.push_back( STRING_MANAGER::TStringInfo() ); + d_ptr->t->setRowCount( d_ptr->t->rowCount() + 1 ); + int row = d_ptr->t->rowCount() - 1; + + QTableWidgetItem *item1 = new QTableWidgetItem(); + QTableWidgetItem *item2 = new QTableWidgetItem(); + d_ptr->t->setItem( row, 0, item1 ); + d_ptr->t->setItem( row, 1, item2 ); + + markRowUntranslated( row ); + + setWindowModified( true ); + + blockTableSignals( false ); +} + + +void UXTEditor::deleteRow() +{ + int r = d_ptr->t->currentRow(); + if( r < 0 ) + return; + + int answer = QMessageBox::question( this, + tr( "Deleting a row" ), + tr( "Are you sure you want to delete this row?" ), + QMessageBox::Yes, + QMessageBox::Cancel ); + if( QMessageBox::Yes != answer ) + return; + + std::vector< STRING_MANAGER::TStringInfo >::iterator itr = d_ptr->infos.begin(); + itr += r; + d_ptr->infos.erase( itr ); + + d_ptr->t->removeRow( r ); + + setWindowModified( true ); +} + +void UXTEditor::closeEvent( QCloseEvent *e ) +{ + if( isWindowModified() ) + { + int reply = QMessageBox::question( this, + tr( "Table changed" ), + tr( "The table has changed. Would you like to save your changes?" ), + QMessageBox::Yes, + QMessageBox::No + ); + + if( reply == QMessageBox::Yes ) + save(); + + } + + e->accept(); + close(); +} + +void UXTEditor::contextMenuEvent( QContextMenuEvent *e ) +{ + QMenu *menu = new QMenu( this ); + QAction *insertAction = new QAction( "Insert row", menu ); + QAction *deleteAction = new QAction( "Delete row", menu ); + QAction *markAction = new QAction( "Mark translated", menu ); + QAction *unmarkAction = new QAction( "Mark not-translated", menu ); + QAction *saveAction = new QAction( "Save", menu ); + QAction *saveAsAction = new QAction( "Save as..", menu ); + + connect( insertAction, SIGNAL( triggered( bool ) ), this, SLOT( insertRow() ) ); + connect( deleteAction, SIGNAL( triggered( bool ) ), this, SLOT( deleteRow() ) ); + connect( markAction, SIGNAL( triggered( bool ) ), this, SLOT( markTranslated() ) ); + connect( unmarkAction, SIGNAL( triggered( bool ) ), this, SLOT( markUntranslated() ) ); + connect( saveAction, SIGNAL( triggered( bool ) ), this, SLOT( onSaveClicked() ) ); + connect( saveAsAction, SIGNAL( triggered( bool ) ), this, SLOT( onSaveAsClicked() ) ); + + menu->addAction( insertAction ); + menu->addAction( deleteAction ); + menu->addAction( markAction ); + menu->addAction( unmarkAction ); + menu->addAction( saveAction ); + menu->addAction( saveAsAction ); + menu->exec( e->globalPos() ); +} + +void UXTEditor::onCellChanged( int row, int column ) +{ + QTableWidgetItem *item = d_ptr->t->item( row, column ); + STRING_MANAGER::TStringInfo &info = d_ptr->infos[ row ]; + + if( column == 0 ) + info.Identifier = item->text().toUtf8().constData(); + else + if( column == 1 ) + info.Text2 = item->text().toUtf8().constData(); + + setWindowModified( true ); + + markRowTranslated( row ); +} + +void UXTEditor::markTranslated() +{ + int r = d_ptr->t->currentRow(); + if( r < 0 ) + return; + + STRING_MANAGER::TStringInfo &info = d_ptr->infos[ r ]; + if( !info.Text2.empty() ) + return; + + info.Text2 = info.Text; + + setWindowModified( true ); + + markRowTranslated( r ); +} + +void UXTEditor::markUntranslated() +{ + int r = d_ptr->t->currentRow(); + if( r < 0 ) + return; + + STRING_MANAGER::TStringInfo &info = d_ptr->infos[ r ]; + + info.Text2.clear(); + info.HashValue = 0; + + setWindowModified( true ); + + markRowUntranslated( r ); +} + +void UXTEditor::onSaveClicked() +{ + save(); +} + +void UXTEditor::onSaveAsClicked() +{ + QString path = current_file; + int idx = path.lastIndexOf( '/' ); + if( idx < 0 ) + path = ""; + else + path = path.left( idx + 1 ); + + QString file = QFileDialog::getSaveFileName( this, + tr( "Save Uxt as.." ), + path, + tr( "Uxt files ( *.uxt)" ) ); + + if( file.isEmpty() ) + return; + + saveAs( file ); +} + +void UXTEditor::setHeaderText( const QString &id, const QString &text ) +{ + QTableWidgetItem *h1 = new QTableWidgetItem( id ); + QTableWidgetItem *h2 = new QTableWidgetItem( text ); + h1->setTextAlignment( Qt::AlignLeft ); + h2->setTextAlignment( Qt::AlignLeft ); + d_ptr->t->setHorizontalHeaderItem( 0, h1 ); + d_ptr->t->setHorizontalHeaderItem( 1, h2 ); +} + +void UXTEditor::blockTableSignals( bool block ) +{ + if( block ) + disconnect( d_ptr->t, SIGNAL( cellChanged( int, int ) ), this, SLOT( onCellChanged( int, int ) ) ); + else + connect( d_ptr->t, SIGNAL( cellChanged( int, int ) ), this, SLOT( onCellChanged( int, int ) ) ); +} + +void UXTEditor::markRowTranslated( int row ) +{ + blockTableSignals( true ); + + QTableWidgetItem *item1 = d_ptr->t->item( row, 0 ); + QTableWidgetItem *item2 = d_ptr->t->item( row, 1 ); + markItemTranslated( item1 ); + markItemTranslated( item2 ); + + blockTableSignals( false ); +} + +void UXTEditor::markRowUntranslated( int row ) +{ + blockTableSignals( true ); + + QTableWidgetItem *item1 = d_ptr->t->item( row, 0 ); + QTableWidgetItem *item2 = d_ptr->t->item( row, 1 ); + markItemUntranslated( item1 ); + markItemUntranslated( item2 ); + + blockTableSignals( false ); +} + +} diff --git a/code/studio/src/settings_dialog.cpp b/code/studio/src/settings_dialog.cpp index 6824b0f56..78773a666 100644 --- a/code/studio/src/settings_dialog.cpp +++ b/code/studio/src/settings_dialog.cpp @@ -1,236 +1,236 @@ -// Ryzom Core - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#include "settings_dialog.h" -#include -#include -#include - -int findListItem( QListWidget *l, const QString &s ) -{ - for( int i = 0; i < l->count(); i++ ) - { - QListWidgetItem *item = l->item( i ); - if( item->text() == s ) - return i; - } - - return -1; -} - -SettingsDialog::SettingsDialog( QDialog *parent ) : -QDialog( parent ) -{ - setupUi( this ); - setupConnections(); - settings = NULL; -} - -SettingsDialog::~SettingsDialog() -{ -} - -void SettingsDialog::load() -{ - pluginsLE->setText( settings->value( "PluginPath" ).toString() ); - - settings->beginGroup( "DataPath" ); - - sheetsLE->setText( settings->value( "LevelDesignPath" ).toString() ); - assetsLE->setText( settings->value( "AssetsPath" ).toString() ); - primitivesLE->setText( settings->value( "PrimitivesPath" ).toString() ); - ligoLE->setText( settings->value( "LigoConfigFile" ).toString() ); - - QStringList l = settings->value( "SearchPaths" ).toStringList(); - { - QStringListIterator itr( l ); - while( itr.hasNext() ) - { - QString p = itr.next(); - if( findListItem( searchLW, p ) == -1 ) - searchLW->addItem( p ); - } - } - - l.clear(); - - l = settings->value( "RecursiveSearchPathes" ).toStringList(); - { - QStringListIterator itr( l ); - while( itr.hasNext() ) - { - QString p = itr.next(); - if( findListItem( recursiveLW, p ) == -1 ) - recursiveLW->addItem( p ); - } - } - - settings->endGroup(); -} - -void SettingsDialog::saveSearchPaths() -{ - QStringList l; - for( int i = 0; i < searchLW->count(); i++ ) - { - l.push_back( searchLW->item( i )->text() ); - } - - settings->setValue( "SearchPaths", l ); -} - -void SettingsDialog::saveRecursivePaths() -{ - QStringList l; - for( int i = 0; i < recursiveLW->count(); i++ ) - { - l.push_back( recursiveLW->item( i )->text() ); - } - - settings->setValue( "RecursiveSearchPathes", l ); -} - -void SettingsDialog::save() -{ - settings->setValue( "PluginPath", pluginsLE->text() ); - - settings->beginGroup( "DataPath" ); - - settings->setValue( "LevelDesignPath", sheetsLE->text() ); - settings->setValue( "AssetsPath", assetsLE->text() ); - settings->setValue( "PrimitivesPath", primitivesLE->text() ); - settings->setValue( "LigoConfigFile", ligoLE->text() ); - - saveSearchPaths(); - saveRecursivePaths(); - - settings->endGroup(); - - settings->sync(); -} - -void SettingsDialog::accept() -{ - save(); - QDialog::accept(); -} - -void SettingsDialog::reject() -{ - QDialog::reject(); -} - -void SettingsDialog::onOKClicked() -{ - accept(); -} - -void SettingsDialog::onCancelClicked() -{ - reject(); -} - -void SettingsDialog::onPluginBClicked() -{ - QString p = QFileDialog::getExistingDirectory( this, tr( "Plugins directory" ), "" ); - pluginsLE->setText( p ); -} - -void SettingsDialog::onSheetsBClicked() -{ - QString p = QFileDialog::getExistingDirectory( this, tr( "Sheets directory" ), "" ); - sheetsLE->setText( p ); -} - -void SettingsDialog::onAssetsBClicked() -{ - QString p = QFileDialog::getExistingDirectory( this, tr( "Assets directory" ), "" ); - assetsLE->setText( p ); -} - -void SettingsDialog::onPrimitivesBClicked() -{ - QString p = QFileDialog::getExistingDirectory( this, tr( "Primitives directory" ), "" ); - primitivesLE->setText( p ); -} - -void SettingsDialog::onLigoBClicked() -{ - QString p = QFileDialog::getExistingDirectory( this, tr( "LIGO directory" ), "" ); - ligoLE->setText( p ); -} - -void SettingsDialog::onPathAddClicked() -{ - QString p = QFileDialog::getExistingDirectory( this, tr( "Search path" ), "" ); - if( p.isEmpty() ) - return; - - if( findListItem( searchLW, p ) != -1 ) - return; - - searchLW->addItem( p ); -} - -void SettingsDialog::onPathRemoveClicked() -{ - QListWidgetItem *i = searchLW->currentItem(); - if( i == NULL ) - return; - - delete i; -} - -void SettingsDialog::onRecursiveAddClicked() -{ - QString p = QFileDialog::getExistingDirectory( this, tr( "Recursive search path" ), "" ); - if( p.isEmpty() ) - return; - - if( findListItem( recursiveLW, p ) != -1 ) - return; - - recursiveLW->addItem( p ); -} - -void SettingsDialog::onRecursiveRemoveClicked() -{ - QListWidgetItem *i = recursiveLW->currentItem(); - if( i == NULL ) - return; - - delete i; -} - - -void SettingsDialog::setupConnections() -{ - connect( bb, SIGNAL( accepted() ), this, SLOT( onOKClicked() ) ); - connect( bb, SIGNAL( rejected() ), this, SLOT( onCancelClicked() ) ); - - connect( pluginsB, SIGNAL( clicked( bool ) ), this, SLOT( onPluginBClicked() ) ); - connect( sheetsB, SIGNAL( clicked( bool ) ), this, SLOT( onSheetsBClicked() ) ); - connect( assetsB, SIGNAL( clicked( bool ) ), this, SLOT( onAssetsBClicked() ) ); - connect( primitivesB, SIGNAL( clicked( bool ) ), this, SLOT( onPrimitivesBClicked() ) ); - connect( ligoB, SIGNAL( clicked( bool ) ), this, SLOT( onLigoBClicked() ) ); - - connect( pathAddB, SIGNAL( clicked( bool ) ), this, SLOT( onPathAddClicked() ) ); - connect( pathRemoveB, SIGNAL( clicked( bool ) ), this, SLOT( onPathRemoveClicked() ) ); - connect( recAddB, SIGNAL( clicked( bool ) ), this, SLOT( onRecursiveAddClicked() ) ); - connect( recRemoveB, SIGNAL( clicked( bool ) ), this, SLOT( onRecursiveRemoveClicked() ) ); -} - +// Ryzom Core - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "settings_dialog.h" +#include +#include +#include + +int findListItem( QListWidget *l, const QString &s ) +{ + for( int i = 0; i < l->count(); i++ ) + { + QListWidgetItem *item = l->item( i ); + if( item->text() == s ) + return i; + } + + return -1; +} + +SettingsDialog::SettingsDialog( QDialog *parent ) : +QDialog( parent ) +{ + setupUi( this ); + setupConnections(); + settings = NULL; +} + +SettingsDialog::~SettingsDialog() +{ +} + +void SettingsDialog::load() +{ + pluginsLE->setText( settings->value( "PluginPath" ).toString() ); + + settings->beginGroup( "DataPath" ); + + sheetsLE->setText( settings->value( "LevelDesignPath" ).toString() ); + assetsLE->setText( settings->value( "AssetsPath" ).toString() ); + primitivesLE->setText( settings->value( "PrimitivesPath" ).toString() ); + ligoLE->setText( settings->value( "LigoConfigFile" ).toString() ); + + QStringList l = settings->value( "SearchPaths" ).toStringList(); + { + QStringListIterator itr( l ); + while( itr.hasNext() ) + { + QString p = itr.next(); + if( findListItem( searchLW, p ) == -1 ) + searchLW->addItem( p ); + } + } + + l.clear(); + + l = settings->value( "RecursiveSearchPathes" ).toStringList(); + { + QStringListIterator itr( l ); + while( itr.hasNext() ) + { + QString p = itr.next(); + if( findListItem( recursiveLW, p ) == -1 ) + recursiveLW->addItem( p ); + } + } + + settings->endGroup(); +} + +void SettingsDialog::saveSearchPaths() +{ + QStringList l; + for( int i = 0; i < searchLW->count(); i++ ) + { + l.push_back( searchLW->item( i )->text() ); + } + + settings->setValue( "SearchPaths", l ); +} + +void SettingsDialog::saveRecursivePaths() +{ + QStringList l; + for( int i = 0; i < recursiveLW->count(); i++ ) + { + l.push_back( recursiveLW->item( i )->text() ); + } + + settings->setValue( "RecursiveSearchPathes", l ); +} + +void SettingsDialog::save() +{ + settings->setValue( "PluginPath", pluginsLE->text() ); + + settings->beginGroup( "DataPath" ); + + settings->setValue( "LevelDesignPath", sheetsLE->text() ); + settings->setValue( "AssetsPath", assetsLE->text() ); + settings->setValue( "PrimitivesPath", primitivesLE->text() ); + settings->setValue( "LigoConfigFile", ligoLE->text() ); + + saveSearchPaths(); + saveRecursivePaths(); + + settings->endGroup(); + + settings->sync(); +} + +void SettingsDialog::accept() +{ + save(); + QDialog::accept(); +} + +void SettingsDialog::reject() +{ + QDialog::reject(); +} + +void SettingsDialog::onOKClicked() +{ + accept(); +} + +void SettingsDialog::onCancelClicked() +{ + reject(); +} + +void SettingsDialog::onPluginBClicked() +{ + QString p = QFileDialog::getExistingDirectory( this, tr( "Plugins directory" ), "" ); + pluginsLE->setText( p ); +} + +void SettingsDialog::onSheetsBClicked() +{ + QString p = QFileDialog::getExistingDirectory( this, tr( "Sheets directory" ), "" ); + sheetsLE->setText( p ); +} + +void SettingsDialog::onAssetsBClicked() +{ + QString p = QFileDialog::getExistingDirectory( this, tr( "Assets directory" ), "" ); + assetsLE->setText( p ); +} + +void SettingsDialog::onPrimitivesBClicked() +{ + QString p = QFileDialog::getExistingDirectory( this, tr( "Primitives directory" ), "" ); + primitivesLE->setText( p ); +} + +void SettingsDialog::onLigoBClicked() +{ + QString p = QFileDialog::getExistingDirectory( this, tr( "LIGO directory" ), "" ); + ligoLE->setText( p ); +} + +void SettingsDialog::onPathAddClicked() +{ + QString p = QFileDialog::getExistingDirectory( this, tr( "Search path" ), "" ); + if( p.isEmpty() ) + return; + + if( findListItem( searchLW, p ) != -1 ) + return; + + searchLW->addItem( p ); +} + +void SettingsDialog::onPathRemoveClicked() +{ + QListWidgetItem *i = searchLW->currentItem(); + if( i == NULL ) + return; + + delete i; +} + +void SettingsDialog::onRecursiveAddClicked() +{ + QString p = QFileDialog::getExistingDirectory( this, tr( "Recursive search path" ), "" ); + if( p.isEmpty() ) + return; + + if( findListItem( recursiveLW, p ) != -1 ) + return; + + recursiveLW->addItem( p ); +} + +void SettingsDialog::onRecursiveRemoveClicked() +{ + QListWidgetItem *i = recursiveLW->currentItem(); + if( i == NULL ) + return; + + delete i; +} + + +void SettingsDialog::setupConnections() +{ + connect( bb, SIGNAL( accepted() ), this, SLOT( onOKClicked() ) ); + connect( bb, SIGNAL( rejected() ), this, SLOT( onCancelClicked() ) ); + + connect( pluginsB, SIGNAL( clicked( bool ) ), this, SLOT( onPluginBClicked() ) ); + connect( sheetsB, SIGNAL( clicked( bool ) ), this, SLOT( onSheetsBClicked() ) ); + connect( assetsB, SIGNAL( clicked( bool ) ), this, SLOT( onAssetsBClicked() ) ); + connect( primitivesB, SIGNAL( clicked( bool ) ), this, SLOT( onPrimitivesBClicked() ) ); + connect( ligoB, SIGNAL( clicked( bool ) ), this, SLOT( onLigoBClicked() ) ); + + connect( pathAddB, SIGNAL( clicked( bool ) ), this, SLOT( onPathAddClicked() ) ); + connect( pathRemoveB, SIGNAL( clicked( bool ) ), this, SLOT( onPathRemoveClicked() ) ); + connect( recAddB, SIGNAL( clicked( bool ) ), this, SLOT( onRecursiveAddClicked() ) ); + connect( recRemoveB, SIGNAL( clicked( bool ) ), this, SLOT( onRecursiveRemoveClicked() ) ); +} + diff --git a/code/studio/src/settings_dialog.h b/code/studio/src/settings_dialog.h index c6e7cc93a..173ba37d4 100644 --- a/code/studio/src/settings_dialog.h +++ b/code/studio/src/settings_dialog.h @@ -1,62 +1,62 @@ -// Ryzom Core - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#ifndef SETTINGS_DIALOG_H -#define SETTINGS_DIALOG_H - -#include "ui_settings_dialog.h" - -class QSettings; - -class SettingsDialog : public QDialog, public Ui::SettingsDialog -{ - Q_OBJECT -public: - SettingsDialog( QDialog *parent = NULL ); - ~SettingsDialog(); - - void setSettings( QSettings *s ){ settings = s; } - - void load(); - -public Q_SLOTS: - void accept(); - void reject(); - - void onOKClicked(); - void onCancelClicked(); - - void onPluginBClicked(); - void onSheetsBClicked(); - void onAssetsBClicked(); - void onPrimitivesBClicked(); - void onLigoBClicked(); - - void onPathAddClicked(); - void onPathRemoveClicked(); - void onRecursiveAddClicked(); - void onRecursiveRemoveClicked(); - -private: - void setupConnections(); - void save(); - void saveSearchPaths(); - void saveRecursivePaths(); - - QSettings *settings; -}; - -#endif +// Ryzom Core - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef SETTINGS_DIALOG_H +#define SETTINGS_DIALOG_H + +#include "ui_settings_dialog.h" + +class QSettings; + +class SettingsDialog : public QDialog, public Ui::SettingsDialog +{ + Q_OBJECT +public: + SettingsDialog( QDialog *parent = NULL ); + ~SettingsDialog(); + + void setSettings( QSettings *s ){ settings = s; } + + void load(); + +public Q_SLOTS: + void accept(); + void reject(); + + void onOKClicked(); + void onCancelClicked(); + + void onPluginBClicked(); + void onSheetsBClicked(); + void onAssetsBClicked(); + void onPrimitivesBClicked(); + void onLigoBClicked(); + + void onPathAddClicked(); + void onPathRemoveClicked(); + void onRecursiveAddClicked(); + void onRecursiveRemoveClicked(); + +private: + void setupConnections(); + void save(); + void saveSearchPaths(); + void saveRecursivePaths(); + + QSettings *settings; +}; + +#endif diff --git a/code/studio/src/splash_screen.cpp b/code/studio/src/splash_screen.cpp index 252472e8d..36f7b3bc0 100644 --- a/code/studio/src/splash_screen.cpp +++ b/code/studio/src/splash_screen.cpp @@ -1,109 +1,109 @@ -// Ryzom Core - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#include "splash_screen.h" -#include -#include -#include -#include - -SplashScreen::SplashScreen() : -QSplashScreen() -{ - progress = 0; - textX = 5; - textY = 20; - pbLeft = 2; - pbTop = 0; - pbWidth = 100; - pbHeight = 20; -} - -SplashScreen::~SplashScreen() -{ -} - -void SplashScreen::setPixmap( const QPixmap &pixmap ) -{ - QSplashScreen::setPixmap( pixmap ); - - if( this->pixmap().width() > 0 ) - pbWidth = this->pixmap().width() - 4; - - if( this->pixmap().height() > 0 ) - pbTop = this->pixmap().height() - pbHeight - 2; - - textY = pbTop - pbHeight / 2; -} - -void SplashScreen::setText( const QString &text ) -{ - this->text = text; - repaint(); - QCoreApplication::instance()->processEvents(); -} - -void SplashScreen::clearText() -{ - setText( "" ); -} - -void SplashScreen::setProgress( int percent ) -{ - progress = percent; - repaint(); - QCoreApplication::instance()->processEvents(); -} - -void SplashScreen::advanceProgress( int percent ) -{ - progress += percent; - repaint(); - QCoreApplication::instance()->processEvents(); -} - -void SplashScreen::drawContents( QPainter *painter ) -{ - QSplashScreen::drawContents( painter ); - - if( progressBarEnabled ) - { - QStyleOptionProgressBarV2 pbStyle; - pbStyle.initFrom( this ); - pbStyle.state = QStyle::State_Enabled; - pbStyle.textVisible = false; - pbStyle.minimum = 0; - pbStyle.maximum = 100; - pbStyle.progress = progress; - pbStyle.invertedAppearance = false; - pbStyle.rect = QRect( pbLeft, pbTop, pbWidth, pbHeight ); - - style()->drawControl( QStyle::CE_ProgressBar, &pbStyle, painter, this ); - } - - if( !text.isEmpty() ) - { - QPen oldPen = painter->pen(); - QPen pen; - pen.setColor( Qt::white ); - painter->setPen( pen ); - painter->drawText( textX, textY, text ); - painter->setPen( oldPen ); - } -} - - +// Ryzom Core - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "splash_screen.h" +#include +#include +#include +#include + +SplashScreen::SplashScreen() : +QSplashScreen() +{ + progress = 0; + textX = 5; + textY = 20; + pbLeft = 2; + pbTop = 0; + pbWidth = 100; + pbHeight = 20; +} + +SplashScreen::~SplashScreen() +{ +} + +void SplashScreen::setPixmap( const QPixmap &pixmap ) +{ + QSplashScreen::setPixmap( pixmap ); + + if( this->pixmap().width() > 0 ) + pbWidth = this->pixmap().width() - 4; + + if( this->pixmap().height() > 0 ) + pbTop = this->pixmap().height() - pbHeight - 2; + + textY = pbTop - pbHeight / 2; +} + +void SplashScreen::setText( const QString &text ) +{ + this->text = text; + repaint(); + QCoreApplication::instance()->processEvents(); +} + +void SplashScreen::clearText() +{ + setText( "" ); +} + +void SplashScreen::setProgress( int percent ) +{ + progress = percent; + repaint(); + QCoreApplication::instance()->processEvents(); +} + +void SplashScreen::advanceProgress( int percent ) +{ + progress += percent; + repaint(); + QCoreApplication::instance()->processEvents(); +} + +void SplashScreen::drawContents( QPainter *painter ) +{ + QSplashScreen::drawContents( painter ); + + if( progressBarEnabled ) + { + QStyleOptionProgressBarV2 pbStyle; + pbStyle.initFrom( this ); + pbStyle.state = QStyle::State_Enabled; + pbStyle.textVisible = false; + pbStyle.minimum = 0; + pbStyle.maximum = 100; + pbStyle.progress = progress; + pbStyle.invertedAppearance = false; + pbStyle.rect = QRect( pbLeft, pbTop, pbWidth, pbHeight ); + + style()->drawControl( QStyle::CE_ProgressBar, &pbStyle, painter, this ); + } + + if( !text.isEmpty() ) + { + QPen oldPen = painter->pen(); + QPen pen; + pen.setColor( Qt::white ); + painter->setPen( pen ); + painter->drawText( textX, textY, text ); + painter->setPen( oldPen ); + } +} + + diff --git a/code/studio/src/splash_screen.h b/code/studio/src/splash_screen.h index ec6cd3da8..c4ba0f648 100644 --- a/code/studio/src/splash_screen.h +++ b/code/studio/src/splash_screen.h @@ -1,60 +1,60 @@ -// Ryzom Core - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - -#ifndef SPLASH_SCREEN_H -#define SPLASH_SCREEN_H - - -#include - -class SplashScreen : public QSplashScreen -{ - Q_OBJECT -public: - SplashScreen(); - ~SplashScreen(); - - void setPixmap( const QPixmap &pixmap ); - - void setText( const QString &text ); - void clearText(); - void setTextXY( int x, int y ){ textX = x; textY = y; } - void setProgress( int percent ); - void advanceProgress( int percent ); - - void setProgressBarEnabled( bool b ){ progressBarEnabled = b; } - void setProgressBarRect( int left, int top, int width, int height ){} - -protected: - void drawContents( QPainter *painter ); - -private: - int progress; - int pbLeft; - int pbTop; - int pbWidth; - int pbHeight; - - QString text; - int textX; - int textY; - - bool progressBarEnabled; -}; - -#endif - +// Ryzom Core - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef SPLASH_SCREEN_H +#define SPLASH_SCREEN_H + + +#include + +class SplashScreen : public QSplashScreen +{ + Q_OBJECT +public: + SplashScreen(); + ~SplashScreen(); + + void setPixmap( const QPixmap &pixmap ); + + void setText( const QString &text ); + void clearText(); + void setTextXY( int x, int y ){ textX = x; textY = y; } + void setProgress( int percent ); + void advanceProgress( int percent ); + + void setProgressBarEnabled( bool b ){ progressBarEnabled = b; } + void setProgressBarRect( int left, int top, int width, int height ){} + +protected: + void drawContents( QPainter *painter ); + +private: + int progress; + int pbLeft; + int pbTop; + int pbWidth; + int pbHeight; + + QString text; + int textX; + int textY; + + bool progressBarEnabled; +}; + +#endif + From 0a3d7d6355b052787fc1bf8686699a9401c6951d Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 31 Aug 2014 20:21:31 +0200 Subject: [PATCH 17/50] Added GUI for DFN dialog. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/CMakeLists.txt | 6 +- .../georges_editor/dfn_browser_ctrl.cpp | 2 + .../plugins/georges_editor/dfn_browser_ctrl.h | 4 + .../georges_editor/georges_dfn_dialog.cpp | 52 +++++++ .../georges_editor/georges_dfn_dialog.h | 24 ++++ .../georges_editor/georges_dfn_dialog.ui | 136 ++++++++++++++++++ .../georges_editor/georges_editor_form.cpp | 15 ++ .../georges_editor/georges_editor_form.h | 2 + 8 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp create mode 100644 code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h create mode 100644 code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp create mode 100644 code/studio/src/plugins/georges_editor/georges_dfn_dialog.h create mode 100644 code/studio/src/plugins/georges_editor/georges_dfn_dialog.ui diff --git a/code/studio/src/plugins/georges_editor/CMakeLists.txt b/code/studio/src/plugins/georges_editor/CMakeLists.txt index c2d3c1da7..62b9de685 100644 --- a/code/studio/src/plugins/georges_editor/CMakeLists.txt +++ b/code/studio/src/plugins/georges_editor/CMakeLists.txt @@ -18,11 +18,15 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h expandable_headerview.h browser_ctrl.h browser_ctrl_pvt.h + dfn_browser_ctrl.h + georges_dfn_dialog.h ) SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui georges_dirtree_form.ui - georges_treeview_form.ui) + georges_treeview_form.ui + georges_dfn_dialog.ui + ) SET(OVQT_PLUGIN_GEORGES_EDITOR_RCS georges_editor.qrc) diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp new file mode 100644 index 000000000..4183e6f6c --- /dev/null +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -0,0 +1,2 @@ +#include "dfn_browser_ctrl.h" + diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h new file mode 100644 index 000000000..fae44bd1e --- /dev/null +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h @@ -0,0 +1,4 @@ +#ifndef DFN_BROWSER_CTRL +#define DFN_BROWSER_CTRL +#endif + diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp new file mode 100644 index 000000000..e9441aa6e --- /dev/null +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -0,0 +1,52 @@ +#include "georges_dfn_dialog.h" +#include +#include + +GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) : +QDockWidget( parent ) +{ + m_ui.setupUi( this ); + setupConnections(); + + m_ui.addButton->setEnabled( false ); + m_ui.removeButton->setEnabled( false ); +} + +GeorgesDFNDialog::~GeorgesDFNDialog() +{ +} + +void GeorgesDFNDialog::onAddClicked() +{ + QString name = QInputDialog::getText( this, + tr( "New element" ), + tr( "Enter name of the new element" ) ); + + QList< QListWidgetItem* > list = m_ui.list->findItems( name, Qt::MatchFixedString ); + if( !list.isEmpty() ) + { + QMessageBox::information( this, + tr( "Item already exists" ), + tr( "That item already exists!" ) ); + return; + } + + m_ui.list->addItem( name ); +} + +void GeorgesDFNDialog::onRemoveClicked() +{ + int row = m_ui.list->currentRow(); + if( row < 0 ) + return; + + QListWidgetItem *item = m_ui.list->takeItem( row ); + delete item; +} + +void GeorgesDFNDialog::setupConnections() +{ + connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); + connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); +} + diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h new file mode 100644 index 000000000..d8811e8ed --- /dev/null +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -0,0 +1,24 @@ +#ifndef GEORGES_DFN_DIALOG +#define GEORGES_DFN_DIALOG + +#include "ui_georges_dfn_dialog.h" + +class GeorgesDFNDialog : public QDockWidget +{ + Q_OBJECT +public: + GeorgesDFNDialog( QWidget *parent = NULL ); + ~GeorgesDFNDialog(); + +private Q_SLOTS: + void onAddClicked(); + void onRemoveClicked(); + +private: + void setupConnections(); + + Ui::GeorgesDFNDialog m_ui; +}; + +#endif + diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.ui b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.ui new file mode 100644 index 000000000..3cbdb7419 --- /dev/null +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.ui @@ -0,0 +1,136 @@ + + + GeorgesDFNDialog + + + + 0 + 0 + 693 + 559 + + + + + + + + + + + QTabWidget::West + + + QTabWidget::Rounded + + + 0 + + + false + + + false + + + + + + + Dfn + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Add + + + + + + + + 0 + 0 + + + + Remove + + + + + + + Qt::Horizontal + + + + 466 + 20 + + + + + + + + + Comments + + + + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + Log + + + + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + + + + + QtTreePropertyBrowser + QWidget +
qttreepropertybrowser.h
+ 1 +
+
+ + +
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 166243adf..9e47fd4cb 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -20,6 +20,7 @@ #include "georges_editor_constants.h" #include "georges_dirtree_dialog.h" #include "georges_treeview_dialog.h" +#include "georges_dfn_dialog.h" #include "../core/icore.h" #include "../core/menu_manager.h" @@ -216,6 +217,12 @@ namespace GeorgesQt } } + if( info.suffix() == "dfn" ) + { + loadDfnDialog( fileName ); + return; + } + CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock); dock->setUndoStack(UndoStack); m_lastActiveDock = dock; @@ -319,4 +326,12 @@ namespace GeorgesQt } } } + + + void GeorgesEditorForm::loadDfnDialog( const QString &fileName ) + { + GeorgesDFNDialog *d = new GeorgesDFNDialog(); + m_mainDock->addDockWidget( Qt::RightDockWidgetArea, d ); + } + } /* namespace GeorgesQt */ 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 6b4e33fcd..a1a4df0d4 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.h +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.h @@ -56,6 +56,8 @@ private: void readSettings(); void writeSettings(); + void loadDfnDialog(const QString &fileName); + Ui::GeorgesEditorForm m_ui; CGeorgesDirTreeDialog *m_georgesDirTreeDialog; From 230159e2b686d305707f20821c04f9af07b231b9 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 31 Aug 2014 21:25:12 +0200 Subject: [PATCH 18/50] Added common base class for Typ, Dfn, and From dialogs: GeorgesDockWidget. --HG-- branch : dfighter-tools --- .../georges_editor/georges_dfn_dialog.cpp | 2 +- .../georges_editor/georges_dfn_dialog.h | 5 +- .../georges_editor/georges_dock_widget.cpp | 14 +++ .../georges_editor/georges_dock_widget.h | 29 +++++ .../georges_editor/georges_editor_form.cpp | 109 +++++++++++------- .../georges_editor/georges_editor_form.h | 10 +- .../georges_treeview_dialog.cpp | 3 +- .../georges_editor/georges_treeview_dialog.h | 14 +-- 8 files changed, 128 insertions(+), 58 deletions(-) create mode 100644 code/studio/src/plugins/georges_editor/georges_dock_widget.cpp create mode 100644 code/studio/src/plugins/georges_editor/georges_dock_widget.h 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 e9441aa6e..c3b579737 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -3,7 +3,7 @@ #include GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) : -QDockWidget( parent ) +GeorgesDockWidget( parent ) { m_ui.setupUi( this ); setupConnections(); 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 d8811e8ed..bffe45368 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -1,15 +1,18 @@ #ifndef GEORGES_DFN_DIALOG #define GEORGES_DFN_DIALOG +#include "georges_dock_widget.h" #include "ui_georges_dfn_dialog.h" -class GeorgesDFNDialog : public QDockWidget +class GeorgesDFNDialog : public GeorgesDockWidget { Q_OBJECT public: GeorgesDFNDialog( QWidget *parent = NULL ); ~GeorgesDFNDialog(); + void write(){} + private Q_SLOTS: void onAddClicked(); void onRemoveClicked(); diff --git a/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp new file mode 100644 index 000000000..7fbc4906b --- /dev/null +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp @@ -0,0 +1,14 @@ +#include "georges_dock_widget.h" + +GeorgesDockWidget::GeorgesDockWidget( QWidget *parent ) : +QDockWidget( parent ) +{ + m_modified = false; + m_undoStack = NULL; +} + +GeorgesDockWidget::~GeorgesDockWidget() +{ +} + + diff --git a/code/studio/src/plugins/georges_editor/georges_dock_widget.h b/code/studio/src/plugins/georges_editor/georges_dock_widget.h new file mode 100644 index 000000000..759986aa0 --- /dev/null +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.h @@ -0,0 +1,29 @@ +#ifndef GEORGES_DOCK_WIDGET +#define GEORGES_DOCK_WIDGET + +#include + +class QUndoStack; + +class GeorgesDockWidget : public QDockWidget +{ +public: + GeorgesDockWidget( QWidget *parent = NULL ); + ~GeorgesDockWidget(); + + void setUndoStack( QUndoStack *stack ){ m_undoStack = stack; } + + bool isModified() const{ return m_modified; } + void setModified( bool b ){ m_modified = b; } + + QString fileName() const{ return m_fileName; } + + virtual void write() = 0; + +protected: + QString m_fileName; + bool m_modified; + QUndoStack *m_undoStack; +}; + +#endif 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 9e47fd4cb..708e710d2 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -207,9 +207,9 @@ namespace GeorgesQt // Check to see if the form is already loaded, if it is just raise it. if (m_dockedWidgets.size()) { - Q_FOREACH(CGeorgesTreeViewDialog *wgt, m_dockedWidgets) + Q_FOREACH(GeorgesDockWidget *wgt, m_dockedWidgets) { - if (info.fileName() == wgt->loadedForm) + if (info.fileName() == wgt->fileName()) { wgt->raise(); return; @@ -217,16 +217,33 @@ namespace GeorgesQt } } + GeorgesDockWidget *w = NULL; + if( info.suffix() == "dfn" ) { - loadDfnDialog( fileName ); + w = loadDfnDialog( fileName ); + } + else + if( info.suffix() == "typ" ) + { + w = loadTypDialog( fileName ); + } + else + { + w = loadFormDialog( fileName, loadFromDfn ); + } + + if( w == NULL ) + { + QMessageBox::information( this, + tr( "Failed to load file..." ), + tr( "Failed to load file '%1'" ).arg( info.fileName() ) ); return; } - CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock); - dock->setUndoStack(UndoStack); - m_lastActiveDock = dock; - m_dockedWidgets.append(dock); + w->setUndoStack(UndoStack); + m_lastActiveDock = w; + m_dockedWidgets.append(w); connect(m_dockedWidgets.last(), SIGNAL(closing()), this, SLOT(closingTreeView())); connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)), m_dockedWidgets.last(), SLOT(checkVisibility(bool))); @@ -241,38 +258,6 @@ namespace GeorgesQt m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); } - // Retrieve the form and load the form. - NLGEORGES::CForm *form; - if(loadFromDfn) - { - // Get the form by DFN name. - form = m_dockedWidgets.last()->getFormByDfnName(info.fileName()); - } - else - { - form = m_dockedWidgets.last()->getFormByName(info.fileName()); - } - - if (form) - { - m_dockedWidgets.last()->setForm(form); - m_dockedWidgets.last()->loadFormIntoDialog(form); - QApplication::processEvents(); - connect(m_dockedWidgets.last(), SIGNAL(modified()), - this, SLOT(setModified())); - m_dockedWidgets.last()->raise(); - connect(m_dockedWidgets.last(), SIGNAL(changeFile(QString)), - m_georgesDirTreeDialog, SLOT(changeFile(QString))); - } - else - { - nlwarning("Failed to load form: %s", info.fileName().toUtf8().constData()); - m_dockedWidgets.last()->close(); - - QMessageBox::information( this, - tr( "Failed to load form..." ), - tr( "Failed to load form '%1'" ).arg( info.fileName() ) ); - } } void GeorgesEditorForm::closingTreeView() @@ -327,11 +312,55 @@ namespace GeorgesQt } } + GeorgesDockWidget* GeorgesEditorForm::loadTypDialog( const QString &fileName ) + { + return NULL; + } - void GeorgesEditorForm::loadDfnDialog( const QString &fileName ) + GeorgesDockWidget* GeorgesEditorForm::loadDfnDialog( const QString &fileName ) { GeorgesDFNDialog *d = new GeorgesDFNDialog(); m_mainDock->addDockWidget( Qt::RightDockWidgetArea, d ); + + return d; + } + + GeorgesDockWidget* GeorgesEditorForm::loadFormDialog( const QString &fileName, bool loadFromDFN ) + { + QFileInfo info( fileName ); + + CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(m_mainDock); + + // Retrieve the form and load the form. + NLGEORGES::CForm *form; + if(loadFromDFN) + { + // Get the form by DFN name. + form = d->getFormByDfnName(info.fileName()); + } + else + { + form = d->getFormByName(info.fileName()); + } + + if (form) + { + d->setForm(form); + d->loadFormIntoDialog(form); + QApplication::processEvents(); + connect(d, SIGNAL(modified()), + this, SLOT(setModified())); + d->raise(); + connect(d, SIGNAL(changeFile(QString)), + m_georgesDirTreeDialog, SLOT(changeFile(QString))); + } + else + { + delete d; + d = NULL; + } + + return d; } } /* namespace GeorgesQt */ 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 a1a4df0d4..4d0310306 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.h +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.h @@ -23,6 +23,8 @@ // Qt includes #include +class GeorgesDockWidget; + namespace GeorgesQt { @@ -56,7 +58,9 @@ private: void readSettings(); void writeSettings(); - void loadDfnDialog(const QString &fileName); + GeorgesDockWidget* loadTypDialog(const QString &fileName); + GeorgesDockWidget* loadDfnDialog(const QString &fileName); + GeorgesDockWidget* loadFormDialog(const QString &fileName, bool loadFromDFN ); Ui::GeorgesEditorForm m_ui; @@ -71,10 +75,10 @@ private: QMainWindow *m_mainDock; /// Contains a list of all of the open forms. - QList m_dockedWidgets; + QList m_dockedWidgets; /// Contains a pointer to the last known focal change for active documents. - CGeorgesTreeViewDialog *m_lastActiveDock; + GeorgesDockWidget *m_lastActiveDock; /// Contains a record of the last directory a sheet file dialog was opened for. QString m_lastSheetDir; 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 9def10065..36efea208 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -52,7 +52,7 @@ namespace GeorgesQt { CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/) - : QDockWidget(parent), + : GeorgesDockWidget(parent), m_header(0), m_modified(false) { @@ -263,6 +263,7 @@ namespace GeorgesQt if (root) { loadedForm = m_form->getFilename().c_str(); + m_fileName = m_form->getFilename().c_str(); CGeorgesFormModel *model = new CGeorgesFormModel(m_form,deps,comments,parents,m_header->expanded()); m_ui.treeView->setModel(model); 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 c3e9937ef..a32439543 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -18,6 +18,7 @@ #define GEORGES_TREEVIEWER_DIALOG_H #include "ui_georges_treeview_form.h" +#include "georges_dock_widget.h" #include "expandable_headerview.h" // Qt includes @@ -49,7 +50,7 @@ namespace GeorgesQt class CGeorges; class CGeorgesFormModel; - class CGeorgesTreeViewDialog: public QDockWidget + class CGeorgesTreeViewDialog: public GeorgesDockWidget { Q_OBJECT @@ -57,9 +58,6 @@ namespace GeorgesQt CGeorgesTreeViewDialog(QWidget *parent = 0); ~CGeorgesTreeViewDialog(); - bool isModified() {return m_modified;} - void setModified(bool m) {m_modified = m;} - NLGEORGES::CForm* getFormByName(const QString formName); NLGEORGES::CForm* getFormByDfnName(const QString dfnName); @@ -75,12 +73,6 @@ namespace GeorgesQt QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; } - void setUndoStack(QUndoStack *stack) { - m_undoStack = stack; - } - - - QString loadedForm; protected: @@ -117,8 +109,6 @@ namespace GeorgesQt UForm *m_form; CGeorges *m_georges; - QUndoStack *m_undoStack; - /// Contains a record of the last directory a sheet file dialog was opened for. QString m_lastSheetDir; From e768506349558972956659690da1df94c2a2e4c6 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 31 Aug 2014 22:42:49 +0200 Subject: [PATCH 19/50] Load DFN. --HG-- branch : dfighter-tools --- .../georges_editor/dfn_browser_ctrl.cpp | 72 +++++++++++++++++++ .../plugins/georges_editor/dfn_browser_ctrl.h | 34 +++++++++ .../georges_editor/georges_dfn_dialog.cpp | 67 +++++++++++++++++ .../georges_editor/georges_dfn_dialog.h | 5 ++ .../georges_editor/georges_editor_form.cpp | 12 +++- 5 files changed, 187 insertions(+), 3 deletions(-) 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 4183e6f6c..e1efa46e5 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -1,2 +1,74 @@ #include "dfn_browser_ctrl.h" +#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" +#include "3rdparty/qtpropertybrowser/qtvariantproperty.h" + +#include "nel/georges/form_dfn.h" + +DFNBrowserCtrl::DFNBrowserCtrl( QObject *parent ) : +QObject( parent ) +{ + m_browser = NULL; + m_dfn = NULL; + + m_manager = new QtVariantPropertyManager(); + m_factory = new QtVariantEditorFactory(); +} + +DFNBrowserCtrl::~DFNBrowserCtrl() +{ + m_browser = NULL; + m_dfn = NULL; + + delete m_manager; + m_manager = NULL; + delete m_factory; + m_factory = NULL; +} + +void DFNBrowserCtrl::onElementSelected( int idx ) +{ + NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( idx ); + + m_browser->clear(); + m_browser->setFactoryForManager( m_manager, m_factory ); + + QtVariantProperty *p = NULL; + + p = m_manager->addProperty( QVariant::String, "name" ); + p->setValue( entry.getName().c_str() ); + m_browser->addProperty( p ); + + + NLGEORGES::UFormDfn::TEntryType et = entry.getType(); + bool isArray = entry.getArrayFlag(); + QString type = ""; + + switch( et ) + { + case NLGEORGES::UFormDfn::EntryType: type = "type"; break; + case NLGEORGES::UFormDfn::EntryDfn: type = "DFN"; break; + case NLGEORGES::UFormDfn::EntryVirtualDfn: type = "Virtual DFN"; break; + } + + if( isArray ) + type += " array"; + + p = m_manager->addProperty( QVariant::String, "type" ); + p->setValue( type ); + m_browser->addProperty( p ); + + p = m_manager->addProperty( QVariant::String, "value" ); + p->setValue( entry.getFilename().c_str() ); + m_browser->addProperty( p ); + + p = m_manager->addProperty( QVariant::String, "default" ); + p->setValue( entry.getDefault().c_str() ); + m_browser->addProperty( p ); + + p = m_manager->addProperty( QVariant::String, "extension" ); + p->setValue( entry.getFilenameExt().c_str() ); + m_browser->addProperty( p ); +} + + diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h index fae44bd1e..0ac8ecd4f 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h @@ -1,4 +1,38 @@ #ifndef DFN_BROWSER_CTRL #define DFN_BROWSER_CTRL + +#include + +namespace NLGEORGES +{ + class CFormDfn; +} + +class QtVariantPropertyManager; +class QtVariantEditorFactory; +class QtTreePropertyBrowser; +class QVariant; +class QtProperty; + +class DFNBrowserCtrl : public QObject +{ + Q_OBJECT +public: + DFNBrowserCtrl( QObject *parent = NULL ); + ~DFNBrowserCtrl(); + + void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } + void setDFN( NLGEORGES::CFormDfn *dfn ){ m_dfn = dfn; } + + void onElementSelected( int idx ); + +private: + QtTreePropertyBrowser *m_browser; + NLGEORGES::CFormDfn *m_dfn; + + QtVariantPropertyManager *m_manager; + QtVariantEditorFactory *m_factory; +}; + #endif 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 c3b579737..a3021563d 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -2,6 +2,28 @@ #include #include +#include "georges.h" +#include "dfn_browser_ctrl.h" + +class GeorgesDFNDialogPvt +{ +public: + GeorgesDFNDialogPvt() + { + dfn = NULL; + ctrl = new DFNBrowserCtrl(); + } + + ~GeorgesDFNDialogPvt() + { + delete ctrl; + ctrl = NULL; + } + + NLGEORGES::CFormDfn *dfn; + DFNBrowserCtrl *ctrl; +}; + GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) : GeorgesDockWidget( parent ) { @@ -10,10 +32,46 @@ GeorgesDockWidget( parent ) m_ui.addButton->setEnabled( false ); m_ui.removeButton->setEnabled( false ); + + m_pvt = new GeorgesDFNDialogPvt(); + m_pvt->ctrl->setBrowser( m_ui.browser ); } GeorgesDFNDialog::~GeorgesDFNDialog() { + delete m_pvt; + m_pvt = NULL; +} + +bool GeorgesDFNDialog::load( const QString &fileName ) +{ + GeorgesQt::CGeorges georges; + NLGEORGES::UFormDfn *udfn = georges.loadFormDfn( fileName.toUtf8().constData() ); + if( udfn == NULL ) + return false; + + setWindowTitle( fileName ); + + NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn ); + m_pvt->dfn = cdfn; + m_pvt->ctrl->setDFN( cdfn ); + + uint c = m_pvt->dfn->getNumEntry(); + for( uint i = 0; i < c; i++ ) + { + NLGEORGES::CFormDfn::CEntry &entry = m_pvt->dfn->getEntry( i ); + m_ui.list->addItem( entry.getName().c_str() ); + } + + if( c > 0 ) + { + m_ui.list->setCurrentRow( 0 ); + } + + m_ui.commentsEdit->setPlainText( cdfn->getComment().c_str() ); + m_ui.logEdit->setPlainText( cdfn->Header.Log.c_str() ); + + return true; } void GeorgesDFNDialog::onAddClicked() @@ -44,9 +102,18 @@ void GeorgesDFNDialog::onRemoveClicked() delete item; } +void GeorgesDFNDialog::onCurrentRowChanged( int row ) +{ + if( row < 0 ) + return; + + m_pvt->ctrl->onElementSelected( row ); +} + void GeorgesDFNDialog::setupConnections() { connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); + connect( m_ui.list, SIGNAL( currentRowChanged( int ) ), this, SLOT( onCurrentRowChanged( int ) ) ); } 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 bffe45368..f88433448 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -4,6 +4,8 @@ #include "georges_dock_widget.h" #include "ui_georges_dfn_dialog.h" +class GeorgesDFNDialogPvt; + class GeorgesDFNDialog : public GeorgesDockWidget { Q_OBJECT @@ -11,16 +13,19 @@ public: GeorgesDFNDialog( QWidget *parent = NULL ); ~GeorgesDFNDialog(); + bool load( const QString &fileName ); void write(){} private Q_SLOTS: void onAddClicked(); void onRemoveClicked(); + void onCurrentRowChanged( int row ); private: void setupConnections(); Ui::GeorgesDFNDialog m_ui; + GeorgesDFNDialogPvt *m_pvt; }; #endif 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 708e710d2..b12b73b2d 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -258,6 +258,8 @@ namespace GeorgesQt m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); } + w->raise(); + } void GeorgesEditorForm::closingTreeView() @@ -320,7 +322,12 @@ namespace GeorgesQt GeorgesDockWidget* GeorgesEditorForm::loadDfnDialog( const QString &fileName ) { GeorgesDFNDialog *d = new GeorgesDFNDialog(); - m_mainDock->addDockWidget( Qt::RightDockWidgetArea, d ); + bool b = d->load( fileName ); + if( !b ) + { + delete d; + d = NULL; + } return d; } @@ -329,7 +336,7 @@ namespace GeorgesQt { QFileInfo info( fileName ); - CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(m_mainDock); + CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(); // Retrieve the form and load the form. NLGEORGES::CForm *form; @@ -350,7 +357,6 @@ namespace GeorgesQt QApplication::processEvents(); connect(d, SIGNAL(modified()), this, SLOT(setModified())); - d->raise(); connect(d, SIGNAL(changeFile(QString)), m_georgesDirTreeDialog, SLOT(changeFile(QString))); } From 259dc63ac492b941dad783f9d1f1fac45ade6812 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 31 Aug 2014 23:21:19 +0200 Subject: [PATCH 20/50] Use enum property manager for the type. --HG-- branch : dfighter-tools --- .../georges_editor/dfn_browser_ctrl.cpp | 80 ++++++++++++++++--- .../plugins/georges_editor/dfn_browser_ctrl.h | 6 ++ 2 files changed, 73 insertions(+), 13 deletions(-) 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 e1efa46e5..fbe672554 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -1,17 +1,65 @@ #include "dfn_browser_ctrl.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" #include "3rdparty/qtpropertybrowser/qtvariantproperty.h" +#include "3rdparty/qtpropertybrowser/qteditorfactory.h" +#include "3rdparty/qtpropertybrowser/qtpropertymanager.h" #include "nel/georges/form_dfn.h" +namespace +{ + enum EntryEnum + { + ENTRY_TYPE, + ENTRY_DFN, + ENTRY_VIRTUAL_DFN, + ENTRY_TYPE_ARRAY, + ENTRY_DFN_ARRAY + }; + + int entryToEnum( const NLGEORGES::UFormDfn::TEntryType &type, bool isArray ) + { + int id = 0; + + switch( type ) + { + case NLGEORGES::UFormDfn::EntryType: + + if( isArray ) + id = ENTRY_TYPE_ARRAY; + else + id = ENTRY_TYPE; + + break; + + case NLGEORGES::UFormDfn::EntryDfn: + if( isArray ) + id = ENTRY_DFN_ARRAY; + else + id = ENTRY_DFN; + + break; + + case NLGEORGES::UFormDfn::EntryVirtualDfn: + id = ENTRY_VIRTUAL_DFN; + break; + } + + return id; + } + +} + + DFNBrowserCtrl::DFNBrowserCtrl( QObject *parent ) : QObject( parent ) { m_browser = NULL; m_dfn = NULL; - m_manager = new QtVariantPropertyManager(); m_factory = new QtVariantEditorFactory(); + m_enumMgr = new QtEnumPropertyManager(); + m_enumFactory = new QtEnumEditorFactory(); } DFNBrowserCtrl::~DFNBrowserCtrl() @@ -23,6 +71,10 @@ DFNBrowserCtrl::~DFNBrowserCtrl() m_manager = NULL; delete m_factory; m_factory = NULL; + delete m_enumMgr; + m_enumMgr = NULL; + delete m_enumFactory; + m_enumFactory = NULL; } void DFNBrowserCtrl::onElementSelected( int idx ) @@ -31,8 +83,10 @@ void DFNBrowserCtrl::onElementSelected( int idx ) m_browser->clear(); m_browser->setFactoryForManager( m_manager, m_factory ); + m_browser->setFactoryForManager( m_enumMgr, m_enumFactory ); QtVariantProperty *p = NULL; + QtProperty *prop = NULL; p = m_manager->addProperty( QVariant::String, "name" ); p->setValue( entry.getName().c_str() ); @@ -41,21 +95,21 @@ void DFNBrowserCtrl::onElementSelected( int idx ) NLGEORGES::UFormDfn::TEntryType et = entry.getType(); bool isArray = entry.getArrayFlag(); - QString type = ""; - switch( et ) - { - case NLGEORGES::UFormDfn::EntryType: type = "type"; break; - case NLGEORGES::UFormDfn::EntryDfn: type = "DFN"; break; - case NLGEORGES::UFormDfn::EntryVirtualDfn: type = "Virtual DFN"; break; - } + QStringList options; + options.push_back( "Type" ); + options.push_back( "DFN" ); + options.push_back( "Virtual DFN" ); + options.push_back( "Type Array" ); + options.push_back( "DFN Array" ); - if( isArray ) - type += " array"; + int enumId = entryToEnum( et, isArray ); + + prop = m_enumMgr->addProperty( "type" ); + m_enumMgr->setEnumNames( prop, options ); + m_enumMgr->setValue( prop, enumId ); + m_browser->addProperty( prop ); - p = m_manager->addProperty( QVariant::String, "type" ); - p->setValue( type ); - m_browser->addProperty( p ); p = m_manager->addProperty( QVariant::String, "value" ); p->setValue( entry.getFilename().c_str() ); diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h index 0ac8ecd4f..178c35977 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h @@ -14,6 +14,9 @@ class QtTreePropertyBrowser; class QVariant; class QtProperty; +class QtEnumPropertyManager; +class QtEnumEditorFactory; + class DFNBrowserCtrl : public QObject { Q_OBJECT @@ -32,6 +35,9 @@ private: QtVariantPropertyManager *m_manager; QtVariantEditorFactory *m_factory; + + QtEnumPropertyManager *m_enumMgr; + QtEnumEditorFactory *m_enumFactory; }; #endif From 25d808f7ea5e070d3b3293c6d43f9da7582e2a93 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 1 Sep 2014 23:06:23 +0200 Subject: [PATCH 21/50] Added first iteration of the file path property manager / editor / factory. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/CMakeLists.txt | 1 + .../georges_editor/dfn_browser_ctrl.cpp | 19 +- .../plugins/georges_editor/dfn_browser_ctrl.h | 5 + .../filepath_property_manager.cpp | 302 ++++++++++++++++++ .../filepath_property_manager.h | 98 ++++++ 5 files changed, 422 insertions(+), 3 deletions(-) create mode 100644 code/studio/src/plugins/georges_editor/filepath_property_manager.cpp create mode 100644 code/studio/src/plugins/georges_editor/filepath_property_manager.h diff --git a/code/studio/src/plugins/georges_editor/CMakeLists.txt b/code/studio/src/plugins/georges_editor/CMakeLists.txt index 62b9de685..36b3fd735 100644 --- a/code/studio/src/plugins/georges_editor/CMakeLists.txt +++ b/code/studio/src/plugins/georges_editor/CMakeLists.txt @@ -20,6 +20,7 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h browser_ctrl_pvt.h dfn_browser_ctrl.h georges_dfn_dialog.h + filepath_property_manager.h ) SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui 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 fbe672554..398794fb5 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -4,6 +4,8 @@ #include "3rdparty/qtpropertybrowser/qteditorfactory.h" #include "3rdparty/qtpropertybrowser/qtpropertymanager.h" +#include "filepath_property_manager.h" + #include "nel/georges/form_dfn.h" namespace @@ -60,6 +62,8 @@ QObject( parent ) m_factory = new QtVariantEditorFactory(); m_enumMgr = new QtEnumPropertyManager(); m_enumFactory = new QtEnumEditorFactory(); + m_fileMgr = new FileManager(); + m_fileFactory = new FileEditFactory(); } DFNBrowserCtrl::~DFNBrowserCtrl() @@ -75,6 +79,10 @@ DFNBrowserCtrl::~DFNBrowserCtrl() m_enumMgr = NULL; delete m_enumFactory; m_enumFactory = NULL; + delete m_fileMgr; + m_fileMgr = NULL; + delete m_fileFactory; + m_fileFactory = NULL; } void DFNBrowserCtrl::onElementSelected( int idx ) @@ -84,6 +92,7 @@ void DFNBrowserCtrl::onElementSelected( int idx ) m_browser->clear(); m_browser->setFactoryForManager( m_manager, m_factory ); m_browser->setFactoryForManager( m_enumMgr, m_enumFactory ); + m_browser->setFactoryForManager( m_fileMgr, m_fileFactory ); QtVariantProperty *p = NULL; QtProperty *prop = NULL; @@ -111,9 +120,13 @@ void DFNBrowserCtrl::onElementSelected( int idx ) m_browser->addProperty( prop ); - p = m_manager->addProperty( QVariant::String, "value" ); - p->setValue( entry.getFilename().c_str() ); - m_browser->addProperty( p ); + prop = m_fileMgr->addProperty( "value" ); + m_fileMgr->setValue( prop, entry.getFilename().c_str() ); + m_browser->addProperty( prop ); + + //p = m_manager->addProperty( QVariant::String, "value" ); + //p->setValue( entry.getFilename().c_str() ); + //m_browser->addProperty( p ); p = m_manager->addProperty( QVariant::String, "default" ); p->setValue( entry.getDefault().c_str() ); diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h index 178c35977..26fdf91e3 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h @@ -16,6 +16,8 @@ class QtProperty; class QtEnumPropertyManager; class QtEnumEditorFactory; +class FileManager; +class FileEditFactory; class DFNBrowserCtrl : public QObject { @@ -38,6 +40,9 @@ private: QtEnumPropertyManager *m_enumMgr; QtEnumEditorFactory *m_enumFactory; + + FileManager *m_fileMgr; + FileEditFactory *m_fileFactory; }; #endif diff --git a/code/studio/src/plugins/georges_editor/filepath_property_manager.cpp b/code/studio/src/plugins/georges_editor/filepath_property_manager.cpp new file mode 100644 index 000000000..30d0afcfe --- /dev/null +++ b/code/studio/src/plugins/georges_editor/filepath_property_manager.cpp @@ -0,0 +1,302 @@ +#include "filepath_property_manager.h" + +#include +#include +#include +#include +#include + + +///////////////////////////////////////////////////////////////////// Manager //////////////////////////////////////////////////////////////////// + + +class FileManagerPvt +{ +public: + QMap< const QtProperty*, QString > values; +}; + +FileManager::FileManager( QObject *parent ) : +QtAbstractPropertyManager( parent ) +{ + m_pvt = new FileManagerPvt(); +} + +FileManager::~FileManager() +{ + delete m_pvt; + m_pvt = NULL; +} + +QString FileManager::value( const QtProperty *p ) const +{ + QMap< const QtProperty*, QString >::const_iterator itr = m_pvt->values.find( p ); + if( itr == m_pvt->values.end() ) + return ""; + else + return itr.value(); +} + +void FileManager::setValue( QtProperty *p, const QString &v ) +{ + if( !m_pvt->values.contains( p ) ) + return; + + if( m_pvt->values[ p ] == v ) + return; + + m_pvt->values[ p ] = v; + + Q_EMIT propertyChanged( p ); + Q_EMIT valueChanged( p, v ); +} + +bool FileManager::hasValue( const QtProperty *p ) const +{ + if( m_pvt->values.contains( p ) ) + return true; + else + return false; +} + +QString FileManager::valueText( const QtProperty *p ) const +{ + return value( p ); +} + +void FileManager::initializeProperty( QtProperty *p ) +{ + if( m_pvt->values.contains( p ) ) + return; + + m_pvt->values[ p ] = ""; +} + +void FileManager::uninitializeProperty( QtProperty *p ) +{ + m_pvt->values.remove( p ); +} + +///////////////////////////////////////////////////////////////// Factory /////////////////////////////////////////////////////////////////////////////// + +class FileEditFactoryPvt +{ +public: + QMap< QtProperty*, QList< FileEdit* > > createdEditors; + QMap< FileEdit*, QtProperty* > editorToProperty; + + void addEditor( QtProperty *p, FileEdit *editor ) + { + editorToProperty[ editor ] = p; + + QMap< QtProperty*, QList< FileEdit* > >::iterator itr = createdEditors.find( p ); + if( itr == createdEditors.end() ) + { + QList< FileEdit* > l; + l.push_back( editor ); + createdEditors[ p ] = l; + } + else + { + QList< FileEdit* > &l = itr.value(); + l.push_back( editor ); + } + } + + void removeEditor( QObject *o ) + { + // Find in editorToProperty + QMap< FileEdit*, QtProperty* >::iterator itr = editorToProperty.begin(); + while( itr != editorToProperty.end() ) + { + if( itr.key() == o ) + break; + ++itr; + } + + // Store the property, and remove the editor from editorToProperty + QtProperty *p = NULL; + if( itr != editorToProperty.end() ) + { + p = itr.value(); + editorToProperty.erase( itr ); + } + + // Find the property in createdEditors + QMap< QtProperty*, QList< FileEdit* > >::iterator mitr = createdEditors.find( p ); + QList< FileEdit* > &l = mitr.value(); + + // Find the editor in the list + QList< FileEdit* >::iterator litr = l.begin(); + while( litr != l.end() ) + { + if( o == *litr ) + break; + litr++; + } + + // Remove the editor and remove the list too if it's empty + if( litr != l.end() ) + l.erase( litr ); + + if( l.isEmpty() ) + createdEditors.erase( mitr ); + } +}; + + +FileEditFactory::FileEditFactory( QObject *parent ) : +QtAbstractEditorFactory( parent ) +{ + m_pvt = new FileEditFactoryPvt(); +} + +FileEditFactory::~FileEditFactory() +{ + delete m_pvt; + m_pvt = NULL; +} + +void FileEditFactory::connectPropertyManager( FileManager *manager ) +{ + connect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ), + this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) ); +} + +void FileEditFactory::disconnectPropertyManager( FileManager *manager ) +{ + disconnect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ), + this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) ); +} + +QWidget* FileEditFactory::createEditor( FileManager *manager, QtProperty *p, QWidget *parent ) +{ + FileEdit *editor = new FileEdit( parent ); + editor->setValue( p->valueText() ); + + connect( editor, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onSetValue( const QString& ) ) ); + connect( editor, SIGNAL( destroyed( QObject* ) ), this, SLOT( onEditorDestroyed( QObject* ) ) ); + + m_pvt->addEditor( p, editor ); + + return editor; +} + +void FileEditFactory::onPropertyChanged( QtProperty *p, const QString &v ) +{ + QMap< QtProperty*, QList< FileEdit* > >::iterator itr = m_pvt->createdEditors.find( p ); + if( itr == m_pvt->createdEditors.end() ) + return; + + QList< FileEdit* > &l = itr.value(); + QList< FileEdit* >::iterator litr = l.begin(); + while( litr != l.end() ) + { + FileEdit *editor = *litr; + editor->blockSignals( true ); + editor->setValue( v ); + editor->blockSignals( false ); + + ++litr; + } +} + +void FileEditFactory::onSetValue( const QString& v ) +{ + QObject *s = sender(); + FileEdit *editor = qobject_cast< FileEdit* >( s ); + if( editor == NULL ) + return; + + QMap< FileEdit*, QtProperty* >::iterator itr = m_pvt->editorToProperty.find( editor ); + if( itr == m_pvt->editorToProperty.end() ) + return; + + QtProperty *p = *itr; + FileManager *manager = qobject_cast< FileManager* >( p->propertyManager() ); + if( manager == NULL ) + return; + + blockSignals( true ); + manager->setValue( p, v ); + blockSignals( false ); +} + +void FileEditFactory::onEditorDestroyed( QObject *editor ) +{ + m_pvt->removeEditor( editor ); +} + + +//////////////////////////////////////////////////////////////// Editor ///////////////////////////////////////////////////////////////////////////////// + + +class FileEditPvt +{ +public: + QLineEdit *lineEdit; + QToolButton *toolButton; +}; + + + +FileEdit::FileEdit( QWidget *parent ) : +QWidget( parent ) +{ + m_pvt = new FileEditPvt(); + + setupUI(); + setupConnections(); +} + +FileEdit::~FileEdit() +{ + delete m_pvt; + m_pvt = NULL; + + Q_EMIT destroyed( this ); +} + +void FileEdit::setValue( const QString &value ) +{ + m_pvt->lineEdit->setText( value ); +} + +void FileEdit::onButtonClicked() +{ + QString file = QFileDialog::getOpenFileName( this, + tr( "" ), + tr( "" ) ); + if( file.isEmpty() ) + return; + + if( m_pvt->lineEdit->text() == file ) + return; + + m_pvt->lineEdit->setText( file ); + + Q_EMIT valueChanged( file ); +} + +void FileEdit::setupUI() +{ + m_pvt->lineEdit = new QLineEdit( this ); + m_pvt->toolButton = new QToolButton( this ); + m_pvt->toolButton->setText( "..." ); + + QHBoxLayout *layout = new QHBoxLayout( this ); + layout->setContentsMargins( 0, 0, 0, 0 ); + layout->setSpacing( 0 ); + layout->addWidget( m_pvt->lineEdit ); + layout->addWidget( m_pvt->toolButton ); + setLayout( layout ); + + setFocusProxy( m_pvt->lineEdit ); + setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ); +} + +void FileEdit::setupConnections() +{ + connect( m_pvt->toolButton, SIGNAL( clicked( bool ) ), this, SLOT( onButtonClicked() ) ); +} + diff --git a/code/studio/src/plugins/georges_editor/filepath_property_manager.h b/code/studio/src/plugins/georges_editor/filepath_property_manager.h new file mode 100644 index 000000000..0b1f5f469 --- /dev/null +++ b/code/studio/src/plugins/georges_editor/filepath_property_manager.h @@ -0,0 +1,98 @@ +#ifndef FILEPATH_PROPERTY_MANAGER +#define FILEPATH_PROPERTY_MANAGER + +#define QT_QTPROPERTYBROWSER_IMPORT + +#include +#include <3rdparty/qtpropertybrowser/qtpropertymanager.h> + +/////////////////////////////////////////////////////////////////////// Manager ///////////////////////////////////////////////////////////////// + +class FileManagerPvt; + +class FileManager : public QtAbstractPropertyManager +{ + Q_OBJECT +public: + FileManager( QObject *parent = NULL ); + ~FileManager(); + + QString value( const QtProperty *p ) const; + +public Q_SLOTS: + void setValue( QtProperty *p, const QString &v ); + +Q_SIGNALS: + void valueChanged( QtProperty *p, const QString &v ); + +protected: + bool hasValue( const QtProperty *p ) const; + QString valueText( const QtProperty *p ) const; + void initializeProperty( QtProperty *p ); + void uninitializeProperty( QtProperty *p ); + +private: + FileManagerPvt *m_pvt; + + Q_DISABLE_COPY( FileManager ); +}; + + + +//////////////////////////////////////////////////////// Factory /////////////////////////////////////////////////////////////////// + +class FileEditFactoryPvt; + +class FileEditFactory : public QtAbstractEditorFactory< FileManager > +{ + Q_OBJECT +public: + FileEditFactory( QObject *parent = NULL ); + ~FileEditFactory(); + +protected: + void connectPropertyManager( FileManager *manager ); + void disconnectPropertyManager( FileManager *manager ); + QWidget* createEditor( FileManager *manager, QtProperty *p, QWidget *parent ); + +private Q_SLOTS: + void onPropertyChanged( QtProperty *p, const QString &value ); + void onSetValue( const QString &value ); + void onEditorDestroyed( QObject *editor ); + +private: + FileEditFactoryPvt *m_pvt; + + Q_DISABLE_COPY( FileEditFactory ); +}; + + +//////////////////////////////////////////////////////// Editor //////////////////////////////////////////////////////////////////// + +class FileEditPvt; + +class FileEdit : public QWidget +{ + Q_OBJECT +public: + FileEdit( QWidget *parent = NULL ); + ~FileEdit(); + + void setValue( const QString &value ); + +Q_SIGNALS: + void valueChanged( const QString &value ); + void destroyed( QObject *editor ); + +private Q_SLOTS: + void onButtonClicked(); + +private: + void setupUI(); + void setupConnections(); + FileEditPvt *m_pvt; + + Q_DISABLE_COPY( FileEdit ); +}; + +#endif From f1a6a8d9cd0a83a3d8c3ff109e3db4c42a7b3bb7 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 14:54:07 +0200 Subject: [PATCH 22/50] Apply changes. --HG-- branch : dfighter-tools --- code/nel/include/nel/georges/form_dfn.h | 2 + code/nel/src/georges/form_dfn.cpp | 5 + .../georges_editor/dfn_browser_ctrl.cpp | 95 ++++++++++++++++++- .../plugins/georges_editor/dfn_browser_ctrl.h | 10 ++ 4 files changed, 108 insertions(+), 4 deletions(-) diff --git a/code/nel/include/nel/georges/form_dfn.h b/code/nel/include/nel/georges/form_dfn.h index 283fd0fdd..fe6fb473a 100644 --- a/code/nel/include/nel/georges/form_dfn.h +++ b/code/nel/include/nel/georges/form_dfn.h @@ -87,6 +87,8 @@ public: // Set as a type void setType (CFormLoader &loader, const char *filename); + void setType (TEntryType type); + // Set as a dfn void setDfn (CFormLoader &loader, const char *filename); diff --git a/code/nel/src/georges/form_dfn.cpp b/code/nel/src/georges/form_dfn.cpp index 715961a72..fa748535a 100644 --- a/code/nel/src/georges/form_dfn.cpp +++ b/code/nel/src/georges/form_dfn.cpp @@ -463,6 +463,11 @@ void CFormDfn::CEntry::setType (CFormLoader &loader, const char *filename) Type = loader.loadType (filename); } +void CFormDfn::CEntry::setType( TEntryType type ) +{ + TypeElement = type; +} + // *************************************************************************** void CFormDfn::CEntry::setDfn (CFormLoader &loader, const char *filename) 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 398794fb5..72d6494dd 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -19,6 +19,37 @@ namespace ENTRY_DFN_ARRAY }; + NLGEORGES::UFormDfn::TEntryType enumToEntry( int value ) + { + NLGEORGES::UFormDfn::TEntryType entry = NLGEORGES::UFormDfn::EntryType; + + switch( value ) + { + case ENTRY_TYPE: entry = NLGEORGES::UFormDfn::EntryType; break; + case ENTRY_DFN: entry = NLGEORGES::UFormDfn::EntryDfn; break; + case ENTRY_VIRTUAL_DFN: entry = NLGEORGES::UFormDfn::EntryVirtualDfn; break; + case ENTRY_TYPE_ARRAY: entry = NLGEORGES::UFormDfn::EntryType; break; + case ENTRY_DFN_ARRAY: entry = NLGEORGES::UFormDfn::EntryDfn; break; + } + + return entry; + } + + bool enumToArray( int value ) + { + bool isArray = false; + + switch( value ) + { + case ENTRY_TYPE_ARRAY: + case ENTRY_DFN_ARRAY: + isArray = true; + break; + } + + return isArray; + } + int entryToEnum( const NLGEORGES::UFormDfn::TEntryType &type, bool isArray ) { int id = 0; @@ -64,6 +95,8 @@ QObject( parent ) m_enumFactory = new QtEnumEditorFactory(); m_fileMgr = new FileManager(); m_fileFactory = new FileEditFactory(); + + m_idx = -1; } DFNBrowserCtrl::~DFNBrowserCtrl() @@ -88,6 +121,9 @@ DFNBrowserCtrl::~DFNBrowserCtrl() void DFNBrowserCtrl::onElementSelected( int idx ) { NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( idx ); + m_idx = idx; + + disconnectManagers(); m_browser->clear(); m_browser->setFactoryForManager( m_manager, m_factory ); @@ -124,10 +160,6 @@ void DFNBrowserCtrl::onElementSelected( int idx ) m_fileMgr->setValue( prop, entry.getFilename().c_str() ); m_browser->addProperty( prop ); - //p = m_manager->addProperty( QVariant::String, "value" ); - //p->setValue( entry.getFilename().c_str() ); - //m_browser->addProperty( p ); - p = m_manager->addProperty( QVariant::String, "default" ); p->setValue( entry.getDefault().c_str() ); m_browser->addProperty( p ); @@ -135,6 +167,61 @@ void DFNBrowserCtrl::onElementSelected( int idx ) p = m_manager->addProperty( QVariant::String, "extension" ); p->setValue( entry.getFilenameExt().c_str() ); m_browser->addProperty( p ); + + connectManagers(); +} + +void DFNBrowserCtrl::onVariantValueChanged( QtProperty *p, const QVariant &v ) +{ + NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx ); + + QString key = p->propertyName(); + std::string value = v.toString().toUtf8().constData(); + + if( key == "name" ) + { + entry.setName( value.c_str() ); + } + else + if( key == "default" ) + { + entry.setDefault( value.c_str() ); + } + else + if( key == "extension" ) + { + entry.setFilenameExt( value.c_str() ); + } +} + +void DFNBrowserCtrl::onEnumValueChanged( QtProperty *p, int v ) +{ + NLGEORGES::UFormDfn::TEntryType tentry = enumToEntry( v ); + bool isArray = enumToArray( v ); + + NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx ); + entry.setArrayFlag( isArray ); + entry.setType( tentry ); +} + +void DFNBrowserCtrl::onFileValueChanged( QtProperty *p, const QString &v ) +{ + NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx ); + entry.setFilename( v.toUtf8().constData() ); +} + +void DFNBrowserCtrl::connectManagers() +{ + connect( m_manager, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), this, SLOT( onVariantValueChanged( QtProperty*, const QVariant& ) ) ); + connect( m_enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ), this, SLOT( onEnumValueChanged( QtProperty*, int ) ) ); + connect( m_fileMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onFileValueChanged( QtProperty*, const QString& ) ) ); +} + +void DFNBrowserCtrl::disconnectManagers() +{ + disconnect( m_manager, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), this, SLOT( onVariantValueChanged( QtProperty*, const QVariant& ) ) ); + disconnect( m_enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ), this, SLOT( onEnumValueChanged( QtProperty*, int ) ) ); + disconnect( m_fileMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onFileValueChanged( QtProperty*, const QString& ) ) ); } diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h index 26fdf91e3..16b8c67c4 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h @@ -31,7 +31,15 @@ public: void onElementSelected( int idx ); +private Q_SLOTS: + void onFileValueChanged( QtProperty *p, const QString &v ); + void onVariantValueChanged( QtProperty *p, const QVariant &v ); + void onEnumValueChanged( QtProperty *p, int v ); + private: + void connectManagers(); + void disconnectManagers(); + QtTreePropertyBrowser *m_browser; NLGEORGES::CFormDfn *m_dfn; @@ -43,6 +51,8 @@ private: FileManager *m_fileMgr; FileEditFactory *m_fileFactory; + + int m_idx; }; #endif From e2cb637a13f564a8cf45b95273243082329cd4d6 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 15:11:28 +0200 Subject: [PATCH 23/50] Enable saving when modified, disable saving after saving. --HG-- branch : dfighter-tools --- .../georges_editor/dfn_browser_ctrl.cpp | 25 +++++++++++++++++++ .../plugins/georges_editor/dfn_browser_ctrl.h | 3 +++ .../georges_editor/georges_dfn_dialog.cpp | 23 +++++++++++++++-- .../georges_editor/georges_dfn_dialog.h | 7 +++++- .../georges_editor/georges_editor_form.cpp | 4 ++- 5 files changed, 58 insertions(+), 4 deletions(-) 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 72d6494dd..00a8bce8e 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -19,6 +19,22 @@ namespace ENTRY_DFN_ARRAY }; + QString enumToString( int value ) + { + QString s; + + switch( value ) + { + case ENTRY_TYPE: s = "type"; break; + case ENTRY_DFN: s = "dfn"; break; + case ENTRY_VIRTUAL_DFN: s = "virtual dfn"; break; + case ENTRY_TYPE_ARRAY: s = "type array"; break; + case ENTRY_DFN_ARRAY: s = "dfn array"; break; + } + + return s; + } + NLGEORGES::UFormDfn::TEntryType enumToEntry( int value ) { NLGEORGES::UFormDfn::TEntryType entry = NLGEORGES::UFormDfn::EntryType; @@ -192,6 +208,10 @@ void DFNBrowserCtrl::onVariantValueChanged( QtProperty *p, const QVariant &v ) { entry.setFilenameExt( value.c_str() ); } + else + return; + + Q_EMIT valueChanged( key, v.toString() ); } void DFNBrowserCtrl::onEnumValueChanged( QtProperty *p, int v ) @@ -202,12 +222,17 @@ void DFNBrowserCtrl::onEnumValueChanged( QtProperty *p, int v ) NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx ); entry.setArrayFlag( isArray ); entry.setType( tentry ); + + QString value = enumToString( v ); + Q_EMIT valueChanged( p->propertyName(), value ); } void DFNBrowserCtrl::onFileValueChanged( QtProperty *p, const QString &v ) { NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx ); entry.setFilename( v.toUtf8().constData() ); + + Q_EMIT valueChanged( p->propertyName(), v ); } void DFNBrowserCtrl::connectManagers() diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h index 16b8c67c4..4b4c7faf3 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h @@ -31,6 +31,9 @@ public: void onElementSelected( int idx ); +Q_SIGNALS: + void valueChanged( const QString &key, const QString &value ); + private Q_SLOTS: void onFileValueChanged( QtProperty *p, const QString &v ); void onVariantValueChanged( QtProperty *p, const QVariant &v ); 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 a3021563d..4db724252 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -28,13 +28,14 @@ GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) : GeorgesDockWidget( parent ) { m_ui.setupUi( this ); - setupConnections(); - + m_ui.addButton->setEnabled( false ); m_ui.removeButton->setEnabled( false ); m_pvt = new GeorgesDFNDialogPvt(); m_pvt->ctrl->setBrowser( m_ui.browser ); + + setupConnections(); } GeorgesDFNDialog::~GeorgesDFNDialog() @@ -74,6 +75,12 @@ bool GeorgesDFNDialog::load( const QString &fileName ) return true; } +void GeorgesDFNDialog::write() +{ + setModified( false ); + setWindowTitle( windowTitle().remove( "*" ) ); +} + void GeorgesDFNDialog::onAddClicked() { QString name = QInputDialog::getText( this, @@ -110,10 +117,22 @@ void GeorgesDFNDialog::onCurrentRowChanged( int row ) m_pvt->ctrl->onElementSelected( row ); } +void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value ) +{ + if( !isModified() ) + { + setModified( true ); + setWindowTitle( windowTitle() + "*" ); + + Q_EMIT modified(); + } +} + void GeorgesDFNDialog::setupConnections() { connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); connect( m_ui.list, SIGNAL( currentRowChanged( int ) ), this, SLOT( onCurrentRowChanged( int ) ) ); + connect( m_pvt->ctrl, SIGNAL( valueChanged( const QString&, const QString& ) ), this, SLOT( onValueChanged( const QString&, const QString& ) ) ); } 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 f88433448..123faf39e 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -14,13 +14,18 @@ public: ~GeorgesDFNDialog(); bool load( const QString &fileName ); - void write(){} + void write(); + +Q_SIGNALS: + void modified(); private Q_SLOTS: void onAddClicked(); void onRemoveClicked(); void onCurrentRowChanged( int row ); + void onValueChanged( const QString& key, const QString &value ); + private: void setupConnections(); 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 b12b73b2d..4cbe90f2e 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -326,9 +326,11 @@ namespace GeorgesQt if( !b ) { delete d; - d = NULL; + return NULL; } + connect( d, SIGNAL( modified() ), this, SLOT( setModified() ) ); + return d; } From afc8aef2381fbfefdb790d839bac64207fe5ee72 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 15:13:48 +0200 Subject: [PATCH 24/50] Change the name in the list too. --HG-- branch : dfighter-tools --- .../studio/src/plugins/georges_editor/georges_dfn_dialog.cpp | 5 +++++ 1 file changed, 5 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 4db724252..59447ff9b 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -126,6 +126,11 @@ void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value Q_EMIT modified(); } + + if( key == "name" ) + { + m_ui.list->currentItem()->setText( value ); + } } void GeorgesDFNDialog::setupConnections() From ed1c600c4de7e956ac789f72a6b2541381ed1e5d Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 15:31:14 +0200 Subject: [PATCH 25/50] Save changes. --HG-- branch : dfighter-tools --- .../georges_editor/georges_dfn_dialog.cpp | 22 +++++++++++++++++++ .../georges_editor/georges_dfn_dialog.h | 1 + 2 files changed, 23 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 59447ff9b..ef9abecf7 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -5,6 +5,10 @@ #include "georges.h" #include "dfn_browser_ctrl.h" +#include "nel/misc/file.h" +#include "nel/misc/o_xml.h" +#include "nel/misc/path.h" + class GeorgesDFNDialogPvt { public: @@ -72,6 +76,8 @@ bool GeorgesDFNDialog::load( const QString &fileName ) m_ui.commentsEdit->setPlainText( cdfn->getComment().c_str() ); m_ui.logEdit->setPlainText( cdfn->Header.Log.c_str() ); + m_fileName = fileName; + return true; } @@ -79,6 +85,22 @@ void GeorgesDFNDialog::write() { setModified( false ); setWindowTitle( windowTitle().remove( "*" ) ); + + std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false ); + if( path.empty() ) + return; + + NLMISC::COFile file; + if( !file.open( path, false, true, false ) ) + return; + + NLMISC::COXml xml; + xml.init( &file ); + + m_pvt->dfn->write( xml.getDocument(), path.c_str() ); + + xml.flush(); + file.close(); } void GeorgesDFNDialog::onAddClicked() 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 123faf39e..2410c66df 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -31,6 +31,7 @@ private: Ui::GeorgesDFNDialog m_ui; GeorgesDFNDialogPvt *m_pvt; + QString m_fileName; }; #endif From c51b5198450505806847fe300ba5ed347040c166 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 19:26:02 +0200 Subject: [PATCH 26/50] Implemented add and remove buttons. --HG-- branch : dfighter-tools --- code/nel/include/nel/georges/form_dfn.h | 4 ++++ code/nel/src/georges/form_dfn.cpp | 15 +++++++++++++++ .../plugins/georges_editor/georges_dfn_dialog.cpp | 7 +++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/code/nel/include/nel/georges/form_dfn.h b/code/nel/include/nel/georges/form_dfn.h index fe6fb473a..a93dcbe48 100644 --- a/code/nel/include/nel/georges/form_dfn.h +++ b/code/nel/include/nel/georges/form_dfn.h @@ -162,6 +162,10 @@ public: NLMISC::CSmartPtr Parent; }; + void addEntry( const std::string &name ); + + void removeEntry( uint idx ); + // ** IO functions void write (xmlDocPtr root, const char *filename); diff --git a/code/nel/src/georges/form_dfn.cpp b/code/nel/src/georges/form_dfn.cpp index fa748535a..d4a16bb50 100644 --- a/code/nel/src/georges/form_dfn.cpp +++ b/code/nel/src/georges/form_dfn.cpp @@ -41,6 +41,21 @@ void warning (bool exception, const char *format, ... ); // *************************************************************************** +void CFormDfn::addEntry( const std::string &name ) +{ + CEntry entry; + entry.setName( name.c_str() ); + Entries.push_back( entry ); +} + +void CFormDfn::removeEntry( uint idx ) +{ + std::vector< CEntry >::iterator itr = Entries.begin() + idx; + Entries.erase( itr ); +} + +// *************************************************************************** + void CFormDfn::write (xmlDocPtr doc, const char *filename) { // Save filename 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 ef9abecf7..89af2d4ea 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -33,8 +33,8 @@ GeorgesDockWidget( parent ) { m_ui.setupUi( this ); - m_ui.addButton->setEnabled( false ); - m_ui.removeButton->setEnabled( false ); + //m_ui.addButton->setEnabled( false ); + //m_ui.removeButton->setEnabled( false ); m_pvt = new GeorgesDFNDialogPvt(); m_pvt->ctrl->setBrowser( m_ui.browser ); @@ -119,6 +119,7 @@ void GeorgesDFNDialog::onAddClicked() } m_ui.list->addItem( name ); + m_pvt->dfn->addEntry( name.toUtf8().constData() ); } void GeorgesDFNDialog::onRemoveClicked() @@ -129,6 +130,8 @@ void GeorgesDFNDialog::onRemoveClicked() QListWidgetItem *item = m_ui.list->takeItem( row ); delete item; + + m_pvt->dfn->removeEntry( row ); } void GeorgesDFNDialog::onCurrentRowChanged( int row ) From e3d405454eac32b6bdca823241893d7be8f9d1d6 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 19:32:05 +0200 Subject: [PATCH 27/50] No comment. Literally! :D --HG-- branch : dfighter-tools --- code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp | 3 --- 1 file changed, 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 89af2d4ea..1dde9a693 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -33,9 +33,6 @@ GeorgesDockWidget( parent ) { m_ui.setupUi( this ); - //m_ui.addButton->setEnabled( false ); - //m_ui.removeButton->setEnabled( false ); - m_pvt = new GeorgesDFNDialogPvt(); m_pvt->ctrl->setBrowser( m_ui.browser ); From 0b9c281b2ffafdaf60a96dcd90ac84f19548a2eb Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 20:13:10 +0200 Subject: [PATCH 28/50] Logging DFN changes. --HG-- branch : dfighter-tools --- .../georges_editor/georges_dfn_dialog.cpp | 14 ++++++++++ .../georges_editor/georges_dfn_dialog.h | 1 + .../georges_editor/georges_dock_widget.cpp | 28 +++++++++++++++++++ .../georges_editor/georges_dock_widget.h | 3 ++ .../georges_treeview_dialog.cpp | 25 +---------------- 5 files changed, 47 insertions(+), 24 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 1dde9a693..56043b958 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -83,6 +83,8 @@ void GeorgesDFNDialog::write() setModified( false ); setWindowTitle( windowTitle().remove( "*" ) ); + m_pvt->dfn->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); + std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false ); if( path.empty() ) return; @@ -117,6 +119,8 @@ void GeorgesDFNDialog::onAddClicked() m_ui.list->addItem( name ); m_pvt->dfn->addEntry( name.toUtf8().constData() ); + + log( "Added " + name ); } void GeorgesDFNDialog::onRemoveClicked() @@ -125,6 +129,8 @@ void GeorgesDFNDialog::onRemoveClicked() if( row < 0 ) return; + log( "Removed " + m_ui.list->currentItem()->text() ); + QListWidgetItem *item = m_ui.list->takeItem( row ); delete item; @@ -149,12 +155,20 @@ void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value Q_EMIT modified(); } + log( m_ui.list->currentItem()->text() + "." + key + " = " + value ); + if( key == "name" ) { m_ui.list->currentItem()->setText( value ); } } +void GeorgesDFNDialog::log( const QString &msg ) +{ + QString logMsg = buildLogMsg( msg ); + m_ui.logEdit->appendPlainText( logMsg ); +} + void GeorgesDFNDialog::setupConnections() { connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); 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 2410c66df..6ce67c2d2 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -27,6 +27,7 @@ private Q_SLOTS: void onValueChanged( const QString& key, const QString &value ); private: + void log( const QString &msg ); void setupConnections(); Ui::GeorgesDFNDialog m_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 7fbc4906b..8736a604b 100644 --- a/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp @@ -11,4 +11,32 @@ GeorgesDockWidget::~GeorgesDockWidget() { } +QString GeorgesDockWidget::buildLogMsg( const QString &msg ) +{ + QString user = getenv( "USER" ); + if( user.isEmpty() ) + user = getenv( "USERNAME" ); + if( user.isEmpty() ) + user = "anonymous"; + + QTime time = QTime::currentTime(); + QDate date = QDate::currentDate(); + + QString dateString = date.toString( "ddd MMM dd" ); + QString timeString = time.toString( "HH:mm:ss" ); + + QString logMsg; + logMsg += dateString; + logMsg += ' '; + logMsg += timeString; + logMsg += ' '; + logMsg += QString::number( date.year() ); + logMsg += ' '; + logMsg += "("; + logMsg += user; + logMsg += ")"; + logMsg += ' '; + logMsg += msg; + return logMsg; +} 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 759986aa0..59aad9e8f 100644 --- a/code/studio/src/plugins/georges_editor/georges_dock_widget.h +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.h @@ -21,6 +21,9 @@ public: virtual void write() = 0; protected: + QString buildLogMsg( const QString &msg ); + virtual void log( const QString &msg ) = 0; + QString m_fileName; bool m_modified; QUndoStack *m_undoStack; 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 36efea208..184a8f845 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -698,30 +698,7 @@ namespace GeorgesQt void CGeorgesTreeViewDialog::log( const QString &msg ) { - QString user = getenv( "USER" ); - if( user.isEmpty() ) - user = getenv( "USERNAME" ); - if( user.isEmpty() ) - user = "anonymous"; - - QTime time = QTime::currentTime(); - QDate date = QDate::currentDate(); - - QString dateString = date.toString( "ddd MMM dd" ); - QString timeString = time.toString( "HH:mm:ss" ); - - QString logMsg; - logMsg += dateString; - logMsg += ' '; - logMsg += timeString; - logMsg += ' '; - logMsg += QString::number( date.year() ); - logMsg += ' '; - logMsg += "("; - logMsg += user; - logMsg += ")"; - logMsg += ' '; - logMsg += msg; + QString logMsg = buildLogMsg( msg ); m_ui.logEdit->appendPlainText( logMsg ); } From 24a7cc4a6d1b6efd414a9031380e62cb59541d65 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 22:32:56 +0200 Subject: [PATCH 29/50] Added GUI for the Type editor. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/CMakeLists.txt | 3 + .../georges_editor/georges_editor_form.cpp | 4 +- .../georges_editor/georges_typ_dialog.cpp | 36 +++++ .../georges_editor/georges_typ_dialog.h | 31 ++++ .../georges_editor/georges_typ_dialog.ui | 140 ++++++++++++++++++ .../georges_editor/typ_browser_ctrl.cpp | 1 + .../plugins/georges_editor/typ_browser_ctrl.h | 3 + 7 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp create mode 100644 code/studio/src/plugins/georges_editor/georges_typ_dialog.h create mode 100644 code/studio/src/plugins/georges_editor/georges_typ_dialog.ui create mode 100644 code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp create mode 100644 code/studio/src/plugins/georges_editor/typ_browser_ctrl.h diff --git a/code/studio/src/plugins/georges_editor/CMakeLists.txt b/code/studio/src/plugins/georges_editor/CMakeLists.txt index 36b3fd735..0f0cbc1e0 100644 --- a/code/studio/src/plugins/georges_editor/CMakeLists.txt +++ b/code/studio/src/plugins/georges_editor/CMakeLists.txt @@ -21,12 +21,15 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h dfn_browser_ctrl.h georges_dfn_dialog.h filepath_property_manager.h + typ_browser_ctrl.h + georges_typ_dialog.h ) SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui georges_dirtree_form.ui georges_treeview_form.ui georges_dfn_dialog.ui + georges_typ_dialog.ui ) SET(OVQT_PLUGIN_GEORGES_EDITOR_RCS georges_editor.qrc) 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 4cbe90f2e..f2c1c3528 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -21,6 +21,7 @@ #include "georges_dirtree_dialog.h" #include "georges_treeview_dialog.h" #include "georges_dfn_dialog.h" +#include "georges_typ_dialog.h" #include "../core/icore.h" #include "../core/menu_manager.h" @@ -316,7 +317,8 @@ namespace GeorgesQt GeorgesDockWidget* GeorgesEditorForm::loadTypDialog( const QString &fileName ) { - return NULL; + GeorgesTypDialog *d = new GeorgesTypDialog(); + return d; } GeorgesDockWidget* GeorgesEditorForm::loadDfnDialog( const QString &fileName ) diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp new file mode 100644 index 000000000..cf0102c71 --- /dev/null +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -0,0 +1,36 @@ +#include "georges_typ_dialog.h" + +GeorgesTypDialog::GeorgesTypDialog( QWidget *parent ) : +GeorgesDockWidget( parent ) +{ + m_ui.setupUi( this ); + setupConnections(); +} + +GeorgesTypDialog::~GeorgesTypDialog() +{ +} + + +void GeorgesTypDialog::write() +{ +} + +void GeorgesTypDialog::onAddClicked() +{ +} + +void GeorgesTypDialog::onRemoveClicked() +{ +} + +void GeorgesTypDialog::setupConnections() +{ + connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); + connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); +} + +void GeorgesTypDialog::log( const QString &msg ) +{ +} + diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h new file mode 100644 index 000000000..3808e019a --- /dev/null +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -0,0 +1,31 @@ +#ifndef GEORGES_TYP_DIALOG +#define GEORGES_TYP_DIALOG + +#include "georges_dock_widget.h" +#include "ui_georges_typ_dialog.h" + + +class GeorgesTypDialog : public GeorgesDockWidget +{ + Q_OBJECT +public: + GeorgesTypDialog( QWidget *parent = NULL ); + ~GeorgesTypDialog(); + + void write(); + +private Q_SLOTS: + void onAddClicked(); + void onRemoveClicked(); + +private: + void setupConnections(); + void log( const QString &msg ); + + + Ui::GeorgesTypDialog m_ui; +}; + + +#endif + diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.ui b/code/studio/src/plugins/georges_editor/georges_typ_dialog.ui new file mode 100644 index 000000000..6cd080579 --- /dev/null +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.ui @@ -0,0 +1,140 @@ + + + GeorgesTypDialog + + + + 0 + 0 + 682 + 425 + + + + + + + + + + + QTabWidget::West + + + 0 + + + + Type + + + + + + Qt::Horizontal + + + + + 0 + 0 + + + + + + + + + + Label + + + + + Value + + + + + + + + + 0 + 0 + + + + Add + + + + + + + + 0 + 0 + + + + Remove + + + + + + + Qt::Horizontal + + + + 15 + 20 + + + + + + + + + + + + + Comment + + + + + + + + + + Log + + + + + + + + + + + + + + + QtTreePropertyBrowser + QWidget +
qttreepropertybrowser.h
+ 1 +
+
+ + +
diff --git a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp new file mode 100644 index 000000000..002a89290 --- /dev/null +++ b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp @@ -0,0 +1 @@ +#include "typ_browser_ctrl.h" diff --git a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h new file mode 100644 index 000000000..bf29e1cc8 --- /dev/null +++ b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h @@ -0,0 +1,3 @@ +#ifndef TYP_BROWSER_CTRL +#define TYP_BROWSER_CTRL +#endif From cfaebcc1ffb6cc5026e0935738bf86aba1ef5dcb Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 22:46:19 +0200 Subject: [PATCH 30/50] Load .typ file. --HG-- branch : dfighter-tools --- .../georges_editor/georges_editor_form.cpp | 6 +++ .../georges_editor/georges_typ_dialog.cpp | 37 +++++++++++++++++++ .../georges_editor/georges_typ_dialog.h | 4 +- 3 files changed, 46 insertions(+), 1 deletion(-) 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 f2c1c3528..47bd9de3d 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -318,6 +318,12 @@ namespace GeorgesQt GeorgesDockWidget* GeorgesEditorForm::loadTypDialog( const QString &fileName ) { GeorgesTypDialog *d = new GeorgesTypDialog(); + if( !d->load( fileName ) ) + { + delete d; + return NULL; + } + return d; } 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 cf0102c71..d91134df6 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -1,14 +1,49 @@ #include "georges_typ_dialog.h" +#include "georges.h" + +class GeorgesTypDialogPvt +{ +public: + GeorgesTypDialogPvt() + { + typ = NULL; + } + + ~GeorgesTypDialogPvt() + { + delete typ; + typ = NULL; + } + + + NLGEORGES::CType *typ; +}; GeorgesTypDialog::GeorgesTypDialog( QWidget *parent ) : GeorgesDockWidget( parent ) { m_ui.setupUi( this ); + m_pvt = new GeorgesTypDialogPvt(); setupConnections(); } GeorgesTypDialog::~GeorgesTypDialog() { + delete m_pvt; + m_pvt = NULL; +} + + +bool GeorgesTypDialog::load( const QString &fileName ) +{ + GeorgesQt::CGeorges georges; + NLGEORGES::UType *utyp = georges.loadFormType( fileName.toUtf8().constData() ); + if( utyp == NULL ) + return false; + + m_pvt->typ = dynamic_cast< NLGEORGES::CType* >( utyp ); + + return true; } @@ -32,5 +67,7 @@ void GeorgesTypDialog::setupConnections() void GeorgesTypDialog::log( const QString &msg ) { + QString logMsg = buildLogMsg( msg ); + m_ui.logEdit->appendPlainText( logMsg ); } 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 3808e019a..0e4346d79 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -4,6 +4,7 @@ #include "georges_dock_widget.h" #include "ui_georges_typ_dialog.h" +class GeorgesTypDialogPvt; class GeorgesTypDialog : public GeorgesDockWidget { @@ -12,6 +13,7 @@ public: GeorgesTypDialog( QWidget *parent = NULL ); ~GeorgesTypDialog(); + bool load( const QString &fileName ); void write(); private Q_SLOTS: @@ -22,8 +24,8 @@ private: void setupConnections(); void log( const QString &msg ); - Ui::GeorgesTypDialog m_ui; + GeorgesTypDialogPvt *m_pvt; }; From a69e09af6ff7186935681e5202535d14163c4439 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 22:47:18 +0200 Subject: [PATCH 31/50] Delete DFN when destroying a DFN editor... --HG-- branch : dfighter-tools --- code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp | 2 ++ 1 file changed, 2 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 56043b958..0638f18b9 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -22,6 +22,8 @@ public: { delete ctrl; ctrl = NULL; + delete dfn; + dfn = NULL; } NLGEORGES::CFormDfn *dfn; From 73a2b9bc90258baf7af4ea3b4e4e370cf17f58b3 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 23:00:32 +0200 Subject: [PATCH 32/50] Load comments, log, and definitions. --HG-- branch : dfighter-tools --- .../georges_editor/georges_typ_dialog.cpp | 23 +++++++++++++++++++ .../georges_editor/georges_typ_dialog.h | 1 + 2 files changed, 24 insertions(+) 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 d91134df6..8305bfbbf 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -43,6 +43,8 @@ bool GeorgesTypDialog::load( const QString &fileName ) m_pvt->typ = dynamic_cast< NLGEORGES::CType* >( utyp ); + loadTyp(); + return true; } @@ -71,3 +73,24 @@ void GeorgesTypDialog::log( const QString &msg ) m_ui.logEdit->appendPlainText( logMsg ); } +void GeorgesTypDialog::loadTyp() +{ + m_ui.logEdit->setPlainText( m_pvt->typ->Header.Log.c_str() ); + m_ui.commentEdit->setPlainText( m_pvt->typ->Header.Comments.c_str() ); + + std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin(); + while( itr != m_pvt->typ->Definitions.end() ) + { + NLGEORGES::CType::CDefinition &def = *itr; + + QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setText( 0, def.Label.c_str() ); + item->setText( 1, def.Value.c_str() ); + m_ui.tree->addTopLevelItem( item ); + + ++itr; + } + + +} + 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 0e4346d79..76d177b35 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -23,6 +23,7 @@ private Q_SLOTS: private: void setupConnections(); void log( const QString &msg ); + void loadTyp(); Ui::GeorgesTypDialog m_ui; GeorgesTypDialogPvt *m_pvt; From ec8a7522b275aec7f9c46e3eec841de767ff76e7 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 23:07:55 +0200 Subject: [PATCH 33/50] Implemented remove button. --HG-- branch : dfighter-tools --- .../georges_editor/georges_typ_dialog.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 8305bfbbf..c3ea462ec 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -59,6 +59,23 @@ void GeorgesTypDialog::onAddClicked() void GeorgesTypDialog::onRemoveClicked() { + QTreeWidgetItem *item = m_ui.tree->currentItem(); + if( item == NULL ) + return; + + int i = 0; + for( i = 0; i < m_ui.tree->topLevelItemCount(); i++ ) + { + if( item == m_ui.tree->topLevelItem( i ) ) + break; + } + + m_ui.tree->takeTopLevelItem( i ); + delete item; + + std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin() + i; + m_pvt->typ->Definitions.erase( itr ); + } void GeorgesTypDialog::setupConnections() From a68dd4c33e6c61ee1aa59eec40e4e87bd22c50a9 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 23:25:47 +0200 Subject: [PATCH 34/50] Implemented definition editing. --HG-- branch : dfighter-tools --- .../georges_editor/georges_typ_dialog.cpp | 20 +++++++++++++++++++ .../georges_editor/georges_typ_dialog.h | 2 ++ 2 files changed, 22 insertions(+) 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 c3ea462ec..2f79697c4 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -78,10 +78,29 @@ void GeorgesTypDialog::onRemoveClicked() } +void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column ) +{ + int i = 0; + for( i = 0; i < m_ui.tree->topLevelItemCount(); i++ ) + { + if( item == m_ui.tree->topLevelItem( i ) ) + break; + } + + NLGEORGES::CType::CDefinition &def = m_pvt->typ->Definitions[ i ]; + + if( i == 0 ) + def.Label = item->text( 0 ).toUtf8().constData(); + else + def.Value = item->text( 1 ).toUtf8().constData(); +} + void GeorgesTypDialog::setupConnections() { connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); + + connect( m_ui.tree, SIGNAL( itemChanged( QTreeWidgetItem*, int ) ), this, SLOT( onItemChanged( QTreeWidgetItem*, int ) ) ); } void GeorgesTypDialog::log( const QString &msg ) @@ -101,6 +120,7 @@ void GeorgesTypDialog::loadTyp() NLGEORGES::CType::CDefinition &def = *itr; QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled ); item->setText( 0, def.Label.c_str() ); item->setText( 1, def.Value.c_str() ); m_ui.tree->addTopLevelItem( item ); 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 76d177b35..8cca31fe6 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -20,6 +20,8 @@ private Q_SLOTS: void onAddClicked(); void onRemoveClicked(); + void onItemChanged( QTreeWidgetItem *item, int column ); + private: void setupConnections(); void log( const QString &msg ); From 173dbba11c4b6a26e396b12a0c033d8e5961a8ef Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 23:37:16 +0200 Subject: [PATCH 35/50] Implemented add button. --HG-- branch : dfighter-tools --- .../georges_editor/georges_typ_dialog.cpp | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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 2f79697c4..b64368535 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -1,6 +1,9 @@ #include "georges_typ_dialog.h" #include "georges.h" +#include +#include + class GeorgesTypDialogPvt { public: @@ -55,6 +58,32 @@ void GeorgesTypDialog::write() void GeorgesTypDialog::onAddClicked() { + QString label = QInputDialog::getText( this, + tr( "Adding new definition" ), + tr( "Please specify the label" ) ); + if( label.isEmpty() ) + return; + + QList< QTreeWidgetItem* > l = m_ui.tree->findItems( label, Qt::MatchExactly, 0 ); + if( !l.isEmpty() ) + { + QMessageBox::information( this, + tr( "Failed to add item" ), + tr( "You can't add an item with the same label more than once!" ) ); + return; + } + + QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled ); + item->setText( 0, label ); + item->setText( 1, "" ); + m_ui.tree->addTopLevelItem( item ); + + NLGEORGES::CType::CDefinition def; + def.Label = label.toUtf8().constData(); + def.Value = ""; + m_pvt->typ->Definitions.push_back( def ); + } void GeorgesTypDialog::onRemoveClicked() From f587e06d7aa276a9c94d9ec1b78e50323fa57c2a Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 23:54:42 +0200 Subject: [PATCH 36/50] Implemented saving. --HG-- branch : dfighter-tools --- .../georges_editor/georges_editor_form.cpp | 2 + .../georges_editor/georges_typ_dialog.cpp | 38 +++++++++++++++++++ .../georges_editor/georges_typ_dialog.h | 6 +++ 3 files changed, 46 insertions(+) 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 47bd9de3d..c870ae668 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -324,6 +324,8 @@ namespace GeorgesQt return NULL; } + connect( d, SIGNAL( modified() ), this, SLOT( setModified() ) ); + return d; } 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 b64368535..4b042d8e0 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -4,6 +4,10 @@ #include #include +#include "nel/misc/file.h" +#include "nel/misc/o_xml.h" +#include "nel/misc/path.h" + class GeorgesTypDialogPvt { public: @@ -48,12 +52,31 @@ bool GeorgesTypDialog::load( const QString &fileName ) loadTyp(); + m_fileName = fileName; + setWindowTitle( fileName ); + return true; } void GeorgesTypDialog::write() { + std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false ); + + NLMISC::COFile file; + if( !file.open( path.c_str(), false, true, false ) ) + return; + + NLMISC::COXml xml; + xml.init( &file ); + + m_pvt->typ->write( xml.getDocument() ); + + xml.flush(); + file.close(); + + setModified( false ); + setWindowTitle( windowTitle().remove( "*" ) ); } void GeorgesTypDialog::onAddClicked() @@ -84,6 +107,7 @@ void GeorgesTypDialog::onAddClicked() def.Value = ""; m_pvt->typ->Definitions.push_back( def ); + onModified(); } void GeorgesTypDialog::onRemoveClicked() @@ -105,6 +129,7 @@ void GeorgesTypDialog::onRemoveClicked() std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin() + i; m_pvt->typ->Definitions.erase( itr ); + onModified(); } void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column ) @@ -122,6 +147,19 @@ void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column ) def.Label = item->text( 0 ).toUtf8().constData(); else def.Value = item->text( 1 ).toUtf8().constData(); + + onModified(); +} + +void GeorgesTypDialog::onModified() +{ + if( isModified() ) + return; + + setModified( true ); + setWindowTitle( windowTitle() + "*" ); + + Q_EMIT modified(); } void GeorgesTypDialog::setupConnections() 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 8cca31fe6..ac203b8f6 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -16,11 +16,15 @@ public: bool load( const QString &fileName ); void write(); +Q_SIGNALS: + void modified(); + private Q_SLOTS: void onAddClicked(); void onRemoveClicked(); void onItemChanged( QTreeWidgetItem *item, int column ); + void onModified(); private: void setupConnections(); @@ -29,6 +33,8 @@ private: Ui::GeorgesTypDialog m_ui; GeorgesTypDialogPvt *m_pvt; + + QString m_fileName; }; From 6cd4d756db3bbac5a44e4441036347741aaffa2d Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 00:00:52 +0200 Subject: [PATCH 37/50] Mark the DFN editor modified after adding / removing an element. --HG-- branch : dfighter-tools --- .../georges_editor/georges_dfn_dialog.cpp | 23 +++++++++++++------ .../georges_editor/georges_dfn_dialog.h | 1 + 2 files changed, 17 insertions(+), 7 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 0638f18b9..1a45a9888 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -123,6 +123,8 @@ void GeorgesDFNDialog::onAddClicked() m_pvt->dfn->addEntry( name.toUtf8().constData() ); log( "Added " + name ); + + onModified(); } void GeorgesDFNDialog::onRemoveClicked() @@ -137,6 +139,8 @@ void GeorgesDFNDialog::onRemoveClicked() delete item; m_pvt->dfn->removeEntry( row ); + + onModified(); } void GeorgesDFNDialog::onCurrentRowChanged( int row ) @@ -149,13 +153,7 @@ void GeorgesDFNDialog::onCurrentRowChanged( int row ) void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value ) { - if( !isModified() ) - { - setModified( true ); - setWindowTitle( windowTitle() + "*" ); - - Q_EMIT modified(); - } + onModified(); log( m_ui.list->currentItem()->text() + "." + key + " = " + value ); @@ -165,6 +163,17 @@ void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value } } +void GeorgesDFNDialog::onModified() +{ + if( !isModified() ) + { + setModified( true ); + setWindowTitle( windowTitle() + "*" ); + + Q_EMIT modified(); + } +} + void GeorgesDFNDialog::log( const QString &msg ) { QString logMsg = buildLogMsg( msg ); 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 6ce67c2d2..5bfb55f44 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -27,6 +27,7 @@ private Q_SLOTS: void onValueChanged( const QString& key, const QString &value ); private: + void onModified(); void log( const QString &msg ); void setupConnections(); From 6e86da4c40b86e0491669c98a8df9652a210fa96 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 16:08:13 +0200 Subject: [PATCH 38/50] Load type data into the property browser. --HG-- branch : dfighter-tools --- .../georges_editor/georges_typ_dialog.cpp | 10 +- .../georges_editor/typ_browser_ctrl.cpp | 100 ++++++++++++++++++ .../plugins/georges_editor/typ_browser_ctrl.h | 45 ++++++++ 3 files changed, 154 insertions(+), 1 deletion(-) 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 4b042d8e0..539de4f96 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -1,5 +1,6 @@ #include "georges_typ_dialog.h" #include "georges.h" +#include "typ_browser_ctrl.h" #include #include @@ -14,16 +15,20 @@ public: GeorgesTypDialogPvt() { typ = NULL; + ctrl = new TypBrowserCtrl(); } ~GeorgesTypDialogPvt() { delete typ; typ = NULL; + delete ctrl; + ctrl = NULL; } NLGEORGES::CType *typ; + TypBrowserCtrl *ctrl; }; GeorgesTypDialog::GeorgesTypDialog( QWidget *parent ) : @@ -31,6 +36,8 @@ GeorgesDockWidget( parent ) { m_ui.setupUi( this ); m_pvt = new GeorgesTypDialogPvt(); + m_pvt->ctrl->setBrowser( m_ui.browser ); + setupConnections(); } @@ -195,6 +202,7 @@ void GeorgesTypDialog::loadTyp() ++itr; } - + m_pvt->ctrl->setTyp( m_pvt->typ ); + m_pvt->ctrl->load(); } diff --git a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp index 002a89290..144156cfc 100644 --- a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp @@ -1 +1,101 @@ #include "typ_browser_ctrl.h" + +#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" +#include "3rdparty/qtpropertybrowser/qtvariantproperty.h" +#include "3rdparty/qtpropertybrowser/qtpropertymanager.h" +#include "3rdparty/qtpropertybrowser/qteditorfactory.h" + +#include "nel/georges/type.h" + +TypBrowserCtrl::TypBrowserCtrl( QObject *parent ) : +QObject( parent ) +{ + m_typ = NULL; + + m_variantMgr = new QtVariantPropertyManager( this ); + m_variantFactory = new QtVariantEditorFactory( this ); + m_enumMgr = new QtEnumPropertyManager( this ); + m_enumFactory = new QtEnumEditorFactory( this ); +} + +TypBrowserCtrl::~TypBrowserCtrl() +{ + m_typ = NULL; + m_variantMgr = NULL; + m_variantFactory = NULL; + m_enumMgr = NULL; + m_enumFactory = NULL; +} + +void TypBrowserCtrl::load() +{ + m_browser->clear(); + m_browser->setFactoryForManager( m_variantMgr, m_variantFactory ); + m_browser->setFactoryForManager( m_enumMgr, m_enumFactory ); + + m_typ->Type; + m_typ->UIType; + + QtProperty *p = NULL; + + p = m_enumMgr->addProperty( "type" ); + QStringList l; + l.push_back( "UnsignedInt" ); + l.push_back( "SignedInt" ); + l.push_back( "Double" ); + l.push_back( "String" ); + l.push_back( "Color" ); + m_enumMgr->setEnumNames( p, l ); + m_enumMgr->setValue( p, m_typ->Type ); + m_browser->addProperty( p ); + + p = m_enumMgr->addProperty( "uitype" ); + l.clear(); + l.push_back( "Edit" ); + l.push_back( "EditSpin" ); + l.push_back( "NonEditableCombo" ); + l.push_back( "FileBrowser" ); + l.push_back( "BigEdit" ); + l.push_back( "ColorEdit" ); + l.push_back( "IconWidget" ); + m_enumMgr->setEnumNames( p, l ); + m_enumMgr->setValue( p, m_typ->UIType ); + m_browser->addProperty( p ); + + + QtVariantProperty *vp = NULL; + + vp = m_variantMgr->addProperty( QVariant::String, "default" ); + vp->setValue( m_typ->Default.c_str() ); + m_browser->addProperty( vp ); + + vp = m_variantMgr->addProperty( QVariant::String, "min" ); + vp->setValue( m_typ->Min.c_str() ); + m_browser->addProperty( vp ); + + vp = m_variantMgr->addProperty( QVariant::String, "Max" ); + vp->setValue( m_typ->Max.c_str() ); + m_browser->addProperty( vp ); + + vp = m_variantMgr->addProperty( QVariant::String, "increment" ); + vp->setValue( m_typ->Increment.c_str() ); + m_browser->addProperty( vp ); + + enableMgrConnections(); +} + +void TypBrowserCtrl::onVariantValueChanged( QtProperty *p, const QVariant &v ) +{ +} + +void TypBrowserCtrl::onEnumValueChanged( QtProperty *p, int v ) +{ +} + +void TypBrowserCtrl::enableMgrConnections() +{ + connect( m_variantMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), this, SLOT( onVariantValueChanged( QtProperty*, const QVariant& ) ) ); + connect( m_enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ), this, SLOT( onEnumValueChanged( QtProperty*, int ) ) ); +} + + diff --git a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h index bf29e1cc8..d565152c4 100644 --- a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h @@ -1,3 +1,48 @@ #ifndef TYP_BROWSER_CTRL #define TYP_BROWSER_CTRL + +#include + +class QtVariantPropertyManager; +class QtVariantEditorFactory; +class QtTreePropertyBrowser; +class QtEnumPropertyManager; +class QtEnumEditorFactory; +class QVariant; +class QtProperty; + +namespace NLGEORGES +{ + class CType; +} + +class TypBrowserCtrl : public QObject +{ + Q_OBJECT +public: + TypBrowserCtrl( QObject *parent = NULL ); + ~TypBrowserCtrl(); + + void load(); + + void setTyp( NLGEORGES::CType *typ ){ m_typ = typ; } + void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } + +private Q_SLOTS: + void onVariantValueChanged( QtProperty *p, const QVariant &v ); + void onEnumValueChanged( QtProperty *p, int v ); + +private: + void enableMgrConnections(); + + NLGEORGES::CType *m_typ; + QtTreePropertyBrowser *m_browser; + + QtVariantPropertyManager *m_variantMgr; + QtVariantEditorFactory *m_variantFactory; + QtEnumPropertyManager *m_enumMgr; + QtEnumEditorFactory *m_enumFactory; + +}; + #endif From 2ee86da670acfa648065d099381e31ded2958c64 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 16:14:38 +0200 Subject: [PATCH 39/50] Apply changes. --HG-- branch : dfighter-tools --- .../georges_editor/typ_browser_ctrl.cpp | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp index 144156cfc..49d5e75fa 100644 --- a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp @@ -73,7 +73,7 @@ void TypBrowserCtrl::load() vp->setValue( m_typ->Min.c_str() ); m_browser->addProperty( vp ); - vp = m_variantMgr->addProperty( QVariant::String, "Max" ); + vp = m_variantMgr->addProperty( QVariant::String, "max" ); vp->setValue( m_typ->Max.c_str() ); m_browser->addProperty( vp ); @@ -86,10 +86,40 @@ void TypBrowserCtrl::load() void TypBrowserCtrl::onVariantValueChanged( QtProperty *p, const QVariant &v ) { + QString n = p->propertyName(); + if( n == "default" ) + { + m_typ->Default = v.toString().toUtf8().constData(); + } + else + if( n == "min" ) + { + m_typ->Min = v.toString().toUtf8().constData(); + } + else + if( n == "max" ) + { + m_typ->Max = v.toString().toUtf8().constData(); + } + else + if( n == "increment" ) + { + m_typ->Increment = v.toString().toUtf8().constData(); + } } void TypBrowserCtrl::onEnumValueChanged( QtProperty *p, int v ) { + QString n = p->propertyName(); + if( n == "type" ) + { + m_typ->Type = NLGEORGES::UType::TType( v ); + } + else + if( n == "uitype" ) + { + m_typ->UIType = NLGEORGES::CType::TUI( v ); + } } void TypBrowserCtrl::enableMgrConnections() From d289b7e030ae31731b67cf95d5daa5f54dbb1d32 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 16:26:52 +0200 Subject: [PATCH 40/50] Mark the typ dialog modified after a modification. --HG-- branch : dfighter-tools --- .../georges_editor/georges_typ_dialog.cpp | 6 +++ .../georges_editor/georges_typ_dialog.h | 1 + .../georges_editor/typ_browser_ctrl.cpp | 49 +++++++++++++++++++ .../plugins/georges_editor/typ_browser_ctrl.h | 3 ++ 4 files changed, 59 insertions(+) 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 539de4f96..f6f470288 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -169,12 +169,18 @@ void GeorgesTypDialog::onModified() Q_EMIT modified(); } +void GeorgesTypDialog::onModified( const QString &k, const QString &v ) +{ + onModified(); +} + void GeorgesTypDialog::setupConnections() { connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); connect( m_ui.tree, SIGNAL( itemChanged( QTreeWidgetItem*, int ) ), this, SLOT( onItemChanged( QTreeWidgetItem*, int ) ) ); + connect( m_pvt->ctrl, SIGNAL( modified( const QString&, const QString& ) ), this, SLOT( onModified( const QString&, const QString& ) ) ); } void GeorgesTypDialog::log( const QString &msg ) 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 ac203b8f6..cba5d4a41 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -25,6 +25,7 @@ private Q_SLOTS: void onItemChanged( QTreeWidgetItem *item, int column ); void onModified(); + void onModified( const QString &k, const QString &v ); private: void setupConnections(); diff --git a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp index 49d5e75fa..12f921c5f 100644 --- a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp @@ -7,6 +7,43 @@ #include "nel/georges/type.h" +namespace +{ + QString typeToString( int v ) + { + QString s; + + switch( v ) + { + case NLGEORGES::UType::UnsignedInt: s = "UnsignedInt"; break; + case NLGEORGES::UType::SignedInt: s = "SignedInt"; break; + case NLGEORGES::UType::Double: s = "Double"; break; + case NLGEORGES::UType::String: s = "String"; break; + case NLGEORGES::UType::Color: s = "Color"; break; + } + + return s; + } + + QString uitypeToString( int v ) + { + QString s; + + switch( v ) + { + case NLGEORGES::CType::Edit: s = "Edit"; break; + case NLGEORGES::CType::EditSpin: s = "EditSpin"; break; + case NLGEORGES::CType::NonEditableCombo: s = "NonEditableCombo"; break; + case NLGEORGES::CType::FileBrowser: s = "FileBrowser"; break; + case NLGEORGES::CType::BigEdit: s = "BigEdit"; break; + case NLGEORGES::CType::ColorEdit: s = "ColorEdit"; break; + case NLGEORGES::CType::IconWidget: s = "IconWidget"; break; + } + + return s; + } +} + TypBrowserCtrl::TypBrowserCtrl( QObject *parent ) : QObject( parent ) { @@ -106,20 +143,32 @@ void TypBrowserCtrl::onVariantValueChanged( QtProperty *p, const QVariant &v ) { m_typ->Increment = v.toString().toUtf8().constData(); } + else + return; + + Q_EMIT modified( n, v.toString().toUtf8().constData() ); } void TypBrowserCtrl::onEnumValueChanged( QtProperty *p, int v ) { QString n = p->propertyName(); + QString value; + if( n == "type" ) { m_typ->Type = NLGEORGES::UType::TType( v ); + value = typeToString( v ); } else if( n == "uitype" ) { m_typ->UIType = NLGEORGES::CType::TUI( v ); + value = uitypeToString( v ); } + else + return; + + Q_EMIT modified( n, value ); } void TypBrowserCtrl::enableMgrConnections() diff --git a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h index d565152c4..f1d361604 100644 --- a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h @@ -28,6 +28,9 @@ public: void setTyp( NLGEORGES::CType *typ ){ m_typ = typ; } void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } +Q_SIGNALS: + void modified( const QString &k, const QString &v ); + private Q_SLOTS: void onVariantValueChanged( QtProperty *p, const QVariant &v ); void onEnumValueChanged( QtProperty *p, int v ); From b68b658f89e9c8cda756a98217fd3d4a21005ea2 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 16:42:12 +0200 Subject: [PATCH 41/50] Log changes and save log. --HG-- branch : dfighter-tools --- .../georges_editor/georges_typ_dialog.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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 f6f470288..b167913b7 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -77,6 +77,7 @@ void GeorgesTypDialog::write() NLMISC::COXml xml; xml.init( &file ); + m_pvt->typ->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); m_pvt->typ->write( xml.getDocument() ); xml.flush(); @@ -114,6 +115,8 @@ void GeorgesTypDialog::onAddClicked() def.Value = ""; m_pvt->typ->Definitions.push_back( def ); + log( "Added definition " + label ); + onModified(); } @@ -130,12 +133,16 @@ void GeorgesTypDialog::onRemoveClicked() break; } + QString definition = item->text( 0 ); + m_ui.tree->takeTopLevelItem( i ); delete item; std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin() + i; m_pvt->typ->Definitions.erase( itr ); + log( "Removed definition" + definition ); + onModified(); } @@ -149,11 +156,24 @@ void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column ) } NLGEORGES::CType::CDefinition &def = m_pvt->typ->Definitions[ i ]; + + QString logMsg; + logMsg = "Changed definition" + QString( def.Label.c_str() ); if( i == 0 ) + { + logMsg += ".label = "; + logMsg += item->text( 0 ); def.Label = item->text( 0 ).toUtf8().constData(); + } else + { + logMsg += ".value = "; + logMsg += item->text( 1 ); def.Value = item->text( 1 ).toUtf8().constData(); + } + + log( logMsg ); onModified(); } @@ -171,6 +191,7 @@ void GeorgesTypDialog::onModified() void GeorgesTypDialog::onModified( const QString &k, const QString &v ) { + log( "Changed " + k + " = " + v ); onModified(); } From 7e66701cbaf94ac574f75148f992ec9065c5cb24 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 17:12:25 +0200 Subject: [PATCH 42/50] Added missing copyright headers. --HG-- branch : dfighter-tools --- .../plugins/georges_editor/browser_ctrl.cpp | 19 +++++++++++++++++++ .../src/plugins/georges_editor/browser_ctrl.h | 18 ++++++++++++++++++ .../georges_editor/browser_ctrl_pvt.cpp | 18 ++++++++++++++++++ .../plugins/georges_editor/browser_ctrl_pvt.h | 18 ++++++++++++++++++ .../georges_editor/dfn_browser_ctrl.cpp | 18 ++++++++++++++++++ .../plugins/georges_editor/dfn_browser_ctrl.h | 18 ++++++++++++++++++ .../filepath_property_manager.cpp | 18 ++++++++++++++++++ .../filepath_property_manager.h | 18 ++++++++++++++++++ .../georges_editor/georges_dfn_dialog.cpp | 18 ++++++++++++++++++ .../georges_editor/georges_dfn_dialog.h | 18 ++++++++++++++++++ .../georges_editor/georges_dock_widget.cpp | 18 ++++++++++++++++++ .../georges_editor/georges_dock_widget.h | 18 ++++++++++++++++++ .../georges_editor/georges_typ_dialog.cpp | 18 ++++++++++++++++++ .../georges_editor/georges_typ_dialog.h | 18 ++++++++++++++++++ .../georges_editor/typ_browser_ctrl.cpp | 18 ++++++++++++++++++ .../plugins/georges_editor/typ_browser_ctrl.h | 18 ++++++++++++++++++ 16 files changed, 289 insertions(+) diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp index dadbeacde..2788bd00a 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp @@ -1,3 +1,22 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + #include "browser_ctrl.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" #include "3rdparty/qtpropertybrowser/qtvariantproperty.h" diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.h b/code/studio/src/plugins/georges_editor/browser_ctrl.h index 7c56deceb..25aeaf49f 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.h @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #ifndef BROWSER_CTRL_H #define BROWSER_CTRL_H 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 765493f0a..492258c71 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #include "browser_ctrl_pvt.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" #include "3rdparty/qtpropertybrowser/qtvariantproperty.h" 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 c3d1cf50e..bebb65c3e 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #ifndef BROWSER_CTRL_PVT_H #define BROWSER_CTRL_PVT_H 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 00a8bce8e..9e2c86a56 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #include "dfn_browser_ctrl.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" #include "3rdparty/qtpropertybrowser/qtvariantproperty.h" diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h index 4b4c7faf3..71988bcc1 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #ifndef DFN_BROWSER_CTRL #define DFN_BROWSER_CTRL diff --git a/code/studio/src/plugins/georges_editor/filepath_property_manager.cpp b/code/studio/src/plugins/georges_editor/filepath_property_manager.cpp index 30d0afcfe..7d5ab8177 100644 --- a/code/studio/src/plugins/georges_editor/filepath_property_manager.cpp +++ b/code/studio/src/plugins/georges_editor/filepath_property_manager.cpp @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #include "filepath_property_manager.h" #include diff --git a/code/studio/src/plugins/georges_editor/filepath_property_manager.h b/code/studio/src/plugins/georges_editor/filepath_property_manager.h index 0b1f5f469..b365f46cb 100644 --- a/code/studio/src/plugins/georges_editor/filepath_property_manager.h +++ b/code/studio/src/plugins/georges_editor/filepath_property_manager.h @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #ifndef FILEPATH_PROPERTY_MANAGER #define FILEPATH_PROPERTY_MANAGER 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 1a45a9888..fd1f8a19b 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #include "georges_dfn_dialog.h" #include #include 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 5bfb55f44..19268b17d 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #ifndef GEORGES_DFN_DIALOG #define GEORGES_DFN_DIALOG 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 8736a604b..921f59e0b 100644 --- a/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #include "georges_dock_widget.h" GeorgesDockWidget::GeorgesDockWidget( QWidget *parent ) : 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 59aad9e8f..7551d8106 100644 --- a/code/studio/src/plugins/georges_editor/georges_dock_widget.h +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.h @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #ifndef GEORGES_DOCK_WIDGET #define GEORGES_DOCK_WIDGET 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 b167913b7..ab4d2c302 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #include "georges_typ_dialog.h" #include "georges.h" #include "typ_browser_ctrl.h" 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 cba5d4a41..eef2b86fc 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #ifndef GEORGES_TYP_DIALOG #define GEORGES_TYP_DIALOG diff --git a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp index 12f921c5f..5c234100d 100644 --- a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.cpp @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #include "typ_browser_ctrl.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" diff --git a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h index f1d361604..58718f5aa 100644 --- a/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/typ_browser_ctrl.h @@ -1,3 +1,21 @@ +// Ryzom Core Studio - Georges Editor Plugin +// +// Copyright (C) 2014 Laszlo Kis-Adam +// Copyright (C) 2010 Ryzom Core +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + #ifndef TYP_BROWSER_CTRL #define TYP_BROWSER_CTRL From 691edb41eb7697c2468cc8c12345b1352ea08480 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 17:22:09 +0200 Subject: [PATCH 43/50] Form editor should trigger the save button properly now. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/georges_treeview_dialog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 184a8f845..e9ecec074 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -310,9 +310,9 @@ namespace GeorgesQt void CGeorgesTreeViewDialog::modifiedFile( ) { - if (!m_modified) + if (!isModified()) { - m_modified = true; + setModified( true ); setWindowTitle(windowTitle() + "*"); } Q_EMIT modified(); @@ -476,6 +476,8 @@ namespace GeorgesQt m_ui.treeView->setCurrentIndex( idx ); log( name + " resized = " + QString::number( size ) ); + + modifiedFile(); } void CGeorgesTreeViewDialog::onAppendArray() From 99e9a2ad76fe86aa87d36fded13c15cce85e8b38 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 17:25:11 +0200 Subject: [PATCH 44/50] Removed m_modified, since the base widget has a field for this. --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/georges_treeview_dialog.cpp | 5 ++--- .../src/plugins/georges_editor/georges_treeview_dialog.h | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) 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 e9ecec074..3a2113417 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -53,8 +53,7 @@ namespace GeorgesQt CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/) : GeorgesDockWidget(parent), - m_header(0), - m_modified(false) + m_header(0) { m_georges = new CGeorges; @@ -373,7 +372,7 @@ namespace GeorgesQt // //((CForm*)(UForm*)Form)->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS); m_form->write(file); setWindowTitle(windowTitle().remove("*")); - m_modified = false; + setModified( false ); // //if (strcmp (xmlStream.getErrorString (), "") != 0) // //{ // // char message[512]; 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 a32439543..765a70a21 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -112,8 +112,6 @@ namespace GeorgesQt /// Contains a record of the last directory a sheet file dialog was opened for. QString m_lastSheetDir; - bool m_modified; - BrowserCtrl *m_browserCtrl; CGeorgesFormModel *m_model; From 7206f060a7b40cc7f665a6a4677db674a2a7439b Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 18:33:09 +0200 Subject: [PATCH 45/50] Added GUI stub for new types/Dfns/forms. --HG-- branch : dfighter-tools --- .../georges_editor/georges_editor_form.cpp | 42 +++++++++++-------- .../georges_editor/georges_editor_form.h | 10 ++++- 2 files changed, 33 insertions(+), 19 deletions(-) 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 c870ae668..81691865b 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -70,11 +70,20 @@ namespace GeorgesQt Core::MenuManager *menuManager = Core::ICore::instance()->menuManager(); m_openAction = menuManager->action(Core::Constants::OPEN); - m_newAction = new QAction(tr("&New..."), this); - m_newAction->setIcon(QIcon(Core::Constants::ICON_NEW)); - m_newAction->setShortcut(QKeySequence::New); - m_newAction->setStatusTip(tr("Create a new file")); - connect(m_newAction, SIGNAL(triggered()), this, SLOT(newFile())); + m_newTypAction = new QAction(tr("New Type"), this ); + m_newTypAction->setIcon(QIcon(Core::Constants::ICON_NEW)); + m_newTypAction->setStatusTip(tr("Create a new type file")); + connect( m_newTypAction, SIGNAL(triggered()), this, SLOT(newTyp())); + + m_newDfnAction = new QAction(tr("New DFN"), this ); + m_newDfnAction->setIcon(QIcon(Core::Constants::ICON_NEW)); + m_newDfnAction->setStatusTip(tr("Create a new definition file")); + connect( m_newDfnAction, SIGNAL(triggered()), this, SLOT(newDfn())); + + m_newFormAction = new QAction(tr("New Form"), this ); + m_newFormAction->setIcon(QIcon(Core::Constants::ICON_NEW)); + m_newFormAction->setStatusTip(tr("Create a new form file")); + connect( m_newFormAction, SIGNAL(triggered()), this, SLOT(newForm())); m_saveAction = new QAction(tr("&Save..."), this); m_saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); @@ -83,8 +92,10 @@ namespace GeorgesQt connect(m_saveAction, SIGNAL(triggered()), this, SLOT(save())); m_fileToolBar = addToolBar(tr("&File")); + m_fileToolBar->addAction(m_newTypAction); + m_fileToolBar->addAction(m_newDfnAction); + m_fileToolBar->addAction(m_newFormAction); m_fileToolBar->addAction(m_openAction); - m_fileToolBar->addAction(m_newAction); m_fileToolBar->addAction(m_saveAction); m_saveAction->setEnabled(false); @@ -128,19 +139,16 @@ namespace GeorgesQt loadFile(fileName); } - void GeorgesEditorForm::newFile() + void GeorgesEditorForm::newTyp() { - // Assume it is a form, for now. We'll have to retrieve the DFN we'll be using as a base. - QString fileName = QFileDialog::getOpenFileName(this, tr("Select Base Form Definition"), m_lastSheetDir, "Form Definition (*.dfn)"); - if(!fileName.isNull()) - { - // Use the file loader to create the new form. - loadFile(fileName, true); + } - // Save the folder we just opened for future dialogs. - QFileInfo pathInfo( fileName ); - m_lastSheetDir = pathInfo.absolutePath(); - } + void GeorgesEditorForm::newDfn() + { + } + + void GeorgesEditorForm::newForm() + { } void GeorgesEditorForm::save() 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 4d0310306..078daec74 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.h +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.h @@ -46,7 +46,11 @@ public Q_SLOTS: void open(); void loadFile(const QString &fileName); void loadFile(const QString &fileName, bool loadFromDfn); - void newFile(); + + void newTyp(); + void newDfn(); + void newForm(); + void save(); void settingsChanged(); void closingTreeView(); @@ -67,7 +71,9 @@ private: CGeorgesDirTreeDialog *m_georgesDirTreeDialog; QToolBar *m_fileToolBar; QAction *m_openAction; - QAction *m_newAction; + QAction *m_newTypAction; + QAction *m_newDfnAction; + QAction *m_newFormAction; QAction *m_saveAction; QString m_leveldesignPath; From 84853839f8ff01e08744194f8615fef537c93af1 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 19:11:38 +0200 Subject: [PATCH 46/50] A little refactoring, dialogs are now loaded using the full filepath. --HG-- branch : dfighter-tools --- .../georges_editor/georges_dfn_dialog.cpp | 11 ++-- .../georges_editor/georges_dock_widget.h | 1 + .../georges_editor/georges_editor_form.cpp | 54 ++++++------------- .../georges_editor/georges_editor_form.h | 3 +- .../georges_treeview_dialog.cpp | 43 +++++++++++---- .../georges_editor/georges_treeview_dialog.h | 1 + .../georges_editor/georges_typ_dialog.cpp | 8 +-- 7 files changed, 60 insertions(+), 61 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 fd1f8a19b..6ec7c80d2 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -72,7 +72,8 @@ bool GeorgesDFNDialog::load( const QString &fileName ) if( udfn == NULL ) return false; - setWindowTitle( fileName ); + QFileInfo info( fileName ); + setWindowTitle( info.fileName() ); NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn ); m_pvt->dfn = cdfn; @@ -105,18 +106,14 @@ void GeorgesDFNDialog::write() m_pvt->dfn->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); - std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false ); - if( path.empty() ) - return; - NLMISC::COFile file; - if( !file.open( path, false, true, false ) ) + if( !file.open( m_fileName.toUtf8().constData(), false, true, false ) ) return; NLMISC::COXml xml; xml.init( &file ); - m_pvt->dfn->write( xml.getDocument(), path.c_str() ); + m_pvt->dfn->write( xml.getDocument(), m_fileName.toUtf8().constData() ); xml.flush(); file.close(); 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 7551d8106..53e4f6841 100644 --- a/code/studio/src/plugins/georges_editor/georges_dock_widget.h +++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.h @@ -36,6 +36,7 @@ public: QString fileName() const{ return m_fileName; } + virtual bool load( const QString &fileName ) = 0; virtual void write() = 0; protected: 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 81691865b..e5136e82f 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -29,6 +29,7 @@ // NeL includes #include +#include // Qt includes #include @@ -205,20 +206,19 @@ namespace GeorgesQt } void GeorgesEditorForm::loadFile(const QString &fileName) - { - loadFile(fileName, false); - } - - void GeorgesEditorForm::loadFile(const QString &fileName, bool loadFromDfn) { - QFileInfo info(fileName); + std::string path = NLMISC::CPath::lookup( fileName.toUtf8().constData(), false ); + if( path.empty() ) + return; + + QFileInfo info( path.c_str() ); // Check to see if the form is already loaded, if it is just raise it. if (m_dockedWidgets.size()) { Q_FOREACH(GeorgesDockWidget *wgt, m_dockedWidgets) { - if (info.fileName() == wgt->fileName()) + if ( QString( path.c_str() ) == wgt->fileName()) { wgt->raise(); return; @@ -230,16 +230,16 @@ namespace GeorgesQt if( info.suffix() == "dfn" ) { - w = loadDfnDialog( fileName ); + w = loadDfnDialog( path.c_str() ); } else if( info.suffix() == "typ" ) { - w = loadTypDialog( fileName ); + w = loadTypDialog( path.c_str() ); } else { - w = loadFormDialog( fileName, loadFromDfn ); + w = loadFormDialog( path.c_str() ); } if( w == NULL ) @@ -352,40 +352,18 @@ namespace GeorgesQt return d; } - GeorgesDockWidget* GeorgesEditorForm::loadFormDialog( const QString &fileName, bool loadFromDFN ) + GeorgesDockWidget* GeorgesEditorForm::loadFormDialog( const QString &fileName ) { - QFileInfo info( fileName ); - CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(); - - // Retrieve the form and load the form. - NLGEORGES::CForm *form; - if(loadFromDFN) - { - // Get the form by DFN name. - form = d->getFormByDfnName(info.fileName()); - } - else - { - form = d->getFormByName(info.fileName()); - } - - if (form) - { - d->setForm(form); - d->loadFormIntoDialog(form); - QApplication::processEvents(); - connect(d, SIGNAL(modified()), - this, SLOT(setModified())); - connect(d, SIGNAL(changeFile(QString)), - m_georgesDirTreeDialog, SLOT(changeFile(QString))); - } - else + if( !d->load( fileName ) ) { delete d; - d = NULL; + return NULL; } + connect(d, SIGNAL(modified()), this, SLOT(setModified())); + connect(d, SIGNAL(changeFile(QString)), m_georgesDirTreeDialog, SLOT(changeFile(QString))); + return d; } 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 078daec74..a1a1a46e7 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.h +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.h @@ -45,7 +45,6 @@ public: public Q_SLOTS: void open(); void loadFile(const QString &fileName); - void loadFile(const QString &fileName, bool loadFromDfn); void newTyp(); void newDfn(); @@ -64,7 +63,7 @@ private: GeorgesDockWidget* loadTypDialog(const QString &fileName); GeorgesDockWidget* loadDfnDialog(const QString &fileName); - GeorgesDockWidget* loadFormDialog(const QString &fileName, bool loadFromDFN ); + GeorgesDockWidget* loadFormDialog(const QString &fileName); Ui::GeorgesEditorForm m_ui; 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 3a2113417..86c0fb8af 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -120,11 +120,7 @@ namespace GeorgesQt NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName) { - if(NLMISC::CPath::exists(formName.toAscii().data())) - { - //NLGEORGES::CForm *form = dynamic_cast(m_georges->loadForm(formName.toAscii().data())); - return (NLGEORGES::CForm *)m_georges->loadForm(formName.toAscii().data()); - } + return (NLGEORGES::CForm *)m_georges->loadForm(formName.toAscii().data()); //else //{ // CForm *form = 0; @@ -159,7 +155,6 @@ namespace GeorgesQt // } // return form; //} - nlinfo("File '%s' does not exist!", formName.toAscii().data()); return 0; } @@ -271,9 +266,6 @@ namespace GeorgesQt connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), this, SLOT(modifiedFile())); - setWindowTitle(loadedForm); - // //Modules::mainWin().getTabBar(); - m_model = model; } } @@ -317,13 +309,44 @@ namespace GeorgesQt Q_EMIT modified(); } + bool CGeorgesTreeViewDialog::load( const QString &fileName ) + { + bool loadFromDFN = false; + + // Retrieve the form and load the form. + NLGEORGES::CForm *form; + if(loadFromDFN) + { + // Get the form by DFN name. + form = getFormByDfnName(fileName); + } + else + { + form = getFormByName(fileName); + } + + if( form == NULL ) + return false; + + setForm(form); + loadFormIntoDialog(form); + QApplication::processEvents(); + + m_fileName = fileName; + + QFileInfo info( fileName ); + setWindowTitle( info.fileName() ); + + return true; + } + void CGeorgesTreeViewDialog::write( ) { NLGEORGES::CForm *form = static_cast< NLGEORGES::CForm* >( m_form ); form->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData(); NLMISC::COFile file; - std::string s = NLMISC::CPath::lookup(loadedForm.toAscii().data(), false); + std::string s = m_fileName.toUtf8().constData(); if(file.open (s)) { try 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 765a70a21..0acb48941 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -69,6 +69,7 @@ namespace GeorgesQt void addParentForm(QString parentFormNm); + bool load( const QString &fileName ); void write ( ); QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; } 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 ab4d2c302..123aa0fd4 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -78,7 +78,9 @@ bool GeorgesTypDialog::load( const QString &fileName ) loadTyp(); m_fileName = fileName; - setWindowTitle( fileName ); + + QFileInfo info( fileName ); + setWindowTitle( info.fileName() ); return true; } @@ -86,10 +88,8 @@ bool GeorgesTypDialog::load( const QString &fileName ) void GeorgesTypDialog::write() { - std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false ); - NLMISC::COFile file; - if( !file.open( path.c_str(), false, true, false ) ) + if( !file.open( m_fileName.toUtf8().constData(), false, true, false ) ) return; NLMISC::COXml xml; From 22d1fe0cbc75bdd94ce81b46848696cbb5a040e5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 19:14:32 +0200 Subject: [PATCH 47/50] Error messages --HG-- branch : dfighter-tools --- .../src/plugins/georges_editor/georges_editor_form.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 e5136e82f..3bcbb91dc 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -209,7 +209,12 @@ namespace GeorgesQt { std::string path = NLMISC::CPath::lookup( fileName.toUtf8().constData(), false ); if( path.empty() ) + { + QMessageBox::information( this, + tr( "Failed to load file..." ), + tr( "Failed to load file '%1': File doesn't exist!" ).arg( fileName ) ); return; + } QFileInfo info( path.c_str() ); @@ -246,7 +251,7 @@ namespace GeorgesQt { QMessageBox::information( this, tr( "Failed to load file..." ), - tr( "Failed to load file '%1'" ).arg( info.fileName() ) ); + tr( "Failed to load file '%1': Not a typ, dfn, or form file!" ).arg( info.fileName() ) ); return; } From ca127f756c64be97798b35b426614e7d41065288 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 19:28:01 +0200 Subject: [PATCH 48/50] Added support for new typ document creation. --HG-- branch : dfighter-tools --- .../georges_editor/georges_editor_form.cpp | 54 ++++++++++++------- .../georges_editor/georges_editor_form.h | 2 + .../georges_editor/georges_typ_dialog.cpp | 12 +++++ .../georges_editor/georges_typ_dialog.h | 1 + 4 files changed, 50 insertions(+), 19 deletions(-) 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 3bcbb91dc..b68e48dd4 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -142,6 +142,18 @@ namespace GeorgesQt void GeorgesEditorForm::newTyp() { + QString fileName = QFileDialog::getSaveFileName( this, + tr( "New Type" ), + "", + "Type files (*.typ)" ); + if( fileName.isEmpty() ) + return; + + + GeorgesTypDialog *d = new GeorgesTypDialog(); + d->newDocument( fileName ); + addGeorgesWidget( d ); + setModified(); } void GeorgesEditorForm::newDfn() @@ -190,6 +202,28 @@ namespace GeorgesQt settings->sync(); } + void GeorgesEditorForm::addGeorgesWidget( GeorgesDockWidget *w ) + { + w->setUndoStack(UndoStack); + m_lastActiveDock = w; + m_dockedWidgets.append(w); + + connect(m_dockedWidgets.last(), SIGNAL(closing()), this, SLOT(closingTreeView())); + 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. + if(m_dockedWidgets.size() > 1) + { + m_mainDock->tabifyDockWidget(m_dockedWidgets.at(m_dockedWidgets.size() - 2), m_dockedWidgets.last()); + } + else + { + m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); + } + + w->raise(); + } + void GeorgesEditorForm::settingsChanged() { QSettings *settings = Core::ICore::instance()->settings(); @@ -255,25 +289,7 @@ namespace GeorgesQt return; } - w->setUndoStack(UndoStack); - m_lastActiveDock = w; - m_dockedWidgets.append(w); - - connect(m_dockedWidgets.last(), SIGNAL(closing()), this, SLOT(closingTreeView())); - 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. - if(m_dockedWidgets.size() > 1) - { - m_mainDock->tabifyDockWidget(m_dockedWidgets.at(m_dockedWidgets.size() - 2), m_dockedWidgets.last()); - } - else - { - m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); - } - - w->raise(); - + addGeorgesWidget( w ); } void GeorgesEditorForm::closingTreeView() 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 a1a1a46e7..adfaf2e59 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.h +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.h @@ -61,6 +61,8 @@ private: void readSettings(); void writeSettings(); + void addGeorgesWidget( GeorgesDockWidget *w ); + GeorgesDockWidget* loadTypDialog(const QString &fileName); GeorgesDockWidget* loadDfnDialog(const QString &fileName); GeorgesDockWidget* loadFormDialog(const QString &fileName); 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 123aa0fd4..7e832ba26 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -105,6 +105,18 @@ void GeorgesTypDialog::write() setWindowTitle( windowTitle().remove( "*" ) ); } +void GeorgesTypDialog::newDocument( const QString &fileName ) +{ + m_pvt->typ = new NLGEORGES::CType(); + m_fileName = fileName; + + QFileInfo info( fileName ); + setWindowTitle( info.fileName() + "*" ); + setModified( true ); + + loadTyp(); +} + void GeorgesTypDialog::onAddClicked() { QString label = QInputDialog::getText( this, 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 eef2b86fc..b241c4c8d 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -33,6 +33,7 @@ public: bool load( const QString &fileName ); void write(); + void newDocument( const QString &fileName ); Q_SIGNALS: void modified(); From 37bbb6be329bc9a48126953180ecc07d94f9e538 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 19:37:49 +0200 Subject: [PATCH 49/50] Added support for new DFN document creation. --HG-- branch : dfighter-tools --- .../georges_editor/georges_dfn_dialog.cpp | 50 +++++++++++++------ .../georges_editor/georges_dfn_dialog.h | 2 + .../georges_editor/georges_editor_form.cpp | 11 ++++ 3 files changed, 47 insertions(+), 16 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 6ec7c80d2..d7d329dac 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -77,22 +77,8 @@ bool GeorgesDFNDialog::load( const QString &fileName ) NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn ); m_pvt->dfn = cdfn; - m_pvt->ctrl->setDFN( cdfn ); - - uint c = m_pvt->dfn->getNumEntry(); - for( uint i = 0; i < c; i++ ) - { - NLGEORGES::CFormDfn::CEntry &entry = m_pvt->dfn->getEntry( i ); - m_ui.list->addItem( entry.getName().c_str() ); - } - - if( c > 0 ) - { - m_ui.list->setCurrentRow( 0 ); - } - - m_ui.commentsEdit->setPlainText( cdfn->getComment().c_str() ); - m_ui.logEdit->setPlainText( cdfn->Header.Log.c_str() ); + + loadDfn(); m_fileName = fileName; @@ -119,6 +105,18 @@ void GeorgesDFNDialog::write() file.close(); } +void GeorgesDFNDialog::newDocument( const QString &fileName ) +{ + m_fileName = fileName; + QFileInfo info( fileName ); + setWindowTitle( info.fileName() + "*" ); + setModified( true ); + + m_pvt->dfn = new NLGEORGES::CFormDfn(); + + loadDfn(); +} + void GeorgesDFNDialog::onAddClicked() { QString name = QInputDialog::getText( this, @@ -178,6 +176,26 @@ void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value } } +void GeorgesDFNDialog::loadDfn() +{ + m_pvt->ctrl->setDFN( m_pvt->dfn ); + + uint c = m_pvt->dfn->getNumEntry(); + for( uint i = 0; i < c; i++ ) + { + NLGEORGES::CFormDfn::CEntry &entry = m_pvt->dfn->getEntry( i ); + m_ui.list->addItem( entry.getName().c_str() ); + } + + if( c > 0 ) + { + m_ui.list->setCurrentRow( 0 ); + } + + m_ui.commentsEdit->setPlainText( m_pvt->dfn->getComment().c_str() ); + m_ui.logEdit->setPlainText( m_pvt->dfn->Header.Log.c_str() ); +} + void GeorgesDFNDialog::onModified() { if( !isModified() ) 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 19268b17d..2d6dc4113 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -33,6 +33,7 @@ public: bool load( const QString &fileName ); void write(); + void newDocument( const QString &fileName ); Q_SIGNALS: void modified(); @@ -45,6 +46,7 @@ private Q_SLOTS: void onValueChanged( const QString& key, const QString &value ); private: + void loadDfn(); void onModified(); void log( const QString &msg ); void setupConnections(); 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 b68e48dd4..cb4069818 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -158,6 +158,17 @@ namespace GeorgesQt void GeorgesEditorForm::newDfn() { + QString fileName = QFileDialog::getSaveFileName( this, + tr( "New Definition" ), + "", + "Definition files (*.dfn)" ); + if( fileName.isEmpty() ) + return; + + GeorgesDFNDialog *d = new GeorgesDFNDialog(); + d->newDocument( fileName ); + addGeorgesWidget( d ); + setModified(); } void GeorgesEditorForm::newForm() From 916810c35d46d756b2bb2f64380ff5aba34b33c0 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 19:55:46 +0200 Subject: [PATCH 50/50] Added support for creating new form documents --HG-- branch : dfighter-tools --- .../georges_editor/georges_editor_form.cpp | 33 +++++++++ .../georges_treeview_dialog.cpp | 67 ++++++++++--------- .../georges_editor/georges_treeview_dialog.h | 1 + 3 files changed, 70 insertions(+), 31 deletions(-) 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 cb4069818..54028b5a4 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -173,6 +173,39 @@ namespace GeorgesQt void GeorgesEditorForm::newForm() { + QString dfnFileName = QFileDialog::getOpenFileName( this, + tr( "New Form" ), + "", + "Definition files (*.dfn)" ); + if( dfnFileName.isEmpty() ) + return; + + QFileInfo dfnInfo( dfnFileName ); + QString baseName = dfnInfo.baseName(); + QString filter; + filter += baseName; + filter += " files (*."; + filter += baseName; + filter += ")"; + + QString fileName = QFileDialog::getSaveFileName( this, + tr( "New Form" ), + "", + filter ); + if( fileName.isEmpty() ) + return; + + CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(); + if( !d->newDocument( fileName, dfnFileName ) ) + { + QMessageBox::information( this, + tr( "Failed to create new form" ), + tr( "Failed to create new form!" ) ); + return; + } + + addGeorgesWidget( d ); + setModified(); } void GeorgesEditorForm::save() 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 86c0fb8af..c2aa78005 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -160,30 +160,25 @@ namespace GeorgesQt NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByDfnName(const QString dfnName) { - if(NLMISC::CPath::exists(dfnName.toAscii().data())) - { - // Create a new form object. - NLGEORGES::CForm *form = new NLGEORGES::CForm(); - m_form = form; - - // Retrieve a copy of the root definition. - NLGEORGES::CFormDfn *formDfn = dynamic_cast(m_georges->loadFormDfn(dfnName.toAscii().data())); + // Create a new form object. + NLGEORGES::CForm *form = new NLGEORGES::CForm(); + m_form = form; - // Next we'll use the root node to build a new form. - NLGEORGES::CFormElmStruct *fes = dynamic_cast(getRootNode(0)); - fes->build(formDfn); + // Retrieve a copy of the root definition. + NLGEORGES::CFormDfn *formDfn = dynamic_cast(m_georges->loadFormDfn(dfnName.toAscii().data())); - // And then initialize the held elements; - for(uint i = 0; i(getRootNode(i+1)); - fes->build(formDfn); - } + // Next we'll use the root node to build a new form. + NLGEORGES::CFormElmStruct *fes = dynamic_cast(getRootNode(0)); + fes->build(formDfn); - return form; + // And then initialize the held elements; + for(uint i = 0; i(getRootNode(i+1)); + fes->build(formDfn); } - nlinfo("File '%s' does not exist!", dfnName.toAscii().data()); - return NULL; + + return form; } NLGEORGES::CFormElm *CGeorgesTreeViewDialog::getRootNode(uint slot) @@ -311,19 +306,9 @@ namespace GeorgesQt bool CGeorgesTreeViewDialog::load( const QString &fileName ) { - bool loadFromDFN = false; // Retrieve the form and load the form. - NLGEORGES::CForm *form; - if(loadFromDFN) - { - // Get the form by DFN name. - form = getFormByDfnName(fileName); - } - else - { - form = getFormByName(fileName); - } + NLGEORGES::CForm *form = getFormByName(fileName); if( form == NULL ) return false; @@ -421,6 +406,26 @@ namespace GeorgesQt } } + bool CGeorgesTreeViewDialog::newDocument( const QString &fileName, const QString &dfn ) + { + NLGEORGES::CForm *form = getFormByDfnName(dfn); + + if( form == NULL ) + return false; + + setForm(form); + loadFormIntoDialog(form); + QApplication::processEvents(); + + m_fileName = fileName; + + QFileInfo info( fileName ); + setWindowTitle( info.fileName() + "*" ); + setModified( true ); + + return true; + } + void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) { //CGeorgesFormModel *model = 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 0acb48941..459258c3f 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -71,6 +71,7 @@ namespace GeorgesQt bool load( const QString &fileName ); void write ( ); + bool newDocument( const QString &fileName, const QString &dfn ); QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; }