29#include "qstackedwidget.h"
35#include <QDesktopServices>
46 mMetadataWidget = widget;
52 if ( !mLayer || !mMetadataWidget )
56 const QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
58 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Load Layer Metadata" ), lastUsedDir,
59 tr(
"QGIS Layer Metadata File" ) +
" (*.qmd)" );
60 if ( fileName.isNull() )
65 bool defaultLoadedFlag =
false;
66 const QString message = mLayer->loadNamedMetadata( fileName, defaultLoadedFlag );
69 if ( defaultLoadedFlag )
71 mMetadataWidget->
setMetadata( &mLayer->metadata() );
76 QMessageBox::warning(
this, tr(
"Load Metadata" ), message );
79 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( fileName ).path() );
86 if ( !mLayer || !mMetadataWidget )
90 const QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
92 QString outputFileName = QFileDialog::getSaveFileName(
this, tr(
"Save Layer Metadata as QMD" ),
93 lastUsedDir, tr(
"QMD File" ) +
" (*.qmd)" );
97 if ( outputFileName.isEmpty() )
110 bool defaultLoadedFlag =
false;
111 const QString message = mLayer->saveNamedMetadata( outputFileName, defaultLoadedFlag );
112 if ( defaultLoadedFlag )
113 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( outputFileName ).absolutePath() );
115 QMessageBox::information(
this, tr(
"Save Metadata" ), message );
122 if ( !mLayer || !mMetadataWidget )
127 bool defaultSavedFlag =
false;
128 const QString infoWindowTitle = QObject::tr(
"Save Default Metadata" );
129 const QString errorMsg = mLayer->saveDefaultMetadata( defaultSavedFlag );
130 if ( !defaultSavedFlag )
132 QMessageBox::warning(
this, infoWindowTitle, errorMsg );
137 QMessageBox::information(
this, infoWindowTitle, tr(
"Metadata saved." ) );
143 if ( !mLayer || !mMetadataWidget )
146 bool defaultLoadedFlag =
false;
147 const QString message = mLayer->loadNamedMetadata( mLayer->metadataUri(), defaultLoadedFlag );
149 if ( defaultLoadedFlag )
151 mMetadataWidget->
setMetadata( &mLayer->metadata() );
155 QMessageBox::information(
this, tr(
"Default Metadata" ), message );
166 const QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
168 QString fileName = QFileDialog::getOpenFileName(
170 tr(
"Load layer properties from style file" ),
172 tr(
"QGIS Layer Style File" ) +
" (*.qml)" );
173 if ( fileName.isEmpty() )
177 if ( !fileName.endsWith( QLatin1String(
".qml" ), Qt::CaseInsensitive ) )
178 fileName += QLatin1String(
".qml" );
182 bool defaultLoadedFlag =
false;
183 const QString message = mLayer->loadNamedStyle( fileName, defaultLoadedFlag );
184 if ( defaultLoadedFlag )
186 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( fileName ).absolutePath() );
191 QMessageBox::information(
this, tr(
"Load Style" ), message );
202 const QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
204 QString outputFileName = QFileDialog::getSaveFileName(
206 tr(
"Save layer properties as style file" ),
208 tr(
"QGIS Layer Style File" ) +
" (*.qml)" );
212 if ( outputFileName.isEmpty() )
221 bool defaultLoadedFlag =
false;
222 const QString message = mLayer->saveNamedStyle( outputFileName, defaultLoadedFlag );
224 if ( defaultLoadedFlag )
226 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( outputFileName ).absolutePath() );
230 QMessageBox::information(
this, tr(
"Save Style" ), message );
243 bool defaultSavedFlag =
false;
249 const QString message = mLayer->saveDefaultStyle( defaultSavedFlag );
251 if ( !defaultSavedFlag )
254 QMessageBox::information(
this,
255 tr(
"Default Style" ),
283 if ( beforePage.isEmpty() )
294 bool defaultLoadedFlag =
false;
301 QMessageBox askToUser;
302 askToUser.setText( tr(
"Load default style from: " ) );
303 askToUser.setIcon( QMessageBox::Question );
304 askToUser.addButton( tr(
"Cancel" ), QMessageBox::RejectRole );
305 askToUser.addButton( tr(
"Local Database" ), QMessageBox::NoRole );
306 askToUser.addButton( tr(
"Datasource Database" ), QMessageBox::YesRole );
308 switch ( askToUser.exec() )
313 msg = mLayer->loadNamedStyle( mLayer->styleURI(), defaultLoadedFlag,
false );
314 if ( !defaultLoadedFlag )
317 QMessageBox::information(
this, tr(
"Default Style" ), msg );
319 if ( msg.compare( tr(
"Loaded from Provider" ) ) )
321 QMessageBox::information(
this, tr(
"Default Style" ),
322 tr(
"No default style was found for this layer." ) );
336 QString myMessage = mLayer->loadNamedStyle( mLayer->styleURI(), defaultLoadedFlag,
true );
339 if ( defaultLoadedFlag )
348 QMessageBox::information(
this, tr(
"Default Style" ), myMessage );
360 QMessageBox askToUser;
361 askToUser.setText( tr(
"Save default style to: " ) );
362 askToUser.setIcon( QMessageBox::Question );
363 askToUser.addButton( tr(
"Cancel" ), QMessageBox::RejectRole );
364 askToUser.addButton( tr(
"Local Database" ), QMessageBox::NoRole );
365 askToUser.addButton( tr(
"Datasource Database" ), QMessageBox::YesRole );
367 switch ( askToUser.exec() )
374 QString errorMessage;
377 if ( QMessageBox::question(
nullptr, QObject::tr(
"Save style in database" ),
378 QObject::tr(
"A matching style already exists in the database for this layer. Do you want to overwrite it?" ),
379 QMessageBox::Yes | QMessageBox::No ) == QMessageBox::No )
384 else if ( !errorMessage.isEmpty() )
386 QMessageBox::warning(
nullptr, QObject::tr(
"Save style in database" ),
391 mLayer->saveStyleToDatabase( QString(), QString(),
true, QString(), errorMsg );
392 if ( errorMsg.isNull() )
408 if ( !mLayer->dataProvider() )
416 bool defaultLoadedFlag =
false;
417 QString errorMessage;
427 errorMessage = mLayer->saveNamedStyle( filePath, defaultLoadedFlag, dlg.
styleCategories() );
431 errorMessage = mLayer->saveSldStyleV2( defaultLoadedFlag, sldContext );
435 if ( defaultLoadedFlag )
442 QMessageBox::information(
this, tr(
"Save Style" ), errorMessage );
449 QString infoWindowTitle = QObject::tr(
"Save style to DB (%1)" ).arg( mLayer->providerType() );
455 if ( QMessageBox::question(
nullptr, QObject::tr(
"Save style in database" ),
456 QObject::tr(
"A matching style already exists in the database for this layer. Do you want to overwrite it?" ),
457 QMessageBox::Yes | QMessageBox::No ) == QMessageBox::No )
462 else if ( !errorMessage.isEmpty() )
464 QMessageBox::warning(
this, infoWindowTitle, errorMessage );
470 if ( !errorMessage.isNull() )
472 QMessageBox::warning(
this, infoWindowTitle, errorMessage );
476 QMessageBox::information(
this, infoWindowTitle, tr(
"Style saved" ) );
482 QString infoWindowTitle = tr(
"Save default style to local database" );
483 errorMessage = mLayer->saveDefaultStyle( defaultLoadedFlag, dlg.
styleCategories() );
484 if ( !defaultLoadedFlag )
486 QMessageBox::warning(
this, infoWindowTitle, errorMessage );
490 QMessageBox::information(
this, infoWindowTitle, tr(
"Style saved" ) );
501 QStringList ids, names, descriptions;
504 int sectionLimit = mLayer->listStylesInDatabase( ids, names, descriptions, errorMsg );
510 mOldStyle = mLayer->styleManager()->style( mLayer->styleManager()->currentStyle() );
513 bool defaultLoadedFlag =
false;
522 errorMsg = mLayer->loadSldStyle( filePath, defaultLoadedFlag );
526 errorMsg = mLayer->loadNamedStyle( filePath, defaultLoadedFlag,
true, categories );
529 if ( defaultLoadedFlag )
537 QMessageBox::warning(
this, tr(
"Load Style" ), errorMsg );
545 QString qmlStyle = mLayer->getStyleFromDatabase( selectedStyleId, errorMsg );
546 if ( !errorMsg.isNull() )
548 QMessageBox::warning(
this, tr(
"Load Styles from Database" ), errorMsg );
552 QDomDocument myDocument( QStringLiteral(
"qgis" ) );
553 myDocument.setContent( qmlStyle );
555 if ( mLayer->importNamedStyle( myDocument, errorMsg, categories ) )
562 QMessageBox::warning(
this, tr(
"Load Styles from Database" ),
563 tr(
"The retrieved style is not a valid named style. Error message: %1" )
570 errorMsg = mLayer->loadNamedStyle( mLayer->styleURI(), defaultLoadedFlag,
true, categories );
572 if ( defaultLoadedFlag )
579 QMessageBox::warning(
this, tr(
"Load Default Style" ), errorMsg );
593 mOldStyle = mLayer->styleManager()->style( mLayer->styleManager()->currentStyle() );
596QString QgsLayerPropertiesDialog::generateDialogTitle()
const
598 QString title = tr(
"Layer Properties - %1" ).arg( mLayer->name() );
600 if ( !mLayer->styleManager()->isDefault( mLayer->styleManager()->currentStyle() ) )
601 title += QStringLiteral(
" (%1)" ).arg( mLayer->styleManager()->currentStyle() );
608 if (
mOldStyle.
xmlData() != mLayer->styleManager()->style( mLayer->styleManager()->currentStyle() ).xmlData() )
612 QDomDocument doc( QStringLiteral(
"qgis" ) );
613 int errorLine, errorColumn;
614 doc.setContent(
mOldStyle.
xmlData(),
false, &message, &errorLine, &errorColumn );
615 mLayer->importNamedStyle( doc, message );
626 const bool isMetadataPanel = ( index ==
mOptStackedWidget->indexOf( mMetadataPage ) );
627 mBtnStyle->setVisible( ! isMetadataPanel );
634 QFileInfo file( url.toLocalFile() );
635 if ( file.exists() && !file.isDir() )
638 QDesktopServices::openUrl( url );
@ NoVendorExtension
No vendor extensions.
Abstract base class for spatial data provider implementations.
virtual Qgis::ProviderStyleStorageCapabilities styleStorageCapabilities() const
Returns the style storage capabilities.
static QString ensureFileNameHasExtension(const QString &fileName, const QStringList &extensions)
Ensures that a fileName ends with an extension from the provided list of extensions.
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
QPushButton * mBtnStyle
Style button.
void saveMetadataToFile()
Allows the user to save the layer's metadata as a file.
virtual void rollback()
Rolls back changes made to the layer.
void optionsStackedWidget_CurrentChanged(int index) override
StyleType
Style storage type.
void saveStyleAsDefault()
Saves the current layer style as the default for the layer.
QList< QgsMapLayerConfigWidget * > mConfigWidgets
Layer config widgets.
void setMetadataWidget(QgsMetadataWidget *widget, QWidget *page)
Sets the metadata widget and page associated with the dialog.
void loadDefaultStyle()
Reloads the default style for the layer.
void saveStyleAs()
Saves a style when appriate button is pressed.
virtual void apply()=0
Applies the dialog settings to the layer.
virtual void syncToLayer()=0
Resets the dialog to the current layer state.
void loadStyle()
Triggers a dialog to load a saved style.
void saveStyleToFile()
Allows the user to save the layer's style to a file.
QgsMapCanvas * mCanvas
Associated map canvas.
void loadDefaultMetadata()
Reloads the default layer metadata for the layer.
void refocusDialog()
Ensures the dialog is focused and activated.
QgsLayerPropertiesDialog(QgsMapLayer *layer, QgsMapCanvas *canvas, const QString &settingsKey, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags(), QgsSettings *settings=nullptr)
Constructor for QgsLayerPropertiesDialog.
void storeCurrentStyleForUndo()
Stores the current layer style so that undo operations can be performed.
QgsMapLayerStyle mOldStyle
Previous layer style.
void loadMetadataFromFile()
Allows the user to load layer metadata from a file.
void saveDefaultStyle()
Saves the default style when appropriate button is pressed.
virtual void addPropertiesPageFactory(const QgsMapLayerConfigWidgetFactory *factory)
Adds properties page from a factory.
void loadStyleFromFile()
Allows the user to load layer style from a file.
QPushButton * mBtnMetadata
Metadata button.
void initialize()
Initialize the dialog.
void saveMetadataAsDefault()
Saves the current layer metadata as the default for the layer.
void openUrl(const QUrl &url)
Handles opening a url from the dialog.
Map canvas is a class for displaying all GIS data types on a canvas.
A reusable dialog which allows users to select stored layer styles and categories to load for a map l...
QgsMapLayer::StyleCategories styleCategories() const
Returns the list of selected style categories the user has opted to load.
void initializeLists(const QStringList &ids, const QStringList &names, const QStringList &descriptions, int sectionLimit)
Initialize list of database stored styles.
QString selectedStyleId()
Returns the ID of the selected database stored style.
QString filePath() const
Returns the full path to the selected layer style source file.
QgsLayerPropertiesDialog::StyleType currentStyleType() const
Returns the selected style type.
The QgsMapLayerSaveStyleDialog class provides the UI to save the current style or multiple styles int...
QString outputFilePath() const
Returns the selected file output path.
Qgis::SldExportOptions sldExportOptions() const
Returns the SLD export options.
SaveToDbSettings saveToDbSettings() const
Returns the database settings for saving the style in the DB.
QgsMapLayer::StyleCategories styleCategories() const
Returns the available style categories.
QgsLayerPropertiesDialog::StyleType currentStyleType() const
Returns the selected style storage type.
QString xmlData() const
Returns XML content of the style.
Base class for all map layer types.
QFlags< StyleCategory > StyleCategories
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
A base dialog for options and properties dialogs that offers vertical tabs.
virtual void optionsStackedWidget_CurrentChanged(int index)
Select relevant tab on current page change.
void addPage(const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QStringList &path=QStringList(), const QString &key=QString())
Adds a new page to the dialog pages.
void restoreOptionsBaseUi(const QString &title=QString())
Restore the base ui.
QStackedWidget * mOptStackedWidget
void insertPage(const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QString &before, const QStringList &path=QStringList(), const QString &key=QString())
Inserts a new page into the dialog pages.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
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.
The QgsSldExportContext class holds SLD export options and other information related to SLD export of...
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH