16 #include <QListWidgetItem>
17 #include <QMessageBox>
36 if ( providerName == QLatin1String(
"ogr" ) )
39 if ( providerName == QLatin1String(
"GPKG" ) )
40 providerName = QStringLiteral(
"GeoPackage" );
43 const QString myLastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
46 connect( mStyleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
53 updateSaveButtonState();
61 connect( mDbStyleNameEdit, &QLineEdit::textChanged,
this, &QgsVectorLayerSaveStyleDialog::updateSaveButtonState );
62 mDbStyleDescriptionEdit->setTabChangesFocus(
true );
63 setTabOrder( mDbStyleNameEdit, mDbStyleDescriptionEdit );
64 setTabOrder( mDbStyleDescriptionEdit, mDbStyleUseAsDefault );
65 mDbStyleUIFileWidget->setDefaultRoot( myLastUsedDir );
66 mDbStyleUIFileWidget->setFilter( tr(
"Qt Designer UI file (*.ui)" ) );
68 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveStyleDialog::showHelp );
73 mFileWidget->setDefaultRoot( myLastUsedDir );
77 const QFileInfo tmplFileInfo( path );
78 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), tmplFileInfo.absolutePath() );
84 mModel->setCategories( lastStyleCategories );
85 mStyleCategoriesListView->setModel( mModel );
87 mStyleCategoriesListView->adjustSize();
89 setupMultipleStyles();
99 void QgsVectorLayerSaveStyleDialog::updateSaveButtonState()
102 bool enabled {
false };
108 enabled = ! mDbStyleNameEdit->text().isEmpty();
117 enabled = ! mFileWidget->filePath().isEmpty();
120 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
126 settings.
name = mDbStyleNameEdit->text();
127 settings.
description = mDbStyleDescriptionEdit->toPlainText();
128 settings.
isDefault = mDbStyleUseAsDefault->isChecked();
135 return mFileWidget->filePath();
148 void QgsVectorLayerSaveStyleDialog::readUiFileContent(
const QString &filePath )
151 mUiFileContent = QString();
153 if ( filePath.isNull() )
158 const QFileInfo myFI( filePath );
159 QFile uiFile( myFI.filePath() );
161 const QString myPath = myFI.path();
162 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
164 if ( uiFile.open( QIODevice::ReadOnly ) )
166 const QString content( uiFile.readAll() );
169 if ( !doc.setContent( content ) || doc.documentElement().tagName().compare( QLatin1String(
"ui" ) ) )
171 QMessageBox::warning(
this, tr(
"Attach UI File" ),
172 tr(
"The selected file does not appear to be a valid Qt Designer UI file." ) );
175 mUiFileContent = content;
179 void QgsVectorLayerSaveStyleDialog::setupMultipleStyles()
182 if ( ! mSaveOnlyCurrentStyle )
185 const QStringList constStyles = styleManager->
styles();
186 for (
const QString &name : constStyles )
188 QListWidgetItem *item =
new QListWidgetItem( name, mStylesWidget );
189 item->setCheckState( Qt::CheckState::Checked );
191 if ( name == styleManager->currentStyle() )
193 item->setToolTip( tr(
"Current style" ) );
194 QFont font { item->font() };
195 font.setItalic(
true );
196 item->setFont( font );
198 mStylesWidget->addItem( item );
200 mDbStyleNameEdit->setToolTip( tr(
"Leave blank to use style names or set the base name (an incremental number will be automatically appended)" ) );
204 mDbStyleNameEdit->setToolTip( QString() );
207 mStylesWidget->setVisible( ! mSaveOnlyCurrentStyle );
208 mStylesWidgetLabel->setVisible( ! mSaveOnlyCurrentStyle );
210 mDbStyleDescriptionEdit->setVisible( mSaveOnlyCurrentStyle );
211 descriptionLabel->setVisible( mSaveOnlyCurrentStyle );
212 mDbStyleUseAsDefault->setVisible( mSaveOnlyCurrentStyle );
217 return mSaveOnlyCurrentStyle;
225 setupMultipleStyles();
231 return mStylesWidget;
235 void QgsVectorLayerSaveStyleDialog::showHelp()
237 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#save-and-share-layer-properties" ) );
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
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.