22 #include "qgssettings.h"
24 #include <QInputDialog>
25 #include <QMessageBox>
27 #include <QMouseEvent>
33 , mProvider( provider )
36 connect( cbxPyramidsLevelsCustom, &QCheckBox::toggled,
this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled );
37 connect( cbxPyramidsFormat,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged );
39 mSaveOptionsWidget->setProvider( provider );
46 void QgsRasterPyramidsOptionsWidget::updateUi()
48 QgsSettings mySettings;
49 QString prefix = mProvider +
"/driverOptions/_pyramids/";
53 tmpStr = mySettings.value( prefix +
"format",
"external" ).toString();
54 if ( tmpStr == QLatin1String(
"internal" ) )
55 cbxPyramidsFormat->setCurrentIndex( INTERNAL );
56 else if ( tmpStr == QLatin1String(
"external_erdas" ) )
57 cbxPyramidsFormat->setCurrentIndex( ERDAS );
59 cbxPyramidsFormat->setCurrentIndex( GTIFF );
62 cboResamplingMethod->clear();
64 for (
const QPair<QString, QString> &method : methods )
66 cboResamplingMethod->addItem( method.second, method.first );
68 QString defaultMethod = mySettings.value( prefix +
"resampling",
"AVERAGE" ).toString();
69 int idx = cboResamplingMethod->findData( defaultMethod );
70 cboResamplingMethod->setCurrentIndex( idx );
73 lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() );
74 lePyramidsLevels->setValidator(
new QRegExpValidator( QRegExp(
"(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) );
75 connect( lePyramidsLevels, &QLineEdit::textEdited,
76 this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
79 if ( mOverviewCheckBoxes.isEmpty() )
83 mOverviewCheckBoxes.clear();
85 for (
int i : constOverviewList )
87 mOverviewCheckBoxes[ i ] =
new QCheckBox( QString::number( i ),
this );
88 connect( mOverviewCheckBoxes[ i ], &QCheckBox::toggled,
89 this, &QgsRasterPyramidsOptionsWidget::setOverviewList );
90 layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[ i ] );
95 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
96 it.value()->setChecked(
false );
98 tmpStr = mySettings.value( prefix +
"overviewList",
"" ).toString();
99 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
100 const QStringList constSplit = tmpStr.split(
' ', QString::SkipEmptyParts );
102 const QStringList constSplit = tmpStr.split(
' ', Qt::SkipEmptyParts );
104 for (
const QString &lev : constSplit )
106 if ( mOverviewCheckBoxes.contains( lev.toInt() ) )
107 mOverviewCheckBoxes[ lev.toInt()]->setChecked(
true );
111 mSaveOptionsWidget->updateProfiles();
113 connect( cbxPyramidsFormat,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
115 connect( cboResamplingMethod,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
123 return cboResamplingMethod->currentData().toString();
128 QgsSettings mySettings;
129 QString prefix = mProvider +
"/driverOptions/_pyramids/";
133 if ( cbxPyramidsFormat->currentIndex() == INTERNAL )
134 tmpStr = QStringLiteral(
"internal" );
135 else if ( cbxPyramidsFormat->currentIndex() == ERDAS )
136 tmpStr = QStringLiteral(
"external_erdas" );
138 tmpStr = QStringLiteral(
"external" );
139 mySettings.setValue( prefix +
"format", tmpStr );
141 mySettings.setValue( prefix +
"overviewStr", lePyramidsLevels->text().trimmed() );
145 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
147 if ( it.value()->isChecked() )
148 tmpStr += QString::number( it.key() ) +
' ';
150 mySettings.setValue( prefix +
"overviewList", tmpStr.trimmed() );
152 mSaveOptionsWidget->apply();
157 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
158 it.value()->setChecked( checked );
161 void QgsRasterPyramidsOptionsWidget::cbxPyramidsLevelsCustom_toggled(
bool toggled )
164 lePyramidsLevels->setEnabled( toggled );
165 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
166 it.value()->setEnabled( ! toggled );
170 void QgsRasterPyramidsOptionsWidget::cbxPyramidsFormat_currentIndexChanged(
int index )
172 mSaveOptionsWidget->setEnabled( index != ERDAS );
186 QgsDebugMsg( QStringLiteral(
"Should not happen !" ) );
190 mSaveOptionsWidget->setPyramidsFormat( format );
193 void QgsRasterPyramidsOptionsWidget::setOverviewList()
196 mOverviewList.clear();
199 if ( cbxPyramidsLevelsCustom->isChecked() )
202 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
203 const QStringList constSplit = lePyramidsLevels->text().trimmed().split(
' ', QString::SkipEmptyParts );
205 const QStringList constSplit = lePyramidsLevels->text().trimmed().split(
' ', Qt::SkipEmptyParts );
207 for (
const QString &lev : constSplit )
210 int tmpInt = lev.toInt();
213 QgsDebugMsg(
"tmpInt= " + QString::number( tmpInt ) );
215 mOverviewList << tmpInt;
221 for (
auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
223 if ( it.value()->isChecked() )
224 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.