QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsstylesavedialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolsavedialog.cpp
3  ---------------------------------------
4  begin : November 2016
5  copyright : (C) 2016 by Mathieu Pellerin
6  email : nirvn dot asia at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsstylesavedialog.h"
19 
20 #include "qgis.h"
21 #include "qgsstyle.h"
22 #include "qgsgui.h"
23 #include "qgsapplication.h"
24 #include "qgsproject.h"
26 
27 #include <QLineEdit>
28 #include <QCheckBox>
29 
31  : QDialog( parent )
32  , mType( type )
33 {
34  setupUi( this );
35 
37 
38  QStringList defaultTags = QgsStyle::defaultStyle()->tags();
39  defaultTags.sort( Qt::CaseInsensitive );
40  mTags->addItems( defaultTags );
41 
42  QList< QgsStyle::StyleEntity > possibleEntities;
43  switch ( type )
44  {
46  this->setWindowTitle( tr( "Save New Symbol" ) );
47  possibleEntities << QgsStyle::SymbolEntity;
48  break;
49 
51  this->setWindowTitle( tr( "Save New Color Ramp" ) );
52  possibleEntities << QgsStyle::ColorrampEntity;
53  break;
54 
56  this->setWindowTitle( tr( "Save New Text Format" ) );
57  possibleEntities << QgsStyle::TextFormatEntity;
58  break;
59 
61  this->setWindowTitle( tr( "Save New Label Settings" ) );
63  break;
64 
66  this->setWindowTitle( tr( "Save New Legend Patch Shape" ) );
67  possibleEntities << QgsStyle::LegendPatchShapeEntity;
68  break;
69 
71  this->setWindowTitle( tr( "Save New 3D Symbol" ) );
72  possibleEntities << QgsStyle::Symbol3DEntity;
73  break;
74 
77  break;
78  }
79 
80 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
81  mLabelDestination->hide();
82  mComboBoxDestination->hide();
83 #else
84  QgsProjectStyleDatabaseModel *projectStyleModel = new QgsProjectStyleDatabaseModel( QgsProject::instance()->styleSettings(), this );
85  QgsProjectStyleDatabaseProxyModel *styleProxyModel = new QgsProjectStyleDatabaseProxyModel( projectStyleModel, this );
87 
88  if ( styleProxyModel->rowCount( QModelIndex() ) == 0 )
89  {
90  mLabelDestination->hide();
91  mComboBoxDestination->hide();
92  }
93  else
94  {
95  projectStyleModel->setShowDefaultStyle( true );
96  mComboBoxDestination->setModel( styleProxyModel );
97  }
98 #endif
99 
100  if ( possibleEntities.size() < 2 )
101  {
102  mLabelSaveAs->hide();
103  mComboSaveAs->hide();
104  }
105  else
106  {
107  for ( QgsStyle::StyleEntity e : std::as_const( possibleEntities ) )
108  {
109  switch ( e )
110  {
112  mComboSaveAs->addItem( tr( "Symbol" ), e );
113  break;
114 
116  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "styleicons/color.svg" ) ), tr( "Color Ramp" ), e );
117  break;
118 
120  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconFieldText.svg" ) ), tr( "Text Format" ), e );
121  break;
122 
124  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingSingle.svg" ) ), tr( "Label Settings" ), e );
125  break;
126 
128  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "legend.svg" ) ), tr( "Legend Patch Shape" ), e );
129  break;
130 
132  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "3d.svg" ) ), tr( "3D Symbol" ), e );
133  break;
134 
135  case QgsStyle::TagEntity:
137  break;
138  }
139  }
140  mComboSaveAs->setCurrentIndex( 0 );
141  }
142 }
143 
145 {
146  return mName->text();
147 }
148 
149 void QgsStyleSaveDialog::setDefaultTags( const QString &tags )
150 {
151  mTags->setCurrentText( tags );
152 }
153 
155 {
156  return mTags->currentText();
157 }
158 
160 {
161  return mFavorite->isChecked();
162 }
163 
165 {
166  if ( mComboSaveAs->count() > 0 )
167  return static_cast< QgsStyle::StyleEntity >( mComboSaveAs->currentData().toInt() );
168  else
169  return mType;
170 }
171 
173 {
174 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
175  return QgsStyle::defaultStyle();
176 #else
177  if ( QgsStyle *style = qobject_cast< QgsStyle * >( mComboBoxDestination->model()->data( mComboBoxDestination->model()->index( mComboBoxDestination->currentIndex(), 0, QModelIndex() ), QgsProjectStyleDatabaseModel::StyleRole ).value< QObject * >() ) )
178  {
179  return style;
180  }
181  else
182  {
183  return QgsStyle::defaultStyle();
184  }
185 #endif
186 }
QgsStyle::ColorrampEntity
@ ColorrampEntity
Color ramps.
Definition: qgsstyle.h:182
qgsprojectstylesettings.h
QgsProjectStyleDatabaseModel
List model representing the style databases associated with a QgsProject.
Definition: qgsprojectstylesettings.h:297
QgsStyleSaveDialog::setDefaultTags
void setDefaultTags(const QString &tags)
Sets the default tags for the newly created item.
Definition: qgsstylesavedialog.cpp:149
qgsgui.h
QgsStyleSaveDialog::destinationStyle
QgsStyle * destinationStyle()
Returns the destination style database.
Definition: qgsstylesavedialog.cpp:172
QgsStyleSaveDialog::QgsStyleSaveDialog
QgsStyleSaveDialog(QWidget *parent=nullptr, QgsStyle::StyleEntity type=QgsStyle::SymbolEntity)
Constructor for QgsSymbolSaveDialog.
Definition: qgsstylesavedialog.cpp:30
qgis.h
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsProjectStyleDatabaseProxyModel::Filter::FilterHideReadOnly
@ FilterHideReadOnly
Hide read-only style databases.
QgsStyle::LegendPatchShapeEntity
@ LegendPatchShapeEntity
Legend patch shape (since QGIS 3.14)
Definition: qgsstyle.h:186
qgsstylesavedialog.h
QgsStyle::SymbolEntity
@ SymbolEntity
Symbols.
Definition: qgsstyle.h:180
QgsStyle::TagEntity
@ TagEntity
Tags.
Definition: qgsstyle.h:181
QgsStyle::LabelSettingsEntity
@ LabelSettingsEntity
Label settings.
Definition: qgsstyle.h:185
QgsStyle::defaultStyle
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
qgsapplication.h
QgsGui::enableAutoGeometryRestore
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...
Definition: qgsgui.cpp:180
QgsStyleSaveDialog::name
QString name() const
Returns the entered name for the new symbol.
Definition: qgsstylesavedialog.cpp:144
QgsStyle::Symbol3DEntity
@ Symbol3DEntity
3D symbol entity (since QGIS 3.14)
Definition: qgsstyle.h:187
QgsStyleSaveDialog::selectedType
QgsStyle::StyleEntity selectedType() const
Returns the type of style entity to save.
Definition: qgsstylesavedialog.cpp:164
QgsStyle::tags
QStringList tags() const
Returns a list of all tags in the style database.
Definition: qgsstyle.cpp:1401
QgsStyle::SmartgroupEntity
@ SmartgroupEntity
Smart groups.
Definition: qgsstyle.h:183
QgsStyleSaveDialog::isFavorite
bool isFavorite() const
Returns true if the favorite is checked for the symbol.
Definition: qgsstylesavedialog.cpp:159
QgsStyleSaveDialog::tags
QString tags() const
Returns any tags entered for the new symbol (as a comma separated value list).
Definition: qgsstylesavedialog.cpp:154
qgsstyle.h
QgsProjectStyleDatabaseProxyModel::setFilters
void setFilters(QgsProjectStyleDatabaseProxyModel::Filters filters)
Sets the current filters used for filtering available styles.
Definition: qgsprojectstylesettings.cpp:683
QgsStyle
Definition: qgsstyle.h:159
QgsStyle::TextFormatEntity
@ TextFormatEntity
Text formats.
Definition: qgsstyle.h:184
QgsProjectStyleDatabaseModel::StyleRole
@ StyleRole
Style object.
Definition: qgsprojectstylesettings.h:306
QgsProjectStyleDatabaseProxyModel
A proxy model for filtering QgsProjectStyleDatabaseModel.
Definition: qgsprojectstylesettings.h:369
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition: qgsapplication.cpp:693
QgsProjectStyleDatabaseModel::setShowDefaultStyle
void setShowDefaultStyle(bool show)
Sets whether the default style should also be included in the model.
Definition: qgsprojectstylesettings.cpp:569
qgsproject.h
QgsStyle::StyleEntity
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:178