QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ), 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  // cbxPyramidsInternal->setChecked( mySettings.value( prefix + "internal", false ).toBool() );
55  tmpStr = mySettings.value( prefix + "format", "gtiff" ).toString();
56  if ( tmpStr == "internal" )
57  cbxPyramidsFormat->setCurrentIndex( 1 );
58  else if ( tmpStr == "external_erdas" )
59  cbxPyramidsFormat->setCurrentIndex( 2 );
60  else
61  cbxPyramidsFormat->setCurrentIndex( 0 );
62 
63  // initialize resampling methods
64  cboResamplingMethod->clear();
65  QPair<QString, QString> method;
66  foreach ( method, QgsRasterDataProvider::pyramidResamplingMethods( mProvider ) )
67  {
68  cboResamplingMethod->addItem( method.second, method.first );
69  }
70  cboResamplingMethod->setCurrentIndex( cboResamplingMethod->findData(
71  mySettings.value( prefix + "resampling", "AVERAGE" ).toString() ) );
72 
73  // validate string, only space-separated positive integers are allowed
74  lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() );
75  lePyramidsLevels->setValidator( new QRegExpValidator( QRegExp( "(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) );
76  connect( lePyramidsLevels, SIGNAL( textEdited( const QString & ) ),
77  this, SLOT( setOverviewList() ) );
78 
79  // overview list
80  if ( mOverviewCheckBoxes.isEmpty() )
81  {
82  QList<int> overviewList;
83  overviewList << 2 << 4 << 8 << 16 << 32 << 64;
84  mOverviewCheckBoxes.clear();
85  foreach ( int i, overviewList )
86  {
87  mOverviewCheckBoxes[ i ] = new QCheckBox( QString::number( i ), this );
88  connect( mOverviewCheckBoxes[ i ], SIGNAL( toggled( bool ) ),
89  this, SLOT( setOverviewList() ) );
90  layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[ i ] );
91  }
92  }
93  else
94  {
95  foreach ( int i, mOverviewCheckBoxes.keys() )
96  mOverviewCheckBoxes[ i ]->setChecked( false );
97  }
98  tmpStr = mySettings.value( prefix + "overviewList", "" ).toString();
99  foreach ( QString lev, tmpStr.split( " ", QString::SkipEmptyParts ) )
100  {
101  if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
102  mOverviewCheckBoxes[ lev.toInt()]->setChecked( true );
103  }
104  setOverviewList();
105 
106  mSaveOptionsWidget->updateProfiles();
107 
108  connect( cbxPyramidsFormat, SIGNAL( currentIndexChanged( int ) ),
109  this, SIGNAL( someValueChanged() ) );
110  connect( cboResamplingMethod, SIGNAL( currentIndexChanged( int ) ),
111  this, SIGNAL( someValueChanged() ) );
112  connect( mSaveOptionsWidget, SIGNAL( optionsChanged() ),
113  this, SIGNAL( someValueChanged() ) );
114 }
115 
117 {
118  return cboResamplingMethod->itemData( cboResamplingMethod->currentIndex() ).toString();
119 }
120 
122 {
123  QSettings mySettings;
124  QString prefix = mProvider + "/driverOptions/_pyramids/";
125  QString tmpStr;
126 
127  // mySettings.setValue( prefix + "internal", cbxPyramidsInternal->isChecked() );
128  if ( cbxPyramidsFormat->currentIndex() == 1 )
129  tmpStr = "internal";
130  else if ( cbxPyramidsFormat->currentIndex() == 2 )
131  tmpStr = "external_erdas";
132  else
133  tmpStr = "external";
134  mySettings.setValue( prefix + "format", tmpStr );
135  mySettings.setValue( prefix + "resampling", resamplingMethod() );
136  mySettings.setValue( prefix + "overviewStr", lePyramidsLevels->text().trimmed() );
137 
138  // overview list
139  tmpStr = "";
140  foreach ( int i, mOverviewCheckBoxes.keys() )
141  {
142  if ( mOverviewCheckBoxes[ i ]->isChecked() )
143  tmpStr += QString::number( i ) + " ";
144  }
145  mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() );
146 
147  mSaveOptionsWidget->apply();
148 }
149 
151 {
152  foreach ( int i, mOverviewCheckBoxes.keys() )
153  mOverviewCheckBoxes[ i ]->setChecked( checked );
154 }
155 
156 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsLevelsCustom_toggled( bool toggled )
157 {
158  // if toggled, disable checkboxes and enable line edit
159  lePyramidsLevels->setEnabled( toggled );
160  foreach ( int i, mOverviewCheckBoxes.keys() )
161  mOverviewCheckBoxes[ i ]->setEnabled( ! toggled );
162  setOverviewList();
163 }
164 
165 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsFormat_currentIndexChanged( int index )
166 {
167  mSaveOptionsWidget->setEnabled( index != 2 );
168  mSaveOptionsWidget->setPyramidsFormat(( QgsRaster::RasterPyramidsFormat ) index );
169 }
170 
171 void QgsRasterPyramidsOptionsWidget::setOverviewList()
172 {
173  QgsDebugMsg( "Entered" );
174 
175  mOverviewList.clear();
176 
177  // if custom levels is toggled, get selection from line edit
178  if ( cbxPyramidsLevelsCustom->isChecked() )
179  {
180  // should we also validate that numbers are increasing?
181  foreach ( QString lev, lePyramidsLevels->text().trimmed().split( " ", QString::SkipEmptyParts ) )
182  {
183  QgsDebugMsg( "lev= " + lev );
184  int tmpInt = lev.toInt();
185  if ( tmpInt > 0 )
186  {
187  QgsDebugMsg( "tmpInt= " + QString::number( tmpInt ) );
188  // if number is valid, add to overview list
189  mOverviewList << tmpInt;
190  }
191  }
192  }
193  else
194  {
195  foreach ( int i, mOverviewCheckBoxes.keys() )
196  {
197  if ( mOverviewCheckBoxes[ i ]->isChecked() )
198  mOverviewList << i;
199  }
200  }
201 
202  emit overviewListChanged();
203 }