diff --git a/python/gui/qgscollapsiblegroupbox.sip b/python/gui/qgscollapsiblegroupbox.sip index 93b909d..1313529 100644 --- a/python/gui/qgscollapsiblegroupbox.sip +++ b/python/gui/qgscollapsiblegroupbox.sip @@ -1,3 +1,14 @@ + +/** + * \class QgsCollapsibleGroupBox + * \brief A groupbox that collapses/expands when toggled. + * + * By default, it auto-saves its collapsed state to the global settings based on the widget and it's parent names. + * + * @note To add Collapsible properties in promoted QtDesigner widgets, you can add the following "Dynamic properties" by clicking on the green + in the propreties palette : + * bool collapsed, bool saveCollapsedState, bool saveCheckedState + */ + class QgsCollapsibleGroupBox : QGroupBox { %TypeHeaderCode diff --git a/python/plugins/GdalTools/tools/widgetDEM.ui b/python/plugins/GdalTools/tools/widgetDEM.ui index d0fe438..9483887 100644 --- a/python/plugins/GdalTools/tools/widgetDEM.ui +++ b/python/plugins/GdalTools/tools/widgetDEM.ui @@ -410,7 +410,7 @@ - + falsefalsetrue true diff --git a/python/plugins/GdalTools/tools/widgetTranslate.ui b/python/plugins/GdalTools/tools/widgetTranslate.ui index 47d4077..3b3d5dc 100644 --- a/python/plugins/GdalTools/tools/widgetTranslate.ui +++ b/python/plugins/GdalTools/tools/widgetTranslate.ui @@ -250,7 +250,7 @@ The 'gray' value (from GDAL 1.7.0) enables to expand a dataset with a color tabl - + falsefalsetrue &Creation Options diff --git a/src/gui/qgscollapsiblegroupbox.cpp b/src/gui/qgscollapsiblegroupbox.cpp index 7680564..0fc52e7 100644 --- a/src/gui/qgscollapsiblegroupbox.cpp +++ b/src/gui/qgscollapsiblegroupbox.cpp @@ -26,56 +26,33 @@ #include #include -QIcon QgsCollapsibleGroupBox::mCollapseIcon; -QIcon QgsCollapsibleGroupBox::mExpandIcon; +QIcon QgsCollapsibleGroupBoxBasic::mCollapseIcon; +QIcon QgsCollapsibleGroupBoxBasic::mExpandIcon; -QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( QWidget *parent, QSettings* settings ) - : QGroupBox( parent ), mSettings( settings ) +QgsCollapsibleGroupBoxBasic::QgsCollapsibleGroupBoxBasic( QWidget *parent ) + : QGroupBox( parent ) { init(); } -QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( const QString &title, - QWidget *parent, QSettings* settings ) - : QGroupBox( title, parent ), mSettings( settings ) +QgsCollapsibleGroupBoxBasic::QgsCollapsibleGroupBoxBasic( const QString &title, + QWidget *parent ) + : QGroupBox( title, parent ) { init(); } -QgsCollapsibleGroupBox::~QgsCollapsibleGroupBox() +QgsCollapsibleGroupBoxBasic::~QgsCollapsibleGroupBoxBasic() { - saveState(); - if ( mDelSettings ) // local settings obj to delete - delete mSettings; - mSettings = 0; // null the pointer (in case of outside settings obj) + QgsDebugMsg("Entered"); } -void QgsCollapsibleGroupBox::setSettings( QSettings* settings ) -{ - if ( mDelSettings ) // local settings obj to delete - delete mSettings; - mSettings = settings; - mDelSettings = false; // don't delete outside obj -} - -void QgsCollapsibleGroupBox::init() +void QgsCollapsibleGroupBoxBasic::init() { - // use pointer to app qsettings if no custom qsettings specified - // custom qsettings object may be from Python plugin - mDelSettings = false; - if ( !mSettings ) - { - mSettings = new QSettings(); - mDelSettings = true; // only delete obj created by class - } + QgsDebugMsg("Entered"); // variables mCollapsed = false; - mSaveCollapsedState = true; - // NOTE: only turn on mSaveCheckedState for groupboxes NOT used - // in multiple places or used as options for different parent objects - mSaveCheckedState = false; - mSettingGroup = ""; // if not set, use window object name mInitFlat = false; mScrollOnExpand = true; mShown = false; @@ -101,8 +78,9 @@ void QgsCollapsibleGroupBox::init() connect( this, SIGNAL( toggled( bool ) ), this, SLOT( checkToggled( bool ) ) ); } -void QgsCollapsibleGroupBox::showEvent( QShowEvent * event ) +void QgsCollapsibleGroupBoxBasic::showEvent( QShowEvent * event ) { + QgsDebugMsg("Entered"); // initialise widget on first show event only if ( mShown ) { @@ -127,8 +105,6 @@ void QgsCollapsibleGroupBox::showEvent( QShowEvent * event ) QgsDebugMsg( "did not find a QScrollArea parent" ); } - loadState(); - updateStyle(); // expand if needed - any calls to setCollapsed() before only set mCollapsed, but have UI effect @@ -147,7 +123,7 @@ void QgsCollapsibleGroupBox::showEvent( QShowEvent * event ) event->accept(); } -void QgsCollapsibleGroupBox::mouseReleaseEvent( QMouseEvent *event ) +void QgsCollapsibleGroupBoxBasic::mouseReleaseEvent( QMouseEvent *event ) { // catch mouse release over title when non checkable, to collapse/expand if ( !isCheckable() && event->button() == Qt::LeftButton ) @@ -162,7 +138,7 @@ void QgsCollapsibleGroupBox::mouseReleaseEvent( QMouseEvent *event ) QGroupBox::mouseReleaseEvent( event ); } -void QgsCollapsibleGroupBox::changeEvent( QEvent *event ) +void QgsCollapsibleGroupBoxBasic::changeEvent( QEvent *event ) { // always re-enable mCollapseButton when groupbox was previously disabled // e.g. resulting from a disabled parent of groupbox, or a signal/slot connection @@ -174,7 +150,7 @@ void QgsCollapsibleGroupBox::changeEvent( QEvent *event ) mCollapseButton->setEnabled( true ); } -QRect QgsCollapsibleGroupBox::titleRect() const +QRect QgsCollapsibleGroupBoxBasic::titleRect() const { QStyleOptionGroupBox box; initStyleOption( &box ); @@ -182,70 +158,7 @@ QRect QgsCollapsibleGroupBox::titleRect() const QStyle::SC_GroupBoxLabel, this ); } -QString QgsCollapsibleGroupBox::saveKey() const -{ - // save key for load/save state - // currently QgsCollapsibleGroupBox/window()/object - QString saveKey = "/" + objectName(); - // QObject* parentWidget = parent(); - // while ( parentWidget != NULL ) - // { - // saveKey = "/" + parentWidget->objectName() + saveKey; - // parentWidget = parentWidget->parent(); - // } - // if ( parent() != NULL ) - // saveKey = "/" + parent()->objectName() + saveKey; - QString setgrp = mSettingGroup.isEmpty() ? window()->objectName() : mSettingGroup; - saveKey = "/" + setgrp + saveKey; - saveKey = "QgsCollapsibleGroupBox" + saveKey; - return saveKey; -} - -void QgsCollapsibleGroupBox::loadState() -{ - if ( !mSettings ) - return; - - if ( !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) ) - return; - - setUpdatesEnabled( false ); - - QString key = saveKey(); - QVariant val; - if ( mSaveCheckedState ) - { - val = mSettings->value( key + "/checked" ); - if ( ! val.isNull() ) - setChecked( val.toBool() ); - } - if ( mSaveCollapsedState ) - { - val = mSettings->value( key + "/collapsed" ); - if ( ! val.isNull() ) - setCollapsed( val.toBool() ); - } - - setUpdatesEnabled( true ); -} - -void QgsCollapsibleGroupBox::saveState() -{ - if ( !mSettings ) - return; - - if ( !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) ) - return; - - QString key = saveKey(); - - if ( mSaveCheckedState ) - mSettings->setValue( key + "/checked", isChecked() ); - if ( mSaveCollapsedState ) - mSettings->setValue( key + "/collapsed", isCollapsed() ); -} - -void QgsCollapsibleGroupBox::checkToggled( bool chkd ) +void QgsCollapsibleGroupBoxBasic::checkToggled( bool chkd ) { mCollapseButton->setEnabled( true ); // always keep enabled // expand/collapse when toggled @@ -255,12 +168,12 @@ void QgsCollapsibleGroupBox::checkToggled( bool chkd ) setCollapsed( true ); } -void QgsCollapsibleGroupBox::toggleCollapsed() +void QgsCollapsibleGroupBoxBasic::toggleCollapsed() { setCollapsed( !mCollapsed ); } -void QgsCollapsibleGroupBox::updateStyle() +void QgsCollapsibleGroupBoxBasic::updateStyle() { setUpdatesEnabled( false ); @@ -336,7 +249,7 @@ void QgsCollapsibleGroupBox::updateStyle() setUpdatesEnabled( true ); } -void QgsCollapsibleGroupBox::setCollapsed( bool collapse ) +void QgsCollapsibleGroupBoxBasic::setCollapsed( bool collapse ) { mCollapsed = collapse; @@ -364,3 +277,138 @@ void QgsCollapsibleGroupBox::setCollapsed( bool collapse ) } emit collapsedStateChanged( this ); } + +// ---- + +QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( QWidget *parent, QSettings* settings ) + : QgsCollapsibleGroupBoxBasic( parent ), mSettings( settings ) +{ + init(); +} + +QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( const QString &title, + QWidget *parent, QSettings* settings ) + : QgsCollapsibleGroupBoxBasic( title, parent ), mSettings( settings ) +{ + init(); +} + +QgsCollapsibleGroupBox::~QgsCollapsibleGroupBox() +{ + QgsDebugMsg("Entered"); + saveState(); + if ( mDelSettings ) // local settings obj to delete + delete mSettings; + mSettings = 0; // null the pointer (in case of outside settings obj) +} + +void QgsCollapsibleGroupBox::setSettings( QSettings* settings ) +{ + if ( mDelSettings ) // local settings obj to delete + delete mSettings; + mSettings = settings; + mDelSettings = false; // don't delete outside obj +} + + +void QgsCollapsibleGroupBox::init() +{ + QgsDebugMsg("Entered"); + // use pointer to app qsettings if no custom qsettings specified + // custom qsettings object may be from Python plugin + mDelSettings = false; + if ( !mSettings ) + { + mSettings = new QSettings(); + mDelSettings = true; // only delete obj created by class + } + // variables + mSaveCollapsedState = true; + // NOTE: only turn on mSaveCheckedState for groupboxes NOT used + // in multiple places or used as options for different parent objects + mSaveCheckedState = false; + mSettingGroup = ""; // if not set, use window object name + mShown = false; + mParentScrollArea = 0; +} + +void QgsCollapsibleGroupBox::showEvent( QShowEvent * event ) +{ + QgsDebugMsg("Entered"); + // initialise widget on first show event only + if ( mShown ) + { + event->accept(); + return; + } + + loadState(); + + QgsCollapsibleGroupBoxBasic::showEvent( event ); +} + +QString QgsCollapsibleGroupBox::saveKey() const +{ + // save key for load/save state + // currently QgsCollapsibleGroupBoxBasic/window()/object + QString saveKey = "/" + objectName(); + // QObject* parentWidget = parent(); + // while ( parentWidget != NULL ) + // { + // saveKey = "/" + parentWidget->objectName() + saveKey; + // parentWidget = parentWidget->parent(); + // } + // if ( parent() != NULL ) + // saveKey = "/" + parent()->objectName() + saveKey; + QString setgrp = mSettingGroup.isEmpty() ? window()->objectName() : mSettingGroup; + saveKey = "/" + setgrp + saveKey; + saveKey = "QgsCollapsibleGroupBoxBasic" + saveKey; + return saveKey; +} + +void QgsCollapsibleGroupBox::loadState() +{ + QgsDebugMsg("Entered"); + if ( !mSettings ) + return; + + if ( !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) ) + return; + + setUpdatesEnabled( false ); + + QString key = saveKey(); + QVariant val; + if ( mSaveCheckedState ) + { + val = mSettings->value( key + "/checked" ); + if ( ! val.isNull() ) + setChecked( val.toBool() ); + } + if ( mSaveCollapsedState ) + { + val = mSettings->value( key + "/collapsed" ); + if ( ! val.isNull() ) + setCollapsed( val.toBool() ); + } + + setUpdatesEnabled( true ); +} + +void QgsCollapsibleGroupBox::saveState() +{ + QgsDebugMsg("Entered"); + if ( !mSettings ) + return; + + if ( !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) ) + return; + + QString key = saveKey(); + + if ( mSaveCheckedState ) + mSettings->setValue( key + "/checked", isChecked() ); + if ( mSaveCollapsedState ) + mSettings->setValue( key + "/collapsed", isCollapsed() ); +} + diff --git a/src/gui/qgscollapsiblegroupbox.h b/src/gui/qgscollapsiblegroupbox.h index 0977ad3..7aaf518 100644 --- a/src/gui/qgscollapsiblegroupbox.h +++ b/src/gui/qgscollapsiblegroupbox.h @@ -20,11 +20,6 @@ #include "qgisgui.h" -/** \ingroup gui - * A groupbox that collapses/expands when toggled. - * @note Collapsible function not shown in promoted QtDesigner widgets. - */ - #include #include #include @@ -32,10 +27,74 @@ class QToolButton; class QScrollArea; -class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox +/** \ingroup gui + * A groupbox that collapses/expands when toggled. + * Basic class QgsCollapsibleGroupBoxBasic does not aut-save collapsed or checked state + * @note To add Collapsible properties in promoted QtDesigner widgets, you can add the following "Dynamic properties" by clicking on the green + in the propreties palette : + * bool collapsed + */ + +class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox +{ + Q_OBJECT + + Q_PROPERTY(bool collapsed READ isCollapsed WRITE setCollapsed USER true) + + public: + QgsCollapsibleGroupBoxBasic( QWidget *parent = 0 ); + QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent = 0 ); + ~QgsCollapsibleGroupBoxBasic(); + + bool isCollapsed() const { return mCollapsed; } + void setCollapsed( bool collapse ); + + //! set this to false to not automatically scroll parent QScrollArea to this widget's contents when expanded + void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; } + + signals: + /** Signal emitted when groupbox collapsed/expanded state is changed, and when first shown */ + void collapsedStateChanged( QgsCollapsibleGroupBoxBasic* ); + + public slots: + void checkToggled( bool ckd ); + void toggleCollapsed(); + + protected: + void init(); + void showEvent( QShowEvent *event ); + void mouseReleaseEvent( QMouseEvent *event ); + void changeEvent( QEvent *event ); + + void updateStyle(); + QRect titleRect() const; + + bool mCollapsed; + bool mInitFlat; + bool mScrollOnExpand; + bool mShown; + QScrollArea* mParentScrollArea; + QToolButton* mCollapseButton; + + static QIcon mCollapseIcon; + static QIcon mExpandIcon; +}; + +/** \ingroup gui + * A groupbox that collapses/expands when toggled and can save its collapsed and checked states. + * By default, it auto-saves its collapsed and checked states to the global settings based on the widget and it's parent names. + * @see basic class QgsCollapsibleGroupBoxBasic which does not save collapsed or checked state + * @note To add Collapsible properties in promoted QtDesigner widgets, you can add the following "Dynamic properties" by clicking on the green + in the propreties palette : + * bool collapsed, bool saveCollapsedState, bool saveCheckedState + */ + +class GUI_EXPORT QgsCollapsibleGroupBox : public QgsCollapsibleGroupBoxBasic { Q_OBJECT + Q_PROPERTY(bool collapsed READ isCollapsed WRITE setCollapsed USER true) + Q_PROPERTY(bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState USER true) + Q_PROPERTY(bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState USER true) + public: QgsCollapsibleGroupBox( QWidget *parent = 0, QSettings* settings = 0 ); QgsCollapsibleGroupBox( const QString &title, QWidget *parent = 0, QSettings* settings = 0 ); @@ -44,9 +103,6 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox // set custom QSettings pointer if group box was already created from QtDesigner promotion void setSettings( QSettings* settings ); - bool isCollapsed() const { return mCollapsed; } - void setCollapsed( bool collapse ); - //! set this to false to not save/restore collapsed state void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; } /** set this to true to save/restore checked state @@ -60,17 +116,6 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox void setSettingGroup( const QString &group ) { mSettingGroup = group; } QString settingGroup() const { return mSettingGroup; } - //! set this to false to not automatically scroll parent QScrollArea to this widget's contents when expanded - void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; } - - signals: - /** Signal emitted when groupbox collapsed/expanded state is changed, and when first shown */ - void collapsedStateChanged( QgsCollapsibleGroupBox* ); - - public slots: - void checkToggled( bool ckd ); - void toggleCollapsed(); - protected slots: void loadState(); void saveState(); @@ -78,11 +123,6 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox protected: void init(); void showEvent( QShowEvent *event ); - void mouseReleaseEvent( QMouseEvent *event ); - void changeEvent( QEvent *event ); - - void updateStyle(); - QRect titleRect() const; QString saveKey() const; // pointer to app or custom, external QSettings @@ -90,18 +130,9 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox QPointer mSettings; bool mDelSettings; - bool mCollapsed; bool mSaveCollapsedState; bool mSaveCheckedState; QString mSettingGroup; - bool mInitFlat; - bool mScrollOnExpand; - bool mShown; - QScrollArea* mParentScrollArea; - QToolButton* mCollapseButton; - - static QIcon mCollapseIcon; - static QIcon mExpandIcon; }; #endif diff --git a/src/ui/qgscomposeritemwidgetbase.ui b/src/ui/qgscomposeritemwidgetbase.ui index 720bba5..5f418ea 100644 --- a/src/ui/qgscomposeritemwidgetbase.ui +++ b/src/ui/qgscomposeritemwidgetbase.ui @@ -25,7 +25,7 @@ - + falsefalsetrue Show frame @@ -60,7 +60,7 @@ - + falsefalsetrue Show background diff --git a/src/ui/qgslabelingguibase.ui b/src/ui/qgslabelingguibase.ui index 82d7461..92c9226 100644 --- a/src/ui/qgslabelingguibase.ui +++ b/src/ui/qgslabelingguibase.ui @@ -169,7 +169,7 @@ false - + falsefalsetrue 0 @@ -462,7 +462,7 @@ 20 - + falsefalsetrue 0 @@ -529,7 +529,7 @@ - + falsefalsetrue 0 @@ -677,7 +677,7 @@ - + falsefalsetrue 0 @@ -1161,7 +1161,7 @@ - + falsefalsetrue 0 @@ -1412,7 +1412,7 @@ - + falsefalsetrue Pixel size-based visibility @@ -1550,7 +1550,7 @@ - + falsefalsetrue 0 @@ -1691,7 +1691,7 @@ - + falsefalsetrue Line direction symbols @@ -1929,7 +1929,7 @@ 6 - + falsefalsetrue 16777215 @@ -1977,7 +1977,7 @@ - + falsefalsetrue 0 @@ -2731,7 +2731,7 @@ - + falsefalsetrue 16777215 @@ -3003,7 +3003,7 @@ 6 - + falsefalsetrue Buffer properties @@ -3049,7 +3049,7 @@ - + falsefalsetrue Position @@ -3147,7 +3147,7 @@ - + falsefalsetrue Display properties @@ -3211,7 +3211,7 @@ - + falsefalsetrue 0 diff --git a/src/ui/qgsoptionsbase.ui b/src/ui/qgsoptionsbase.ui index cfa101c..9fa68fb 100644 --- a/src/ui/qgsoptionsbase.ui +++ b/src/ui/qgsoptionsbase.ui @@ -997,7 +997,7 @@ - + falsefalsetrue 0 @@ -3790,7 +3790,7 @@ - + falsefalsetrue Use proxy for web access diff --git a/src/ui/qgsprojectpropertiesbase.ui b/src/ui/qgsprojectpropertiesbase.ui index f963ddc..d7b385f 100644 --- a/src/ui/qgsprojectpropertiesbase.ui +++ b/src/ui/qgsprojectpropertiesbase.ui @@ -843,7 +843,7 @@ - + falsefalsetrue Service Capabilitities @@ -979,7 +979,7 @@ - + falsefalsetrue Advertised Extent @@ -1082,7 +1082,7 @@ - + falsefalsetrue Coordinate Systems Restrictions @@ -1121,7 +1121,7 @@ - + falsefalsetrue Exclude composers @@ -1174,7 +1174,7 @@ - + falsefalsetrue Exclude layers diff --git a/src/ui/qgsrasterlayerpropertiesbase.ui b/src/ui/qgsrasterlayerpropertiesbase.ui index 990e8db..9cb1e52 100644 --- a/src/ui/qgsrasterlayerpropertiesbase.ui +++ b/src/ui/qgsrasterlayerpropertiesbase.ui @@ -158,7 +158,7 @@ - + falsefalsetrue Resampling diff --git a/src/ui/qgsrasterlayersaveasdialogbase.ui b/src/ui/qgsrasterlayersaveasdialogbase.ui index cc5b759..ba30377 100644 --- a/src/ui/qgsrasterlayersaveasdialogbase.ui +++ b/src/ui/qgsrasterlayersaveasdialogbase.ui @@ -222,7 +222,7 @@ datasets with maximum width and height specified below. 0 - + falsefalsetrue 0 @@ -380,7 +380,7 @@ datasets with maximum width and height specified below. - + falsefalsetrue 0 @@ -465,7 +465,7 @@ datasets with maximum width and height specified below. - + falsefalsetrue 0 @@ -520,7 +520,7 @@ datasets with maximum width and height specified below. - + falsefalsetrue 0 @@ -544,7 +544,7 @@ datasets with maximum width and height specified below. - + falsefalsetrue 0 @@ -628,7 +628,7 @@ datasets with maximum width and height specified below. - + falsefalsetrue 0 diff --git a/tests/testdata/zip/testzip.zip b/tests/testdata/zip/testzip.zip index 47d83b3..1a3dc68 100644 Binary files a/tests/testdata/zip/testzip.zip and b/tests/testdata/zip/testzip.zip differ