Skip to content
Permalink
Browse files

Different approach, fixes several issues

- Just set max height instead of hiding widgets
- Default is to show expanded
- Removed check in favor of just toggled signal
- setCollapsed() now sets desired state for first show, if not visible
- Added another test with Adv Labeling dialog (all grpbxs are now collapsible)
- Wording cleanup
  • Loading branch information
dakcarto committed Sep 11, 2012
1 parent 849b83e commit 0ee89e2470872ec9c9cf825e041eae749b3db512
Showing with 38 additions and 52 deletions.
  1. +5 −0 src/app/qgslabelinggui.cpp
  2. +14 −38 src/gui/qgscollapsiblegroupbox.cpp
  3. +1 −2 src/gui/qgscollapsiblegroupbox.h
  4. +18 −12 src/ui/qgslabelingguibase.ui
@@ -267,6 +267,11 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
{
connect( quadrantRadios[i], SIGNAL( toggled( bool ) ), this, SLOT( updateQuadrant() ) );
}

chkBuffer->setCollapsed( true );
groupBox_2->setCollapsed( true );
chkFormattedNumbers->setCollapsed( true );
chkScaleBasedVisibility->setCollapsed( true );
}

QgsLabelingGui::~QgsLabelingGui()
@@ -27,14 +27,14 @@ QIcon QgsCollapsibleGroupBox::mCollapseIcon;
QIcon QgsCollapsibleGroupBox::mExpandIcon;

QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( QWidget *parent )
: QGroupBox( parent ), mCollapsed( true )
: QGroupBox( parent ), mCollapsed( false )
{
init();
}

QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( const QString &title,
QWidget *parent )
: QGroupBox( title, parent ), mCollapsed( true )
: QGroupBox( title, parent ), mCollapsed( false )
{
init();
}
@@ -65,7 +65,7 @@ void QgsCollapsibleGroupBox::init()
mCollapseButton->setFixedSize( 16, 16 );
// TODO set size (as well as margins) depending on theme
mCollapseButton->setIconSize( QSize( 12, 12 ) );
mCollapseButton->setIcon( mExpandIcon );
mCollapseButton->setIcon( mCollapseIcon );

// clear toolbutton default background and border
// TODO: move to app stylesheet system, when appropriate
@@ -76,82 +76,58 @@ void QgsCollapsibleGroupBox::init()
mCollapseButton->setStyleSheet( ssd );

connect( mCollapseButton, SIGNAL( clicked() ), this, SLOT( toggleCollapsed() ) );
connect( this, SIGNAL( clicked( bool ) ), this, SLOT( checkClicked() ) );
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( checkToggled() ) );
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( checkToggled( bool ) ) );
}

void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
{
QGroupBox::showEvent( event );
// expand if needed - any calls to setCollapsed() before have no effect
// expand if needed - any calls to setCollapsed() before only set mCollapsed
if ( mCollapsed )
{
setCollapsed( mCollapsed );
}
else
{
/* manually uncollapsing (already default) on show may scroll scroll areas
still emit signal for connections using uncollapsed state */
/* manually expanding (already default) on show may scroll scroll areas;
still emit signal for connections using expanded state */
emit collapsedStateChanged( this );
}
}

void QgsCollapsibleGroupBox::checkClicked()
void QgsCollapsibleGroupBox::checkToggled( bool chkd )
{
mCollapseButton->setEnabled( true ); // always keep enabled
// expand/collapse when clicked
if ( isChecked() && isCollapsed() )
// expand/collapse when toggled
if ( chkd && isCollapsed() )
setCollapsed( false );
else if ( ! isChecked() && ! isCollapsed() )
else if ( ! chkd && ! isCollapsed() )
setCollapsed( true );
}

void QgsCollapsibleGroupBox::checkToggled()
{
mCollapseButton->setEnabled( true ); // always keep enabled
}

void QgsCollapsibleGroupBox::toggleCollapsed()
{
setCollapsed( !mCollapsed );
}

void QgsCollapsibleGroupBox::setCollapsed( bool collapse )
{
mCollapsed = collapse;

if ( !isVisible() )
return;

mCollapsed = collapse;

// for consistent look/spacing across platforms when collapsed
setFlat( collapse );
setMaximumHeight( collapse ? 28 : 16777215 );

// if we are collapsing, save hidden widgets in a list
if ( collapse )
{
mCollapseButton->setIcon( mExpandIcon );
mHiddenWidgets.clear();
foreach ( QWidget *widget, findChildren<QWidget*>() )
{
if ( widget->isHidden() && widget->objectName() != mCollapseButton->objectName() )
mHiddenWidgets << widget;
}
}

// show/hide widgets
foreach ( QWidget *widget, findChildren<QWidget*>() )
if ( widget->objectName() != mCollapseButton->objectName() )
widget->setHidden( collapse );

// if we are expanding, re-hide saved hidden widgets
if ( ! collapse )
else
{
mCollapseButton->setIcon( mCollapseIcon );
foreach ( QWidget *widget, mHiddenWidgets )
{
widget->setHidden( true );
}
}

emit collapsedStateChanged( this );
@@ -44,8 +44,7 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
void collapsedStateChanged( QWidget* );

public slots:
void checkClicked();
void checkToggled();
void checkToggled( bool ckd );
void toggleCollapsed();

protected:
@@ -438,7 +438,7 @@
<number>20</number>
</property>
<item row="5" column="0">
<widget class="QGroupBox" name="groupBox_2">
<widget class="QgsCollapsibleGroupBox" name="groupBox_2">
<property name="minimumSize">
<size>
<width>0</width>
@@ -586,7 +586,7 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_6">
<widget class="QgsCollapsibleGroupBox" name="groupBox_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
@@ -1058,7 +1058,7 @@
</widget>
</item>
<item row="4" column="0">
<widget class="QGroupBox" name="chkBuffer">
<widget class="QgsCollapsibleGroupBox" name="chkBuffer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
@@ -1296,7 +1296,7 @@
</widget>
</item>
<item row="7" column="0">
<widget class="QGroupBox" name="chkScaleBasedVisibility">
<widget class="QgsCollapsibleGroupBox" name="chkScaleBasedVisibility">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
@@ -1375,7 +1375,7 @@
</spacer>
</item>
<item row="6" column="0">
<widget class="QGroupBox" name="chkFormattedNumbers">
<widget class="QgsCollapsibleGroupBox" name="chkFormattedNumbers">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
@@ -1478,7 +1478,7 @@
<number>6</number>
</property>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox">
<widget class="QgsCollapsibleGroupBox" name="groupBox">
<property name="maximumSize">
<size>
<width>16777215</width>
@@ -1579,7 +1579,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_7">
<widget class="QgsCollapsibleGroupBox" name="groupBox_7">
<property name="maximumSize">
<size>
<width>16777215</width>
@@ -1627,7 +1627,7 @@
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_5">
<widget class="QgsCollapsibleGroupBox" name="groupBox_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
@@ -2281,7 +2281,7 @@
<number>6</number>
</property>
<item row="3" column="0">
<widget class="QGroupBox" name="mBufferAttributesPropertiesGroupBox">
<widget class="QgsCollapsibleGroupBox" name="mBufferAttributesPropertiesGroupBox">
<property name="title">
<string>Buffer properties</string>
</property>
@@ -2327,7 +2327,7 @@
</widget>
</item>
<item row="4" column="0">
<widget class="QGroupBox" name="mPositionAttributeGroupBox">
<widget class="QgsCollapsibleGroupBox" name="mPositionAttributeGroupBox">
<property name="title">
<string>Position</string>
</property>
@@ -2425,7 +2425,7 @@
</spacer>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="mDisplayAttributesPropertiesGroupBox">
<widget class="QgsCollapsibleGroupBox" name="mDisplayAttributesPropertiesGroupBox">
<property name="title">
<string>Display properties</string>
</property>
@@ -2479,7 +2479,7 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="mFontAttributePropertiesGroupBox">
<widget class="QgsCollapsibleGroupBox" name="mFontAttributePropertiesGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -2707,6 +2707,12 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>

0 comments on commit 0ee89e2

Please sign in to comment.
You can’t perform that action at this time.