From 259dc63ac492b941dad783f9d1f1fac45ade6812 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 31 Aug 2014 23:21:19 +0200 Subject: [PATCH] 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