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