25 #include <QInputDialog>
26 #include <QMessageBox>
28 #include <QMouseEvent>
36 :
QWidget( parent ), mFormat( format ), mProvider( provider ), mRasterLayer( 0 )
37 , mRasterFileName(
QString() ), mPyramids( false )
38 , mPyramidsFormat(
QgsRaster::PyramidsGTiff )
45 if ( mBuiltinProfiles.
isEmpty() )
48 mBuiltinProfiles[
"z_adefault" ] = (
QStringList() <<
"" <<
tr(
"Default" ) <<
"" );
53 mBuiltinProfiles[
"z_gtiff_1big" ] =
55 <<
"COMPRESS=NONE BIGTIFF=IF_NEEDED" );
56 mBuiltinProfiles[
"z_gtiff_2medium" ] =
58 <<
"COMPRESS=PACKBITS" );
59 mBuiltinProfiles[
"z_gtiff_3small" ] =
61 <<
"COMPRESS=DEFLATE PREDICTOR=2 ZLEVEL=9" );
62 mBuiltinProfiles[
"z_gtiff_4jpeg" ] =
64 <<
"COMPRESS=JPEG JPEG_QUALITY=75" );
69 mBuiltinProfiles[
"z__pyramids_gtiff_1big" ] =
71 <<
"COMPRESS_OVERVIEW=NONE BIGTIFF_OVERVIEW=IF_NEEDED" );
72 mBuiltinProfiles[
"z__pyramids_gtiff_2medium" ] =
74 <<
"COMPRESS_OVERVIEW=PACKBITS" );
75 mBuiltinProfiles[
"z__pyramids_gtiff_3small" ] =
77 <<
"COMPRESS_OVERVIEW=DEFLATE PREDICTOR_OVERVIEW=2 ZLEVEL=9" );
78 mBuiltinProfiles[
"z__pyramids_gtiff_4jpeg" ] =
80 <<
"JPEG_QUALITY_OVERVIEW=75 COMPRESS_OVERVIEW=JPEG PHOTOMETRIC_OVERVIEW=YCBCR INTERLEAVE_OVERVIEW=PIXEL" );
83 connect( mProfileComboBox, SIGNAL( currentIndexChanged(
const QString & ) ),
84 this, SLOT( updateOptions() ) );
85 connect( mOptionsTable, SIGNAL( cellChanged(
int,
int ) ),
this, SLOT( optionsTableChanged() ) );
91 mOptionsLineEdit->installEventFilter(
this );
92 mOptionsStackedWidget->installEventFilter(
this );
113 mProvider = provider;
124 Q_FOREACH (
QWidget* widget, widgets )
126 mOptionsStackedWidget->setVisible(
true );
139 Q_FOREACH (
QWidget* widget, widgets )
142 mProfileButtons->setVisible(
false );
153 QString format = mPyramids ?
"_pyramids" : mFormat;
160 if ( ! profileKeys.
contains( profileKey ) && it.
value().count() > 0 )
163 if ( it.
value()[0] ==
"" || it.
value()[0] == format )
165 profileKeys.
insert( 0, profileKey );
169 qSort( profileKeys );
173 mProfileComboBox->blockSignals(
true );
174 mProfileComboBox->clear();
175 Q_FOREACH (
const QString& profileKey, profileKeys )
177 QString profileName, profileOptions;
178 profileOptions = createOptions( profileKey );
179 if ( mBuiltinProfiles.
contains( profileKey ) )
181 profileName = mBuiltinProfiles[ profileKey ][ 1 ];
182 if ( profileOptions.
isEmpty() )
183 profileOptions = mBuiltinProfiles[ profileKey ][ 2 ];
187 profileName = profileKey;
189 mOptionsMap[ profileKey ] = profileOptions;
190 mProfileComboBox->addItem( profileName, profileKey );
194 mProfileComboBox->blockSignals(
false );
197 mProfileComboBox->setCurrentIndex( mProfileComboBox->findData( mySettings.
value(
198 mProvider +
"/driverOptions/" + format.
toLower() +
"/defaultProfile",
203 void QgsRasterFormatSaveOptionsWidget::updateOptions()
205 QString myOptions = mOptionsMap.
value( currentProfileKey() );
208 if ( mOptionsStackedWidget->currentIndex() == 0 )
210 mOptionsTable->setRowCount( 0 );
211 for (
int i = 0; i < myOptionsList.
count(); i++ )
214 if ( key_value.
count() == 2 )
216 mOptionsTable->insertRow( i );
224 mOptionsLineEdit->setText( myOptions );
225 mOptionsLineEdit->setCursorPosition( 0 );
244 if ( mProvider ==
"gdal" && mFormat !=
"" && ! mPyramids )
252 if ( helpCreationOptionsFormat )
254 message = helpCreationOptionsFormat( mFormat );
258 message = library->
fileName() +
" does not have helpCreationOptionsFormat";
262 message =
QString(
"cannot load provider library %1" ).
arg( mProvider );
266 message =
tr(
"Cannot get create options for driver %1" ).
arg( mFormat );
268 else if ( mProvider ==
"gdal" && mPyramids )
270 message =
tr(
"For details on pyramids options please see the following pages" );
271 message +=
"\n\nhttp://www.gdal.org/gdaladdo.html\n\nhttp://www.gdal.org/frmt_gtiff.html";
274 message =
tr(
"No help available" );
296 QgsDebugMsg(
QString(
"layer: [%1] file: [%2] format: [%3]" ).arg( mRasterLayer ? mRasterLayer->
id() :
"none", mRasterFileName, mFormat ) );
300 bool tmpLayer =
false;
307 QString defaultProjectionOption = settings.
value(
"/Projections/defaultBehaviour",
"prompt" ).
toString();
308 if ( settings.
value(
"/Projections/defaultBehaviour",
"prompt" ).
toString() ==
"prompt" )
310 settings.
setValue(
"/Projections/defaultBehaviour",
"useProject" );
315 if ( defaultProjectionOption ==
"prompt" )
317 settings.
setValue(
"/Projections/defaultBehaviour", defaultProjectionOption );
321 if ( mProvider ==
"gdal" && mPyramids )
325 QgsDebugMsg(
"calling validate pyramids on layer's data provider" );
330 message =
tr(
"cannot validate pyramid options" );
333 else if ( !createOptions.
isEmpty() && mProvider ==
"gdal" && mFormat !=
"" )
337 QgsDebugMsg(
"calling validate on layer's data provider" );
348 if ( validateCreationOptionsFormat )
350 message = validateCreationOptionsFormat( createOptions, mFormat );
354 message = library->
fileName() +
" does not have validateCreationOptionsFormat";
358 message =
QString(
"cannot load provider library %1" ).
arg( mProvider );
361 else if ( ! createOptions.
isEmpty() )
378 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 );
388 void QgsRasterFormatSaveOptionsWidget::optionsTableChanged()
392 for (
int i = 0 ; i < mOptionsTable->rowCount(); i++ )
394 key = mOptionsTable->item( i, 0 );
397 value = mOptionsTable->item( i, 1 );
400 options += key->
text() +
"=" + value->
text() +
" ";
403 mOptionsMap[ currentProfileKey()] =
options;
404 mOptionsLineEdit->setText( options );
405 mOptionsLineEdit->setCursorPosition( 0 );
408 void QgsRasterFormatSaveOptionsWidget::on_mOptionsLineEdit_editingFinished()
410 mOptionsMap[ currentProfileKey()] = mOptionsLineEdit->text().trimmed();
413 void QgsRasterFormatSaveOptionsWidget::on_mProfileNewButton_clicked()
418 profileName = profileName.
trimmed();
419 mOptionsMap[ profileName ] =
"";
420 mProfileComboBox->addItem( profileName, profileName );
421 mProfileComboBox->setCurrentIndex( mProfileComboBox->count() - 1 );
425 void QgsRasterFormatSaveOptionsWidget::on_mProfileDeleteButton_clicked()
427 int index = mProfileComboBox->currentIndex();
428 QString profileKey = currentProfileKey();
429 if ( index != -1 && ! mBuiltinProfiles.
contains( profileKey ) )
431 mOptionsMap.
remove( profileKey );
432 mProfileComboBox->removeItem( index );
436 void QgsRasterFormatSaveOptionsWidget::on_mProfileResetButton_clicked()
438 QString profileKey = currentProfileKey();
439 if ( mBuiltinProfiles.
contains( profileKey ) )
441 mOptionsMap[ profileKey ] = mBuiltinProfiles[ profileKey ][ 2 ];
445 mOptionsMap[ profileKey ] =
"";
447 mOptionsLineEdit->setText( mOptionsMap.
value( currentProfileKey() ) );
448 mOptionsLineEdit->setCursorPosition( 0 );
452 void QgsRasterFormatSaveOptionsWidget::optionsTableEnableDeleteButton()
454 mOptionsDeleteButton->setEnabled( mOptionsTable->currentRow() >= 0 );
457 void QgsRasterFormatSaveOptionsWidget::on_mOptionsAddButton_clicked()
459 mOptionsTable->insertRow( mOptionsTable->rowCount() );
461 int newRow = mOptionsTable->rowCount() - 1;
463 mOptionsTable->setItem( newRow, 0, item );
464 mOptionsTable->setCurrentItem( item );
467 void QgsRasterFormatSaveOptionsWidget::on_mOptionsDeleteButton_clicked()
469 if ( mOptionsTable->currentRow() >= 0 )
471 mOptionsTable->removeRow( mOptionsTable->currentRow() );
473 QTableWidgetItem* item = mOptionsTable->item( mOptionsTable->currentRow(), 0 );
474 mOptionsTable->setCurrentItem( item );
475 optionsTableChanged();
480 QString QgsRasterFormatSaveOptionsWidget::settingsKey(
QString profileName )
const
482 if ( profileName !=
"" )
483 profileName =
"/profile_" + profileName;
485 profileName =
"/profile_default" + profileName;
486 return mProvider +
"/driverOptions/" + mFormat.
toLower() + profileName +
"/create";
489 QString QgsRasterFormatSaveOptionsWidget::currentProfileKey()
const
491 return mProfileComboBox->itemData( mProfileComboBox->currentIndex() ).
toString();
496 return mOptionsMap.
value( currentProfileKey() ).trimmed().split(
" ", QString::SkipEmptyParts );
499 QString QgsRasterFormatSaveOptionsWidget::createOptions(
const QString& profileName )
const
502 return mySettings.
value( settingsKey( profileName ),
"" ).
toString();
505 void QgsRasterFormatSaveOptionsWidget::deleteCreateOptions(
const QString& profileName )
508 mySettings.
remove( settingsKey( profileName ) );
511 void QgsRasterFormatSaveOptionsWidget::setCreateOptions()
516 while ( i != mOptionsMap.
end() )
518 setCreateOptions( i.
key(), i.
value() );
522 mySettings.
setValue( mProvider +
"/driverOptions/" + mFormat.
toLower() +
"/profiles",
524 mySettings.
setValue( mProvider +
"/driverOptions/" + mFormat.
toLower() +
"/defaultProfile",
525 currentProfileKey().
trimmed() );
528 void QgsRasterFormatSaveOptionsWidget::setCreateOptions(
const QString& profileName,
const QString& options )
534 void QgsRasterFormatSaveOptionsWidget::setCreateOptions(
const QString& profileName,
const QStringList& list )
536 setCreateOptions( profileName, list.
join(
" " ) );
539 QStringList QgsRasterFormatSaveOptionsWidget::profiles()
const
542 return mySettings.
value( mProvider +
"/driverOptions/" + mFormat.
toLower() +
"/profiles",
"" ).
toString().trimmed().split(
" ", QString::SkipEmptyParts );
545 void QgsRasterFormatSaveOptionsWidget::swapOptionsUI(
int newIndex )
549 if ( newIndex == -1 )
551 oldIndex = mOptionsStackedWidget->currentIndex();
552 newIndex = ( oldIndex + 1 ) % 2;
556 oldIndex = ( newIndex + 1 ) % 2;
560 mOptionsStackedWidget->setCurrentIndex( newIndex );
561 mOptionsStackedWidget->widget( newIndex )->setSizePolicy(
562 QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
563 mOptionsStackedWidget->widget( oldIndex )->setSizePolicy(
564 QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ) );
570 void QgsRasterFormatSaveOptionsWidget::updateControls()
572 bool valid = mProvider ==
"gdal" && mFormat !=
"";
573 mOptionsValidateButton->setEnabled( valid );
574 mOptionsHelpButton->setEnabled( valid );
578 bool QgsRasterFormatSaveOptionsWidget::eventFilter(
QObject *obj,
QEvent *event )
580 if ( event->
type() == QEvent::MouseButtonPress )
583 if ( mouseEvent && ( mouseEvent->
button() == Qt::RightButton ) )
587 if ( mOptionsStackedWidget->currentIndex() == 0 )
588 text =
tr(
"Use simple interface" );
590 text =
tr(
"Use table interface" );
591 if ( obj->
objectName() ==
"mOptionsLineEdit" )
593 menu = mOptionsLineEdit->createStandardContextMenu();
597 menu =
new QMenu(
this );
600 connect( action, SIGNAL( triggered() ),
this, SLOT( swapOptionsUI() ) );
613 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
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
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.
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)
QLibrary * providerLibrary(const QString &providerKey) const
const Key key(const T &value) const
QVariant value(const QString &key, const QVariant &defaultValue) const
QTestData & newRow(const char *dataTag)
void * resolve(const char *symbol)
void insert(int i, const T &value)
virtual QString validateCreationOptions(const QStringList &createOptions, QString format)
Validates creation options for a specific dataset and destination format.
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)
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
char * toString(const QLatin1String &string)
const T value(const Key &key) const
int remove(const Key &key)