16#include <QListWidgetItem>
35 const QString myLastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
38 connect( mStyleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
46 updateSaveButtonState();
50 connect( mDbStyleNameEdit, &QLineEdit::textChanged,
this, &QgsVectorLayerSaveStyleDialog::updateSaveButtonState );
51 mDbStyleDescriptionEdit->setTabChangesFocus(
true );
52 setTabOrder( mDbStyleNameEdit, mDbStyleDescriptionEdit );
53 setTabOrder( mDbStyleDescriptionEdit, mDbStyleUseAsDefault );
54 mDbStyleUIFileWidget->setDefaultRoot( myLastUsedDir );
55 mDbStyleUIFileWidget->setFilter( tr(
"Qt Designer UI file (*.ui)" ) );
57 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorLayerSaveStyleDialog::showHelp );
62 mFileWidget->setDefaultRoot( myLastUsedDir );
66 const QFileInfo tmplFileInfo( path );
67 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), tmplFileInfo.absolutePath() );
73 mModel->setCategories( lastStyleCategories );
74 mStyleCategoriesListView->setModel( mModel );
76 mStyleCategoriesListView->adjustSize();
78 setupMultipleStyles();
82void QgsVectorLayerSaveStyleDialog::populateStyleComboBox()
85 if ( providerName == QLatin1String(
"ogr" ) )
88 if ( providerName == QLatin1String(
"GPKG" ) )
89 providerName = QStringLiteral(
"GeoPackage" );
92 mStyleTypeComboBox->clear();
99 if ( mSaveOnlyCurrentStyle )
109void QgsVectorLayerSaveStyleDialog::updateSaveButtonState()
112 bool enabled {
false };
118 enabled = ! mDbStyleNameEdit->text().isEmpty();
127 enabled = ! mFileWidget->filePath().isEmpty();
133 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
139 settings.
name = mDbStyleNameEdit->text();
140 settings.
description = mDbStyleDescriptionEdit->toPlainText();
141 settings.
isDefault = mDbStyleUseAsDefault->isChecked();
148 return mFileWidget->filePath();
161void QgsVectorLayerSaveStyleDialog::readUiFileContent(
const QString &filePath )
164 mUiFileContent = QString();
166 if ( filePath.isNull() )
171 const QFileInfo myFI( filePath );
172 QFile uiFile( myFI.filePath() );
174 const QString myPath = myFI.path();
175 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
177 if ( uiFile.open( QIODevice::ReadOnly ) )
179 const QString content( uiFile.readAll() );
182 if ( !doc.setContent( content ) || doc.documentElement().tagName().compare( QLatin1String(
"ui" ) ) )
184 QMessageBox::warning(
this, tr(
"Attach UI File" ),
185 tr(
"The selected file does not appear to be a valid Qt Designer UI file." ) );
188 mUiFileContent = content;
192void QgsVectorLayerSaveStyleDialog::setupMultipleStyles()
195 if ( ! mSaveOnlyCurrentStyle )
198 const QStringList constStyles = styleManager->
styles();
199 for (
const QString &name : constStyles )
201 QListWidgetItem *item =
new QListWidgetItem( name, mStylesWidget );
202 item->setCheckState( Qt::CheckState::Checked );
204 if ( name == styleManager->currentStyle() )
206 item->setToolTip( tr(
"Current style" ) );
207 QFont font { item->font() };
208 font.setItalic(
true );
209 item->setFont( font );
211 mStylesWidget->addItem( item );
213 mDbStyleNameEdit->setToolTip( tr(
"Leave blank to use style names or set the base name (an incremental number will be automatically appended)" ) );
217 mDbStyleNameEdit->setToolTip( QString() );
220 mStylesWidget->setVisible( ! mSaveOnlyCurrentStyle );
221 mStylesWidgetLabel->setVisible( ! mSaveOnlyCurrentStyle );
223 mDbStyleDescriptionEdit->setVisible( mSaveOnlyCurrentStyle );
224 descriptionLabel->setVisible( mSaveOnlyCurrentStyle );
225 mDbStyleUseAsDefault->setVisible( mSaveOnlyCurrentStyle );
227 populateStyleComboBox();
232 return mSaveOnlyCurrentStyle;
240 setupMultipleStyles();
246 return mStylesWidget;
250void QgsVectorLayerSaveStyleDialog::showHelp()
252 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.