Use a file browser for setting files.

This commit is contained in:
dfighter1985 2014-09-10 17:59:22 +02:00
parent 90b3bd0338
commit b69169af71
4 changed files with 88 additions and 5 deletions

View file

@ -20,6 +20,7 @@
#include "browser_ctrl.h"
#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h"
#include "3rdparty/qtpropertybrowser/qtvariantproperty.h"
#include "filepath_property_manager.h"
#include <QModelIndex>
#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 & ) ) );
}

View file

@ -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 );

View file

@ -24,16 +24,32 @@
#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 )
{
case NLGEORGES::UType::UnsignedInt: t = QVariant::UInt; break;
@ -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;
}

View file

@ -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;