25#include <QListWidgetItem>
30#include "moc_qgsmaplayersavestyledialog.cpp"
32using namespace Qt::StringLiterals;
43 const QString myLastUsedDir = settings.
value( u
"style/lastStyleDir"_s, QDir::homePath() ).toString();
46 connect( mStyleTypeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this, layer](
int ) {
51 mSaveToSldWidget->setVisible(
56 updateSaveButtonState();
60 connect( mDbStyleNameEdit, &QLineEdit::textChanged,
this, &QgsMapLayerSaveStyleDialog::updateSaveButtonState );
61 mDbStyleDescriptionEdit->setTabChangesFocus(
true );
62 setTabOrder( mDbStyleNameEdit, mDbStyleDescriptionEdit );
63 setTabOrder( mDbStyleDescriptionEdit, mDbStyleUseAsDefault );
64 mDbStyleUIFileWidget->setDefaultRoot( myLastUsedDir );
65 mDbStyleUIFileWidget->setFilter( tr(
"Qt Designer UI file (*.ui)" ) );
67 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsMapLayerSaveStyleDialog::showHelp );
72 mFileWidget->setDefaultRoot( myLastUsedDir );
75 const QFileInfo tmplFileInfo( path );
76 settings.
setValue( u
"style/lastStyleDir"_s, tmplFileInfo.absolutePath() );
82 mModel->setCategories( lastStyleCategories );
83 mStyleCategoriesListView->setModel( mModel );
84 mStyleCategoriesListView->setWordWrap(
true );
88 connect( mSelectAllButton, &QPushButton::clicked,
this, &QgsMapLayerSaveStyleDialog::selectAll );
89 connect( mDeselectAllButton, &QPushButton::clicked,
this, &QgsMapLayerSaveStyleDialog::deselectAll );
90 connect( mInvertSelectionButton, &QPushButton::clicked,
this, &QgsMapLayerSaveStyleDialog::invertSelection );
92 mStyleCategoriesListView->adjustSize();
94 setupMultipleStyles();
97void QgsMapLayerSaveStyleDialog::invertSelection()
99 for (
int i = 0; i < mModel->
rowCount( QModelIndex() ); i++ )
101 QModelIndex index = mModel->index( i, 0 );
102 Qt::CheckState currentState = Qt::CheckState( mModel->
data( index, Qt::CheckStateRole ).toInt() );
103 Qt::CheckState newState = ( currentState == Qt::Checked ) ? Qt::Unchecked : Qt::Checked;
104 mModel->
setData( index, newState, Qt::CheckStateRole );
108void QgsMapLayerSaveStyleDialog::selectAll()
110 for (
int i = 0; i < mModel->rowCount( QModelIndex() ); i++ )
112 QModelIndex index = mModel->index( i, 0 );
113 mModel->setData( index, Qt::Checked, Qt::CheckStateRole );
117void QgsMapLayerSaveStyleDialog::deselectAll()
119 for (
int i = 0; i < mModel->rowCount( QModelIndex() ); i++ )
121 QModelIndex index = mModel->index( i, 0 );
122 mModel->setData( index, Qt::Unchecked, Qt::CheckStateRole );
126void QgsMapLayerSaveStyleDialog::populateStyleComboBox()
128 mStyleTypeComboBox->clear();
135 if ( mSaveOnlyCurrentStyle )
145void QgsMapLayerSaveStyleDialog::updateSaveButtonState()
148 bool enabled {
false };
154 enabled = !mDbStyleNameEdit->text().isEmpty();
163 enabled = !mFileWidget->filePath().isEmpty();
169 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
175 settings.
name = mDbStyleNameEdit->text();
176 settings.
description = mDbStyleDescriptionEdit->toPlainText();
177 settings.
isDefault = mDbStyleUseAsDefault->isChecked();
184 return mFileWidget->filePath();
189 return mModel->categories();
197void QgsMapLayerSaveStyleDialog::readUiFileContent(
const QString &filePath )
200 mUiFileContent = QString();
202 if ( filePath.isNull() )
207 const QFileInfo myFI( filePath );
208 QFile uiFile( myFI.filePath() );
210 const QString myPath = myFI.path();
211 myQSettings.
setValue( u
"style/lastStyleDir"_s, myPath );
213 if ( uiFile.open( QIODevice::ReadOnly ) )
215 const QString content( uiFile.readAll() );
218 if ( !doc.setContent( content ) || doc.documentElement().tagName().compare(
"ui"_L1 ) )
220 QMessageBox::warning(
this, tr(
"Attach UI File" ), tr(
"The selected file does not appear to be a valid Qt Designer UI file." ) );
223 mUiFileContent = content;
227void QgsMapLayerSaveStyleDialog::setupMultipleStyles()
230 if ( !mSaveOnlyCurrentStyle )
232 const QgsMapLayerStyleManager *styleManager { mLayer->styleManager() };
233 const QStringList constStyles = styleManager->
styles();
234 for (
const QString &name : constStyles )
236 QListWidgetItem *item =
new QListWidgetItem( name, mStylesWidget );
237 item->setCheckState( Qt::CheckState::Checked );
241 item->setToolTip( tr(
"Current style" ) );
242 QFont font { item->font() };
243 font.setItalic(
true );
244 item->setFont( font );
246 mStylesWidget->addItem( item );
248 mDbStyleNameEdit->setToolTip( tr(
"Leave blank to use style names or set the base name (an incremental number will be automatically appended)" ) );
252 mDbStyleNameEdit->setToolTip( QString() );
255 mStylesWidget->setVisible( !mSaveOnlyCurrentStyle );
256 mStylesWidgetLabel->setVisible( !mSaveOnlyCurrentStyle );
258 mDbStyleDescriptionEdit->setVisible( mSaveOnlyCurrentStyle );
259 descriptionLabel->setVisible( mSaveOnlyCurrentStyle );
260 mDbStyleUseAsDefault->setVisible( mSaveOnlyCurrentStyle );
262 populateStyleComboBox();
267 return mSaveOnlyCurrentStyle;
275 setupMultipleStyles();
281 return mStylesWidget;
295void QgsMapLayerSaveStyleDialog::showHelp()
297 QgsHelp::openHelp( u
"introduction/general_tools.html#save-and-share-layer-properties"_s );
@ 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.