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?
3435char ** papszFromStringList ( const QStringList& list )
@@ -43,12 +44,17 @@ char** papszFromStringList( const QStringList& list )
4344
4445QMap< 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
104140void 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()
396457bool 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+
0 commit comments