From 4dcbd2182dc441ad33b0cf6b8377d7ad40480da2 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 12 Aug 2014 20:17:10 +0200 Subject: [PATCH] Shown properties can now be edited. --- .../plugins/georges_editor/browser_ctrl.cpp | 93 +++++++++++++------ 1 file changed, 67 insertions(+), 26 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp index 1e9ed2606..b82c7733c 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp @@ -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 ); }