QGIS API Documentation  2.99.0-Master (a18066b)
qgsrasterpyramidsoptionswidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterpyramidsoptionswidget.cpp
3  -------------------
4  begin : July 2012
5  copyright : (C) 2012 by Etienne Tourigny
6  email : etourigny dot dev at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgsrasterdataprovider.h"
20 #include "qgslogger.h"
21 #include "qgsdialog.h"
22 
23 #include <QSettings>
24 #include <QInputDialog>
25 #include <QMessageBox>
26 #include <QTextEdit>
27 #include <QMouseEvent>
28 #include <QMenu>
29 #include <QCheckBox>
30 
31 QgsRasterPyramidsOptionsWidget::QgsRasterPyramidsOptionsWidget( QWidget* parent, const QString& provider )
32  : QWidget( parent )
33  , mProvider( provider )
34 {
35  setupUi( this );
36 
37  mSaveOptionsWidget->setProvider( provider );
38  mSaveOptionsWidget->setPyramidsFormat( QgsRaster::PyramidsGTiff );
39  mSaveOptionsWidget->setType( QgsRasterFormatSaveOptionsWidget::ProfileLineEdit );
40 
41  updateUi();
42 }
43 
44 void QgsRasterPyramidsOptionsWidget::updateUi()
45 {
46  QSettings mySettings;
47  QString prefix = mProvider + "/driverOptions/_pyramids/";
48  QString tmpStr;
49 
50  // keep it in sync with qgsrasterlayerproperties.cpp
51  tmpStr = mySettings.value( prefix + "format", "external" ).toString();
52  if ( tmpStr == QLatin1String( "internal" ) )
53  cbxPyramidsFormat->setCurrentIndex( INTERNAL );
54  else if ( tmpStr == QLatin1String( "external_erdas" ) )
55  cbxPyramidsFormat->setCurrentIndex( ERDAS );
56  else
57  cbxPyramidsFormat->setCurrentIndex( GTIFF );
58 
59  // initialize resampling methods
60  cboResamplingMethod->clear();
61  QPair<QString, QString> method;
62  Q_FOREACH ( method, QgsRasterDataProvider::pyramidResamplingMethods( mProvider ) )
63  {
64  cboResamplingMethod->addItem( method.second, method.first );
65  }
66  QString defaultMethod = mySettings.value( prefix + "resampling", "AVERAGE" ).toString();
67  int idx = cboResamplingMethod->findData( defaultMethod );
68  cboResamplingMethod->setCurrentIndex( idx );
69 
70  // validate string, only space-separated positive integers are allowed
71  lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() );
72  lePyramidsLevels->setValidator( new QRegExpValidator( QRegExp( "(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) );
73  connect( lePyramidsLevels, SIGNAL( textEdited( const QString & ) ),
74  this, SLOT( setOverviewList() ) );
75 
76  // overview list
77  if ( mOverviewCheckBoxes.isEmpty() )
78  {
79  QList<int> overviewList;
80  overviewList << 2 << 4 << 8 << 16 << 32 << 64;
81  mOverviewCheckBoxes.clear();
82  Q_FOREACH ( int i, overviewList )
83  {
84  mOverviewCheckBoxes[ i ] = new QCheckBox( QString::number( i ), this );
85  connect( mOverviewCheckBoxes[ i ], SIGNAL( toggled( bool ) ),
86  this, SLOT( setOverviewList() ) );
87  layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[ i ] );
88  }
89  }
90  else
91  {
92  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
93  mOverviewCheckBoxes[ i ]->setChecked( false );
94  }
95  tmpStr = mySettings.value( prefix + "overviewList", "" ).toString();
96  Q_FOREACH ( const QString& lev, tmpStr.split( ' ', QString::SkipEmptyParts ) )
97  {
98  if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
99  mOverviewCheckBoxes[ lev.toInt()]->setChecked( true );
100  }
101  setOverviewList();
102 
103  mSaveOptionsWidget->updateProfiles();
104 
105  connect( cbxPyramidsFormat, SIGNAL( currentIndexChanged( int ) ),
106  this, SIGNAL( someValueChanged() ) );
107  connect( cboResamplingMethod, SIGNAL( currentIndexChanged( int ) ),
108  this, SIGNAL( someValueChanged() ) );
109  connect( mSaveOptionsWidget, SIGNAL( optionsChanged() ),
110  this, SIGNAL( someValueChanged() ) );
111 }
112 
114 {
115  return cboResamplingMethod->currentData().toString();
116 }
117 
119 {
120  QSettings mySettings;
121  QString prefix = mProvider + "/driverOptions/_pyramids/";
122  QString tmpStr;
123 
124  // mySettings.setValue( prefix + "internal", cbxPyramidsInternal->isChecked() );
125  if ( cbxPyramidsFormat->currentIndex() == INTERNAL )
126  tmpStr = QStringLiteral( "internal" );
127  else if ( cbxPyramidsFormat->currentIndex() == ERDAS )
128  tmpStr = QStringLiteral( "external_erdas" );
129  else
130  tmpStr = QStringLiteral( "external" );
131  mySettings.setValue( prefix + "format", tmpStr );
132  mySettings.setValue( prefix + "resampling", resamplingMethod() );
133  mySettings.setValue( prefix + "overviewStr", lePyramidsLevels->text().trimmed() );
134 
135  // overview list
136  tmpStr = QLatin1String( "" );
137  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
138  {
139  if ( mOverviewCheckBoxes[ i ]->isChecked() )
140  tmpStr += QString::number( i ) + ' ';
141  }
142  mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() );
143 
144  mSaveOptionsWidget->apply();
145 }
146 
148 {
149  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
150  mOverviewCheckBoxes[ i ]->setChecked( checked );
151 }
152 
153 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsLevelsCustom_toggled( bool toggled )
154 {
155  // if toggled, disable checkboxes and enable line edit
156  lePyramidsLevels->setEnabled( toggled );
157  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
158  mOverviewCheckBoxes[ i ]->setEnabled( ! toggled );
159  setOverviewList();
160 }
161 
162 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsFormat_currentIndexChanged( int index )
163 {
164  mSaveOptionsWidget->setEnabled( index != ERDAS );
166  switch ( index )
167  {
168  case GTIFF:
169  format = QgsRaster::PyramidsGTiff;
170  break;
171  case INTERNAL:
173  break;
174  case ERDAS:
175  format = QgsRaster::PyramidsErdas;
176  break;
177  default:
178  QgsDebugMsg( "Should not happen !" );
179  format = QgsRaster::PyramidsGTiff;
180  break;
181  }
182  mSaveOptionsWidget->setPyramidsFormat( format );
183 }
184 
185 void QgsRasterPyramidsOptionsWidget::setOverviewList()
186 {
187 
188  mOverviewList.clear();
189 
190  // if custom levels is toggled, get selection from line edit
191  if ( cbxPyramidsLevelsCustom->isChecked() )
192  {
193  // should we also validate that numbers are increasing?
194  Q_FOREACH ( const QString& lev, lePyramidsLevels->text().trimmed().split( ' ', QString::SkipEmptyParts ) )
195  {
196  QgsDebugMsg( "lev= " + lev );
197  int tmpInt = lev.toInt();
198  if ( tmpInt > 0 )
199  {
200  QgsDebugMsg( "tmpInt= " + QString::number( tmpInt ) );
201  // if number is valid, add to overview list
202  mOverviewList << tmpInt;
203  }
204  }
205  }
206  else
207  {
208  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
209  {
210  if ( mOverviewCheckBoxes[ i ]->isChecked() )
211  mOverviewList << i;
212  }
213  }
214 
215  emit overviewListChanged();
216 }
static unsigned index
QgsRasterPyramidsOptionsWidget(QWidget *parent=nullptr, const QString &provider="gdal")
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
static QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
RasterPyramidsFormat
Definition: qgsraster.h:96