diff --git a/code/studio/src/plugins/georges_editor/CMakeLists.txt b/code/studio/src/plugins/georges_editor/CMakeLists.txt index bab12b7e1..679af334e 100644 --- a/code/studio/src/plugins/georges_editor/CMakeLists.txt +++ b/code/studio/src/plugins/georges_editor/CMakeLists.txt @@ -15,7 +15,8 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h georges_dirtree_dialog.h georges_filesystem_model.h georges_treeview_dialog.h - expandable_headerview.h) + expandable_headerview.h + browser_ctrl.h) SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui georges_dirtree_form.ui diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp new file mode 100644 index 000000000..1e9ed2606 --- /dev/null +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp @@ -0,0 +1,89 @@ +#include "browser_ctrl.h" +#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" +#include "3rdparty/qtpropertybrowser/qtvariantproperty.h" +#include + +#include "nel/georges/form.h" + +#include "formitem.h" + +class BrowserCtrlPvt +{ +public: + BrowserCtrlPvt() + { + mgr = new QtVariantPropertyManager(); + factory = new QtVariantEditorFactory(); + } + + ~BrowserCtrlPvt() + { + delete mgr; + mgr = NULL; + delete factory; + factory = NULL; + } + + QtVariantPropertyManager *mgr; + QtVariantEditorFactory *factory; + QtTreePropertyBrowser *m_browser; +}; + +BrowserCtrl::BrowserCtrl( QtTreePropertyBrowser *browser ) : +QObject( browser ) +{ + m_pvt = new BrowserCtrlPvt(); + m_pvt->m_browser = browser; +} + +BrowserCtrl::~BrowserCtrl() +{ + delete m_pvt; + m_pvt = NULL; +} + +void BrowserCtrl::clicked( const QModelIndex &idx ) +{ + m_pvt->m_browser->clear(); + + GeorgesQt::CFormItem *item = static_cast< GeorgesQt::CFormItem* >( idx.internalPointer() ); + NLGEORGES::UFormElm &root = m_form->getRootNode(); + NLGEORGES::UFormElm *node = NULL; + bool b = false; + + b = m_form->getRootNode().getNodeByName( &node, item->formName().c_str() ); + + if( !b || ( node == NULL ) ) + return; + + if( !node->isStruct() ) + return; + + NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( node ); + for( int i = 0; i < st->Elements.size(); i++ ) + { + NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ i ]; + + QString key = elm.Name.c_str(); + QString value = ""; + + if( elm.Element != NULL ) + { + const NLGEORGES::UType *typ = elm.Element->getType(); + NLGEORGES::UType::TType ttyp = NLGEORGES::UType::String; + if( typ != NULL ) + ttyp = typ->getType(); + + NLGEORGES::CFormElmAtom *atom = static_cast< NLGEORGES::CFormElmAtom* >( elm.Element ); + std::string v; + atom->getValue( v, NLGEORGES::UFormElm::NoEval ); + value = v.c_str(); + } + + QtVariantProperty *p = m_pvt->mgr->addProperty( QVariant::String, key ); + p->setValue( value ); + m_pvt->m_browser->addProperty( p ); + } + +} + diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.h b/code/studio/src/plugins/georges_editor/browser_ctrl.h new file mode 100644 index 000000000..52655c141 --- /dev/null +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.h @@ -0,0 +1,33 @@ +#ifndef BROWSER_CTRL_H +#define BROWSER_CTRL_H + +#include + +namespace NLGEORGES +{ + class UForm; +} + +class QtTreePropertyBrowser; +class QModelIndex; + +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 ); + +private: + BrowserCtrlPvt *m_pvt; + + NLGEORGES::UForm *m_form; +}; + +#endif 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 f1819f52a..a8e7e7451 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -43,6 +43,7 @@ #include "formitem.h" #include "formdelegate.h" #include "expandable_headerview.h" +#include "browser_ctrl.h" using namespace NLMISC; using namespace NLGEORGES; @@ -76,16 +77,22 @@ namespace GeorgesQt m_ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu); + m_browserCtrl = new BrowserCtrl( m_ui.propertiesBrowser ); + connect(m_ui.treeView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&))); connect(m_ui.treeView, SIGNAL(doubleClicked (QModelIndex)), this, SLOT(doubleClicked (QModelIndex))); + connect(m_ui.treeView, SIGNAL(clicked(const QModelIndex&)), + m_browserCtrl, SLOT(clicked(const QModelIndex&))); connect(m_header, SIGNAL(headerClicked(int)), this, SLOT(headerClicked(int))); } CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog() { + m_browserCtrl = NULL; + delete m_form; qDebug() << "DTOR"; } @@ -104,6 +111,7 @@ namespace GeorgesQt void CGeorgesTreeViewDialog::setForm(const CForm *form) { m_form = (UForm*)form; + m_browserCtrl->setForm( (UForm*)form ); } NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName) 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 6f7b57acc..b2171cf03 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -32,6 +32,8 @@ // Project includes +class BrowserCtrl; + namespace NLGEORGES { class UForm; @@ -113,6 +115,8 @@ namespace GeorgesQt bool m_modified; + BrowserCtrl *m_browserCtrl; + }; /* CGeorgesTreeViewDialog */ } /* namespace GeorgesQt */ diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index 387bc8917..2cc5c1280 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -307,7 +307,7 @@ namespace GeorgesQt // Is a struct ? if ( (entry.getType () == NLGEORGES::UFormDfn::EntryDfn) || (entry.getType () == NLGEORGES::UFormDfn::EntryVirtualDfn) ) - { + { // Is an array of struct ? if (entry.getArrayFlag ()) {