23#include <QInputDialog>
29#include <QRegularExpressionValidator>
30#include <QRegularExpression>
34 , mProvider( provider )
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 ) );
42 connect( cbxPyramidsLevelsCustom, &QCheckBox::toggled,
this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled );
43 connect( cbxPyramidsFormat,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged );
45 mSaveOptionsWidget->setProvider( provider );
46 mSaveOptionsWidget->setPyramidsFormat( Qgis::RasterPyramidFormat::GeoTiff );
52void QgsRasterPyramidsOptionsWidget::updateUi()
55 const QString prefix = mProvider +
"/driverOptions/_pyramids/";
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 ) ) );
65 cbxPyramidsFormat->setCurrentIndex( cbxPyramidsFormat->findData( QVariant::fromValue( Qgis::RasterPyramidFormat::GeoTiff ) ) );
68 cboResamplingMethod->clear();
70 for (
const QPair<QString, QString> &method : methods )
72 cboResamplingMethod->addItem( method.second, method.first );
74 const QString defaultMethod = mySettings.
value( prefix +
"resampling",
"AVERAGE" ).toString();
75 const int idx = cboResamplingMethod->findData( defaultMethod );
76 cboResamplingMethod->setCurrentIndex( idx );
79 lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() );
80 lePyramidsLevels->setValidator(
new QRegularExpressionValidator( QRegularExpression(
"(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) );
81 connect( lePyramidsLevels, &QLineEdit::textEdited,
82 this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
85 if ( mOverviewCheckBoxes.isEmpty() )
89 mOverviewCheckBoxes.clear();
91 for (
const int i : constOverviewList )
93 mOverviewCheckBoxes[ i ] =
new QCheckBox( QString::number( i ),
this );
94 connect( mOverviewCheckBoxes[ i ], &QCheckBox::toggled,
95 this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
96 layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[ i ] );
101 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
102 it.value()->setChecked(
false );
104 tmpStr = mySettings.
value( prefix +
"overviewList",
"" ).toString();
105#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
106 const QStringList constSplit = tmpStr.split(
' ', QString::SkipEmptyParts );
108 const QStringList constSplit = tmpStr.split(
' ', Qt::SkipEmptyParts );
110 for (
const QString &lev : constSplit )
112 if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
113 mOverviewCheckBoxes[ lev.toInt()]->setChecked(
true );
117 mSaveOptionsWidget->updateProfiles();
119 connect( cbxPyramidsFormat,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
121 connect( cboResamplingMethod,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
129 return cboResamplingMethod->currentData().toString();
135 const QString prefix = mProvider +
"/driverOptions/_pyramids/";
143 case Qgis::RasterPyramidFormat::GeoTiff:
144 tmpStr = QStringLiteral(
"external" );
146 case Qgis::RasterPyramidFormat::Internal:
147 tmpStr = QStringLiteral(
"internal" );
149 case Qgis::RasterPyramidFormat::Erdas:
150 tmpStr = QStringLiteral(
"external_erdas" );
153 mySettings.
setValue( prefix +
"format", tmpStr );
155 mySettings.
setValue( prefix +
"overviewStr", lePyramidsLevels->text().trimmed() );
159 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
161 if ( it.value()->isChecked() )
162 tmpStr += QString::number( it.key() ) +
' ';
164 mySettings.
setValue( prefix +
"overviewList", tmpStr.trimmed() );
166 mSaveOptionsWidget->apply();
171 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
172 it.value()->setChecked( checked );
175void QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled(
bool toggled )
178 lePyramidsLevels->setEnabled( toggled );
179 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
180 it.value()->setEnabled( ! toggled );
184void QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged(
int )
187 mSaveOptionsWidget->setEnabled( format != Qgis::RasterPyramidFormat::Erdas );
188 mSaveOptionsWidget->setPyramidsFormat( format );
191void QgsRasterPyramidsOptionsWidget::setOverviewList()
194 mOverviewList.clear();
197 if ( cbxPyramidsLevelsCustom->isChecked() )
200#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
201 const QStringList constSplit = lePyramidsLevels->text().trimmed().split(
' ', QString::SkipEmptyParts );
203 const QStringList constSplit = lePyramidsLevels->text().trimmed().split(
' ', Qt::SkipEmptyParts );
205 for (
const QString &lev : constSplit )
208 const int tmpInt = lev.toInt();
211 QgsDebugMsg(
"tmpInt= " + QString::number( tmpInt ) );
213 mOverviewList << tmpInt;
219 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
221 if ( it.value()->isChecked() )
222 mOverviewList << it.key();
RasterPyramidFormat
Raster pyramid formats.
static QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
This class is a composition of two QSettings instances:
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.