mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-27 17:46:18 +00:00
Use enum property manager for the type.
This commit is contained in:
parent
283a9519e9
commit
dfc5576f8a
2 changed files with 73 additions and 13 deletions
|
@ -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() );
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue