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