Skip to content

Commit ce61402

Browse files
committed
ui tweaks to make dialog more compact, add right-click action to swap options ui
1 parent e3855de commit ce61402

File tree

6 files changed

+154
-82
lines changed

6 files changed

+154
-82
lines changed

python/gui/qgsrasterformatsaveoptionswidget.sip

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ class QgsRasterFormatSaveOptionsWidget : QWidget
66
%End
77

88
public:
9-
QgsRasterFormatSaveOptionsWidget( QWidget* parent = 0, QString format = "GTiff", QString provider = "gdal" );
9+
10+
enum Type
11+
{
12+
Default, // everything except profile buttons (save as dlg)
13+
Full, // everything (options dlg)
14+
Table, // just table
15+
LineEdit // just the line edit
16+
};
17+
18+
QgsRasterFormatSaveOptionsWidget( QWidget* parent = 0, QString format = "GTiff",
19+
QgsRasterFormatSaveOptionsWidget::Type type = Default,
20+
QString provider = "gdal" );
1021
~QgsRasterFormatSaveOptionsWidget();
1122

1223
void setFormat( QString format );
1324
void setProvider( QString provider );
1425
QStringList options() const;
15-
void showProfileButtons( bool show = true );
26+
void setType( QgsRasterFormatSaveOptionsWidget::Type type = Default );
1627

1728
public slots:
1829

@@ -32,6 +43,7 @@ class QgsRasterFormatSaveOptionsWidget : QWidget
3243
void optionsTableChanged();
3344
void optionsTableEnableDeleteButton();
3445
void updateOptions();
46+
void swapOptionsUI( int newIndex = -1 );
3547

3648
private:
3749

python/plugins/GdalTools/tools/doMerge.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def __init__(self, iface):
2020
self.inSelector.setType( self.inSelector.FILE )
2121
self.outSelector.setType( self.outSelector.FILE )
2222
self.recurseCheck.hide()
23+
# use this for approx. previous UI
24+
#self.creationOptionsTable.setType(QgsRasterFormatSaveOptionsWidget.Table)
2325

2426
self.outputFormat = Utils.fillRasterOutputFormat()
2527
self.extent = None

src/app/qgsoptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,9 @@ void QgsOptions::editGdalDriver( const QString& driverName )
11041104
label->setAlignment( Qt::AlignHCenter );
11051105
layout->addWidget( label );
11061106
QgsRasterFormatSaveOptionsWidget* optionsWidget =
1107-
new QgsRasterFormatSaveOptionsWidget( &dlg, driverName, "gdal" );
1107+
new QgsRasterFormatSaveOptionsWidget( &dlg, driverName,
1108+
QgsRasterFormatSaveOptionsWidget::Full, "gdal" );
11081109
layout->addWidget( optionsWidget );
1109-
optionsWidget->showProfileButtons( true );
11101110

11111111
if ( dlg.exec() == QDialog::Accepted )
11121112
{

src/gui/qgsrasterformatsaveoptionswidget.cpp

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QMessageBox>
3030
#include <QTextEdit>
3131
#include <QMouseEvent>
32+
#include <QMenu>
3233

3334
// todo put this somewhere else - how can we access gdal provider?
3435
char** papszFromStringList( const QStringList& list )
@@ -43,12 +44,17 @@ char** papszFromStringList( const QStringList& list )
4344

4445
QMap< QString, QStringList > QgsRasterFormatSaveOptionsWidget::mBuiltinProfiles;
4546

46-
QgsRasterFormatSaveOptionsWidget::QgsRasterFormatSaveOptionsWidget( QWidget* parent, QString format, QString provider )
47+
QgsRasterFormatSaveOptionsWidget::QgsRasterFormatSaveOptionsWidget( QWidget* parent, QString format,
48+
QgsRasterFormatSaveOptionsWidget::Type type,
49+
QString provider )
4750
: QWidget( parent ), mFormat( format ), mProvider( provider )
4851

4952
{
5053
setupUi( this );
5154

55+
56+
setType( type );
57+
5258
if ( mBuiltinProfiles.isEmpty() )
5359
{
5460
// key=profileKey values=format,profileName,options
@@ -66,16 +72,16 @@ QgsRasterFormatSaveOptionsWidget::QgsRasterFormatSaveOptionsWidget( QWidget* par
6672
<< "COMPRESS=JPEG" );
6773
}
6874

69-
showProfileButtons( false );
70-
7175
connect( mProfileComboBox, SIGNAL( currentIndexChanged( const QString & ) ),
7276
this, SLOT( updateOptions() ) );
7377
connect( mOptionsTable, SIGNAL( cellChanged( int, int ) ), this, SLOT( optionsTableChanged() ) );
7478
connect( mOptionsHelpButton, SIGNAL( clicked() ), this, SLOT( helpOptions() ) );
7579
connect( mOptionsValidateButton, SIGNAL( clicked() ), this, SLOT( validateOptions() ) );
7680

77-
// map options label left mouse click to optionsToggle()
78-
mOptionsLabel->installEventFilter( this );
81+
// create eventFilter to map right click to swapOptionsUI()
82+
// mOptionsLabel->installEventFilter( this );
83+
mOptionsLineEdit->installEventFilter( this );
84+
mOptionsStackedWidget->installEventFilter( this );
7985

8086
updateProfiles();
8187
}
@@ -95,10 +101,40 @@ void QgsRasterFormatSaveOptionsWidget::setProvider( QString provider )
95101
mProvider = provider;
96102
}
97103

98-
99-
void QgsRasterFormatSaveOptionsWidget::showProfileButtons( bool show )
104+
// show/hide widgets - we need this function if widget is used in creator
105+
void QgsRasterFormatSaveOptionsWidget::setType( QgsRasterFormatSaveOptionsWidget::Type type )
100106
{
101-
mProfileButtons->setVisible( show );
107+
QList< QWidget* > widgets = this->findChildren<QWidget *>();
108+
if (( type == Table ) || ( type == LineEdit ) )
109+
{
110+
// hide all controls, except stacked widget
111+
foreach( QWidget* widget, widgets )
112+
{
113+
widget->setVisible( false );
114+
}
115+
mOptionsStackedWidget->setVisible( true );
116+
foreach( QWidget* widget, mOptionsStackedWidget->findChildren<QWidget *>() )
117+
{
118+
widget->setVisible( true );
119+
}
120+
// show page relevant page
121+
if ( type == Table )
122+
swapOptionsUI( 0 );
123+
else if ( type == LineEdit )
124+
swapOptionsUI( 1 );
125+
}
126+
else
127+
{
128+
// show all widgets, except profile buttons (unless Full)
129+
foreach( QWidget* widget, widgets )
130+
{
131+
widget->setVisible( true );
132+
}
133+
if ( type != Full )
134+
{
135+
mProfileButtons->setVisible( false );
136+
}
137+
}
102138
}
103139

104140
void QgsRasterFormatSaveOptionsWidget::updateProfiles()
@@ -152,7 +188,7 @@ void QgsRasterFormatSaveOptionsWidget::updateOptions()
152188
QString myOptions = mOptionsMap.value( currentProfileKey() );
153189
QStringList myOptionsList = myOptions.trimmed().split( " ", QString::SkipEmptyParts );
154190

155-
if ( mOptionsStackedWIdget->currentIndex() == 0 )
191+
if ( mOptionsStackedWidget->currentIndex() == 0 )
156192
{
157193
mOptionsTable->setRowCount( 0 );
158194
for ( int i = 0; i < myOptionsList.count(); i++ )
@@ -392,19 +428,61 @@ QStringList QgsRasterFormatSaveOptionsWidget::profiles() const
392428
return mySettings.value( mProvider + "/driverOptions/" + mFormat.toLower() + "/profiles", "" ).toString().trimmed().split( " ", QString::SkipEmptyParts );
393429
}
394430

431+
void QgsRasterFormatSaveOptionsWidget::swapOptionsUI( int newIndex )
432+
{
433+
// set new page
434+
int oldIndex;
435+
if ( newIndex == -1 )
436+
{
437+
oldIndex = mOptionsStackedWidget->currentIndex();
438+
newIndex = ( oldIndex + 1 ) % 2;
439+
}
440+
else
441+
{
442+
oldIndex = ( newIndex + 1 ) % 2;
443+
}
444+
445+
// resize pages to minimum - this works well with gdaltools merge ui, but not raster save as...
446+
mOptionsStackedWidget->setCurrentIndex( newIndex );
447+
mOptionsStackedWidget->widget( newIndex )->setSizePolicy(
448+
QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
449+
mOptionsStackedWidget->widget( oldIndex )->setSizePolicy(
450+
QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ) );
451+
layout()->activate();
452+
453+
updateOptions();
454+
}
455+
395456
// map options label left mouse click to optionsToggle()
396457
bool QgsRasterFormatSaveOptionsWidget::eventFilter( QObject *obj, QEvent *event )
397458
{
398459
if ( event->type() == QEvent::MouseButtonPress )
399460
{
400461
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>( event );
401-
if ( mouseEvent && ( mouseEvent->button() == Qt::LeftButton ) )
462+
if ( mouseEvent && ( mouseEvent->button() == Qt::RightButton ) )
402463
{
403-
mOptionsStackedWIdget->setCurrentIndex(( mOptionsStackedWIdget->currentIndex() + 1 ) % 2 );
404-
updateOptions();
464+
QMenu* menu = 0;
465+
QString text;
466+
if ( mOptionsStackedWidget->currentIndex() == 0 )
467+
text = tr( "Use simple interface" );
468+
else
469+
text = tr( "Use table interface" );
470+
if ( obj->objectName() == "mOptionsLineEdit" )
471+
{
472+
menu = mOptionsLineEdit->createStandardContextMenu();
473+
menu->addSeparator();
474+
}
475+
else
476+
menu = new QMenu( this );
477+
QAction* action = new QAction( text, menu );
478+
menu->addAction( action );
479+
connect( action, SIGNAL( triggered() ), this, SLOT( swapOptionsUI() ) );
480+
menu->exec( mouseEvent->globalPos() );
481+
delete menu;
405482
return true;
406483
}
407484
}
408485
// standard event processing
409486
return QObject::eventFilter( obj, event );
410487
}
488+

src/gui/qgsrasterformatsaveoptionswidget.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,30 @@
2323
/** \ingroup gui
2424
* A widget to select format-specific raster saving options
2525
*/
26-
class GUI_EXPORT QgsRasterFormatSaveOptionsWidget: public QWidget, private Ui::QgsRasterFormatSaveOptionsWidgetBase
26+
class GUI_EXPORT QgsRasterFormatSaveOptionsWidget: public QWidget,
27+
private Ui::QgsRasterFormatSaveOptionsWidgetBase
2728
{
2829
Q_OBJECT
2930

3031
public:
3132

32-
QgsRasterFormatSaveOptionsWidget( QWidget* parent = 0, QString format = "GTiff", QString provider = "gdal" );
33+
enum Type
34+
{
35+
Default, // everything except profile buttons (save as dlg)
36+
Full, // everything (options dlg)
37+
Table, // just table
38+
LineEdit // just the line edit
39+
};
40+
41+
QgsRasterFormatSaveOptionsWidget( QWidget* parent = 0, QString format = "GTiff",
42+
QgsRasterFormatSaveOptionsWidget::Type type = Default,
43+
QString provider = "gdal" );
3344
~QgsRasterFormatSaveOptionsWidget();
3445

3546
void setFormat( QString format );
3647
void setProvider( QString provider );
3748
QStringList options() const;
38-
void showProfileButtons( bool show = true );
49+
void setType( QgsRasterFormatSaveOptionsWidget::Type type = Default );
3950

4051
public slots:
4152

@@ -54,6 +65,7 @@ class GUI_EXPORT QgsRasterFormatSaveOptionsWidget: public QWidget, private Ui::Q
5465
void optionsTableChanged();
5566
void optionsTableEnableDeleteButton();
5667
void updateOptions();
68+
void swapOptionsUI( int newIndex = -1 );
5769

5870
private:
5971

src/ui/qgsrasterformatsaveoptionswidgetbase.ui

Lines changed: 31 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,17 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>389</width>
9+
<width>341</width>
1010
<height>203</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
17-
<item row="1" column="0">
18-
<spacer name="verticalSpacer_2">
19-
<property name="orientation">
20-
<enum>Qt::Vertical</enum>
21-
</property>
22-
<property name="sizeType">
23-
<enum>QSizePolicy::Fixed</enum>
24-
</property>
25-
<property name="sizeHint" stdset="0">
26-
<size>
27-
<width>20</width>
28-
<height>5</height>
29-
</size>
30-
</property>
31-
</spacer>
32-
</item>
33-
<item row="2" column="0">
34-
<widget class="QLabel" name="mOptionsLabel">
35-
<property name="text">
36-
<string>Options</string>
37-
</property>
38-
</widget>
39-
</item>
40-
<item row="0" column="2">
17+
<item row="0" column="1">
4118
<layout class="QGridLayout" name="gridLayout_3">
42-
<item row="0" column="0">
43-
<widget class="QComboBox" name="mProfileComboBox">
44-
<property name="sizePolicy">
45-
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
46-
<horstretch>0</horstretch>
47-
<verstretch>0</verstretch>
48-
</sizepolicy>
49-
</property>
50-
<property name="minimumSize">
51-
<size>
52-
<width>150</width>
53-
<height>0</height>
54-
</size>
55-
</property>
56-
</widget>
57-
</item>
58-
<item row="1" column="0">
19+
<item row="1" column="1">
5920
<widget class="QWidget" name="mProfileButtons" native="true">
6021
<layout class="QHBoxLayout" name="mProfileButtonsLayout">
6122
<property name="margin">
@@ -85,10 +46,33 @@
8546
</layout>
8647
</widget>
8748
</item>
49+
<item row="0" column="1">
50+
<widget class="QComboBox" name="mProfileComboBox">
51+
<property name="sizePolicy">
52+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
53+
<horstretch>0</horstretch>
54+
<verstretch>0</verstretch>
55+
</sizepolicy>
56+
</property>
57+
<property name="minimumSize">
58+
<size>
59+
<width>150</width>
60+
<height>0</height>
61+
</size>
62+
</property>
63+
</widget>
64+
</item>
65+
<item row="0" column="0">
66+
<widget class="QLabel" name="mProfileLabel">
67+
<property name="text">
68+
<string>Profile</string>
69+
</property>
70+
</widget>
71+
</item>
8872
</layout>
8973
</item>
90-
<item row="2" column="2">
91-
<widget class="QStackedWidget" name="mOptionsStackedWIdget">
74+
<item row="2" column="1">
75+
<widget class="QStackedWidget" name="mOptionsStackedWidget">
9276
<property name="currentIndex">
9377
<number>0</number>
9478
</property>
@@ -207,28 +191,12 @@
207191
</widget>
208192
</widget>
209193
</item>
210-
<item row="0" column="0">
211-
<widget class="QLabel" name="mProfileLabel">
212-
<property name="text">
213-
<string>Profile</string>
214-
</property>
215-
</widget>
216-
</item>
217-
<item row="0" column="1">
218-
<spacer name="horizontalSpacer">
194+
<item row="1" column="1">
195+
<widget class="Line" name="mSeparator">
219196
<property name="orientation">
220197
<enum>Qt::Horizontal</enum>
221198
</property>
222-
<property name="sizeType">
223-
<enum>QSizePolicy::Fixed</enum>
224-
</property>
225-
<property name="sizeHint" stdset="0">
226-
<size>
227-
<width>5</width>
228-
<height>20</height>
229-
</size>
230-
</property>
231-
</spacer>
199+
</widget>
232200
</item>
233201
</layout>
234202
</widget>

0 commit comments

Comments
 (0)