16#include <QListWidgetItem>
36 const QString myLastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
39 connect( mStyleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
48 updateSaveButtonState();
52 connect( mDbStyleNameEdit, &QLineEdit::textChanged,
this, &QgsVectorLayerSaveStyleDialog::updateSaveButtonState );
53 mDbStyleDescriptionEdit->setTabChangesFocus(
true );
54 setTabOrder( mDbStyleNameEdit, mDbStyleDescriptionEdit );
55 setTabOrder( mDbStyleDescriptionEdit, mDbStyleUseAsDefault );
56 mDbStyleUIFileWidget->setDefaultRoot( myLastUsedDir );
57 mDbStyleUIFileWidget->setFilter( tr(
"Qt Designer UI file (*.ui)" ) );
59 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveStyleDialog::showHelp );
64 mFileWidget->setDefaultRoot( myLastUsedDir );
68 const QFileInfo tmplFileInfo( path );
69 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), tmplFileInfo.absolutePath() );
75 mModel->setCategories( lastStyleCategories );
76 mStyleCategoriesListView->setModel( mModel );
78 mStyleCategoriesListView->adjustSize();
80 setupMultipleStyles();
84void QgsVectorLayerSaveStyleDialog::populateStyleComboBox()
87 if ( providerName == QLatin1String(
"ogr" ) )
90 if ( providerName == QLatin1String(
"GPKG" ) )
91 providerName = QStringLiteral(
"GeoPackage" );
94 mStyleTypeComboBox->clear();
101 if ( mSaveOnlyCurrentStyle )
111void QgsVectorLayerSaveStyleDialog::updateSaveButtonState()
114 bool enabled {
false };
120 enabled = ! mDbStyleNameEdit->text().isEmpty();
129 enabled = ! mFileWidget->filePath().isEmpty();
135 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
141 settings.
name = mDbStyleNameEdit->text();
142 settings.
description = mDbStyleDescriptionEdit->toPlainText();
143 settings.
isDefault = mDbStyleUseAsDefault->isChecked();
150 return mFileWidget->filePath();
163void QgsVectorLayerSaveStyleDialog::readUiFileContent(
const QString &filePath )
166 mUiFileContent = QString();
168 if ( filePath.isNull() )
173 const QFileInfo myFI( filePath );
174 QFile uiFile( myFI.filePath() );
176 const QString myPath = myFI.path();
177 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
179 if ( uiFile.open( QIODevice::ReadOnly ) )
181 const QString content( uiFile.readAll() );
184 if ( !doc.setContent( content ) || doc.documentElement().tagName().compare( QLatin1String(
"ui" ) ) )
186 QMessageBox::warning(
this, tr(
"Attach UI File" ),
187 tr(
"The selected file does not appear to be a valid Qt Designer UI file." ) );
190 mUiFileContent = content;
194void QgsVectorLayerSaveStyleDialog::setupMultipleStyles()
197 if ( ! mSaveOnlyCurrentStyle )
200 const QStringList constStyles = styleManager->
styles();
201 for (
const QString &name : constStyles )
203 QListWidgetItem *item =
new QListWidgetItem( name, mStylesWidget );
204 item->setCheckState( Qt::CheckState::Checked );
206 if ( name == styleManager->currentStyle() )
208 item->setToolTip( tr(
"Current style" ) );
209 QFont font { item->font() };
210 font.setItalic(
true );
211 item->setFont( font );
213 mStylesWidget->addItem( item );
215 mDbStyleNameEdit->setToolTip( tr(
"Leave blank to use style names or set the base name (an incremental number will be automatically appended)" ) );
219 mDbStyleNameEdit->setToolTip( QString() );
222 mStylesWidget->setVisible( ! mSaveOnlyCurrentStyle );
223 mStylesWidgetLabel->setVisible( ! mSaveOnlyCurrentStyle );
225 mDbStyleDescriptionEdit->setVisible( mSaveOnlyCurrentStyle );
226 descriptionLabel->setVisible( mSaveOnlyCurrentStyle );
227 mDbStyleUseAsDefault->setVisible( mSaveOnlyCurrentStyle );
229 populateStyleComboBox();
234 return mSaveOnlyCurrentStyle;
242 setupMultipleStyles();
248 return mStylesWidget;
253 Qgis::SldExportOptions options;
262void QgsVectorLayerSaveStyleDialog::showHelp()
264 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.
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.
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.
QString providerType() const
Returns the provider type (provider key) for this layer.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
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.
virtual bool isSaveAndLoadStyleToDatabaseSupported() const
It returns false by default.
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
const QListWidget * stylesWidget()
bool saveOnlyCurrentStyle() const
Qgis::SldExportOptions sldExportOptions() const
Returns the SLD export options.
SaveToDbSettings saveToDbSettings() const
void setSaveOnlyCurrentStyle(bool saveCurrentStyle)
QgsVectorLayerSaveStyleDialog(QgsVectorLayer *layer, QWidget *parent=nullptr)
QgsMapLayer::StyleCategories styleCategories() const
QgsVectorLayerProperties::StyleType currentStyleType() const
QString outputFilePath() const
Represents a vector layer which manages a vector based data sets.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.