From 7a9e141e766912dc7c3c097a3b2743ec7f0be7fc Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Tue, 27 Nov 2012 10:15:39 +0100 Subject: [PATCH] properly track changed state modifications from exception list widget. --- clients/oxygen/config/oxygenconfig.cpp | 5 --- clients/oxygen/config/oxygenconfig.h | 3 -- clients/oxygen/config/oxygenconfigwidget.cpp | 24 ++++++++----- .../config/oxygenexceptionlistwidget.cpp | 34 +++++++++++++------ .../oxygen/config/oxygenexceptionlistwidget.h | 20 +++++++++-- 5 files changed, 55 insertions(+), 31 deletions(-) diff --git a/clients/oxygen/config/oxygenconfig.cpp b/clients/oxygen/config/oxygenconfig.cpp index 5c3805fe8e..77093700c9 100644 --- a/clients/oxygen/config/oxygenconfig.cpp +++ b/clients/oxygen/config/oxygenconfig.cpp @@ -115,7 +115,6 @@ namespace Oxygen // exceptions if( _configWidget->isChanged() ) modified = true; - // else if( exceptionListChanged() ) modified = true; // emit relevant signals if( modified ) emit changed(); @@ -180,8 +179,4 @@ namespace Oxygen } - //_______________________________________________________________________ - bool Config::exceptionListChanged( void ) const - { return true; } - } diff --git a/clients/oxygen/config/oxygenconfig.h b/clients/oxygen/config/oxygenconfig.h index 2dd1b614a9..4edff42548 100644 --- a/clients/oxygen/config/oxygenconfig.h +++ b/clients/oxygen/config/oxygenconfig.h @@ -87,9 +87,6 @@ namespace Oxygen { //! load configuration void loadConfiguration( ConfigurationPtr ); - //! returns true if exception list is changed - bool exceptionListChanged( void ) const; - //! user interface ConfigWidget* _configWidget; diff --git a/clients/oxygen/config/oxygenconfigwidget.cpp b/clients/oxygen/config/oxygenconfigwidget.cpp index 5cb212e9da..92df141fa1 100644 --- a/clients/oxygen/config/oxygenconfigwidget.cpp +++ b/clients/oxygen/config/oxygenconfigwidget.cpp @@ -64,12 +64,10 @@ namespace Oxygen // connections connect( ui.titleOutline, SIGNAL( toggled( bool ) ), ui.separatorMode, SLOT(setDisabled(bool)) ); - connect( shadowConfigurations[0], SIGNAL( changed( void ) ), SLOT( updateChanged( void ) ) ); - connect( shadowConfigurations[0], SIGNAL( toggled( bool ) ), SLOT( updateChanged( void ) ) ); - - connect( shadowConfigurations[1], SIGNAL( changed( void ) ), SLOT( updateChanged( void ) ) ); - connect( shadowConfigurations[1], SIGNAL( toggled( bool ) ), SLOT( updateChanged( void ) ) ); + connect( ui._expertModeButton, SIGNAL( clicked( void ) ), SLOT( toggleExpertModeInternal( void ) ) ); + connect( _animationConfigWidget, SIGNAL( layoutChanged( void ) ), SLOT(updateLayout( void ) ) ); + // track ui changes connect( ui.titleAlignment, SIGNAL( currentIndexChanged( int ) ), SLOT( updateChanged( void ) ) ); connect( ui.buttonSize, SIGNAL( currentIndexChanged( int ) ), SLOT( updateChanged( void ) ) ); connect( ui.frameBorder, SIGNAL( currentIndexChanged( int ) ), SLOT( updateChanged( void ) ) ); @@ -80,14 +78,19 @@ namespace Oxygen connect( ui.narrowButtonSpacing, SIGNAL( clicked( void ) ), SLOT( updateChanged( void ) ) ); connect( ui.closeFromMenuButton, SIGNAL( clicked( void ) ), SLOT( updateChanged( void ) ) ); connect( ui.separatorMode, SIGNAL( currentIndexChanged( int ) ), SLOT( updateChanged( void ) ) ); - connect( ui.exceptions, SIGNAL( changed( void ) ), SLOT( updateChanged( void ) ) ); - connect( ui._expertModeButton, SIGNAL( clicked( void ) ), SLOT( toggleExpertModeInternal( void ) ) ); + // track exception changes + connect( ui.exceptions, SIGNAL( changed( bool ) ), SLOT( updateChanged( void ) ) ); - // animation config widget + // track shadow configuration changes + connect( shadowConfigurations[0], SIGNAL( changed( void ) ), SLOT( updateChanged( void ) ) ); + connect( shadowConfigurations[0], SIGNAL( toggled( bool ) ), SLOT( updateChanged( void ) ) ); + connect( shadowConfigurations[1], SIGNAL( changed( void ) ), SLOT( updateChanged( void ) ) ); + connect( shadowConfigurations[1], SIGNAL( toggled( bool ) ), SLOT( updateChanged( void ) ) ); + + // track animations changes connect( ui.animationsEnabled, SIGNAL( clicked( void ) ), SLOT( updateChanged( void ) ) ); connect( _animationConfigWidget, SIGNAL( changed( bool ) ), SLOT( updateChanged( void ) ) ); - connect( _animationConfigWidget, SIGNAL( layoutChanged( void ) ), SLOT(updateLayout( void ) ) ); } @@ -235,6 +238,9 @@ namespace Oxygen else if( ui.narrowButtonSpacing->isChecked() != _configuration->useNarrowButtonSpacing() ) modified = true; else if( ui.closeFromMenuButton->isChecked() != _configuration->closeWindowFromMenuButton() ) modified = true; + // exceptions + else if( ui.exceptions->isChanged() ) modified = true; + // shadow configurations else if( shadowConfigurations[0]->isModified() ) modified = true; else if( shadowConfigurations[1]->isModified() ) modified = true; diff --git a/clients/oxygen/config/oxygenexceptionlistwidget.cpp b/clients/oxygen/config/oxygenexceptionlistwidget.cpp index ed16cef4cf..31a0ba68b2 100644 --- a/clients/oxygen/config/oxygenexceptionlistwidget.cpp +++ b/clients/oxygen/config/oxygenexceptionlistwidget.cpp @@ -37,7 +37,8 @@ namespace Oxygen //__________________________________________________________ ExceptionListWidget::ExceptionListWidget( QWidget* parent ): - QWidget( parent ) + QWidget( parent ), + _changed( false ) { //! ui @@ -79,11 +80,15 @@ namespace Oxygen { model().set( exceptions ); resizeColumns(); + setChanged( false ); } //__________________________________________________________ - ConfigurationList ExceptionListWidget::exceptions( void ) const - { return model().get(); } + ConfigurationList ExceptionListWidget::exceptions( void ) + { + return model().get(); + setChanged( false ); + } //__________________________________________________________ void ExceptionListWidget::updateButtons( void ) @@ -124,6 +129,7 @@ namespace Oxygen // create new item model().add( exception ); + setChanged( true ); // make sure item is selected QModelIndex index( model().index( exception ) ); @@ -134,7 +140,6 @@ namespace Oxygen } resizeColumns(); - emit changed(); return; } @@ -160,15 +165,19 @@ namespace Oxygen return; } + // check modifications + if( !dialog->isChanged() ) return; + // retrieve exception dialog->save(); delete dialog; // check new exception validity checkException( exception ); - resizeColumns(); - emit changed(); + + setChanged( true ); + return; } @@ -184,7 +193,9 @@ namespace Oxygen model().remove( model().get( ui.exceptionListView->selectionModel()->selectedRows() ) ); resizeColumns(); updateButtons(); - emit changed(); + + setChanged( true ); + return; } @@ -199,8 +210,7 @@ namespace Oxygen // get matching exception ConfigurationPtr exception( model().get( index ) ); exception->setEnabled( !exception->enabled() ); - - emit changed(); + setChanged( true ); return; } @@ -245,7 +255,8 @@ namespace Oxygen for( ConfigurationList::const_iterator iter = selectedExceptions.constBegin(); iter != selectedExceptions.constEnd(); ++iter ) { ui.exceptionListView->selectionModel()->select( model().index( *iter ), QItemSelectionModel::Select|QItemSelectionModel::Rows ); } - emit changed(); + setChanged( true ); + return; } @@ -296,7 +307,8 @@ namespace Oxygen for( ConfigurationList::const_iterator iter = selectedExceptions.constBegin(); iter != selectedExceptions.constEnd(); ++iter ) { ui.exceptionListView->selectionModel()->select( model().index( *iter ), QItemSelectionModel::Select|QItemSelectionModel::Rows ); } - emit changed(); + setChanged( true ); + return; } diff --git a/clients/oxygen/config/oxygenexceptionlistwidget.h b/clients/oxygen/config/oxygenexceptionlistwidget.h index 88e18ef4da..fea223c436 100644 --- a/clients/oxygen/config/oxygenexceptionlistwidget.h +++ b/clients/oxygen/config/oxygenexceptionlistwidget.h @@ -47,12 +47,16 @@ namespace Oxygen void setExceptions( const ConfigurationList& ); //! get exceptions - ConfigurationList exceptions( void ) const; + ConfigurationList exceptions( void ); + + //! true if changed + virtual bool isChanged( void ) const + { return _changed; } signals: - //! emitted when list is changed - void changed( void ); + //! emitted when changed + void changed( bool ); protected: @@ -95,6 +99,13 @@ namespace Oxygen //! check exception bool checkException( ConfigurationPtr ); + //! set changed state + virtual void setChanged( bool value ) + { + _changed = value; + emit changed( value ); + } + private: //! model @@ -103,6 +114,9 @@ namespace Oxygen //! ui Ui_OxygenExceptionListWidget ui; + //! changed state + bool _changed; + }; }