QGIS API Documentation 3.38.0-Grenoble (exported)
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 const QStringList constSplit = tmpStr.split( ' ', Qt::SkipEmptyParts );
105 for ( const QString &lev : constSplit )
106 {
107 if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
108 mOverviewCheckBoxes[ lev.toInt()]->setChecked( true );
109 }
110 setOverviewList();
111
112 mSaveOptionsWidget->updateProfiles();
113
114 connect( cbxPyramidsFormat, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
116 connect( cboResamplingMethod, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
118 connect( mSaveOptionsWidget, &QgsRasterFormatSaveOptionsWidget::optionsChanged,
120}
121
123{
124 return cboResamplingMethod->currentData().toString();
125}
126
128{
129 QgsSettings mySettings;
130 const QString prefix = mProvider + "/driverOptions/_pyramids/";
131 QString tmpStr;
132
133 // mySettings.setValue( prefix + "internal", cbxPyramidsInternal->isChecked() );
134
135 const Qgis::RasterPyramidFormat format = cbxPyramidsFormat->currentData().value< Qgis::RasterPyramidFormat >();
136 switch ( format )
137 {
139 tmpStr = QStringLiteral( "external" );
140 break;
142 tmpStr = QStringLiteral( "internal" );
143 break;
145 tmpStr = QStringLiteral( "external_erdas" );
146 break;
147 }
148 mySettings.setValue( prefix + "format", tmpStr );
149 mySettings.setValue( prefix + "resampling", resamplingMethod() );
150 mySettings.setValue( prefix + "overviewStr", lePyramidsLevels->text().trimmed() );
151
152 // overview list
153 tmpStr.clear();
154 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
155 {
156 if ( it.value()->isChecked() )
157 tmpStr += QString::number( it.key() ) + ' ';
158 }
159 mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() );
160
161 mSaveOptionsWidget->apply();
162}
163
165{
166 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
167 it.value()->setChecked( checked );
168}
169
170void QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled( bool toggled )
171{
172 // if toggled, disable checkboxes and enable line edit
173 lePyramidsLevels->setEnabled( toggled );
174 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
175 it.value()->setEnabled( ! toggled );
176 setOverviewList();
177}
178
179void QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged( int )
180{
181 const Qgis::RasterPyramidFormat format = cbxPyramidsFormat->currentData().value< Qgis::RasterPyramidFormat >();
182 mSaveOptionsWidget->setEnabled( format != Qgis::RasterPyramidFormat::Erdas );
183 mSaveOptionsWidget->setPyramidsFormat( format );
184}
185
186void QgsRasterPyramidsOptionsWidget::setOverviewList()
187{
188
189 mOverviewList.clear();
190
191 // if custom levels is toggled, get selection from line edit
192 if ( cbxPyramidsLevelsCustom->isChecked() )
193 {
194 // should we also validate that numbers are increasing?
195 const QStringList constSplit = lePyramidsLevels->text().trimmed().split( ' ', Qt::SkipEmptyParts );
196 for ( const QString &lev : constSplit )
197 {
198 QgsDebugMsgLevel( "lev= " + lev, 3 );
199 const int tmpInt = lev.toInt();
200 if ( tmpInt > 0 )
201 {
202 QgsDebugMsgLevel( "tmpInt= " + QString::number( tmpInt ), 3 );
203 // if number is valid, add to overview list
204 mOverviewList << tmpInt;
205 }
206 }
207 }
208 else
209 {
210 for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
211 {
212 if ( it.value()->isChecked() )
213 mOverviewList << it.key();
214 }
215 }
216
217 emit overviewListChanged();
218}
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:4147
@ 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: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