Skip to content

Commit

Permalink
Split QgsCollapsibleGroupBox into basic class and subclass that auto-…
Browse files Browse the repository at this point in the history
…saves collapsed state

- Split authored by Etienne Tourigny
- Add Q_PROPERTY declarations to make some class properties settable for promoted widget in QtDesigner (by Olivier Dalang)
- Update existing .ui files with dynamic properties (but not saveCheckedState, which should be cautiously used)
- Update sip file so both classes are available
  • Loading branch information
dakcarto committed Feb 12, 2013
1 parent 4fe2074 commit f4c5bc8
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 210 deletions.
76 changes: 54 additions & 22 deletions python/gui/qgscollapsiblegroupbox.sip
@@ -1,4 +1,56 @@
class QgsCollapsibleGroupBox : QGroupBox

/** \ingroup gui
* \class QgsCollapsibleGroupBoxBasic
* A groupbox that collapses/expands when toggled.
* Basic class QgsCollapsibleGroupBoxBasic does not auto-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 QgsCollapsibleGroupBoxBasic : QGroupBox
{
%TypeHeaderCode
#include <qgscollapsiblegroupbox.h>
%End
public:
QgsCollapsibleGroupBoxBasic( QWidget *parent = 0 );
QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent = 0 );
~QgsCollapsibleGroupBoxBasic();

bool isCollapsed() const;
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 );

signals:
/** Signal emitted when groupbox collapsed/expanded state is changed, and when first shown */
void collapsedStateChanged( bool collapsed );

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

/** \ingroup gui
* \class QgsCollapsibleGroupBox
* A groupbox that collapses/expands when toggled and can save its collapsed and checked states.
* By default, it auto-saves only its collapsed state to the global settings based on the widget and it's parent names.
* @see basic class QgsCollapsibleGroupBoxBasic which does not auto-save states
* @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 : QgsCollapsibleGroupBoxBasic
{
%TypeHeaderCode
#include <qgscollapsiblegroupbox.h>
Expand All @@ -11,9 +63,6 @@ class QgsCollapsibleGroupBox : QGroupBox
// set custom QSettings pointer if group box was already created from QtDesigner promotion
void setSettings( QSettings* settings );

bool isCollapsed() const;
void setCollapsed( bool collapse );

//! set this to false to not save/restore collapsed state
void setSaveCollapsedState( bool save );
/** set this to true to save/restore checked state
Expand All @@ -23,33 +72,16 @@ class QgsCollapsibleGroupBox : QGroupBox
bool saveCollapsedState();
bool saveCheckedState();

//! set this to a defined string to share save/restore collapsed state across dialogs
//! set this to a defined string to share save/restore states across different parent dialogs
void setSettingGroup( const QString &group );
QString settingGroup() const;

//! set this to false to not automatically scroll parent QScrollArea to this widget's contents when expanded
void setScrollOnExpand( bool 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();

protected:
void init();
void showEvent( QShowEvent *event );
void mouseReleaseEvent( QMouseEvent *event );
void changeEvent( QEvent *event );

void updateStyle();
QRect titleRect() const;
QString saveKey() const;

};
2 changes: 1 addition & 1 deletion python/plugins/GdalTools/tools/widgetDEM.ui
Expand Up @@ -410,7 +410,7 @@
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="creationOptionsGroupBox">
<widget class="QgsCollapsibleGroupBox" name="creationOptionsGroupBox"><property name="collapsed" stdset="0"><bool>false</bool></property><property name="saveCollapsedState" stdset="0"><bool>true</bool></property>
<property name="enabled">
<bool>true</bool>
</property>
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/GdalTools/tools/widgetTranslate.ui
Expand Up @@ -250,7 +250,7 @@ The 'gray' value (from GDAL 1.7.0) enables to expand a dataset with a color tabl
</layout>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="creationOptionsGroupBox">
<widget class="QgsCollapsibleGroupBox" name="creationOptionsGroupBox"><property name="collapsed" stdset="0"><bool>false</bool></property><property name="saveCollapsedState" stdset="0"><bool>true</bool></property>
<property name="title">
<string>&amp;Creation Options</string>
</property>
Expand Down
12 changes: 6 additions & 6 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -333,23 +333,23 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
}

connect( groupBox_mPreview,
SIGNAL( collapsedStateChanged( QgsCollapsibleGroupBox* ) ),
SIGNAL( collapsedStateChanged( bool ) ),
this,
SLOT( collapseSample( QgsCollapsibleGroupBox* ) ) );
SLOT( collapseSample( bool ) ) );
}

QgsLabelingGui::~QgsLabelingGui()
{
}

void QgsLabelingGui::collapseSample( QgsCollapsibleGroupBox* grpbx )
void QgsLabelingGui::collapseSample( bool collapse )
{
if ( grpbx->isCollapsed() )
if ( collapse )
{
QList<int> splitSizes = mFontPreviewSplitter->sizes();
if ( splitSizes[0] > grpbx->height() )
if ( splitSizes[0] > groupBox_mPreview->height() )
{
int delta = splitSizes[0] - grpbx->height();
int delta = splitSizes[0] - groupBox_mPreview->height();
splitSizes[0] -= delta;
splitSizes[1] += delta;
mFontPreviewSplitter->setSizes( splitSizes );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslabelinggui.h
Expand Up @@ -40,7 +40,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void writeSettingsToLayer();

public slots:
void collapseSample( QgsCollapsibleGroupBox* grpbx );
void collapseSample( bool collapse );
void apply();
void changeTextColor();
void changeTextFont();
Expand Down

0 comments on commit f4c5bc8

Please sign in to comment.