From 6000fe187f15932076b7c67a73dbfa5126856ce1 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 18 Aug 2014 01:50:07 +0200 Subject: [PATCH] Moved BrowserCtrlPvt to it's own files. --HG-- branch : gsoc2014-dfighter --- .../src/plugins/georges_editor/CMakeLists.txt | 4 +- .../plugins/georges_editor/browser_ctrl.cpp | 164 +----------------- .../georges_editor/browser_ctrl_pvt.cpp | 156 +++++++++++++++++ .../plugins/georges_editor/browser_ctrl_pvt.h | 50 ++++++ 4 files changed, 210 insertions(+), 164 deletions(-) create mode 100644 code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp create mode 100644 code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h diff --git a/code/studio/src/plugins/georges_editor/CMakeLists.txt b/code/studio/src/plugins/georges_editor/CMakeLists.txt index 679af334e..c2d3c1da7 100644 --- a/code/studio/src/plugins/georges_editor/CMakeLists.txt +++ b/code/studio/src/plugins/georges_editor/CMakeLists.txt @@ -16,7 +16,9 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h georges_filesystem_model.h georges_treeview_dialog.h expandable_headerview.h - browser_ctrl.h) + browser_ctrl.h + browser_ctrl_pvt.h + ) SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui georges_dirtree_form.ui diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp index f430ff675..8801894e2 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp @@ -7,169 +7,7 @@ #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: - BrowserCtrlPvt() - { - mgr = new QtVariantPropertyManager(); - factory = new QtVariantEditorFactory(); - m_currentNode = NULL; - m_rootNode = NULL; - } - - ~BrowserCtrlPvt() - { - delete mgr; - mgr = NULL; - delete factory; - factory = NULL; - m_browser = NULL; - } - - void setupAtom( 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() ); - - std::string formName; - elm.Element->getFormName( formName, NULL ); - - std::string v; - m_rootNode->getValueByName( v, formName.c_str(), NLGEORGES::UFormElm::NoEval, NULL, 0 ); - value = v.c_str(); - } - - QtVariantProperty *p = mgr->addProperty( t, key ); - p->setValue( value ); - m_browser->addProperty( p ); - } - - void setupArray( NLGEORGES::UFormElm *node ) - { - NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( node ); - uint size = 0; - arr->getArraySize( size ); - - QString key = QObject::tr( "Array size" ); - QtVariantProperty *p = mgr->addProperty( QVariant::Int, key ); - p->setValue( size ); - m_browser->addProperty( p ); - - } - - void setupStruct( NLGEORGES::UFormElm *node ) - { - NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( node ); - - for( int i = 0; i < st->Elements.size(); i++ ) - { - NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ i ]; - if( ( elm.Element != NULL ) && !elm.Element->isAtom() ) - continue; - - if( elm.Element == NULL ) - { - NLGEORGES::CFormDfn::CEntry &entry = st->FormDfn->getEntry( i ); - if( entry.getArrayFlag() ) - continue; - } - - setupAtom( elm ); - } - } - - void setupNode( NLGEORGES::UFormElm *node ) - { - if( node->isStruct() ) - setupStruct( node ); - else - if( node->isArray() ) - setupArray( node ); - else - return; - - m_currentNode = node; - m_browser->setFactoryForManager( mgr, factory ); - } - - void clear() - { - m_browser->clear(); - m_currentNode = NULL; - } - - void setBrowser( QtTreePropertyBrowser *browser ) - { - m_browser = browser; - } - - void onStructValueChanged( QtProperty *p, const QVariant &value ) - { - std::string k = p->propertyName().toUtf8().constData(); - std::string v = value.toString().toUtf8().constData(); - - bool created = false; - m_currentNode->setValueByName( v.c_str(), k.c_str(), &created ); - } - - void onArrayValueChanged( QtProperty *p, const QVariant &value ) - { - NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode ); - std::string formName; - arr->getFormName( formName, NULL ); - - } - - void onValueChanged( QtProperty *p, const QVariant &value ) - { - if( m_currentNode == NULL ) - return; - - if( m_currentNode->isStruct() ) - onStructValueChanged( p, value ); - else - if( m_currentNode->isArray() ) - onArrayValueChanged( p, value ); - } - - QtVariantPropertyManager* manager() const{ return mgr; } - - void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; } - -private: - QtVariantPropertyManager *mgr; - QtVariantEditorFactory *factory; - QtTreePropertyBrowser *m_browser; - - NLGEORGES::UFormElm *m_currentNode; - NLGEORGES::CFormElm *m_rootNode; -}; +#include "browser_ctrl_pvt.h" BrowserCtrl::BrowserCtrl( QtTreePropertyBrowser *browser ) : QObject( browser ) diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp new file mode 100644 index 000000000..f49ebc1ba --- /dev/null +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -0,0 +1,156 @@ +#include "browser_ctrl_pvt.h" +#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" +#include "3rdparty/qtpropertybrowser/qtvariantproperty.h" +#include + +namespace +{ + + 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; + } + +} + + +BrowserCtrlPvt::BrowserCtrlPvt( QObject *parent ) : +QObject( parent ) +{ + mgr = new QtVariantPropertyManager(); + factory = new QtVariantEditorFactory(); + m_currentNode = NULL; + m_rootNode = NULL; +} + +BrowserCtrlPvt::~BrowserCtrlPvt() +{ + delete mgr; + mgr = NULL; + delete factory; + factory = NULL; + m_browser = NULL; +} + +void BrowserCtrlPvt::setupAtom( 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() ); + + std::string formName; + elm.Element->getFormName( formName, NULL ); + + std::string v; + m_rootNode->getValueByName( v, formName.c_str(), NLGEORGES::UFormElm::NoEval, NULL, 0 ); + value = v.c_str(); + } + + QtVariantProperty *p = mgr->addProperty( t, key ); + p->setValue( value ); + m_browser->addProperty( p ); +} + +void BrowserCtrlPvt::setupArray( NLGEORGES::UFormElm *node ) +{ + NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( node ); + uint size = 0; + arr->getArraySize( size ); + + QString key = QObject::tr( "Array size" ); + QtVariantProperty *p = mgr->addProperty( QVariant::Int, key ); + p->setValue( size ); + m_browser->addProperty( p ); + +} + +void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node ) +{ + NLGEORGES::CFormElmStruct *st = static_cast< NLGEORGES::CFormElmStruct* >( node ); + + for( int i = 0; i < st->Elements.size(); i++ ) + { + NLGEORGES::CFormElmStruct::CFormElmStructElm &elm = st->Elements[ i ]; + if( ( elm.Element != NULL ) && !elm.Element->isAtom() ) + continue; + + if( elm.Element == NULL ) + { + NLGEORGES::CFormDfn::CEntry &entry = st->FormDfn->getEntry( i ); + if( entry.getArrayFlag() ) + continue; + } + + setupAtom( elm ); + } +} + +void BrowserCtrlPvt::setupNode( NLGEORGES::UFormElm *node ) +{ + if( node->isStruct() ) + setupStruct( node ); + else + if( node->isArray() ) + setupArray( node ); + else + return; + + m_currentNode = node; + m_browser->setFactoryForManager( mgr, factory ); +} + +void BrowserCtrlPvt::clear() +{ + m_browser->clear(); + m_currentNode = NULL; +} + + +void BrowserCtrlPvt::onStructValueChanged( QtProperty *p, const QVariant &value ) +{ + std::string k = p->propertyName().toUtf8().constData(); + std::string v = value.toString().toUtf8().constData(); + + bool created = false; + m_currentNode->setValueByName( v.c_str(), k.c_str(), &created ); +} + +void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value ) +{ + NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode ); + std::string formName; + arr->getFormName( formName, NULL ); +} + +void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) +{ + if( m_currentNode == NULL ) + return; + + if( m_currentNode->isStruct() ) + onStructValueChanged( p, value ); + else + if( m_currentNode->isArray() ) + onArrayValueChanged( p, value ); +} + + diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h new file mode 100644 index 000000000..51d756cfa --- /dev/null +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -0,0 +1,50 @@ +#ifndef BROWSER_CTRL_PVT_H +#define BROWSER_CTRL_PVT_H + +#include + +namespace NLGEORGES +{ + class CFormElm; + class UFormElm; + class CFormElmStruct; +} + +class QtVariantPropertyManager; +class QtVariantEditorFactory; +class QtTreePropertyBrowser; +class QVariant; +class QtProperty; + +class BrowserCtrlPvt : public QObject +{ + Q_OBJECT +public: + BrowserCtrlPvt( QObject *parent = NULL ); + ~BrowserCtrlPvt(); + + void clear(); + void setupNode( NLGEORGES::UFormElm *node ); + void onValueChanged( QtProperty *p, const QVariant &value ); + + QtVariantPropertyManager* manager() const{ return mgr; } + void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; } + void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } + +private: + void setupStruct( NLGEORGES::UFormElm *node ); + void setupArray( NLGEORGES::UFormElm *node ); + void setupAtom( NLGEORGES::CFormElmStruct::CFormElmStructElm &elm ); + + void onStructValueChanged( QtProperty *p, const QVariant &value ); + void onArrayValueChanged( QtProperty *p, const QVariant &value ); + + QtVariantPropertyManager *mgr; + QtVariantEditorFactory *factory; + QtTreePropertyBrowser *m_browser; + + NLGEORGES::UFormElm *m_currentNode; + NLGEORGES::CFormElm *m_rootNode; +}; + +#endif