QGIS API Documentation  2.15.0-Master (13f053b)
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 
30 
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  // cbxPyramidsInternal->setChecked( mySettings.value( prefix + "internal", false ).toBool() );
56  tmpStr = mySettings.value( prefix + "format", "gtiff" ).toString();
57  if ( tmpStr == "internal" )
58  cbxPyramidsFormat->setCurrentIndex( 1 );
59  else if ( tmpStr == "external_erdas" )
60  cbxPyramidsFormat->setCurrentIndex( 2 );
61  else
62  cbxPyramidsFormat->setCurrentIndex( 0 );
63 
64  // initialize resampling methods
65  cboResamplingMethod->clear();
67  Q_FOREACH ( method, QgsRasterDataProvider::pyramidResamplingMethods( mProvider ) )
68  {
69  cboResamplingMethod->addItem( method.second, method.first );
70  }
71  cboResamplingMethod->setCurrentIndex( cboResamplingMethod->findData(
72  mySettings.value( prefix + "resampling", "AVERAGE" ).toString() ) );
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() == 1 )
130  tmpStr = "internal";
131  else if ( cbxPyramidsFormat->currentIndex() == 2 )
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 != 2 );
169  mSaveOptionsWidget->setPyramidsFormat(( QgsRaster::RasterPyramidsFormat ) index );
170 }
171 
172 void QgsRasterPyramidsOptionsWidget::setOverviewList()
173 {
174  QgsDebugMsg( "Entered" );
175 
176  mOverviewList.clear();
177 
178  // if custom levels is toggled, get selection from line edit
179  if ( cbxPyramidsLevelsCustom->isChecked() )
180  {
181  // should we also validate that numbers are increasing?
182  Q_FOREACH ( const QString& lev, lePyramidsLevels->text().trimmed().split( ' ', QString::SkipEmptyParts ) )
183  {
184  QgsDebugMsg( "lev= " + lev );
185  int tmpInt = lev.toInt();
186  if ( tmpInt > 0 )
187  {
188  QgsDebugMsg( "tmpInt= " + QString::number( tmpInt ) );
189  // if number is valid, add to overview list
190  mOverviewList << tmpInt;
191  }
192  }
193  }
194  else
195  {
196  Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
197  {
198  if ( mOverviewCheckBoxes[ i ]->isChecked() )
199  mOverviewList << i;
200  }
201  }
202 
203  emit overviewListChanged();
204 }
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