QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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
20#include "qgslogger.h"
22#include "qgssettings.h"
23
24#include <QCheckBox>
25#include <QInputDialog>
26#include <QMenu>
27#include <QMessageBox>
28#include <QMouseEvent>
29#include <QRegularExpression>
30#include <QRegularExpressionValidator>
31#include <QTextEdit>
32
33#include "moc_qgsrasterpyramidsoptionswidget.cpp"
34
35QgsRasterPyramidsOptionsWidget::QgsRasterPyramidsOptionsWidget( QWidget *parent, const QString &provider )
36 : QWidget( parent )
37 , mProvider( provider )
38{
39 setupUi( this );
40
41 cbxPyramidsFormat->addItem( tr( "External (GeoTiff .ovr)" ), QVariant::fromValue( Qgis::RasterPyramidFormat::GeoTiff ) );
42 cbxPyramidsFormat->addItem( tr( "Internal (if possible)" ), QVariant::fromValue( Qgis::RasterPyramidFormat::Internal ) );
43 cbxPyramidsFormat->addItem( tr( "External (Erdas Imagine .aux)" ), QVariant::fromValue( Qgis::RasterPyramidFormat::Erdas ) );
44
45 connect( cbxPyramidsLevelsCustom, &QCheckBox::toggled, this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled );
46 connect( cbxPyramidsFormat, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged );
47
48 mSaveOptionsWidget->setProvider( provider );
49 mSaveOptionsWidget->setPyramidsFormat( Qgis::RasterPyramidFormat::GeoTiff );
50
51 updateUi();
52}
53
54void QgsRasterPyramidsOptionsWidget::updateUi()
55{
56 const QgsSettings mySettings;
57 const QString prefix = mProvider + "/driverOptions/_pyramids/";
58 QString tmpStr;
59
60 // keep it in sync with qgsrasterlayerproperties.cpp
61 tmpStr = mySettings.value( prefix + "format", "external" ).toString();
62 if ( tmpStr == QLatin1String( "internal" ) )
63 cbxPyramidsFormat->setCurrentIndex( cbxPyramidsFormat->findData( QVariant::fromValue( Qgis::RasterPyramidFormat::Internal ) ) );
64 else if ( tmpStr == QLatin1String( "external_erdas" ) )
65 cbxPyramidsFormat->setCurrentIndex( cbxPyramidsFormat->findData( QVariant::fromValue( Qgis::RasterPyramidFormat::Erdas ) ) );
66 else
67 cbxPyramidsFormat->setCurrentIndex( cbxPyramidsFormat->findData( QVariant::fromValue( Qgis::RasterPyramidFormat::GeoTiff ) ) );
68
69 // initialize resampling methods
70 cboResamplingMethod->clear();
71 const auto methods { QgsRasterDataProvider::pyramidResamplingMethods( mProvider ) };
72 for ( const QPair<QString, QString> &method : methods )
73 {
74 cboResamplingMethod->addItem( method.second, method.first );
75 }
76 const QString defaultMethod = mySettings.value( prefix + "resampling", "AVERAGE" ).toString();
77 const int idx = cboResamplingMethod->findData( defaultMethod );
78 cboResamplingMethod->setCurrentIndex( idx );
79
80 // validate string, only space-separated positive integers are allowed
81 lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() );
82 lePyramidsLevels->setValidator( new QRegularExpressionValidator( QRegularExpression( "(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) );
83 connect( lePyramidsLevels, &QLineEdit::textEdited, this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
84
85 // overview list
86 if ( mOverviewCheckBoxes.isEmpty() )
87 {
88 QList<int> overviewList;
89 overviewList << 2 << 4 << 8 << 16 << 32 << 64;
90 mOverviewCheckBoxes.clear();
91 const auto constOverviewList = overviewList;
92 for ( const int i : constOverviewList )
93 {
94 mOverviewCheckBoxes[i] = new QCheckBox( QString::number( i ), this );
95 connect( mOverviewCheckBoxes[i], &QCheckBox::toggled, this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
96 layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[i] );
97 }
98 }
99 else
100 {
101 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
102 it.value()->setChecked( false );
103 }
104 tmpStr = mySettings.value( prefix + "overviewList", "" ).toString();
105 const QStringList constSplit = tmpStr.split( ' ', Qt::SkipEmptyParts );
106 for ( const QString &lev : constSplit )
107 {
108 if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
109 mOverviewCheckBoxes[lev.toInt()]->setChecked( true );
110 }
111 setOverviewList();
112
113 mSaveOptionsWidget->updateProfiles();
114
115 connect( cbxPyramidsFormat, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterPyramidsOptionsWidget::someValueChanged );
116 connect( cboResamplingMethod, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterPyramidsOptionsWidget::someValueChanged );
118}
119
121{
122 return cboResamplingMethod->currentData().toString();
123}
124
126{
127 QgsSettings mySettings;
128 const QString prefix = mProvider + "/driverOptions/_pyramids/";
129 QString tmpStr;
130
131 // mySettings.setValue( prefix + "internal", cbxPyramidsInternal->isChecked() );
132
133 const Qgis::RasterPyramidFormat format = cbxPyramidsFormat->currentData().value<Qgis::RasterPyramidFormat>();
134 switch ( format )
135 {
137 tmpStr = QStringLiteral( "external" );
138 break;
140 tmpStr = QStringLiteral( "internal" );
141 break;
143 tmpStr = QStringLiteral( "external_erdas" );
144 break;
145 }
146 mySettings.setValue( prefix + "format", tmpStr );
147 mySettings.setValue( prefix + "resampling", resamplingMethod() );
148 mySettings.setValue( prefix + "overviewStr", lePyramidsLevels->text().trimmed() );
149
150 // overview list
151 tmpStr.clear();
152 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
153 {
154 if ( it.value()->isChecked() )
155 tmpStr += QString::number( it.key() ) + ' ';
156 }
157 mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() );
158
159 mSaveOptionsWidget->apply();
160}
161
163{
164 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
165 it.value()->setChecked( checked );
166}
167
168void QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled( bool toggled )
169{
170 // if toggled, disable checkboxes and enable line edit
171 lePyramidsLevels->setEnabled( toggled );
172 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
173 it.value()->setEnabled( !toggled );
174 setOverviewList();
175}
176
177void QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged( int )
178{
179 const Qgis::RasterPyramidFormat format = cbxPyramidsFormat->currentData().value<Qgis::RasterPyramidFormat>();
180 mSaveOptionsWidget->setEnabled( format != Qgis::RasterPyramidFormat::Erdas );
181 mSaveOptionsWidget->setPyramidsFormat( format );
182}
183
184void QgsRasterPyramidsOptionsWidget::setOverviewList()
185{
186 mOverviewList.clear();
187
188 // if custom levels is toggled, get selection from line edit
189 if ( cbxPyramidsLevelsCustom->isChecked() )
190 {
191 // should we also validate that numbers are increasing?
192 const QStringList constSplit = lePyramidsLevels->text().trimmed().split( ' ', Qt::SkipEmptyParts );
193 for ( const QString &lev : constSplit )
194 {
195 QgsDebugMsgLevel( "lev= " + lev, 3 );
196 const int tmpInt = lev.toInt();
197 if ( tmpInt > 0 )
198 {
199 QgsDebugMsgLevel( "tmpInt= " + QString::number( tmpInt ), 3 );
200 // if number is valid, add to overview list
201 mOverviewList << tmpInt;
202 }
203 }
204 }
205 else
206 {
207 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
208 {
209 if ( it.value()->isChecked() )
210 mOverviewList << it.key();
211 }
212 }
213
214 emit overviewListChanged();
215}
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:4802
@ GeoTiff
Geotiff .ovr (external).
Definition qgis.h:4803
@ Erdas
Erdas Image .aux (external).
Definition qgis.h:4805
static QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
void optionsChanged()
Emitted when the options configured in the widget are changed.
void someValueChanged()
Emitted when settings are changed in the widget.
QgsRasterPyramidsOptionsWidget(QWidget *parent=nullptr, const QString &provider="gdal")
Constructor for QgsRasterPyramidsOptionsWidget.
void overviewListChanged()
Emitted when the list of configured overviews is changed.
Stores settings for use within QGIS.
Definition qgssettings.h:65
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:61