mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-10 01:09:50 +00:00
Added first iteration of the file path property manager / editor / factory.
--HG-- branch : dfighter-tools
This commit is contained in:
parent
259dc63ac4
commit
25d808f7ea
5 changed files with 422 additions and 3 deletions
|
@ -20,6 +20,7 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h
|
|||
browser_ctrl_pvt.h
|
||||
dfn_browser_ctrl.h
|
||||
georges_dfn_dialog.h
|
||||
filepath_property_manager.h
|
||||
)
|
||||
|
||||
SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "3rdparty/qtpropertybrowser/qteditorfactory.h"
|
||||
#include "3rdparty/qtpropertybrowser/qtpropertymanager.h"
|
||||
|
||||
#include "filepath_property_manager.h"
|
||||
|
||||
#include "nel/georges/form_dfn.h"
|
||||
|
||||
namespace
|
||||
|
@ -60,6 +62,8 @@ QObject( parent )
|
|||
m_factory = new QtVariantEditorFactory();
|
||||
m_enumMgr = new QtEnumPropertyManager();
|
||||
m_enumFactory = new QtEnumEditorFactory();
|
||||
m_fileMgr = new FileManager();
|
||||
m_fileFactory = new FileEditFactory();
|
||||
}
|
||||
|
||||
DFNBrowserCtrl::~DFNBrowserCtrl()
|
||||
|
@ -75,6 +79,10 @@ DFNBrowserCtrl::~DFNBrowserCtrl()
|
|||
m_enumMgr = NULL;
|
||||
delete m_enumFactory;
|
||||
m_enumFactory = NULL;
|
||||
delete m_fileMgr;
|
||||
m_fileMgr = NULL;
|
||||
delete m_fileFactory;
|
||||
m_fileFactory = NULL;
|
||||
}
|
||||
|
||||
void DFNBrowserCtrl::onElementSelected( int idx )
|
||||
|
@ -84,6 +92,7 @@ void DFNBrowserCtrl::onElementSelected( int idx )
|
|||
m_browser->clear();
|
||||
m_browser->setFactoryForManager( m_manager, m_factory );
|
||||
m_browser->setFactoryForManager( m_enumMgr, m_enumFactory );
|
||||
m_browser->setFactoryForManager( m_fileMgr, m_fileFactory );
|
||||
|
||||
QtVariantProperty *p = NULL;
|
||||
QtProperty *prop = NULL;
|
||||
|
@ -111,9 +120,13 @@ void DFNBrowserCtrl::onElementSelected( int idx )
|
|||
m_browser->addProperty( prop );
|
||||
|
||||
|
||||
p = m_manager->addProperty( QVariant::String, "value" );
|
||||
p->setValue( entry.getFilename().c_str() );
|
||||
m_browser->addProperty( p );
|
||||
prop = m_fileMgr->addProperty( "value" );
|
||||
m_fileMgr->setValue( prop, entry.getFilename().c_str() );
|
||||
m_browser->addProperty( prop );
|
||||
|
||||
//p = m_manager->addProperty( QVariant::String, "value" );
|
||||
//p->setValue( entry.getFilename().c_str() );
|
||||
//m_browser->addProperty( p );
|
||||
|
||||
p = m_manager->addProperty( QVariant::String, "default" );
|
||||
p->setValue( entry.getDefault().c_str() );
|
||||
|
|
|
@ -16,6 +16,8 @@ class QtProperty;
|
|||
|
||||
class QtEnumPropertyManager;
|
||||
class QtEnumEditorFactory;
|
||||
class FileManager;
|
||||
class FileEditFactory;
|
||||
|
||||
class DFNBrowserCtrl : public QObject
|
||||
{
|
||||
|
@ -38,6 +40,9 @@ private:
|
|||
|
||||
QtEnumPropertyManager *m_enumMgr;
|
||||
QtEnumEditorFactory *m_enumFactory;
|
||||
|
||||
FileManager *m_fileMgr;
|
||||
FileEditFactory *m_fileFactory;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,302 @@
|
|||
#include "filepath_property_manager.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QToolButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QFileDialog>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////// Manager ////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class FileManagerPvt
|
||||
{
|
||||
public:
|
||||
QMap< const QtProperty*, QString > values;
|
||||
};
|
||||
|
||||
FileManager::FileManager( QObject *parent ) :
|
||||
QtAbstractPropertyManager( parent )
|
||||
{
|
||||
m_pvt = new FileManagerPvt();
|
||||
}
|
||||
|
||||
FileManager::~FileManager()
|
||||
{
|
||||
delete m_pvt;
|
||||
m_pvt = NULL;
|
||||
}
|
||||
|
||||
QString FileManager::value( const QtProperty *p ) const
|
||||
{
|
||||
QMap< const QtProperty*, QString >::const_iterator itr = m_pvt->values.find( p );
|
||||
if( itr == m_pvt->values.end() )
|
||||
return "";
|
||||
else
|
||||
return itr.value();
|
||||
}
|
||||
|
||||
void FileManager::setValue( QtProperty *p, const QString &v )
|
||||
{
|
||||
if( !m_pvt->values.contains( p ) )
|
||||
return;
|
||||
|
||||
if( m_pvt->values[ p ] == v )
|
||||
return;
|
||||
|
||||
m_pvt->values[ p ] = v;
|
||||
|
||||
Q_EMIT propertyChanged( p );
|
||||
Q_EMIT valueChanged( p, v );
|
||||
}
|
||||
|
||||
bool FileManager::hasValue( const QtProperty *p ) const
|
||||
{
|
||||
if( m_pvt->values.contains( p ) )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
QString FileManager::valueText( const QtProperty *p ) const
|
||||
{
|
||||
return value( p );
|
||||
}
|
||||
|
||||
void FileManager::initializeProperty( QtProperty *p )
|
||||
{
|
||||
if( m_pvt->values.contains( p ) )
|
||||
return;
|
||||
|
||||
m_pvt->values[ p ] = "";
|
||||
}
|
||||
|
||||
void FileManager::uninitializeProperty( QtProperty *p )
|
||||
{
|
||||
m_pvt->values.remove( p );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////// Factory ///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class FileEditFactoryPvt
|
||||
{
|
||||
public:
|
||||
QMap< QtProperty*, QList< FileEdit* > > createdEditors;
|
||||
QMap< FileEdit*, QtProperty* > editorToProperty;
|
||||
|
||||
void addEditor( QtProperty *p, FileEdit *editor )
|
||||
{
|
||||
editorToProperty[ editor ] = p;
|
||||
|
||||
QMap< QtProperty*, QList< FileEdit* > >::iterator itr = createdEditors.find( p );
|
||||
if( itr == createdEditors.end() )
|
||||
{
|
||||
QList< FileEdit* > l;
|
||||
l.push_back( editor );
|
||||
createdEditors[ p ] = l;
|
||||
}
|
||||
else
|
||||
{
|
||||
QList< FileEdit* > &l = itr.value();
|
||||
l.push_back( editor );
|
||||
}
|
||||
}
|
||||
|
||||
void removeEditor( QObject *o )
|
||||
{
|
||||
// Find in editorToProperty
|
||||
QMap< FileEdit*, QtProperty* >::iterator itr = editorToProperty.begin();
|
||||
while( itr != editorToProperty.end() )
|
||||
{
|
||||
if( itr.key() == o )
|
||||
break;
|
||||
++itr;
|
||||
}
|
||||
|
||||
// Store the property, and remove the editor from editorToProperty
|
||||
QtProperty *p = NULL;
|
||||
if( itr != editorToProperty.end() )
|
||||
{
|
||||
p = itr.value();
|
||||
editorToProperty.erase( itr );
|
||||
}
|
||||
|
||||
// Find the property in createdEditors
|
||||
QMap< QtProperty*, QList< FileEdit* > >::iterator mitr = createdEditors.find( p );
|
||||
QList< FileEdit* > &l = mitr.value();
|
||||
|
||||
// Find the editor in the list
|
||||
QList< FileEdit* >::iterator litr = l.begin();
|
||||
while( litr != l.end() )
|
||||
{
|
||||
if( o == *litr )
|
||||
break;
|
||||
litr++;
|
||||
}
|
||||
|
||||
// Remove the editor and remove the list too if it's empty
|
||||
if( litr != l.end() )
|
||||
l.erase( litr );
|
||||
|
||||
if( l.isEmpty() )
|
||||
createdEditors.erase( mitr );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
FileEditFactory::FileEditFactory( QObject *parent ) :
|
||||
QtAbstractEditorFactory( parent )
|
||||
{
|
||||
m_pvt = new FileEditFactoryPvt();
|
||||
}
|
||||
|
||||
FileEditFactory::~FileEditFactory()
|
||||
{
|
||||
delete m_pvt;
|
||||
m_pvt = NULL;
|
||||
}
|
||||
|
||||
void FileEditFactory::connectPropertyManager( FileManager *manager )
|
||||
{
|
||||
connect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
|
||||
this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
|
||||
}
|
||||
|
||||
void FileEditFactory::disconnectPropertyManager( FileManager *manager )
|
||||
{
|
||||
disconnect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
|
||||
this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
|
||||
}
|
||||
|
||||
QWidget* FileEditFactory::createEditor( FileManager *manager, QtProperty *p, QWidget *parent )
|
||||
{
|
||||
FileEdit *editor = new FileEdit( parent );
|
||||
editor->setValue( p->valueText() );
|
||||
|
||||
connect( editor, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onSetValue( const QString& ) ) );
|
||||
connect( editor, SIGNAL( destroyed( QObject* ) ), this, SLOT( onEditorDestroyed( QObject* ) ) );
|
||||
|
||||
m_pvt->addEditor( p, editor );
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
void FileEditFactory::onPropertyChanged( QtProperty *p, const QString &v )
|
||||
{
|
||||
QMap< QtProperty*, QList< FileEdit* > >::iterator itr = m_pvt->createdEditors.find( p );
|
||||
if( itr == m_pvt->createdEditors.end() )
|
||||
return;
|
||||
|
||||
QList< FileEdit* > &l = itr.value();
|
||||
QList< FileEdit* >::iterator litr = l.begin();
|
||||
while( litr != l.end() )
|
||||
{
|
||||
FileEdit *editor = *litr;
|
||||
editor->blockSignals( true );
|
||||
editor->setValue( v );
|
||||
editor->blockSignals( false );
|
||||
|
||||
++litr;
|
||||
}
|
||||
}
|
||||
|
||||
void FileEditFactory::onSetValue( const QString& v )
|
||||
{
|
||||
QObject *s = sender();
|
||||
FileEdit *editor = qobject_cast< FileEdit* >( s );
|
||||
if( editor == NULL )
|
||||
return;
|
||||
|
||||
QMap< FileEdit*, QtProperty* >::iterator itr = m_pvt->editorToProperty.find( editor );
|
||||
if( itr == m_pvt->editorToProperty.end() )
|
||||
return;
|
||||
|
||||
QtProperty *p = *itr;
|
||||
FileManager *manager = qobject_cast< FileManager* >( p->propertyManager() );
|
||||
if( manager == NULL )
|
||||
return;
|
||||
|
||||
blockSignals( true );
|
||||
manager->setValue( p, v );
|
||||
blockSignals( false );
|
||||
}
|
||||
|
||||
void FileEditFactory::onEditorDestroyed( QObject *editor )
|
||||
{
|
||||
m_pvt->removeEditor( editor );
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////// Editor /////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class FileEditPvt
|
||||
{
|
||||
public:
|
||||
QLineEdit *lineEdit;
|
||||
QToolButton *toolButton;
|
||||
};
|
||||
|
||||
|
||||
|
||||
FileEdit::FileEdit( QWidget *parent ) :
|
||||
QWidget( parent )
|
||||
{
|
||||
m_pvt = new FileEditPvt();
|
||||
|
||||
setupUI();
|
||||
setupConnections();
|
||||
}
|
||||
|
||||
FileEdit::~FileEdit()
|
||||
{
|
||||
delete m_pvt;
|
||||
m_pvt = NULL;
|
||||
|
||||
Q_EMIT destroyed( this );
|
||||
}
|
||||
|
||||
void FileEdit::setValue( const QString &value )
|
||||
{
|
||||
m_pvt->lineEdit->setText( value );
|
||||
}
|
||||
|
||||
void FileEdit::onButtonClicked()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName( this,
|
||||
tr( "" ),
|
||||
tr( "" ) );
|
||||
if( file.isEmpty() )
|
||||
return;
|
||||
|
||||
if( m_pvt->lineEdit->text() == file )
|
||||
return;
|
||||
|
||||
m_pvt->lineEdit->setText( file );
|
||||
|
||||
Q_EMIT valueChanged( file );
|
||||
}
|
||||
|
||||
void FileEdit::setupUI()
|
||||
{
|
||||
m_pvt->lineEdit = new QLineEdit( this );
|
||||
m_pvt->toolButton = new QToolButton( this );
|
||||
m_pvt->toolButton->setText( "..." );
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout( this );
|
||||
layout->setContentsMargins( 0, 0, 0, 0 );
|
||||
layout->setSpacing( 0 );
|
||||
layout->addWidget( m_pvt->lineEdit );
|
||||
layout->addWidget( m_pvt->toolButton );
|
||||
setLayout( layout );
|
||||
|
||||
setFocusProxy( m_pvt->lineEdit );
|
||||
setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed );
|
||||
}
|
||||
|
||||
void FileEdit::setupConnections()
|
||||
{
|
||||
connect( m_pvt->toolButton, SIGNAL( clicked( bool ) ), this, SLOT( onButtonClicked() ) );
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
#ifndef FILEPATH_PROPERTY_MANAGER
|
||||
#define FILEPATH_PROPERTY_MANAGER
|
||||
|
||||
#define QT_QTPROPERTYBROWSER_IMPORT
|
||||
|
||||
#include <QWidget>
|
||||
#include <3rdparty/qtpropertybrowser/qtpropertymanager.h>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////// Manager /////////////////////////////////////////////////////////////////
|
||||
|
||||
class FileManagerPvt;
|
||||
|
||||
class FileManager : public QtAbstractPropertyManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileManager( QObject *parent = NULL );
|
||||
~FileManager();
|
||||
|
||||
QString value( const QtProperty *p ) const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setValue( QtProperty *p, const QString &v );
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged( QtProperty *p, const QString &v );
|
||||
|
||||
protected:
|
||||
bool hasValue( const QtProperty *p ) const;
|
||||
QString valueText( const QtProperty *p ) const;
|
||||
void initializeProperty( QtProperty *p );
|
||||
void uninitializeProperty( QtProperty *p );
|
||||
|
||||
private:
|
||||
FileManagerPvt *m_pvt;
|
||||
|
||||
Q_DISABLE_COPY( FileManager );
|
||||
};
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////// Factory ///////////////////////////////////////////////////////////////////
|
||||
|
||||
class FileEditFactoryPvt;
|
||||
|
||||
class FileEditFactory : public QtAbstractEditorFactory< FileManager >
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileEditFactory( QObject *parent = NULL );
|
||||
~FileEditFactory();
|
||||
|
||||
protected:
|
||||
void connectPropertyManager( FileManager *manager );
|
||||
void disconnectPropertyManager( FileManager *manager );
|
||||
QWidget* createEditor( FileManager *manager, QtProperty *p, QWidget *parent );
|
||||
|
||||
private Q_SLOTS:
|
||||
void onPropertyChanged( QtProperty *p, const QString &value );
|
||||
void onSetValue( const QString &value );
|
||||
void onEditorDestroyed( QObject *editor );
|
||||
|
||||
private:
|
||||
FileEditFactoryPvt *m_pvt;
|
||||
|
||||
Q_DISABLE_COPY( FileEditFactory );
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////// Editor ////////////////////////////////////////////////////////////////////
|
||||
|
||||
class FileEditPvt;
|
||||
|
||||
class FileEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileEdit( QWidget *parent = NULL );
|
||||
~FileEdit();
|
||||
|
||||
void setValue( const QString &value );
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged( const QString &value );
|
||||
void destroyed( QObject *editor );
|
||||
|
||||
private Q_SLOTS:
|
||||
void onButtonClicked();
|
||||
|
||||
private:
|
||||
void setupUI();
|
||||
void setupConnections();
|
||||
FileEditPvt *m_pvt;
|
||||
|
||||
Q_DISABLE_COPY( FileEdit );
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue