24#include <QInputDialog>
30#include <QRegularExpressionValidator>
31#include <QRegularExpression>
35 , mProvider( provider )
38 connect( cbxPyramidsLevelsCustom, &QCheckBox::toggled,
this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled );
39 connect( cbxPyramidsFormat,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged );
41 mSaveOptionsWidget->setProvider( provider );
48void QgsRasterPyramidsOptionsWidget::updateUi()
51 const QString prefix = mProvider +
"/driverOptions/_pyramids/";
55 tmpStr = mySettings.
value( prefix +
"format",
"external" ).toString();
56 if ( tmpStr == QLatin1String(
"internal" ) )
57 cbxPyramidsFormat->setCurrentIndex( INTERNAL );
58 else if ( tmpStr == QLatin1String(
"external_erdas" ) )
59 cbxPyramidsFormat->setCurrentIndex( ERDAS );
61 cbxPyramidsFormat->setCurrentIndex( GTIFF );
64 cboResamplingMethod->clear();
66 for (
const QPair<QString, QString> &method : methods )
68 cboResamplingMethod->addItem( method.second, method.first );
70 const QString defaultMethod = mySettings.
value( prefix +
"resampling",
"AVERAGE" ).toString();
71 const int idx = cboResamplingMethod->findData( defaultMethod );
72 cboResamplingMethod->setCurrentIndex( idx );
75 lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() );
76 lePyramidsLevels->setValidator(
new QRegularExpressionValidator( QRegularExpression(
"(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) );
77 connect( lePyramidsLevels, &QLineEdit::textEdited,
78 this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
81 if ( mOverviewCheckBoxes.isEmpty() )
85 mOverviewCheckBoxes.clear();
87 for (
const int i : constOverviewList )
89 mOverviewCheckBoxes[ i ] =
new QCheckBox( QString::number( i ),
this );
90 connect( mOverviewCheckBoxes[ i ], &QCheckBox::toggled,
91 this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
92 layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[ i ] );
97 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
98 it.value()->setChecked(
false );
100 tmpStr = mySettings.
value( prefix +
"overviewList",
"" ).toString();
101#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
102 const QStringList constSplit = tmpStr.split(
' ', QString::SkipEmptyParts );
104 const QStringList constSplit = tmpStr.split(
' ', Qt::SkipEmptyParts );
106 for (
const QString &lev : constSplit )
108 if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
109 mOverviewCheckBoxes[ lev.toInt()]->setChecked(
true );
113 mSaveOptionsWidget->updateProfiles();
115 connect( cbxPyramidsFormat,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
117 connect( cboResamplingMethod,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
125 return cboResamplingMethod->currentData().toString();
131 const QString prefix = mProvider +
"/driverOptions/_pyramids/";
135 if ( cbxPyramidsFormat->currentIndex() == INTERNAL )
136 tmpStr = QStringLiteral(
"internal" );
137 else if ( cbxPyramidsFormat->currentIndex() == ERDAS )
138 tmpStr = QStringLiteral(
"external_erdas" );
140 tmpStr = QStringLiteral(
"external" );
141 mySettings.
setValue( prefix +
"format", tmpStr );
143 mySettings.
setValue( prefix +
"overviewStr", lePyramidsLevels->text().trimmed() );
147 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
149 if ( it.value()->isChecked() )
150 tmpStr += QString::number( it.key() ) +
' ';
152 mySettings.
setValue( prefix +
"overviewList", tmpStr.trimmed() );
154 mSaveOptionsWidget->apply();
159 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
160 it.value()->setChecked( checked );
163void QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled(
bool toggled )
166 lePyramidsLevels->setEnabled( toggled );
167 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
168 it.value()->setEnabled( ! toggled );
172void QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged(
int index )
174 mSaveOptionsWidget->setEnabled( index != ERDAS );
188 QgsDebugMsg( QStringLiteral(
"Should not happen !" ) );
192 mSaveOptionsWidget->setPyramidsFormat( format );
195void QgsRasterPyramidsOptionsWidget::setOverviewList()
198 mOverviewList.clear();
201 if ( cbxPyramidsLevelsCustom->isChecked() )
204#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
205 const QStringList constSplit = lePyramidsLevels->text().trimmed().split(
' ', QString::SkipEmptyParts );
207 const QStringList constSplit = lePyramidsLevels->text().trimmed().split(
' ', Qt::SkipEmptyParts );
209 for (
const QString &lev : constSplit )
212 const int tmpInt = lev.toInt();
215 QgsDebugMsg(
"tmpInt= " + QString::number( tmpInt ) );
217 mOverviewList << tmpInt;
223 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
225 if ( it.value()->isChecked() )
226 mOverviewList << it.key();
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.