Skip to content

Commit 523b56f

Browse files
committedAug 23, 2012
implement collapsible groupbox items - needs feedback before implementing as a widget in qgis_gui
1 parent 5579962 commit 523b56f

File tree

3 files changed

+344
-94
lines changed

3 files changed

+344
-94
lines changed
 

‎src/gui/qgsrasterlayersaveasdialog.cpp

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,109 @@
99
#include <QFileDialog>
1010
#include <QSettings>
1111

12+
13+
// this widget class will go into its separate file
14+
15+
// #include <QMouseEvent>
16+
// #include <QStyleOptionGroupBox>
17+
// #include <QStylePainter>
18+
19+
GroupBox::GroupBox( QWidget *parent )
20+
: QGroupBox( parent ), m_collapsed( false )
21+
{
22+
connect( this, SIGNAL( toggled ( bool ) ), this, SLOT( setToggled( bool ) ) );
23+
//setToggled( isChecked() );
24+
}
25+
26+
GroupBox::GroupBox( const QString &title, QWidget *parent )
27+
: QGroupBox(title, parent ), m_collapsed( false )
28+
{}
29+
30+
bool GroupBox::isCollapsed() { return m_collapsed; }
31+
32+
// void GroupBox::mousePressEvent( QMouseEvent *e )
33+
// {
34+
// QgsDebugMsg("press event");
35+
// if( e->button() == Qt::LeftButton )
36+
// {
37+
// QgsDebugMsg("left but");
38+
// QStyleOptionGroupBox option;
39+
// initStyleOption( &option );
40+
// QRect buttonArea( 0, 0, 16, 16 );
41+
// buttonArea.moveTopRight( option.rect.adjusted( 0, 0, -10, 0
42+
// ).topRight() );
43+
// if( buttonArea.contains( e->pos() ) )
44+
// {
45+
// clickPos = e->pos();
46+
// return;
47+
// }
48+
// }
49+
// QGroupBox::mousePressEvent( e );
50+
// }
51+
52+
// void GroupBox::mouseReleaseEvent( QMouseEvent *e )
53+
// {
54+
// QgsDebugMsg("release");
55+
// if( e->button() == Qt::LeftButton && clickPos == e->pos() )
56+
// setCollapse( !isCollapsed() );
57+
// }
58+
59+
// void GroupBox::paintEvent( QPaintEvent * )
60+
// {
61+
// QgsDebugMsg("paint event");
62+
63+
// QStylePainter paint( this );
64+
// QStyleOptionGroupBox option;
65+
// initStyleOption( &option );
66+
// paint.drawComplexControl( QStyle::CC_GroupBox, option );
67+
// paint.drawItemPixmap(
68+
// option.rect.adjusted( 0, 0, -10, 0 ),
69+
// Qt::AlignTop | Qt::AlignRight,
70+
// QPixmap( m_collapsed ?
71+
// ":/images/images/navigate_down2_16x16.png" :
72+
// ":/images/images/navigate_up2_16x16.png" ) );
73+
// }
74+
75+
void GroupBox::showEvent( QShowEvent * event )
76+
{
77+
// QgsDebugMsg(QString("%1 showEvent %2 %3").arg(objectName()).arg(isChecked()).arg(isCollapsed()));
78+
QGroupBox::showEvent( event );
79+
if ( ! isChecked() && ! isCollapsed() )
80+
setCollapsed( true );
81+
}
82+
83+
void GroupBox::setCollapsed( bool collapse )
84+
{
85+
if ( ! isVisible() )
86+
return;
87+
// QgsDebugMsg(QString("%1 setcollapse %2").arg(objectName()).arg(collapse));
88+
89+
// minimize layout margins, restore later
90+
if ( collapse )
91+
{
92+
if ( layout() )
93+
{
94+
margins = layout()->contentsMargins();
95+
layout()->setContentsMargins(1,1,1,1);
96+
}
97+
}
98+
else
99+
{
100+
if ( layout() )
101+
{
102+
layout()->setContentsMargins( margins );
103+
}
104+
}
105+
m_collapsed = collapse;
106+
foreach( QWidget *widget, findChildren<QWidget*>() )
107+
widget->setHidden( collapse );
108+
109+
if ( m_collapsed )
110+
emit collapsed( this );
111+
else
112+
emit expanded( this );
113+
}
114+
12115
QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent,
13116
const QgsCoordinateReferenceSystem& layerCrs,
14117
const QgsCoordinateReferenceSystem& currentCrs,
@@ -26,7 +129,7 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
26129
mLoadTransparentNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionCopySelected.png" ) );
27130
mRemoveSelectedNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) );
28131
mRemoveAllNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionRemove.png" ) );
29-
mNoDataGroupBox->setEnabled( false ); // not yet implemented
132+
// mNoDataGroupBox->setEnabled( false ); // not yet implemented
30133

31134
setValidators();
32135
// Translated labels + EPSG are updated later
@@ -81,6 +184,12 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
81184
{
82185
okButton->setEnabled( false );
83186
}
187+
188+
// this should scroll down to make widget visible, but it's not happening
189+
// (at least part of it is visible)...
190+
connect( mCreateOptionsGroupBox, SIGNAL( expanded( QWidget* ) ),
191+
this, SLOT( groupBoxExpanded( QWidget* ) ) );
192+
84193
}
85194

86195
void QgsRasterLayerSaveAsDialog::setValidators()

‎src/gui/qgsrasterlayersaveasdialog.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
7979

8080
void on_mCrsComboBox_currentIndexChanged( int ) { crsChanged(); }
8181

82+
void groupBoxExpanded( QWidget * widget ) { mScrollArea->ensureWidgetVisible( widget ); }
83+
8284
private:
8385
QgsRasterDataProvider* mDataProvider;
8486
QgsRectangle mCurrentExtent;
@@ -105,4 +107,44 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
105107
void updateCrsGroup();
106108
};
107109

110+
108111
#endif // QGSRASTERLAYERSAVEASDIALOG_H
112+
113+
114+
// this widget class will go into its separate file
115+
#ifndef GROUPBOX_H
116+
#define GROUPBOX_H
117+
118+
#include <QGroupBox>
119+
120+
class GroupBox : public QGroupBox
121+
{
122+
Q_OBJECT
123+
124+
public:
125+
GroupBox( QWidget *parent = 0 );
126+
GroupBox( const QString &title, QWidget *parent = 0 );
127+
128+
bool isCollapsed();
129+
130+
signals:
131+
void collapsed( QWidget* );
132+
void expanded( QWidget* );
133+
134+
public slots:
135+
void setToggled( bool toggled ) { setCollapsed( ! toggled ); }
136+
void setCollapsed( bool collapsed );
137+
138+
protected:
139+
/* void mousePressEvent( QMouseEvent *e ); */
140+
/* void mouseReleaseEvent( QMouseEvent *e ); */
141+
/* void paintEvent( QPaintEvent * ); */
142+
void showEvent( QShowEvent * event );
143+
144+
private:
145+
QPoint clickPos;
146+
bool m_collapsed;
147+
QMargins margins;
148+
};
149+
150+
#endif

‎src/ui/qgsrasterlayersaveasdialogbase.ui

Lines changed: 192 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>518</width>
9+
<width>550</width>
1010
<height>580</height>
1111
</rect>
1212
</property>
@@ -15,7 +15,7 @@
1515
</property>
1616
<layout class="QVBoxLayout" name="verticalLayout">
1717
<item>
18-
<widget class="QScrollArea" name="scrollArea">
18+
<widget class="QScrollArea" name="mScrollArea">
1919
<property name="frameShape">
2020
<enum>QFrame::NoFrame</enum>
2121
</property>
@@ -29,9 +29,9 @@
2929
<property name="geometry">
3030
<rect>
3131
<x>0</x>
32-
<y>-118</y>
33-
<width>492</width>
34-
<height>661</height>
32+
<y>0</y>
33+
<width>514</width>
34+
<height>686</height>
3535
</rect>
3636
</property>
3737
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -167,7 +167,7 @@
167167
<item>
168168
<widget class="QComboBox" name="mCrsComboBox">
169169
<property name="sizePolicy">
170-
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
170+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
171171
<horstretch>0</horstretch>
172172
<verstretch>0</verstretch>
173173
</sizepolicy>
@@ -190,10 +190,13 @@
190190
</layout>
191191
</item>
192192
<item>
193-
<widget class="QGroupBox" name="mExtentGroupBox">
193+
<widget class="GroupBox" name="mExtentGroupBox">
194194
<property name="title">
195195
<string>Extent</string>
196196
</property>
197+
<property name="checkable">
198+
<bool>true</bool>
199+
</property>
197200
<layout class="QVBoxLayout" name="verticalLayout_2">
198201
<item>
199202
<layout class="QGridLayout" name="gridLayout_4">
@@ -256,44 +259,90 @@
256259
</layout>
257260
</item>
258261
<item>
259-
<layout class="QHBoxLayout" name="horizontalLayout_2">
260-
<item>
261-
<spacer name="horizontalSpacer_3">
262-
<property name="orientation">
263-
<enum>Qt::Horizontal</enum>
264-
</property>
265-
<property name="sizeHint" stdset="0">
266-
<size>
267-
<width>40</width>
268-
<height>20</height>
269-
</size>
270-
</property>
271-
</spacer>
272-
</item>
273-
<item>
274-
<widget class="QPushButton" name="mCurrentExtentButton">
275-
<property name="text">
276-
<string>Map view extent</string>
277-
</property>
278-
</widget>
279-
</item>
280-
<item>
281-
<widget class="QPushButton" name="mOriginalExtentButton">
282-
<property name="text">
283-
<string>Layer extent</string>
284-
</property>
285-
</widget>
286-
</item>
287-
</layout>
262+
<widget class="QWidget" name="widget_2" native="true">
263+
<layout class="QHBoxLayout" name="horizontalLayout_8">
264+
<item>
265+
<spacer name="horizontalSpacer_3">
266+
<property name="orientation">
267+
<enum>Qt::Horizontal</enum>
268+
</property>
269+
<property name="sizeHint" stdset="0">
270+
<size>
271+
<width>40</width>
272+
<height>20</height>
273+
</size>
274+
</property>
275+
</spacer>
276+
</item>
277+
<item>
278+
<widget class="QPushButton" name="mOriginalExtentButton">
279+
<property name="minimumSize">
280+
<size>
281+
<width>140</width>
282+
<height>0</height>
283+
</size>
284+
</property>
285+
<property name="text">
286+
<string>Layer extent</string>
287+
</property>
288+
</widget>
289+
</item>
290+
<item>
291+
<spacer name="horizontalSpacer_4">
292+
<property name="orientation">
293+
<enum>Qt::Horizontal</enum>
294+
</property>
295+
<property name="sizeType">
296+
<enum>QSizePolicy::Fixed</enum>
297+
</property>
298+
<property name="sizeHint" stdset="0">
299+
<size>
300+
<width>20</width>
301+
<height>20</height>
302+
</size>
303+
</property>
304+
</spacer>
305+
</item>
306+
<item>
307+
<widget class="QPushButton" name="mCurrentExtentButton">
308+
<property name="minimumSize">
309+
<size>
310+
<width>140</width>
311+
<height>0</height>
312+
</size>
313+
</property>
314+
<property name="text">
315+
<string>Map view extent</string>
316+
</property>
317+
</widget>
318+
</item>
319+
<item>
320+
<spacer name="horizontalSpacer_2">
321+
<property name="orientation">
322+
<enum>Qt::Horizontal</enum>
323+
</property>
324+
<property name="sizeHint" stdset="0">
325+
<size>
326+
<width>40</width>
327+
<height>20</height>
328+
</size>
329+
</property>
330+
</spacer>
331+
</item>
332+
</layout>
333+
</widget>
288334
</item>
289335
</layout>
290336
</widget>
291337
</item>
292338
<item>
293-
<widget class="QGroupBox" name="mResolutionGroupBox">
339+
<widget class="GroupBox" name="mResolutionGroupBox">
294340
<property name="title">
295341
<string>Resolution</string>
296342
</property>
343+
<property name="checkable">
344+
<bool>true</bool>
345+
</property>
297346
<layout class="QVBoxLayout" name="verticalLayout_3">
298347
<item>
299348
<layout class="QGridLayout" name="gridLayout_2">
@@ -363,23 +412,36 @@
363412
</widget>
364413
</item>
365414
<item>
366-
<widget class="QGroupBox" name="mNoDataGroupBox">
415+
<widget class="GroupBox" name="mNoDataGroupBox">
367416
<property name="enabled">
368-
<bool>false</bool>
417+
<bool>true</bool>
369418
</property>
370419
<property name="toolTip">
371420
<string>Additional no data values. The specified values will be set to no data in output raster.</string>
372421
</property>
373422
<property name="title">
374423
<string>No data values (not yet implemented)</string>
375424
</property>
425+
<property name="checkable">
426+
<bool>true</bool>
427+
</property>
428+
<property name="checked">
429+
<bool>false</bool>
430+
</property>
376431
<layout class="QHBoxLayout" name="horizontalLayout_7">
377432
<item>
378-
<widget class="QTableWidget" name="mNoDataTableWidget"/>
433+
<widget class="QTableWidget" name="mNoDataTableWidget">
434+
<property name="sizePolicy">
435+
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
436+
<horstretch>0</horstretch>
437+
<verstretch>0</verstretch>
438+
</sizepolicy>
439+
</property>
440+
</widget>
379441
</item>
380442
<item>
381-
<layout class="QVBoxLayout" name="verticalLayout_4">
382-
<item>
443+
<layout class="QGridLayout" name="gridLayout">
444+
<item row="1" column="0">
383445
<widget class="QToolButton" name="mAddNoDataManuallyToolButton">
384446
<property name="toolTip">
385447
<string>Add values manually</string>
@@ -393,7 +455,7 @@
393455
</property>
394456
</widget>
395457
</item>
396-
<item>
458+
<item row="2" column="0">
397459
<widget class="QToolButton" name="mLoadTransparentNoDataToolButton">
398460
<property name="toolTip">
399461
<string>Load user defined fully transparent (100%) values </string>
@@ -407,7 +469,7 @@
407469
</property>
408470
</widget>
409471
</item>
410-
<item>
472+
<item row="1" column="1">
411473
<widget class="QToolButton" name="mRemoveSelectedNoDataToolButton">
412474
<property name="toolTip">
413475
<string>Remove selected row</string>
@@ -421,7 +483,7 @@
421483
</property>
422484
</widget>
423485
</item>
424-
<item>
486+
<item row="2" column="1">
425487
<widget class="QToolButton" name="mRemoveAllNoDataToolButton">
426488
<property name="toolTip">
427489
<string>Clear all</string>
@@ -441,70 +503,101 @@
441503
</widget>
442504
</item>
443505
<item>
444-
<widget class="QGroupBox" name="groupBox">
506+
<widget class="GroupBox" name="mCreateOptionsGroupBox">
445507
<property name="title">
446508
<string>Create Options</string>
447509
</property>
510+
<property name="checkable">
511+
<bool>true</bool>
512+
</property>
513+
<property name="checked">
514+
<bool>false</bool>
515+
</property>
448516
<layout class="QGridLayout" name="gridLayout_5">
449517
<property name="margin">
450518
<number>0</number>
451519
</property>
452520
<item row="0" column="0">
453521
<widget class="QgsRasterFormatSaveOptionsWidget" name="mOptionsWidget" native="true"/>
454522
</item>
455-
<item row="1" column="0">
456-
<widget class="QGroupBox" name="mTilesGroupBox">
457-
<property name="title">
458-
<string>Tiles</string>
523+
</layout>
524+
</widget>
525+
</item>
526+
<item>
527+
<widget class="GroupBox" name="mTilesGroupBox">
528+
<property name="title">
529+
<string>Tiles</string>
530+
</property>
531+
<property name="checkable">
532+
<bool>true</bool>
533+
</property>
534+
<property name="checked">
535+
<bool>false</bool>
536+
</property>
537+
<layout class="QHBoxLayout" name="horizontalLayout_5">
538+
<property name="spacing">
539+
<number>6</number>
540+
</property>
541+
<property name="margin">
542+
<number>9</number>
543+
</property>
544+
<item>
545+
<widget class="QLabel" name="mMaximumSizeXLabel">
546+
<property name="toolTip">
547+
<string>Maximum number of columns in one tile.</string>
548+
</property>
549+
<property name="text">
550+
<string>Max columns</string>
551+
</property>
552+
</widget>
553+
</item>
554+
<item>
555+
<widget class="QLineEdit" name="mMaximumSizeXLineEdit">
556+
<property name="toolTip">
557+
<string>Maximum number of columns in one tile.</string>
558+
</property>
559+
</widget>
560+
</item>
561+
<item>
562+
<widget class="QLabel" name="mMaximumSizeYLabel">
563+
<property name="toolTip">
564+
<string>Maximum number of rows in one tile.</string>
565+
</property>
566+
<property name="text">
567+
<string>Max rows</string>
568+
</property>
569+
</widget>
570+
</item>
571+
<item>
572+
<widget class="QLineEdit" name="mMaximumSizeYLineEdit">
573+
<property name="toolTip">
574+
<string>Maximum number of rows in one tile.</string>
575+
</property>
576+
</widget>
577+
</item>
578+
<item>
579+
<widget class="QCheckBox" name="mTileModeCheckBox">
580+
<property name="text">
581+
<string>Create VRT</string>
459582
</property>
460-
<layout class="QHBoxLayout" name="horizontalLayout_5">
461-
<item>
462-
<widget class="QLabel" name="mMaximumSizeXLabel">
463-
<property name="toolTip">
464-
<string>Maximum number of columns in one tile.</string>
465-
</property>
466-
<property name="text">
467-
<string>Max columns</string>
468-
</property>
469-
</widget>
470-
</item>
471-
<item>
472-
<widget class="QLineEdit" name="mMaximumSizeXLineEdit">
473-
<property name="toolTip">
474-
<string>Maximum number of columns in one tile.</string>
475-
</property>
476-
</widget>
477-
</item>
478-
<item>
479-
<widget class="QLabel" name="mMaximumSizeYLabel">
480-
<property name="toolTip">
481-
<string>Maximum number of rows in one tile.</string>
482-
</property>
483-
<property name="text">
484-
<string>Max rows</string>
485-
</property>
486-
</widget>
487-
</item>
488-
<item>
489-
<widget class="QLineEdit" name="mMaximumSizeYLineEdit">
490-
<property name="toolTip">
491-
<string>Maximum number of rows in one tile.</string>
492-
</property>
493-
</widget>
494-
</item>
495-
<item>
496-
<widget class="QCheckBox" name="mTileModeCheckBox">
497-
<property name="text">
498-
<string>Create VRT</string>
499-
</property>
500-
</widget>
501-
</item>
502-
</layout>
503583
</widget>
504584
</item>
505585
</layout>
506586
</widget>
507587
</item>
588+
<item>
589+
<spacer name="verticalSpacer">
590+
<property name="orientation">
591+
<enum>Qt::Vertical</enum>
592+
</property>
593+
<property name="sizeHint" stdset="0">
594+
<size>
595+
<width>20</width>
596+
<height>40</height>
597+
</size>
598+
</property>
599+
</spacer>
600+
</item>
508601
</layout>
509602
</widget>
510603
</widget>
@@ -528,6 +621,12 @@
528621
<header>qgsrasterformatsaveoptionswidget.h</header>
529622
<container>1</container>
530623
</customwidget>
624+
<customwidget>
625+
<class>GroupBox</class>
626+
<extends>QGroupBox</extends>
627+
<header>qgsrasterlayersaveasdialog.h</header>
628+
<container>1</container>
629+
</customwidget>
531630
</customwidgets>
532631
<resources/>
533632
<connections>

0 commit comments

Comments
 (0)
Please sign in to comment.