QGIS API Documentation 3.41.0-Master (cea29feecf2)
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, this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
82
83 // overview list
84 if ( mOverviewCheckBoxes.isEmpty() )
85 {
86 QList<int> overviewList;
87 overviewList << 2 << 4 << 8 << 16 << 32 << 64;
88 mOverviewCheckBoxes.clear();
89 const auto constOverviewList = overviewList;
90 for ( const int i : constOverviewList )
91 {
92 mOverviewCheckBoxes[i] = new QCheckBox( QString::number( i ), this );
93 connect( mOverviewCheckBoxes[i], &QCheckBox::toggled, this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
94 layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[i] );
95 }
96 }
97 else
98 {
99 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
100 it.value()->setChecked( false );
101 }
102 tmpStr = mySettings.value( prefix + "overviewList", "" ).toString();
103 const QStringList constSplit = tmpStr.split( ' ', Qt::SkipEmptyParts );
104 for ( const QString &lev : constSplit )
105 {
106 if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
107 mOverviewCheckBoxes[lev.toInt()]->setChecked( true );
108 }
109 setOverviewList();
110
111 mSaveOptionsWidget->updateProfiles();
112
113 connect( cbxPyramidsFormat, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterPyramidsOptionsWidget::someValueChanged );
114 connect( cboResamplingMethod, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterPyramidsOptionsWidget::someValueChanged );
116}
117
119{
120 return cboResamplingMethod->currentData().toString();
121}
122
124{
125 QgsSettings mySettings;
126 const QString prefix = mProvider + "/driverOptions/_pyramids/";
127 QString tmpStr;
128
129 // mySettings.setValue( prefix + "internal", cbxPyramidsInternal->isChecked() );
130
131 const Qgis::RasterPyramidFormat format = cbxPyramidsFormat->currentData().value<Qgis::RasterPyramidFormat>();
132 switch ( format )
133 {
135 tmpStr = QStringLiteral( "external" );
136 break;
138 tmpStr = QStringLiteral( "internal" );
139 break;
141 tmpStr = QStringLiteral( "external_erdas" );
142 break;
143 }
144 mySettings.setValue( prefix + "format", tmpStr );
145 mySettings.setValue( prefix + "resampling", resamplingMethod() );
146 mySettings.setValue( prefix + "overviewStr", lePyramidsLevels->text().trimmed() );
147
148 // overview list
149 tmpStr.clear();
150 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
151 {
152 if ( it.value()->isChecked() )
153 tmpStr += QString::number( it.key() ) + ' ';
154 }
155 mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() );
156
157 mSaveOptionsWidget->apply();
158}
159
161{
162 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
163 it.value()->setChecked( checked );
164}
165
166void QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled( bool toggled )
167{
168 // if toggled, disable checkboxes and enable line edit
169 lePyramidsLevels->setEnabled( toggled );
170 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
171 it.value()->setEnabled( !toggled );
172 setOverviewList();
173}
174
175void QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged( int )
176{
177 const Qgis::RasterPyramidFormat format = cbxPyramidsFormat->currentData().value<Qgis::RasterPyramidFormat>();
178 mSaveOptionsWidget->setEnabled( format != Qgis::RasterPyramidFormat::Erdas );
179 mSaveOptionsWidget->setPyramidsFormat( format );
180}
181
182void QgsRasterPyramidsOptionsWidget::setOverviewList()
183{
184 mOverviewList.clear();
185
186 // if custom levels is toggled, get selection from line edit
187 if ( cbxPyramidsLevelsCustom->isChecked() )
188 {
189 // should we also validate that numbers are increasing?
190 const QStringList constSplit = lePyramidsLevels->text().trimmed().split( ' ', Qt::SkipEmptyParts );
191 for ( const QString &lev : constSplit )
192 {
193 QgsDebugMsgLevel( "lev= " + lev, 3 );
194 const int tmpInt = lev.toInt();
195 if ( tmpInt > 0 )
196 {
197 QgsDebugMsgLevel( "tmpInt= " + QString::number( tmpInt ), 3 );
198 // if number is valid, add to overview list
199 mOverviewList << tmpInt;
200 }
201 }
202 }
203 else
204 {
205 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
206 {
207 if ( it.value()->isChecked() )
208 mOverviewList << it.key();
209 }
210 }
211
212 emit overviewListChanged();
213}
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:4511
@ 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