QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
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
48 updateUi();
49}
50
51void QgsRasterPyramidsOptionsWidget::updateUi()
52{
53 const QgsSettings mySettings;
54 const QString prefix = mProvider + "/driverOptions/_pyramids/";
55 QString tmpStr;
56
57 // keep it in sync with qgsrasterlayerproperties.cpp
58 tmpStr = mySettings.value( prefix + "format", "external" ).toString();
59 if ( tmpStr == QLatin1String( "internal" ) )
60 cbxPyramidsFormat->setCurrentIndex( cbxPyramidsFormat->findData( QVariant::fromValue( Qgis::RasterPyramidFormat::Internal ) ) );
61 else if ( tmpStr == QLatin1String( "external_erdas" ) )
62 cbxPyramidsFormat->setCurrentIndex( cbxPyramidsFormat->findData( QVariant::fromValue( Qgis::RasterPyramidFormat::Erdas ) ) );
63 else
64 cbxPyramidsFormat->setCurrentIndex( cbxPyramidsFormat->findData( QVariant::fromValue( Qgis::RasterPyramidFormat::GeoTiff ) ) );
65
66 // initialize resampling methods
67 cboResamplingMethod->clear();
68 const auto methods {QgsRasterDataProvider::pyramidResamplingMethods( mProvider )};
69 for ( const QPair<QString, QString> &method : methods )
70 {
71 cboResamplingMethod->addItem( method.second, method.first );
72 }
73 const QString defaultMethod = mySettings.value( prefix + "resampling", "AVERAGE" ).toString();
74 const int idx = cboResamplingMethod->findData( defaultMethod );
75 cboResamplingMethod->setCurrentIndex( idx );
76
77 // validate string, only space-separated positive integers are allowed
78 lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() );
79 lePyramidsLevels->setValidator( new QRegularExpressionValidator( QRegularExpression( "(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) );
80 connect( lePyramidsLevels, &QLineEdit::textEdited,
81 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,
94 this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
95 layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[ i ] );
96 }
97 }
98 else
99 {
100 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
101 it.value()->setChecked( false );
102 }
103 tmpStr = mySettings.value( prefix + "overviewList", "" ).toString();
104#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
105 const QStringList constSplit = tmpStr.split( ' ', QString::SkipEmptyParts );
106#else
107 const QStringList constSplit = tmpStr.split( ' ', Qt::SkipEmptyParts );
108#endif
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 ),
120 connect( cboResamplingMethod, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
122 connect( mSaveOptionsWidget, &QgsRasterFormatSaveOptionsWidget::optionsChanged,
124}
125
127{
128 return cboResamplingMethod->currentData().toString();
129}
130
132{
133 QgsSettings mySettings;
134 const QString prefix = mProvider + "/driverOptions/_pyramids/";
135 QString tmpStr;
136
137 // mySettings.setValue( prefix + "internal", cbxPyramidsInternal->isChecked() );
138
139 const Qgis::RasterPyramidFormat format = cbxPyramidsFormat->currentData().value< Qgis::RasterPyramidFormat >();
140 switch ( format )
141 {
143 tmpStr = QStringLiteral( "external" );
144 break;
146 tmpStr = QStringLiteral( "internal" );
147 break;
149 tmpStr = QStringLiteral( "external_erdas" );
150 break;
151 }
152 mySettings.setValue( prefix + "format", tmpStr );
153 mySettings.setValue( prefix + "resampling", resamplingMethod() );
154 mySettings.setValue( prefix + "overviewStr", lePyramidsLevels->text().trimmed() );
155
156 // overview list
157 tmpStr.clear();
158 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
159 {
160 if ( it.value()->isChecked() )
161 tmpStr += QString::number( it.key() ) + ' ';
162 }
163 mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() );
164
165 mSaveOptionsWidget->apply();
166}
167
169{
170 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
171 it.value()->setChecked( checked );
172}
173
174void QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled( bool toggled )
175{
176 // if toggled, disable checkboxes and enable line edit
177 lePyramidsLevels->setEnabled( toggled );
178 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
179 it.value()->setEnabled( ! toggled );
180 setOverviewList();
181}
182
183void QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged( int )
184{
185 const Qgis::RasterPyramidFormat format = cbxPyramidsFormat->currentData().value< Qgis::RasterPyramidFormat >();
186 mSaveOptionsWidget->setEnabled( format != Qgis::RasterPyramidFormat::Erdas );
187 mSaveOptionsWidget->setPyramidsFormat( format );
188}
189
190void QgsRasterPyramidsOptionsWidget::setOverviewList()
191{
192
193 mOverviewList.clear();
194
195 // if custom levels is toggled, get selection from line edit
196 if ( cbxPyramidsLevelsCustom->isChecked() )
197 {
198 // should we also validate that numbers are increasing?
199#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
200 const QStringList constSplit = lePyramidsLevels->text().trimmed().split( ' ', QString::SkipEmptyParts );
201#else
202 const QStringList constSplit = lePyramidsLevels->text().trimmed().split( ' ', Qt::SkipEmptyParts );
203#endif
204 for ( const QString &lev : constSplit )
205 {
206 QgsDebugMsgLevel( "lev= " + lev, 3 );
207 const int tmpInt = lev.toInt();
208 if ( tmpInt > 0 )
209 {
210 QgsDebugMsgLevel( "tmpInt= " + QString::number( tmpInt ), 3 );
211 // if number is valid, add to overview list
212 mOverviewList << tmpInt;
213 }
214 }
215 }
216 else
217 {
218 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
219 {
220 if ( it.value()->isChecked() )
221 mOverviewList << it.key();
222 }
223 }
224
225 emit overviewListChanged();
226}
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:3353
@ 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.
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 QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39