Use enum property manager for the type.

This commit is contained in:
dfighter1985 2014-08-31 23:21:19 +02:00
parent 23c27349c3
commit 3929b62e48
2 changed files with 73 additions and 13 deletions

View file

@ -1,17 +1,65 @@
#include "dfn_browser_ctrl.h" #include "dfn_browser_ctrl.h"
#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h"
#include "3rdparty/qtpropertybrowser/qtvariantproperty.h" #include "3rdparty/qtpropertybrowser/qtvariantproperty.h"
#include "3rdparty/qtpropertybrowser/qteditorfactory.h"
#include "3rdparty/qtpropertybrowser/qtpropertymanager.h"
#include "nel/georges/form_dfn.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 ) : DFNBrowserCtrl::DFNBrowserCtrl( QObject *parent ) :
QObject( parent ) QObject( parent )
{ {
m_browser = NULL; m_browser = NULL;
m_dfn = NULL; m_dfn = NULL;
m_manager = new QtVariantPropertyManager(); m_manager = new QtVariantPropertyManager();
m_factory = new QtVariantEditorFactory(); m_factory = new QtVariantEditorFactory();
m_enumMgr = new QtEnumPropertyManager();
m_enumFactory = new QtEnumEditorFactory();
} }
DFNBrowserCtrl::~DFNBrowserCtrl() DFNBrowserCtrl::~DFNBrowserCtrl()
@ -23,6 +71,10 @@ DFNBrowserCtrl::~DFNBrowserCtrl()
m_manager = NULL; m_manager = NULL;
delete m_factory; delete m_factory;
m_factory = NULL; m_factory = NULL;
delete m_enumMgr;
m_enumMgr = NULL;
delete m_enumFactory;
m_enumFactory = NULL;
} }
void DFNBrowserCtrl::onElementSelected( int idx ) void DFNBrowserCtrl::onElementSelected( int idx )
@ -31,8 +83,10 @@ void DFNBrowserCtrl::onElementSelected( int idx )
m_browser->clear(); m_browser->clear();
m_browser->setFactoryForManager( m_manager, m_factory ); m_browser->setFactoryForManager( m_manager, m_factory );
m_browser->setFactoryForManager( m_enumMgr, m_enumFactory );
QtVariantProperty *p = NULL; QtVariantProperty *p = NULL;
QtProperty *prop = NULL;
p = m_manager->addProperty( QVariant::String, "name" ); p = m_manager->addProperty( QVariant::String, "name" );
p->setValue( entry.getName().c_str() ); p->setValue( entry.getName().c_str() );
@ -41,21 +95,21 @@ void DFNBrowserCtrl::onElementSelected( int idx )
NLGEORGES::UFormDfn::TEntryType et = entry.getType(); NLGEORGES::UFormDfn::TEntryType et = entry.getType();
bool isArray = entry.getArrayFlag(); bool isArray = entry.getArrayFlag();
QString type = "";
switch( et ) QStringList options;
{ options.push_back( "Type" );
case NLGEORGES::UFormDfn::EntryType: type = "type"; break; options.push_back( "DFN" );
case NLGEORGES::UFormDfn::EntryDfn: type = "DFN"; break; options.push_back( "Virtual DFN" );
case NLGEORGES::UFormDfn::EntryVirtualDfn: type = "Virtual DFN"; break; options.push_back( "Type Array" );
} options.push_back( "DFN Array" );
if( isArray ) int enumId = entryToEnum( et, isArray );
type += " array";
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 = m_manager->addProperty( QVariant::String, "value" );
p->setValue( entry.getFilename().c_str() ); p->setValue( entry.getFilename().c_str() );

View file

@ -14,6 +14,9 @@ class QtTreePropertyBrowser;
class QVariant; class QVariant;
class QtProperty; class QtProperty;
class QtEnumPropertyManager;
class QtEnumEditorFactory;
class DFNBrowserCtrl : public QObject class DFNBrowserCtrl : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -32,6 +35,9 @@ private:
QtVariantPropertyManager *m_manager; QtVariantPropertyManager *m_manager;
QtVariantEditorFactory *m_factory; QtVariantEditorFactory *m_factory;
QtEnumPropertyManager *m_enumMgr;
QtEnumEditorFactory *m_enumFactory;
}; };
#endif #endif