From e2cb637a13f564a8cf45b95273243082329cd4d6 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 15:11:28 +0200 Subject: [PATCH] Enable saving when modified, disable saving after saving. --HG-- branch : dfighter-tools --- .../georges_editor/dfn_browser_ctrl.cpp | 25 +++++++++++++++++++ .../plugins/georges_editor/dfn_browser_ctrl.h | 3 +++ .../georges_editor/georges_dfn_dialog.cpp | 23 +++++++++++++++-- .../georges_editor/georges_dfn_dialog.h | 7 +++++- .../georges_editor/georges_editor_form.cpp | 4 ++- 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp index 72d6494dd..00a8bce8e 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.cpp @@ -19,6 +19,22 @@ namespace ENTRY_DFN_ARRAY }; + QString enumToString( int value ) + { + QString s; + + switch( value ) + { + case ENTRY_TYPE: s = "type"; break; + case ENTRY_DFN: s = "dfn"; break; + case ENTRY_VIRTUAL_DFN: s = "virtual dfn"; break; + case ENTRY_TYPE_ARRAY: s = "type array"; break; + case ENTRY_DFN_ARRAY: s = "dfn array"; break; + } + + return s; + } + NLGEORGES::UFormDfn::TEntryType enumToEntry( int value ) { NLGEORGES::UFormDfn::TEntryType entry = NLGEORGES::UFormDfn::EntryType; @@ -192,6 +208,10 @@ void DFNBrowserCtrl::onVariantValueChanged( QtProperty *p, const QVariant &v ) { entry.setFilenameExt( value.c_str() ); } + else + return; + + Q_EMIT valueChanged( key, v.toString() ); } void DFNBrowserCtrl::onEnumValueChanged( QtProperty *p, int v ) @@ -202,12 +222,17 @@ void DFNBrowserCtrl::onEnumValueChanged( QtProperty *p, int v ) NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx ); entry.setArrayFlag( isArray ); entry.setType( tentry ); + + QString value = enumToString( v ); + Q_EMIT valueChanged( p->propertyName(), value ); } void DFNBrowserCtrl::onFileValueChanged( QtProperty *p, const QString &v ) { NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx ); entry.setFilename( v.toUtf8().constData() ); + + Q_EMIT valueChanged( p->propertyName(), v ); } void DFNBrowserCtrl::connectManagers() diff --git a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h index 16b8c67c4..4b4c7faf3 100644 --- a/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h +++ b/code/studio/src/plugins/georges_editor/dfn_browser_ctrl.h @@ -31,6 +31,9 @@ public: void onElementSelected( int idx ); +Q_SIGNALS: + void valueChanged( const QString &key, const QString &value ); + private Q_SLOTS: void onFileValueChanged( QtProperty *p, const QString &v ); void onVariantValueChanged( QtProperty *p, const QVariant &v ); diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp index a3021563d..4db724252 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp @@ -28,13 +28,14 @@ GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) : GeorgesDockWidget( parent ) { m_ui.setupUi( this ); - setupConnections(); - + m_ui.addButton->setEnabled( false ); m_ui.removeButton->setEnabled( false ); m_pvt = new GeorgesDFNDialogPvt(); m_pvt->ctrl->setBrowser( m_ui.browser ); + + setupConnections(); } GeorgesDFNDialog::~GeorgesDFNDialog() @@ -74,6 +75,12 @@ bool GeorgesDFNDialog::load( const QString &fileName ) return true; } +void GeorgesDFNDialog::write() +{ + setModified( false ); + setWindowTitle( windowTitle().remove( "*" ) ); +} + void GeorgesDFNDialog::onAddClicked() { QString name = QInputDialog::getText( this, @@ -110,10 +117,22 @@ void GeorgesDFNDialog::onCurrentRowChanged( int row ) m_pvt->ctrl->onElementSelected( row ); } +void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value ) +{ + if( !isModified() ) + { + setModified( true ); + setWindowTitle( windowTitle() + "*" ); + + Q_EMIT modified(); + } +} + void GeorgesDFNDialog::setupConnections() { connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); connect( m_ui.list, SIGNAL( currentRowChanged( int ) ), this, SLOT( onCurrentRowChanged( int ) ) ); + connect( m_pvt->ctrl, SIGNAL( valueChanged( const QString&, const QString& ) ), this, SLOT( onValueChanged( const QString&, const QString& ) ) ); } diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h index f88433448..123faf39e 100644 --- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h @@ -14,13 +14,18 @@ public: ~GeorgesDFNDialog(); bool load( const QString &fileName ); - void write(){} + void write(); + +Q_SIGNALS: + void modified(); private Q_SLOTS: void onAddClicked(); void onRemoveClicked(); void onCurrentRowChanged( int row ); + void onValueChanged( const QString& key, const QString &value ); + private: void setupConnections(); diff --git a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp index b12b73b2d..4cbe90f2e 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -326,9 +326,11 @@ namespace GeorgesQt if( !b ) { delete d; - d = NULL; + return NULL; } + connect( d, SIGNAL( modified() ), this, SLOT( setModified() ) ); + return d; }