Shown properties can now be edited.

This commit is contained in:
dfighter1985 2014-08-12 20:17:10 +02:00
parent 63fd3faad6
commit 964a5d4e4c

View file

@ -7,6 +7,26 @@
#include "formitem.h"
QVariant::Type getValueType( const NLGEORGES::UType *typ )
{
QVariant::Type t = QVariant::String;
NLGEORGES::UType::TType ttyp = NLGEORGES::UType::String;
if( typ != NULL )
ttyp = typ->getType();
switch( ttyp )
{
case NLGEORGES::UType::UnsignedInt: t = QVariant::UInt; break;
case NLGEORGES::UType::SignedInt: t = QVariant::Int; break;
case NLGEORGES::UType::Double: t = QVariant::Double; break;
case NLGEORGES::UType::Color: t = QVariant::Color; break;
case NLGEORGES::UType::String: t = QVariant::String; break;
}
return t;
}
class BrowserCtrlPvt
{
public:
@ -22,8 +42,52 @@ public:
mgr = NULL;
delete factory;
factory = NULL;
m_browser = NULL;
}
void setupElement( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm )
{
QString key = elm.Name.c_str();
QString value = "";
QVariant::Type t = QVariant::String;
if( elm.Element != NULL )
{
t = getValueType( elm.Element->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 = mgr->addProperty( t, key );
p->setValue( value );
m_browser->addProperty( p );
}
void setupForm( NLGEORGES::CFormElmStruct *st )
{
for( int i = 0; i < st->Elements.size(); i++ )
{
NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ i ];
setupElement( elm );
}
m_browser->setFactoryForManager( mgr, factory );
}
void clear()
{
m_browser->clear();
}
void setBrowser( QtTreePropertyBrowser *browser )
{
m_browser = browser;
}
private:
QtVariantPropertyManager *mgr;
QtVariantEditorFactory *factory;
QtTreePropertyBrowser *m_browser;
@ -33,7 +97,7 @@ BrowserCtrl::BrowserCtrl( QtTreePropertyBrowser *browser ) :
QObject( browser )
{
m_pvt = new BrowserCtrlPvt();
m_pvt->m_browser = browser;
m_pvt->setBrowser( browser );
}
BrowserCtrl::~BrowserCtrl()
@ -44,7 +108,7 @@ BrowserCtrl::~BrowserCtrl()
void BrowserCtrl::clicked( const QModelIndex &idx )
{
m_pvt->m_browser->clear();
m_pvt->clear();
GeorgesQt::CFormItem *item = static_cast< GeorgesQt::CFormItem* >( idx.internalPointer() );
NLGEORGES::UFormElm &root = m_form->getRootNode();
@ -60,30 +124,7 @@ void BrowserCtrl::clicked( const QModelIndex &idx )
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 );
}
m_pvt->setupForm( st );
}