QGIS API Documentation 3.41.0-Master (3440c17df1d)
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#include "moc_qgsrasterpyramidsoptionswidget.cpp"
21#include "qgslogger.h"
22#include "qgssettings.h"
23
24#include <QInputDialog>
25#include <QMessageBox>
26#include <QTextEdit>
27#include <QMouseEvent>
28#include <QMenu>
29#include <QCheckBox>
30#include <QRegularExpressionValidator>
31#include <QRegularExpression>
32
33QgsRasterPyramidsOptionsWidget::QgsRasterPyramidsOptionsWidget( QWidget *parent, const QString &provider )
34 : QWidget( parent )
35 , mProvider( provider )
36{
37 setupUi( this );
38
39 cbxPyramidsFormat->addItem( tr( "External (GeoTiff .ovr)" ), QVariant::fromValue( Qgis::RasterPyramidFormat::GeoTiff ) );
40 cbxPyramidsFormat->addItem( tr( "Internal (if possible)" ), QVariant::fromValue( Qgis::RasterPyramidFormat::Internal ) );
41 cbxPyramidsFormat->addItem( tr( "External (Erdas Imagine .aux)" ), QVariant::fromValue( Qgis::RasterPyramidFormat::Erdas ) );
42
43 connect( cbxPyramidsLevelsCustom, &QCheckBox::toggled, this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled );
44 connect( cbxPyramidsFormat, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged );
45
46 mSaveOptionsWidget->setProvider( provider );
47 mSaveOptionsWidget->setPyramidsFormat( Qgis::RasterPyramidFormat::GeoTiff );
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 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 ),
117 connect( cboResamplingMethod, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
119 connect( mSaveOptionsWidget, &QgsRasterFormatSaveOptionsWidget::optionsChanged,
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 = QStringLiteral( "external" );
141 break;
143 tmpStr = QStringLiteral( "internal" );
144 break;
146 tmpStr = QStringLiteral( "external_erdas" );
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
166{
167 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
168 it.value()->setChecked( checked );
169}
170
171void QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled( bool toggled )
172{
173 // if toggled, disable checkboxes and enable line edit
174 lePyramidsLevels->setEnabled( toggled );
175 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
176 it.value()->setEnabled( ! toggled );
177 setOverviewList();
178}
179
180void QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged( int )
181{
182 const Qgis::RasterPyramidFormat format = cbxPyramidsFormat->currentData().value< Qgis::RasterPyramidFormat >();
183 mSaveOptionsWidget->setEnabled( format != Qgis::RasterPyramidFormat::Erdas );
184 mSaveOptionsWidget->setPyramidsFormat( format );
185}
186
187void QgsRasterPyramidsOptionsWidget::setOverviewList()
188{
189
190 mOverviewList.clear();
191
192 // if custom levels is toggled, get selection from line edit
193 if ( cbxPyramidsLevelsCustom->isChecked() )
194 {
195 // should we also validate that numbers are increasing?
196 const QStringList constSplit = lePyramidsLevels->text().trimmed().split( ' ', Qt::SkipEmptyParts );
197 for ( const QString &lev : constSplit )
198 {
199 QgsDebugMsgLevel( "lev= " + lev, 3 );
200 const int tmpInt = lev.toInt();
201 if ( tmpInt > 0 )
202 {
203 QgsDebugMsgLevel( "tmpInt= " + QString::number( tmpInt ), 3 );
204 // if number is valid, add to overview list
205 mOverviewList << tmpInt;
206 }
207 }
208 }
209 else
210 {
211 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
212 {
213 if ( it.value()->isChecked() )
214 mOverviewList << it.key();
215 }
216 }
217
218 emit overviewListChanged();
219}
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:4466
@ GeoTiff
Geotiff .ovr (external)
@ Erdas
Erdas Image .aux (external)
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.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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:39