16#include <QListWidgetItem>
37 const QString myLastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
40 connect( mStyleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
49 updateSaveButtonState();
53 connect( mDbStyleNameEdit, &QLineEdit::textChanged,
this, &QgsMapLayerSaveStyleDialog::updateSaveButtonState );
54 mDbStyleDescriptionEdit->setTabChangesFocus(
true );
55 setTabOrder( mDbStyleNameEdit, mDbStyleDescriptionEdit );
56 setTabOrder( mDbStyleDescriptionEdit, mDbStyleUseAsDefault );
57 mDbStyleUIFileWidget->setDefaultRoot( myLastUsedDir );
58 mDbStyleUIFileWidget->setFilter( tr(
"Qt Designer UI file (*.ui)" ) );
60 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsMapLayerSaveStyleDialog::showHelp );
65 mFileWidget->setDefaultRoot( myLastUsedDir );
69 const QFileInfo tmplFileInfo( path );
70 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), tmplFileInfo.absolutePath() );
76 mModel->setCategories( lastStyleCategories );
77 mStyleCategoriesListView->setModel( mModel );
79 mStyleCategoriesListView->adjustSize();
81 setupMultipleStyles();
85void QgsMapLayerSaveStyleDialog::populateStyleComboBox()
87 mStyleTypeComboBox->clear();
94 if ( mSaveOnlyCurrentStyle )
104void QgsMapLayerSaveStyleDialog::updateSaveButtonState()
107 bool enabled {
false };
113 enabled = ! mDbStyleNameEdit->text().isEmpty();
122 enabled = ! mFileWidget->filePath().isEmpty();
128 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
134 settings.
name = mDbStyleNameEdit->text();
135 settings.
description = mDbStyleDescriptionEdit->toPlainText();
136 settings.
isDefault = mDbStyleUseAsDefault->isChecked();
143 return mFileWidget->filePath();
156void QgsMapLayerSaveStyleDialog::readUiFileContent(
const QString &filePath )
159 mUiFileContent = QString();
161 if ( filePath.isNull() )
166 const QFileInfo myFI( filePath );
167 QFile uiFile( myFI.filePath() );
169 const QString myPath = myFI.path();
170 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
172 if ( uiFile.open( QIODevice::ReadOnly ) )
174 const QString content( uiFile.readAll() );
177 if ( !doc.setContent( content ) || doc.documentElement().tagName().compare( QLatin1String(
"ui" ) ) )
179 QMessageBox::warning(
this, tr(
"Attach UI File" ),
180 tr(
"The selected file does not appear to be a valid Qt Designer UI file." ) );
183 mUiFileContent = content;
187void QgsMapLayerSaveStyleDialog::setupMultipleStyles()
190 if ( ! mSaveOnlyCurrentStyle )
193 const QStringList constStyles = styleManager->
styles();
194 for (
const QString &name : constStyles )
196 QListWidgetItem *item =
new QListWidgetItem( name, mStylesWidget );
197 item->setCheckState( Qt::CheckState::Checked );
199 if ( name == styleManager->currentStyle() )
201 item->setToolTip( tr(
"Current style" ) );
202 QFont font { item->font() };
203 font.setItalic(
true );
204 item->setFont( font );
206 mStylesWidget->addItem( item );
208 mDbStyleNameEdit->setToolTip( tr(
"Leave blank to use style names or set the base name (an incremental number will be automatically appended)" ) );
212 mDbStyleNameEdit->setToolTip( QString() );
215 mStylesWidget->setVisible( ! mSaveOnlyCurrentStyle );
216 mStylesWidgetLabel->setVisible( ! mSaveOnlyCurrentStyle );
218 mDbStyleDescriptionEdit->setVisible( mSaveOnlyCurrentStyle );
219 descriptionLabel->setVisible( mSaveOnlyCurrentStyle );
220 mDbStyleUseAsDefault->setVisible( mSaveOnlyCurrentStyle );
222 populateStyleComboBox();
227 return mSaveOnlyCurrentStyle;
235 setupMultipleStyles();
241 return mStylesWidget;
246 Qgis::SldExportOptions options;
255void QgsMapLayerSaveStyleDialog::showHelp()
257 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#save-and-share-layer-properties" ) );
@ Png
Export complex styles to separate PNG files for better compatibility with OGC servers.
virtual Qgis::ProviderStyleStorageCapabilities styleStorageCapabilities() const
Returns the style storage capabilities.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
StyleType
Style storage type.
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.
void setSaveOnlyCurrentStyle(bool saveCurrentStyle)
Sets whether the user only allowed to save the current style.
bool saveOnlyCurrentStyle() const
Returns whether the user only allowed to save the current style.
QgsMapLayer::StyleCategories styleCategories() const
Returns the available style categories.
QgsLayerPropertiesDialog::StyleType currentStyleType() const
Returns the selected style storage type.
QgsMapLayerSaveStyleDialog(QgsMapLayer *layer, QWidget *parent=nullptr)
Constructor.
const QListWidget * stylesWidget()
Returns the styles list widget.
Model for layer style categories.
QgsMapLayer::StyleCategories categories() const
Returns the categories as defined in the model.
Management of styles for use with one map layer.
QStringList styles() const
Returns list of all defined style names.
Base class for all map layer types.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
This class is a composition of two QSettings instances:
T flagValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on a flag.
void setFlagValue(const QString &key, const T &value, const Section section=NoSection)
Set the value of a setting based on a flag.
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.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.