16#include <QListWidgetItem>
21#include "moc_qgsmaplayersavestyledialog.cpp"
38 const QString myLastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
41 connect( mStyleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
50 updateSaveButtonState();
54 connect( mDbStyleNameEdit, &QLineEdit::textChanged,
this, &QgsMapLayerSaveStyleDialog::updateSaveButtonState );
55 mDbStyleDescriptionEdit->setTabChangesFocus(
true );
56 setTabOrder( mDbStyleNameEdit, mDbStyleDescriptionEdit );
57 setTabOrder( mDbStyleDescriptionEdit, mDbStyleUseAsDefault );
58 mDbStyleUIFileWidget->setDefaultRoot( myLastUsedDir );
59 mDbStyleUIFileWidget->setFilter( tr(
"Qt Designer UI file (*.ui)" ) );
61 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsMapLayerSaveStyleDialog::showHelp );
66 mFileWidget->setDefaultRoot( myLastUsedDir );
70 const QFileInfo tmplFileInfo( path );
71 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), tmplFileInfo.absolutePath() );
77 mModel->setCategories( lastStyleCategories );
78 mStyleCategoriesListView->setModel( mModel );
79 mStyleCategoriesListView->setWordWrap(
true );
83 connect( mSelectAllButton, &QPushButton::clicked,
this, &QgsMapLayerSaveStyleDialog::selectAll );
84 connect( mDeselectAllButton, &QPushButton::clicked,
this, &QgsMapLayerSaveStyleDialog::deselectAll );
85 connect( mInvertSelectionButton, &QPushButton::clicked,
this, &QgsMapLayerSaveStyleDialog::invertSelection );
87 mStyleCategoriesListView->adjustSize();
89 setupMultipleStyles();
93void QgsMapLayerSaveStyleDialog::invertSelection()
95 for (
int i = 0; i < mModel->
rowCount( QModelIndex() ); i++ )
97 QModelIndex index = mModel->index( i, 0 );
98 Qt::CheckState currentState = Qt::CheckState( mModel->
data( index, Qt::CheckStateRole ).toInt() );
99 Qt::CheckState newState = ( currentState == Qt::Checked ) ? Qt::Unchecked : Qt::Checked;
100 mModel->
setData( index, newState, Qt::CheckStateRole );
104void QgsMapLayerSaveStyleDialog::selectAll()
106 for (
int i = 0; i < mModel->
rowCount( QModelIndex() ); i++ )
108 QModelIndex index = mModel->index( i, 0 );
109 mModel->
setData( index, Qt::Checked, Qt::CheckStateRole );
113void QgsMapLayerSaveStyleDialog::deselectAll()
115 for (
int i = 0; i < mModel->
rowCount( QModelIndex() ); i++ )
117 QModelIndex index = mModel->index( i, 0 );
118 mModel->
setData( index, Qt::Unchecked, Qt::CheckStateRole );
122void QgsMapLayerSaveStyleDialog::populateStyleComboBox()
124 mStyleTypeComboBox->clear();
131 if ( mSaveOnlyCurrentStyle )
141void QgsMapLayerSaveStyleDialog::updateSaveButtonState()
144 bool enabled {
false };
150 enabled = ! mDbStyleNameEdit->text().isEmpty();
159 enabled = ! mFileWidget->filePath().isEmpty();
165 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
171 settings.
name = mDbStyleNameEdit->text();
172 settings.
description = mDbStyleDescriptionEdit->toPlainText();
173 settings.
isDefault = mDbStyleUseAsDefault->isChecked();
180 return mFileWidget->filePath();
193void QgsMapLayerSaveStyleDialog::readUiFileContent(
const QString &filePath )
196 mUiFileContent = QString();
198 if ( filePath.isNull() )
203 const QFileInfo myFI( filePath );
204 QFile uiFile( myFI.filePath() );
206 const QString myPath = myFI.path();
207 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
209 if ( uiFile.open( QIODevice::ReadOnly ) )
211 const QString content( uiFile.readAll() );
214 if ( !doc.setContent( content ) || doc.documentElement().tagName().compare( QLatin1String(
"ui" ) ) )
216 QMessageBox::warning(
this, tr(
"Attach UI File" ),
217 tr(
"The selected file does not appear to be a valid Qt Designer UI file." ) );
220 mUiFileContent = content;
224void QgsMapLayerSaveStyleDialog::setupMultipleStyles()
227 if ( ! mSaveOnlyCurrentStyle )
230 const QStringList constStyles = styleManager->
styles();
231 for (
const QString &name : constStyles )
233 QListWidgetItem *item =
new QListWidgetItem( name, mStylesWidget );
234 item->setCheckState( Qt::CheckState::Checked );
236 if ( name == styleManager->currentStyle() )
238 item->setToolTip( tr(
"Current style" ) );
239 QFont font { item->font() };
240 font.setItalic(
true );
241 item->setFont( font );
243 mStylesWidget->addItem( item );
245 mDbStyleNameEdit->setToolTip( tr(
"Leave blank to use style names or set the base name (an incremental number will be automatically appended)" ) );
249 mDbStyleNameEdit->setToolTip( QString() );
252 mStylesWidget->setVisible( ! mSaveOnlyCurrentStyle );
253 mStylesWidgetLabel->setVisible( ! mSaveOnlyCurrentStyle );
255 mDbStyleDescriptionEdit->setVisible( mSaveOnlyCurrentStyle );
256 descriptionLabel->setVisible( mSaveOnlyCurrentStyle );
257 mDbStyleUseAsDefault->setVisible( mSaveOnlyCurrentStyle );
259 populateStyleComboBox();
264 return mSaveOnlyCurrentStyle;
272 setupMultipleStyles();
278 return mStylesWidget;
292void QgsMapLayerSaveStyleDialog::showHelp()
294 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.
QFlags< SldExportOption > SldExportOptions
A label delegate being able to display html encoded content.
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.
QVariant data(const QModelIndex &index, int role) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
QgsMapLayer::StyleCategories categories() const
Returns the categories as defined in the model.
int rowCount(const QModelIndex &=QModelIndex()) const override
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.
QFlags< StyleCategory > StyleCategories
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.