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 ) {
49 updateSaveButtonState();
53 connect( mDbStyleNameEdit, &QLineEdit::textChanged,
this, &QgsMapLayerSaveStyleDialog::updateSaveButtonState );
54 mDbStyleDescriptionEdit->setTabChangesFocus(
true );
55 setTabOrder( mDbStyleNameEdit, mDbStyleDescriptionEdit );
56 setTabOrder( mDbStyleDescriptionEdit, mDbStyleUseAsDefault );
57 mDbStyleUIFileWidget->setDefaultRoot( myLastUsedDir );
58 mDbStyleUIFileWidget->setFilter( tr(
"Qt Designer UI file (*.ui)" ) );
60 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsMapLayerSaveStyleDialog::showHelp );
65 mFileWidget->setDefaultRoot( myLastUsedDir );
68 const QFileInfo tmplFileInfo( path );
69 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), tmplFileInfo.absolutePath() );
75 mModel->setCategories( lastStyleCategories );
76 mStyleCategoriesListView->setModel( mModel );
77 mStyleCategoriesListView->setWordWrap(
true );
81 connect( mSelectAllButton, &QPushButton::clicked,
this, &QgsMapLayerSaveStyleDialog::selectAll );
82 connect( mDeselectAllButton, &QPushButton::clicked,
this, &QgsMapLayerSaveStyleDialog::deselectAll );
83 connect( mInvertSelectionButton, &QPushButton::clicked,
this, &QgsMapLayerSaveStyleDialog::invertSelection );
85 mStyleCategoriesListView->adjustSize();
87 setupMultipleStyles();
90void QgsMapLayerSaveStyleDialog::invertSelection()
92 for (
int i = 0; i < mModel->
rowCount( QModelIndex() ); i++ )
94 QModelIndex index = mModel->index( i, 0 );
95 Qt::CheckState currentState = Qt::CheckState( mModel->
data( index, Qt::CheckStateRole ).toInt() );
96 Qt::CheckState newState = ( currentState == Qt::Checked ) ? Qt::Unchecked : Qt::Checked;
97 mModel->
setData( index, newState, Qt::CheckStateRole );
101void QgsMapLayerSaveStyleDialog::selectAll()
103 for (
int i = 0; i < mModel->
rowCount( QModelIndex() ); i++ )
105 QModelIndex index = mModel->index( i, 0 );
106 mModel->
setData( index, Qt::Checked, Qt::CheckStateRole );
110void QgsMapLayerSaveStyleDialog::deselectAll()
112 for (
int i = 0; i < mModel->
rowCount( QModelIndex() ); i++ )
114 QModelIndex index = mModel->index( i, 0 );
115 mModel->
setData( index, Qt::Unchecked, Qt::CheckStateRole );
119void QgsMapLayerSaveStyleDialog::populateStyleComboBox()
121 mStyleTypeComboBox->clear();
128 if ( mSaveOnlyCurrentStyle )
138void QgsMapLayerSaveStyleDialog::updateSaveButtonState()
141 bool enabled {
false };
147 enabled = !mDbStyleNameEdit->text().isEmpty();
156 enabled = !mFileWidget->filePath().isEmpty();
162 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
168 settings.
name = mDbStyleNameEdit->text();
169 settings.
description = mDbStyleDescriptionEdit->toPlainText();
170 settings.
isDefault = mDbStyleUseAsDefault->isChecked();
177 return mFileWidget->filePath();
190void QgsMapLayerSaveStyleDialog::readUiFileContent(
const QString &filePath )
193 mUiFileContent = QString();
195 if ( filePath.isNull() )
200 const QFileInfo myFI( filePath );
201 QFile uiFile( myFI.filePath() );
203 const QString myPath = myFI.path();
204 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
206 if ( uiFile.open( QIODevice::ReadOnly ) )
208 const QString content( uiFile.readAll() );
211 if ( !doc.setContent( content ) || doc.documentElement().tagName().compare( QLatin1String(
"ui" ) ) )
213 QMessageBox::warning(
this, tr(
"Attach UI File" ), tr(
"The selected file does not appear to be a valid Qt Designer UI file." ) );
216 mUiFileContent = content;
220void QgsMapLayerSaveStyleDialog::setupMultipleStyles()
223 if ( !mSaveOnlyCurrentStyle )
226 const QStringList constStyles = styleManager->
styles();
227 for (
const QString &name : constStyles )
229 QListWidgetItem *item =
new QListWidgetItem( name, mStylesWidget );
230 item->setCheckState( Qt::CheckState::Checked );
232 if ( name == styleManager->currentStyle() )
234 item->setToolTip( tr(
"Current style" ) );
235 QFont font { item->font() };
236 font.setItalic(
true );
237 item->setFont( font );
239 mStylesWidget->addItem( item );
241 mDbStyleNameEdit->setToolTip( tr(
"Leave blank to use style names or set the base name (an incremental number will be automatically appended)" ) );
245 mDbStyleNameEdit->setToolTip( QString() );
248 mStylesWidget->setVisible( !mSaveOnlyCurrentStyle );
249 mStylesWidgetLabel->setVisible( !mSaveOnlyCurrentStyle );
251 mDbStyleDescriptionEdit->setVisible( mSaveOnlyCurrentStyle );
252 descriptionLabel->setVisible( mSaveOnlyCurrentStyle );
253 mDbStyleUseAsDefault->setVisible( mSaveOnlyCurrentStyle );
255 populateStyleComboBox();
260 return mSaveOnlyCurrentStyle;
268 setupMultipleStyles();
274 return mStylesWidget;
288void QgsMapLayerSaveStyleDialog::showHelp()
290 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.