Use a file browser for setting files.

--HG--
branch : dfighter-tools
This commit is contained in:
dfighter1985 2014-09-10 17:59:22 +02:00
parent 946685dfac
commit 1d028c759c
4 changed files with 88 additions and 5 deletions

View file

@ -20,6 +20,7 @@
#include "browser_ctrl.h" #include "browser_ctrl.h"
#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h"
#include "3rdparty/qtpropertybrowser/qtvariantproperty.h" #include "3rdparty/qtpropertybrowser/qtvariantproperty.h"
#include "filepath_property_manager.h"
#include <QModelIndex> #include <QModelIndex>
#include "nel/georges/form.h" #include "nel/georges/form.h"
@ -69,6 +70,11 @@ void BrowserCtrl::onValueChanged( const QString &key, const QString &value )
Q_EMIT valueChanged( key, 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 ) void BrowserCtrl::onArrayResized( const QString &name, int size )
{ {
Q_EMIT arrayResized( name, size ); Q_EMIT arrayResized( name, size );
@ -87,16 +93,22 @@ void BrowserCtrl::onVStructChanged( const QString &name )
void BrowserCtrl::enableMgrConnections() void BrowserCtrl::enableMgrConnections()
{ {
QtVariantPropertyManager *mgr = m_pvt->manager(); QtVariantPropertyManager *mgr = m_pvt->manager();
FileManager *fileMgr = m_pvt->fileManager();
connect( mgr, SIGNAL( valueChanged( QtProperty*, const QVariant & ) ), connect( mgr, SIGNAL( valueChanged( QtProperty*, const QVariant & ) ),
this, SLOT( onValueChanged( 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() void BrowserCtrl::disableMgrConnections()
{ {
QtVariantPropertyManager *mgr = m_pvt->manager(); QtVariantPropertyManager *mgr = m_pvt->manager();
FileManager *fileMgr = m_pvt->fileManager();
disconnect( mgr, SIGNAL( valueChanged( QtProperty*, const QVariant & ) ), disconnect( mgr, SIGNAL( valueChanged( QtProperty*, const QVariant & ) ),
this, SLOT( onValueChanged( QtProperty*, const QVariant & ) ) ); this, SLOT( onValueChanged( QtProperty*, const QVariant & ) ) );
disconnect( fileMgr, SIGNAL( valueChanged( QtProperty*, const QString & ) ),
this, SLOT( onFileValueChanged( QtProperty*, const QString & ) ) );
} }

View file

@ -53,6 +53,7 @@ Q_SIGNALS:
private Q_SLOTS: private Q_SLOTS:
void onValueChanged( QtProperty *p, const QVariant &value ); void onValueChanged( QtProperty *p, const QVariant &value );
void onValueChanged( const QString &key, const QString &value ); void onValueChanged( const QString &key, const QString &value );
void onFileValueChanged( QtProperty *p, const QString &value );
void onArrayResized( const QString &name, int size ); void onArrayResized( const QString &name, int size );
void onModified(); void onModified();
void onVStructChanged( const QString &name ); void onVStructChanged( const QString &name );

View file

@ -24,16 +24,32 @@
#include "nel/georges/form.h" #include "nel/georges/form.h"
#include "filepath_property_manager.h"
namespace namespace
{ {
const unsigned int FILEBROWSER = 9000000;
QVariant::Type getValueType( const NLGEORGES::UType *typ ) QVariant::Type getValueType( const NLGEORGES::UType *typ )
{ {
QVariant::Type t = QVariant::String; QVariant::Type t = QVariant::String;
bool file = false;
NLGEORGES::UType::TType ttyp = NLGEORGES::UType::String; NLGEORGES::UType::TType ttyp = NLGEORGES::UType::String;
if( typ != NULL ) if( typ != NULL )
{
ttyp = typ->getType(); 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 ) switch( ttyp )
{ {
case NLGEORGES::UType::UnsignedInt: t = QVariant::UInt; break; case NLGEORGES::UType::UnsignedInt: t = QVariant::UInt; break;
@ -159,6 +175,8 @@ QObject( parent )
{ {
mgr = new QtVariantPropertyManager(); mgr = new QtVariantPropertyManager();
factory = new QtVariantEditorFactory(); factory = new QtVariantEditorFactory();
m_fileMgr = new FileManager( this );
m_fileFactory = new FileEditFactory( this );
m_rootNode = NULL; m_rootNode = NULL;
} }
@ -168,6 +186,8 @@ BrowserCtrlPvt::~BrowserCtrlPvt()
mgr = NULL; mgr = NULL;
delete factory; delete factory;
factory = NULL; factory = NULL;
m_fileMgr = NULL;
m_fileFactory = NULL;
m_browser = NULL; m_browser = NULL;
} }
@ -227,7 +247,10 @@ void BrowserCtrlPvt::setupAtom( NLGEORGES::CFormElmStruct *st, int idx )
t = getValueTypeFromDfn( st, 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 ) void BrowserCtrlPvt::setupStruct( NLGEORGES::UFormElm *node )
@ -253,13 +276,13 @@ void BrowserCtrlPvt::setupVStruct( GeorgesQt::CFormItem *node )
{ {
NLGEORGES::UFormElm *n = getGeorgesNode( node ); NLGEORGES::UFormElm *n = getGeorgesNode( node );
QtVariantProperty *p; QtProperty *p = NULL;
p = addVariantProperty( QVariant::String, "Dfn filename", QVariant() ); p = addFileProperty( "Dfn filename", "" );
if( n != NULL ) if( n != NULL )
{ {
NLGEORGES::CFormElmVirtualStruct *vs = static_cast< NLGEORGES::CFormElmVirtualStruct* >( n ); 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 ); setupStruct( n );
} }
} }
@ -300,7 +323,10 @@ void BrowserCtrlPvt::setupAtom( GeorgesQt::CFormItem *node )
tt = getValueTypeFromDfn( atom ); 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 ) void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node )
@ -324,6 +350,7 @@ void BrowserCtrlPvt::setupNode( GeorgesQt::CFormItem *node )
setupAtom( node ); setupAtom( node );
m_browser->setFactoryForManager( mgr, factory ); m_browser->setFactoryForManager( mgr, factory );
m_browser->setFactoryForManager( m_fileMgr, m_fileFactory );
} }
void BrowserCtrlPvt::clear() void BrowserCtrlPvt::clear()
@ -508,6 +535,28 @@ void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value )
onAtomValueChanged( p, 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* BrowserCtrlPvt::addVariantProperty( QVariant::Type type, const QString &key, const QVariant &value )
{ {
QtVariantProperty *p = mgr->addProperty( type, key ); QtVariantProperty *p = mgr->addProperty( type, key );
@ -532,3 +581,15 @@ QtVariantProperty* BrowserCtrlPvt::addVariantProperty( QVariant::Type type, cons
return p; 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;
}

View file

@ -40,6 +40,9 @@ class QVariant;
class QtProperty; class QtProperty;
class QtVariantProperty; class QtVariantProperty;
class FileManager;
class FileEditFactory;
class BrowserCtrlPvt : public QObject class BrowserCtrlPvt : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -50,8 +53,10 @@ public:
void clear(); void clear();
void setupNode( GeorgesQt::CFormItem *node ); void setupNode( GeorgesQt::CFormItem *node );
void onValueChanged( QtProperty *p, const QVariant &value ); void onValueChanged( QtProperty *p, const QVariant &value );
void onFileValueChanged( QtProperty *p, const QString &value );
QtVariantPropertyManager* manager() const{ return mgr; } QtVariantPropertyManager* manager() const{ return mgr; }
FileManager* fileManager() const{ return m_fileMgr; }
void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; } void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; }
void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; } void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; }
@ -80,11 +85,15 @@ private:
void createArray(); void createArray();
QtVariantProperty* addVariantProperty( QVariant::Type type, const QString &key, const QVariant &value ); QtVariantProperty* addVariantProperty( QVariant::Type type, const QString &key, const QVariant &value );
QtProperty *addFileProperty( const QString &key, const QString &value );
QtVariantPropertyManager *mgr; QtVariantPropertyManager *mgr;
QtVariantEditorFactory *factory; QtVariantEditorFactory *factory;
QtTreePropertyBrowser *m_browser; QtTreePropertyBrowser *m_browser;
FileManager *m_fileMgr;
FileEditFactory *m_fileFactory;
QString m_currentNodeName; QString m_currentNodeName;
NLGEORGES::CFormElm *m_rootNode; NLGEORGES::CFormElm *m_rootNode;