QGIS API Documentation  2.99.0-Master (c558d51)
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 
45 {
46 }
47 
48 
49 void QgsRasterPyramidsOptionsWidget::updateUi()
50 {
51  QSettings mySettings;
52  QString prefix = mProvider + "/driverOptions/_pyramids/";
53  QString tmpStr;
54 
55  // keep it in sync with qgsrasterlayerproperties.cpp
56  tmpStr = mySettings.value( prefix + "format", "external" ).toString();
57  if ( tmpStr == QLatin1String( "internal" ) )
58  cbxPyramidsFormat->setCurrentIndex( INTERNAL );
59  else if ( tmpStr == QLatin1String( "external_erdas" ) )
60  cbxPyramidsFormat->setCurrentIndex( ERDAS );
61  else
62  cbxPyramidsFormat->setCurrentIndex( GTIFF );
63 
64  // initialize resampling methods
65  cboResamplingMethod->clear();
66  QPair<QString, QString> method;
67  Q_FOREACH ( method, QgsRasterDataProvider::pyramidResamplingMethods( mProvider ) )
68  {
69  cboResamplingMethod->addItem( method.second, method.first );
70  }
71  QString defaultMethod = mySettings.value( prefix + "resampling", "AVERAGE" ).toString();
72  int idx = cboResamplingMethod->findData( defaultMethod );
73  cboResamplingMethod->setCurrentIndex( idx );
74 
75  // validate string, only space-separated positive integers are allowed
76  lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() );
77  lePyramidsLevels->setValidator( new QRegExpValidator( QRegExp( "(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) );
78  connect( lePyramidsLevels, SIGNAL( textEdited( const QString & ) ),
79  this, SLOT( setOverviewList() ) );
80 
81  // overview list
82  if ( mOverviewCheckBoxes.isEmpty() )
83  {
84  QList<int> overviewList;
85  overviewList << 2 << 4 << 8 << 16 << 32 << 64;
86  mOverviewCheckBoxes.clear();
87  Q_FOREACH ( int i, overviewList )
88  {
89  mOverviewCheckBoxes[ i ] = new QCheckBox( QString::number( i ), this );
90  connect( mOverviewCheckBoxes[ i ], SIGNAL( toggled( bool ) ),
91  this, SLOT( setOverviewList() ) );
92  layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[ i ] );
93  }
94  }
95  else
96  {
97  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
98  mOverviewCheckBoxes[ i ]->setChecked( false );
99  }
100  tmpStr = mySettings.value( prefix + "overviewList", "" ).toString();
101  Q_FOREACH ( const QString& lev, tmpStr.split( ' ', QString::SkipEmptyParts ) )
102  {
103  if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
104  mOverviewCheckBoxes[ lev.toInt()]->setChecked( true );
105  }
106  setOverviewList();
107 
108  mSaveOptionsWidget->updateProfiles();
109 
110  connect( cbxPyramidsFormat, SIGNAL( currentIndexChanged( int ) ),
111  this, SIGNAL( someValueChanged() ) );
112  connect( cboResamplingMethod, SIGNAL( currentIndexChanged( int ) ),
113  this, SIGNAL( someValueChanged() ) );
114  connect( mSaveOptionsWidget, SIGNAL( optionsChanged() ),
115  this, SIGNAL( someValueChanged() ) );
116 }
117 
119 {
120  return cboResamplingMethod->currentData().toString();
121 }
122 
124 {
125  QSettings mySettings;
126  QString prefix = mProvider + "/driverOptions/_pyramids/";
127  QString tmpStr;
128 
129  // mySettings.setValue( prefix + "internal", cbxPyramidsInternal->isChecked() );
130  if ( cbxPyramidsFormat->currentIndex() == INTERNAL )
131  tmpStr = QStringLiteral( "internal" );
132  else if ( cbxPyramidsFormat->currentIndex() == ERDAS )
133  tmpStr = QStringLiteral( "external_erdas" );
134  else
135  tmpStr = QStringLiteral( "external" );
136  mySettings.setValue( prefix + "format", tmpStr );
137  mySettings.setValue( prefix + "resampling", resamplingMethod() );
138  mySettings.setValue( prefix + "overviewStr", lePyramidsLevels->text().trimmed() );
139 
140  // overview list
141  tmpStr = QLatin1String( "" );
142  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
143  {
144  if ( mOverviewCheckBoxes[ i ]->isChecked() )
145  tmpStr += QString::number( i ) + ' ';
146  }
147  mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() );
148 
149  mSaveOptionsWidget->apply();
150 }
151 
153 {
154  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
155  mOverviewCheckBoxes[ i ]->setChecked( checked );
156 }
157 
158 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsLevelsCustom_toggled( bool toggled )
159 {
160  // if toggled, disable checkboxes and enable line edit
161  lePyramidsLevels->setEnabled( toggled );
162  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
163  mOverviewCheckBoxes[ i ]->setEnabled( ! toggled );
164  setOverviewList();
165 }
166 
167 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsFormat_currentIndexChanged( int index )
168 {
169  mSaveOptionsWidget->setEnabled( index != ERDAS );
171  switch ( index )
172  {
173  case GTIFF:
174  format = QgsRaster::PyramidsGTiff;
175  break;
176  case INTERNAL:
178  break;
179  case ERDAS:
180  format = QgsRaster::PyramidsErdas;
181  break;
182  default:
183  QgsDebugMsg( "Should not happen !" );
184  format = QgsRaster::PyramidsGTiff;
185  break;
186  }
187  mSaveOptionsWidget->setPyramidsFormat( format );
188 }
189 
190 void QgsRasterPyramidsOptionsWidget::setOverviewList()
191 {
192 
193  mOverviewList.clear();
194 
195  // if custom levels is toggled, get selection from line edit
196  if ( cbxPyramidsLevelsCustom->isChecked() )
197  {
198  // should we also validate that numbers are increasing?
199  Q_FOREACH ( const QString& lev, lePyramidsLevels->text().trimmed().split( ' ', QString::SkipEmptyParts ) )
200  {
201  QgsDebugMsg( "lev= " + lev );
202  int tmpInt = lev.toInt();
203  if ( tmpInt > 0 )
204  {
205  QgsDebugMsg( "tmpInt= " + QString::number( tmpInt ) );
206  // if number is valid, add to overview list
207  mOverviewList << tmpInt;
208  }
209  }
210  }
211  else
212  {
213  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
214  {
215  if ( mOverviewCheckBoxes[ i ]->isChecked() )
216  mOverviewList << i;
217  }
218  }
219 
220  emit overviewListChanged();
221 }
static unsigned index
QgsRasterPyramidsOptionsWidget(QWidget *parent=nullptr, const QString &provider="gdal")
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
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:95