From 1d028c759c47291b427e735ac28857d2455e0be0 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 10 Sep 2014 17:59:22 +0200 Subject: [PATCH] Use a file browser for setting files. --HG-- branch : dfighter-tools --- .../plugins/georges_editor/browser_ctrl.cpp | 12 ++++ .../src/plugins/georges_editor/browser_ctrl.h | 1 + .../georges_editor/browser_ctrl_pvt.cpp | 71 +++++++++++++++++-- .../plugins/georges_editor/browser_ctrl_pvt.h | 9 +++ 4 files changed, 88 insertions(+), 5 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp index 722faf096..ad947edcf 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.cpp @@ -20,6 +20,7 @@ #include "browser_ctrl.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" #include "3rdparty/qtpropertybrowser/qtvariantproperty.h" +#include "filepath_property_manager.h" #include #include "nel/georges/form.h" @@ -69,6 +70,11 @@ void BrowserCtrl::onValueChanged( const QString &key, const QString &value ) Q_EMIT valueChanged( key, value ); } +void BrowserCtrl::onFileValueChanged( QtProperty *p, const QString &value ) +{ + m_pvt->onFileValueChanged( p, value ); +} + void BrowserCtrl::onArrayResized( const QString &name, int size ) { Q_EMIT arrayResized( name, size ); @@ -87,16 +93,22 @@ void BrowserCtrl::onVStructChanged( const QString &name ) void BrowserCtrl::enableMgrConnections() { QtVariantPropertyManager *mgr = m_pvt->manager(); + FileManager *fileMgr = m_pvt->fileManager(); connect( mgr, SIGNAL( valueChanged( QtProperty*, const QVariant & ) ), this, SLOT( onValueChanged( QtProperty*, const QVariant & ) ) ); + connect( fileMgr, SIGNAL( valueChanged( QtProperty*, const QString & ) ), + this, SLOT( onFileValueChanged( QtProperty*, const QString & ) ) ); } void BrowserCtrl::disableMgrConnections() { QtVariantPropertyManager *mgr = m_pvt->manager(); + FileManager *fileMgr = m_pvt->fileManager(); disconnect( mgr, SIGNAL( valueChanged( QtProperty*, const QVariant & ) ), this, SLOT( onValueChanged( QtProperty*, const QVariant & ) ) ); + disconnect( fileMgr, SIGNAL( valueChanged( QtProperty*, const QString & ) ), + this, SLOT( onFileValueChanged( QtProperty*, const QString & ) ) ); } diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl.h b/code/studio/src/plugins/georges_editor/browser_ctrl.h index 42ff5d6e7..a70b57356 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl.h @@ -53,6 +53,7 @@ Q_SIGNALS: private Q_SLOTS: void onValueChanged( QtProperty *p, const QVariant &value ); void onValueChanged( const QString &key, const QString &value ); + void onFileValueChanged( QtProperty *p, const QString &value ); void onArrayResized( const QString &name, int size ); void onModified(); void onVStructChanged( const QString &name ); diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp index 969e1ce91..0ce72d39b 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.cpp @@ -24,15 +24,31 @@ #include "nel/georges/form.h" +#include "filepath_property_manager.h" namespace { + const unsigned int FILEBROWSER = 9000000; + QVariant::Type getValueType( const NLGEORGES::UType *typ ) { QVariant::Type t = QVariant::String; + bool file = false; + NLGEORGES::UType::TType ttyp = NLGEORGES::UType::String; if( typ != NULL ) + { ttyp = typ->getType(); + + const NLGEORGES::CType *ctyp = static_cast< const NLGEORGES::CType* >( typ ); + if(ctyp->UIType == NLGEORGES::CType::FileBrowser ) + { + file = true; + } + } + + if( file ) + return QVariant::Type( FILEBROWSER ); switch( ttyp ) { @@ -159,6 +175,8 @@ QObject( parent ) { mgr = new QtVariantPropertyManager(); factory = new QtVariantEditorFactory(); + m_fileMgr = new FileManager( this ); + m_fileFactory = new FileEditFactory( this ); m_rootNode = NULL; } @@ -168,6 +186,8 @@ BrowserCtrlPvt::~BrowserCtrlPvt() mgr = NULL; delete factory; factory = NULL; + m_fileMgr = NULL; + m_fileFactory = NULL; m_browser = NULL; } @@ -227,7 +247,10 @@ void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx ) t = getValueTypeFromDfn( st, idx ); } - QtVariantProperty *p = addVariantProperty( t, key, value ); + if( t == QVariant::Type( FILEBROWSER ) ) + addFileProperty( key, value ); + else + addVariantProperty( t, key, value ); } void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node ) @@ -253,13 +276,13 @@ void BrowserCtrlPvt::setupVStruct( GeorgesQt::CFormItem *node ) { NLGEORGES::UFormElm *n = getGeorgesNode( node ); - QtVariantProperty *p; - p = addVariantProperty( QVariant::String, "Dfn filename", QVariant() ); + QtProperty *p = NULL; + p = addFileProperty( "Dfn filename", "" ); if( n != NULL ) { NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( n ); - mgr->setValue( p, vs->DfnFilename.c_str() ); + m_fileMgr->setValue( p, vs->DfnFilename.c_str() ); setupStruct( n ); } } @@ -300,7 +323,10 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node ) tt = getValueTypeFromDfn( atom ); } - QtVariantProperty *p = addVariantProperty( tt, "value", v.c_str() ); + if( tt = QVariant::Type( FILEBROWSER ) ) + addFileProperty( "value", v.c_str() ); + else + addVariantProperty( tt, "value", v.c_str() ); } void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) @@ -324,6 +350,7 @@ void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node ) setupAtom( node ); m_browser->setFactoryForManager( mgr, factory ); + m_browser->setFactoryForManager( m_fileMgr, m_fileFactory ); } void BrowserCtrlPvt::clear() @@ -508,6 +535,28 @@ void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value ) onAtomValueChanged( p, value ); } +void BrowserCtrlPvt::onFileValueChanged( QtProperty *p, const QString &value ) +{ + QString v = value; + QFileInfo info( value ); + if( !info.exists() ) + return; + + v = info.fileName(); + blockSignals( true ); + m_fileMgr->setValue( p, v ); + blockSignals( false ); + + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_VSTRUCT ) + onVStructValueChanged( p, v ); + else + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_STRUCT ) + onStructValueChanged( p, v ); + else + if( m_currentNode.type == GeorgesQt::CFormItem::TYPE_ATOM ) + onAtomValueChanged( p, v ); +} + QtVariantProperty* BrowserCtrlPvt::addVariantProperty( QVariant::Type type, const QString &key, const QVariant &value ) { QtVariantProperty *p = mgr->addProperty( type, key ); @@ -532,3 +581,15 @@ QtVariantProperty* BrowserCtrlPvt::addVariantProperty( QVariant::Type type, cons return p; } +QtProperty* BrowserCtrlPvt::addFileProperty( const QString &key, const QString &value ) +{ + QtProperty *p = m_fileMgr->addProperty( key ); + + m_fileMgr->setValue( p, value ); + m_browser->addProperty( p ); + + return p; +} + + + diff --git a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h index dd630b962..2f9785411 100644 --- a/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h +++ b/code/studio/src/plugins/georges_editor/browser_ctrl_pvt.h @@ -40,6 +40,9 @@ class QVariant; class QtProperty; class QtVariantProperty; +class FileManager; +class FileEditFactory; + class BrowserCtrlPvt : public QObject { Q_OBJECT @@ -50,8 +53,10 @@ public: void clear(); void setupNode( GeorgesQt::CFormItem *node ); void onValueChanged( QtProperty *p, const QVariant &value ); + void onFileValueChanged( QtProperty *p, const QString &value ); QtVariantPropertyManager* manager() const{ return mgr; } + FileManager* fileManager() const{ return m_fileMgr; } void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; } void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } @@ -80,11 +85,15 @@ private: void createArray(); QtVariantProperty* addVariantProperty( QVariant::Type type, const QString &key, const QVariant &value ); + QtProperty *addFileProperty( const QString &key, const QString &value ); QtVariantPropertyManager *mgr; QtVariantEditorFactory *factory; QtTreePropertyBrowser *m_browser; + FileManager *m_fileMgr; + FileEditFactory *m_fileFactory; + QString m_currentNodeName; NLGEORGES::CFormElm *m_rootNode;