25 #include <QInputDialog> 26 #include <QMessageBox> 28 #include <QMouseEvent> 41 , mProvider( provider )
42 , mRasterLayer( nullptr )
45 , mPyramidsFormat(
QgsRaster::PyramidsGTiff )
52 if ( mBuiltinProfiles.
isEmpty() )
55 mBuiltinProfiles[
"z_adefault" ] = (
QStringList() <<
"" <<
tr(
"Default" ) <<
"" );
60 mBuiltinProfiles[
"z_gtiff_1big" ] =
62 <<
"COMPRESS=NONE BIGTIFF=IF_NEEDED" );
63 mBuiltinProfiles[
"z_gtiff_2medium" ] =
65 <<
"COMPRESS=PACKBITS" );
66 mBuiltinProfiles[
"z_gtiff_3small" ] =
68 <<
"COMPRESS=DEFLATE PREDICTOR=2 ZLEVEL=9" );
69 mBuiltinProfiles[
"z_gtiff_4jpeg" ] =
71 <<
"COMPRESS=JPEG JPEG_QUALITY=75" );
76 mBuiltinProfiles[
"z__pyramids_gtiff_1big" ] =
78 <<
"COMPRESS_OVERVIEW=NONE BIGTIFF_OVERVIEW=IF_NEEDED" );
79 mBuiltinProfiles[
"z__pyramids_gtiff_2medium" ] =
81 <<
"COMPRESS_OVERVIEW=PACKBITS" );
82 mBuiltinProfiles[
"z__pyramids_gtiff_3small" ] =
84 <<
"COMPRESS_OVERVIEW=DEFLATE PREDICTOR_OVERVIEW=2 ZLEVEL=9" );
85 mBuiltinProfiles[
"z__pyramids_gtiff_4jpeg" ] =
90 connect( mProfileComboBox, SIGNAL( currentIndexChanged(
const QString & ) ),
91 this, SLOT( updateOptions() ) );
92 connect( mOptionsTable, SIGNAL( cellChanged(
int,
int ) ),
this, SLOT( optionsTableChanged() ) );
98 mOptionsLineEdit->installEventFilter(
this );
99 mOptionsStackedWidget->installEventFilter(
this );
120 mProvider = provider;
131 Q_FOREACH (
QWidget* widget, widgets )
133 mOptionsStackedWidget->setVisible(
true );
146 Q_FOREACH (
QWidget* widget, widgets )
149 mProfileButtons->setVisible(
false );
157 QString QgsRasterFormatSaveOptionsWidget::pseudoFormat()
const 159 return mPyramids ?
"_pyramids" : mFormat;
165 QString format = pseudoFormat();
172 if ( ! profileKeys.
contains( profileKey ) && !it.
value().isEmpty() )
175 if ( it.
value()[0] ==
"" || it.
value()[0] == format )
177 profileKeys.
insert( 0, profileKey );
181 qSort( profileKeys );
185 mProfileComboBox->blockSignals(
true );
186 mProfileComboBox->clear();
187 Q_FOREACH (
const QString& profileKey, profileKeys )
189 QString profileName, profileOptions;
190 profileOptions = createOptions( profileKey );
191 if ( mBuiltinProfiles.
contains( profileKey ) )
193 profileName = mBuiltinProfiles[ profileKey ][ 1 ];
194 if ( profileOptions.
isEmpty() )
195 profileOptions = mBuiltinProfiles[ profileKey ][ 2 ];
199 profileName = profileKey;
201 mOptionsMap[ profileKey ] = profileOptions;
202 mProfileComboBox->addItem( profileName, profileKey );
206 mProfileComboBox->blockSignals(
false );
209 mProfileComboBox->setCurrentIndex( mProfileComboBox->findData( mySettings.
value(
210 mProvider +
"/driverOptions/" + format.
toLower() +
"/defaultProfile",
215 void QgsRasterFormatSaveOptionsWidget::updateOptions()
217 QString myOptions = mOptionsMap.
value( currentProfileKey() );
222 if ( mRasterLayer && mRasterLayer->
bandCount() != 3 &&
228 if ( mOptionsStackedWidget->currentIndex() == 0 )
230 mOptionsTable->setRowCount( 0 );
231 for (
int i = 0; i < myOptionsList.
count(); i++ )
234 if ( key_value.
count() == 2 )
236 mOptionsTable->insertRow( i );
244 mOptionsLineEdit->setText( myOptions );
245 mOptionsLineEdit->setCursorPosition( 0 );
264 if ( mProvider ==
"gdal" && mFormat !=
"" && ! mPyramids )
272 if ( helpCreationOptionsFormat )
274 message = helpCreationOptionsFormat( mFormat );
278 message = library->
fileName() +
" does not have helpCreationOptionsFormat";
282 message =
QString(
"cannot load provider library %1" ).
arg( mProvider );
286 message =
tr(
"Cannot get create options for driver %1" ).
arg( mFormat );
288 else if ( mProvider ==
"gdal" && mPyramids )
290 message =
tr(
"For details on pyramids options please see the following pages" );
291 message +=
"\n\nhttp://www.gdal.org/gdaladdo.html\n\nhttp://www.gdal.org/frmt_gtiff.html";
294 message =
tr(
"No help available" );
316 QgsDebugMsg(
QString(
"layer: [%1] file: [%2] format: [%3]" ).arg( mRasterLayer ? mRasterLayer->
id() :
"none", mRasterFileName, mFormat ) );
320 bool tmpLayer =
false;
327 QString defaultProjectionOption = settings.
value(
"/Projections/defaultBehaviour",
"prompt" ).
toString();
328 if ( settings.
value(
"/Projections/defaultBehaviour",
"prompt" ).
toString() ==
"prompt" )
330 settings.
setValue(
"/Projections/defaultBehaviour",
"useProject" );
335 if ( defaultProjectionOption ==
"prompt" )
337 settings.
setValue(
"/Projections/defaultBehaviour", defaultProjectionOption );
341 if ( mProvider ==
"gdal" && mPyramids )
345 QgsDebugMsg(
"calling validate pyramids on layer's data provider" );
350 message =
tr(
"cannot validate pyramid options" );
353 else if ( !createOptions.
isEmpty() && mProvider ==
"gdal" && mFormat !=
"" )
357 QgsDebugMsg(
"calling validate on layer's data provider" );
368 if ( validateCreationOptionsFormat )
370 message = validateCreationOptionsFormat( createOptions, mFormat );
374 message = library->
fileName() +
" does not have validateCreationOptionsFormat";
378 message =
QString(
"cannot load provider library %1" ).
arg( mProvider );
381 else if ( ! createOptions.
isEmpty() )
398 QMessageBox::warning(
this,
"",
tr(
"Invalid %1:\n\n%2\n\nClick on help button to get valid creation options for this format." ).arg( mPyramids ?
tr(
"pyramid creation option" ) :
tr(
"creation option" ), message ), QMessageBox::Close );
408 void QgsRasterFormatSaveOptionsWidget::optionsTableChanged()
412 for (
int i = 0 ; i < mOptionsTable->rowCount(); i++ )
414 key = mOptionsTable->item( i, 0 );
417 value = mOptionsTable->item( i, 1 );
420 options += key->
text() +
'=' + value->
text() +
' ';
423 mOptionsMap[ currentProfileKey()] =
options;
424 mOptionsLineEdit->setText( options );
425 mOptionsLineEdit->setCursorPosition( 0 );
428 void QgsRasterFormatSaveOptionsWidget::on_mOptionsLineEdit_editingFinished()
430 mOptionsMap[ currentProfileKey()] = mOptionsLineEdit->text().trimmed();
433 void QgsRasterFormatSaveOptionsWidget::on_mProfileNewButton_clicked()
438 profileName = profileName.
trimmed();
439 mOptionsMap[ profileName ] =
"";
440 mProfileComboBox->addItem( profileName, profileName );
441 mProfileComboBox->setCurrentIndex( mProfileComboBox->count() - 1 );
445 void QgsRasterFormatSaveOptionsWidget::on_mProfileDeleteButton_clicked()
447 int index = mProfileComboBox->currentIndex();
448 QString profileKey = currentProfileKey();
449 if ( index != -1 && ! mBuiltinProfiles.
contains( profileKey ) )
451 mOptionsMap.
remove( profileKey );
452 mProfileComboBox->removeItem( index );
456 void QgsRasterFormatSaveOptionsWidget::on_mProfileResetButton_clicked()
458 QString profileKey = currentProfileKey();
459 if ( mBuiltinProfiles.
contains( profileKey ) )
461 mOptionsMap[ profileKey ] = mBuiltinProfiles[ profileKey ][ 2 ];
465 mOptionsMap[ profileKey ] =
"";
467 mOptionsLineEdit->setText( mOptionsMap.
value( currentProfileKey() ) );
468 mOptionsLineEdit->setCursorPosition( 0 );
472 void QgsRasterFormatSaveOptionsWidget::optionsTableEnableDeleteButton()
474 mOptionsDeleteButton->setEnabled( mOptionsTable->currentRow() >= 0 );
477 void QgsRasterFormatSaveOptionsWidget::on_mOptionsAddButton_clicked()
479 mOptionsTable->insertRow( mOptionsTable->rowCount() );
481 int newRow = mOptionsTable->rowCount() - 1;
483 mOptionsTable->setItem( newRow, 0, item );
484 mOptionsTable->setCurrentItem( item );
487 void QgsRasterFormatSaveOptionsWidget::on_mOptionsDeleteButton_clicked()
489 if ( mOptionsTable->currentRow() >= 0 )
491 mOptionsTable->removeRow( mOptionsTable->currentRow() );
493 QTableWidgetItem* item = mOptionsTable->item( mOptionsTable->currentRow(), 0 );
494 mOptionsTable->setCurrentItem( item );
495 optionsTableChanged();
500 QString QgsRasterFormatSaveOptionsWidget::settingsKey(
QString profileName )
const 502 if ( profileName !=
"" )
503 profileName =
"/profile_" + profileName;
505 profileName =
"/profile_default" + profileName;
506 return mProvider +
"/driverOptions/" + pseudoFormat().
toLower() + profileName +
"/create";
509 QString QgsRasterFormatSaveOptionsWidget::currentProfileKey()
const 511 return mProfileComboBox->itemData( mProfileComboBox->currentIndex() ).toString();
516 return mOptionsMap.
value( currentProfileKey() ).trimmed().split(
' ', QString::SkipEmptyParts );
519 QString QgsRasterFormatSaveOptionsWidget::createOptions(
const QString& profileName )
const 522 return mySettings.
value( settingsKey( profileName ),
"" ).
toString();
525 void QgsRasterFormatSaveOptionsWidget::deleteCreateOptions(
const QString& profileName )
528 mySettings.
remove( settingsKey( profileName ) );
531 void QgsRasterFormatSaveOptionsWidget::setCreateOptions()
536 while ( i != mOptionsMap.
constEnd() )
538 setCreateOptions( i.
key(), i.
value() );
542 mySettings.
setValue( mProvider +
"/driverOptions/" + pseudoFormat().toLower() +
"/profiles",
544 mySettings.
setValue( mProvider +
"/driverOptions/" + pseudoFormat().toLower() +
"/defaultProfile",
545 currentProfileKey().trimmed() );
548 void QgsRasterFormatSaveOptionsWidget::setCreateOptions(
const QString& profileName,
const QString&
options )
554 void QgsRasterFormatSaveOptionsWidget::setCreateOptions(
const QString& profileName,
const QStringList& list )
556 setCreateOptions( profileName, list.
join(
" " ) );
559 QStringList QgsRasterFormatSaveOptionsWidget::profiles()
const 562 return mySettings.
value( mProvider +
"/driverOptions/" + pseudoFormat().toLower() +
"/profiles",
"" ).
toString().
trimmed().
split(
' ', QString::SkipEmptyParts );
565 void QgsRasterFormatSaveOptionsWidget::swapOptionsUI(
int newIndex )
569 if ( newIndex == -1 )
571 oldIndex = mOptionsStackedWidget->currentIndex();
572 newIndex = ( oldIndex + 1 ) % 2;
576 oldIndex = ( newIndex + 1 ) % 2;
580 mOptionsStackedWidget->setCurrentIndex( newIndex );
581 mOptionsStackedWidget->widget( newIndex )->setSizePolicy(
582 QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
583 mOptionsStackedWidget->widget( oldIndex )->setSizePolicy(
584 QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ) );
590 void QgsRasterFormatSaveOptionsWidget::updateControls()
592 bool valid = mProvider ==
"gdal" && mFormat !=
"";
593 mOptionsValidateButton->setEnabled( valid );
594 mOptionsHelpButton->setEnabled( valid );
600 if ( event->
type() == QEvent::MouseButtonPress )
603 if ( mouseEvent && ( mouseEvent->
button() == Qt::RightButton ) )
605 QMenu* menu =
nullptr;
607 if ( mOptionsStackedWidget->currentIndex() == 0 )
608 text =
tr(
"Use simple interface" );
610 text =
tr(
"Use table interface" );
611 if ( obj->
objectName() ==
"mOptionsLineEdit" )
613 menu = mOptionsLineEdit->createStandardContextMenu();
617 menu =
new QMenu(
this );
620 connect( action, SIGNAL( triggered() ),
this, SLOT( swapOptionsUI() ) );
633 mOptionsTable->horizontalHeader()->resizeSection( 0, mOptionsTable->width() - 115 );
static QgsProviderRegistry * instance(const QString &pluginPath=QString::null)
Means of accessing canonical single instance.
bool contains(const Key &key) const
int bandCount() const
Get the number of bands in this layer.
virtual QString validatePyramidsConfigOptions(QgsRaster::RasterPyramidsFormat pyramidsFormat, const QStringList &theConfigOptions, const QString &fileFormat)
Validates pyramid creation options for a specific dataset and destination format. ...
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QLibrary * providerLibrary(const QString &providerKey) const
const_iterator constBegin() const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
A generic dialog with layout and button box.
QString join(const QString &separator) const
QString tr(const char *sourceText, const char *disambiguation, int n)
QList< T > findChildren(const QString &name) const
void setValue(const QString &key, const QVariant &value)
int count(const T &value) const
const QPoint & globalPos() const
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
const_iterator constEnd() const
virtual bool eventFilter(QObject *watched, QEvent *event)
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, QFlags< Qt::WindowType > flags, QFlags< Qt::InputMethodHint > inputMethodHints)
void remove(const QString &key)
const Key key(const T &value) const
QVariant value(const QString &key, const QVariant &defaultValue) const
void * resolve(const char *symbol)
void insert(int i, const T &value)
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
virtual QString validateCreationOptions(const QStringList &createOptions, const QString &format)
Validates creation options for a specific dataset and destination format.
void(*)() cast_to_fptr(void *p)
QgsRasterDataProvider * dataProvider()
Returns the data provider.
void setReadOnly(bool ro)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setText(const QString &text)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
const T value(const Key &key) const
int remove(const Key &key)