25#include <QListWidgetItem>
29#include "moc_qgsmaplayersavestyledialog.cpp"
40 const QString myLastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
43 connect( mStyleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this, layer](
int ) {
51 updateSaveButtonState();
55 connect( mDbStyleNameEdit, &QLineEdit::textChanged,
this, &QgsMapLayerSaveStyleDialog::updateSaveButtonState );
56 mDbStyleDescriptionEdit->setTabChangesFocus(
true );
57 setTabOrder( mDbStyleNameEdit, mDbStyleDescriptionEdit );
58 setTabOrder( mDbStyleDescriptionEdit, mDbStyleUseAsDefault );
59 mDbStyleUIFileWidget->setDefaultRoot( myLastUsedDir );
60 mDbStyleUIFileWidget->setFilter( tr(
"Qt Designer UI file (*.ui)" ) );
62 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsMapLayerSaveStyleDialog::showHelp );
67 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();
92void QgsMapLayerSaveStyleDialog::invertSelection()
94 for (
int i = 0; i < mModel->
rowCount( QModelIndex() ); i++ )
96 QModelIndex index = mModel->index( i, 0 );
97 Qt::CheckState currentState = Qt::CheckState( mModel->
data( index, Qt::CheckStateRole ).toInt() );
98 Qt::CheckState newState = ( currentState == Qt::Checked ) ? Qt::Unchecked : Qt::Checked;
99 mModel->
setData( index, newState, Qt::CheckStateRole );
103void QgsMapLayerSaveStyleDialog::selectAll()
105 for (
int i = 0; i < mModel->rowCount( QModelIndex() ); i++ )
107 QModelIndex index = mModel->index( i, 0 );
108 mModel->setData( index, Qt::Checked, Qt::CheckStateRole );
112void QgsMapLayerSaveStyleDialog::deselectAll()
114 for (
int i = 0; i < mModel->rowCount( QModelIndex() ); i++ )
116 QModelIndex index = mModel->index( i, 0 );
117 mModel->setData( index, Qt::Unchecked, Qt::CheckStateRole );
121void QgsMapLayerSaveStyleDialog::populateStyleComboBox()
123 mStyleTypeComboBox->clear();
130 if ( mSaveOnlyCurrentStyle )
140void QgsMapLayerSaveStyleDialog::updateSaveButtonState()
143 bool enabled {
false };
149 enabled = !mDbStyleNameEdit->text().isEmpty();
158 enabled = !mFileWidget->filePath().isEmpty();
164 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
170 settings.
name = mDbStyleNameEdit->text();
171 settings.
description = mDbStyleDescriptionEdit->toPlainText();
172 settings.
isDefault = mDbStyleUseAsDefault->isChecked();
179 return mFileWidget->filePath();
184 return mModel->categories();
192void QgsMapLayerSaveStyleDialog::readUiFileContent(
const QString &filePath )
195 mUiFileContent = QString();
197 if ( filePath.isNull() )
202 const QFileInfo myFI( filePath );
203 QFile uiFile( myFI.filePath() );
205 const QString myPath = myFI.path();
206 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
208 if ( uiFile.open( QIODevice::ReadOnly ) )
210 const QString content( uiFile.readAll() );
213 if ( !doc.setContent( content ) || doc.documentElement().tagName().compare( QLatin1String(
"ui" ) ) )
215 QMessageBox::warning(
this, tr(
"Attach UI File" ), tr(
"The selected file does not appear to be a valid Qt Designer UI file." ) );
218 mUiFileContent = content;
222void QgsMapLayerSaveStyleDialog::setupMultipleStyles()
225 if ( !mSaveOnlyCurrentStyle )
227 const QgsMapLayerStyleManager *styleManager { mLayer->styleManager() };
228 const QStringList constStyles = styleManager->
styles();
229 for (
const QString &name : constStyles )
231 QListWidgetItem *item =
new QListWidgetItem( name, mStylesWidget );
232 item->setCheckState( Qt::CheckState::Checked );
236 item->setToolTip( tr(
"Current style" ) );
237 QFont font { item->font() };
238 font.setItalic(
true );
239 item->setFont( font );
241 mStylesWidget->addItem( item );
243 mDbStyleNameEdit->setToolTip( tr(
"Leave blank to use style names or set the base name (an incremental number will be automatically appended)" ) );
247 mDbStyleNameEdit->setToolTip( QString() );
250 mStylesWidget->setVisible( !mSaveOnlyCurrentStyle );
251 mStylesWidgetLabel->setVisible( !mSaveOnlyCurrentStyle );
253 mDbStyleDescriptionEdit->setVisible( mSaveOnlyCurrentStyle );
254 descriptionLabel->setVisible( mSaveOnlyCurrentStyle );
255 mDbStyleUseAsDefault->setVisible( mSaveOnlyCurrentStyle );
257 populateStyleComboBox();
262 return mSaveOnlyCurrentStyle;
270 setupMultipleStyles();
276 return mStylesWidget;
290void QgsMapLayerSaveStyleDialog::showHelp()
292 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 able to display HTML encoded content.
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
int rowCount(const QModelIndex &=QModelIndex()) const override
QString currentStyle() const
Returns name of the current style.
QStringList styles() const
Returns list of all defined style names.
Base class for all map layer types.
QFlags< StyleCategory > StyleCategories
Stores settings for use within QGIS.
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 dataset.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.