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