QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgslogger.h"
20 #include "qgsdialog.h"
21 
22 #include <QSettings>
23 #include <QInputDialog>
24 #include <QMessageBox>
25 #include <QTextEdit>
26 #include <QMouseEvent>
27 #include <QMenu>
28 #include <QCheckBox>
29 
31  : QWidget( parent )
32  , mProvider( provider )
33 {
34  setupUi( this );
35 
36  mSaveOptionsWidget->setProvider( provider );
37  mSaveOptionsWidget->setPyramidsFormat( QgsRaster::PyramidsGTiff );
38  mSaveOptionsWidget->setType( QgsRasterFormatSaveOptionsWidget::ProfileLineEdit );
39 
40  updateUi();
41 }
42 
44 {
45 }
46 
47 
48 void QgsRasterPyramidsOptionsWidget::updateUi()
49 {
50  QSettings mySettings;
51  QString prefix = mProvider + "/driverOptions/_pyramids/";
52  QString tmpStr;
53 
54  // keep it in sync with qgsrasterlayerproperties.cpp
55  tmpStr = mySettings.value( prefix + "format", "external" ).toString();
56  if ( tmpStr == "internal" )
57  cbxPyramidsFormat->setCurrentIndex( INTERNAL );
58  else if ( tmpStr == "external_erdas" )
59  cbxPyramidsFormat->setCurrentIndex( ERDAS );
60  else
61  cbxPyramidsFormat->setCurrentIndex( GTIFF );
62 
63  // initialize resampling methods
64  cboResamplingMethod->clear();
66  Q_FOREACH ( method, QgsRasterDataProvider::pyramidResamplingMethods( mProvider ) )
67  {
68  cboResamplingMethod->addItem( method.second, method.first );
69  }
70  QString defaultMethod = mySettings.value( prefix + "resampling", "AVERAGE" ).toString();
71  int idx = cboResamplingMethod->findData( defaultMethod );
72  cboResamplingMethod->setCurrentIndex( idx );
73 
74  // validate string, only space-separated positive integers are allowed
75  lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() );
76  lePyramidsLevels->setValidator( new QRegExpValidator( QRegExp( "(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) );
77  connect( lePyramidsLevels, SIGNAL( textEdited( const QString & ) ),
78  this, SLOT( setOverviewList() ) );
79 
80  // overview list
81  if ( mOverviewCheckBoxes.isEmpty() )
82  {
84  overviewList << 2 << 4 << 8 << 16 << 32 << 64;
85  mOverviewCheckBoxes.clear();
86  Q_FOREACH ( int i, overviewList )
87  {
88  mOverviewCheckBoxes[ i ] = new QCheckBox( QString::number( i ), this );
89  connect( mOverviewCheckBoxes[ i ], SIGNAL( toggled( bool ) ),
90  this, SLOT( setOverviewList() ) );
91  layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[ i ] );
92  }
93  }
94  else
95  {
96  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
97  mOverviewCheckBoxes[ i ]->setChecked( false );
98  }
99  tmpStr = mySettings.value( prefix + "overviewList", "" ).toString();
100  Q_FOREACH ( const QString& lev, tmpStr.split( ' ', QString::SkipEmptyParts ) )
101  {
102  if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
103  mOverviewCheckBoxes[ lev.toInt()]->setChecked( true );
104  }
105  setOverviewList();
106 
107  mSaveOptionsWidget->updateProfiles();
108 
109  connect( cbxPyramidsFormat, SIGNAL( currentIndexChanged( int ) ),
110  this, SIGNAL( someValueChanged() ) );
111  connect( cboResamplingMethod, SIGNAL( currentIndexChanged( int ) ),
112  this, SIGNAL( someValueChanged() ) );
113  connect( mSaveOptionsWidget, SIGNAL( optionsChanged() ),
114  this, SIGNAL( someValueChanged() ) );
115 }
116 
118 {
119  return cboResamplingMethod->itemData( cboResamplingMethod->currentIndex() ).toString();
120 }
121 
123 {
124  QSettings mySettings;
125  QString prefix = mProvider + "/driverOptions/_pyramids/";
126  QString tmpStr;
127 
128  // mySettings.setValue( prefix + "internal", cbxPyramidsInternal->isChecked() );
129  if ( cbxPyramidsFormat->currentIndex() == INTERNAL )
130  tmpStr = "internal";
131  else if ( cbxPyramidsFormat->currentIndex() == ERDAS )
132  tmpStr = "external_erdas";
133  else
134  tmpStr = "external";
135  mySettings.setValue( prefix + "format", tmpStr );
136  mySettings.setValue( prefix + "resampling", resamplingMethod() );
137  mySettings.setValue( prefix + "overviewStr", lePyramidsLevels->text().trimmed() );
138 
139  // overview list
140  tmpStr = "";
141  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
142  {
143  if ( mOverviewCheckBoxes[ i ]->isChecked() )
144  tmpStr += QString::number( i ) + ' ';
145  }
146  mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() );
147 
148  mSaveOptionsWidget->apply();
149 }
150 
152 {
153  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
154  mOverviewCheckBoxes[ i ]->setChecked( checked );
155 }
156 
157 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsLevelsCustom_toggled( bool toggled )
158 {
159  // if toggled, disable checkboxes and enable line edit
160  lePyramidsLevels->setEnabled( toggled );
161  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
162  mOverviewCheckBoxes[ i ]->setEnabled( ! toggled );
163  setOverviewList();
164 }
165 
166 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsFormat_currentIndexChanged( int index )
167 {
168  mSaveOptionsWidget->setEnabled( index != ERDAS );
170  switch ( index )
171  {
172  case GTIFF:
173  format = QgsRaster::PyramidsGTiff;
174  break;
175  case INTERNAL:
177  break;
178  case ERDAS:
179  format = QgsRaster::PyramidsErdas;
180  break;
181  default:
182  QgsDebugMsg( "Should not happen !" );
183  format = QgsRaster::PyramidsGTiff;
184  break;
185  }
186  mSaveOptionsWidget->setPyramidsFormat( format );
187 }
188 
189 void QgsRasterPyramidsOptionsWidget::setOverviewList()
190 {
191 
192  mOverviewList.clear();
193 
194  // if custom levels is toggled, get selection from line edit
195  if ( cbxPyramidsLevelsCustom->isChecked() )
196  {
197  // should we also validate that numbers are increasing?
198  Q_FOREACH ( const QString& lev, lePyramidsLevels->text().trimmed().split( ' ', QString::SkipEmptyParts ) )
199  {
200  QgsDebugMsg( "lev= " + lev );
201  int tmpInt = lev.toInt();
202  if ( tmpInt > 0 )
203  {
204  QgsDebugMsg( "tmpInt= " + QString::number( tmpInt ) );
205  // if number is valid, add to overview list
206  mOverviewList << tmpInt;
207  }
208  }
209  }
210  else
211  {
212  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
213  {
214  if ( mOverviewCheckBoxes[ i ]->isChecked() )
215  mOverviewList << i;
216  }
217  }
218 
219  emit overviewListChanged();
220 }
void clear()
static unsigned index
void setupUi(QWidget *widget)
bool contains(const Key &key) const
QgsRasterPyramidsOptionsWidget(QWidget *parent=nullptr, const QString &provider="gdal")
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
void clear()
void clear()
QList< Key > keys() const
void setValue(const QString &key, const QVariant &value)
void setEnabled(bool)
QString number(int n, int base)
int toInt(bool *ok, int base) const
QString trimmed() const
static QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
QVariant value(const QString &key, const QVariant &defaultValue) const
bool isEmpty() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
RasterPyramidsFormat
Definition: qgsraster.h:78
QString toString() const