QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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 "qgsapplication.h"
22#include "qgsgui.h"
23#include "qgsproject.h"
25#include "qgsstyle.h"
26
27#include <QCheckBox>
28#include <QLineEdit>
29#include <QString>
30
31#include "moc_qgsstylesavedialog.cpp"
32
33using namespace Qt::StringLiterals;
34
36 : QDialog( parent )
37 , mType( type )
38{
39 setupUi( this );
40
42
43 QStringList defaultTags = QgsStyle::defaultStyle()->tags();
44 defaultTags.sort( Qt::CaseInsensitive );
45 mTags->addItems( defaultTags );
46
47 QList<QgsStyle::StyleEntity> possibleEntities;
48 switch ( type )
49 {
51 this->setWindowTitle( tr( "Save New Symbol" ) );
52 possibleEntities << QgsStyle::SymbolEntity;
53 break;
54
56 this->setWindowTitle( tr( "Save New Color Ramp" ) );
57 possibleEntities << QgsStyle::ColorrampEntity;
58 break;
59
61 this->setWindowTitle( tr( "Save New Text Format" ) );
62 possibleEntities << QgsStyle::TextFormatEntity;
63 break;
64
66 this->setWindowTitle( tr( "Save New Label Settings" ) );
68 break;
69
71 this->setWindowTitle( tr( "Save New Legend Patch Shape" ) );
72 possibleEntities << QgsStyle::LegendPatchShapeEntity;
73 break;
74
76 this->setWindowTitle( tr( "Save New 3D Symbol" ) );
77 possibleEntities << QgsStyle::Symbol3DEntity;
78 break;
79
82 break;
83 }
84
85 QgsProjectStyleDatabaseModel *projectStyleModel = new QgsProjectStyleDatabaseModel( QgsProject::instance()->styleSettings(), this );
86 QgsProjectStyleDatabaseProxyModel *styleProxyModel = new QgsProjectStyleDatabaseProxyModel( projectStyleModel, this );
88
89 if ( styleProxyModel->rowCount( QModelIndex() ) == 0 )
90 {
91 mLabelDestination->hide();
92 mComboBoxDestination->hide();
93 }
94 else
95 {
96 projectStyleModel->setShowDefaultStyle( true );
97 mComboBoxDestination->setModel( styleProxyModel );
98 }
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( u"styleicons/color.svg"_s ), tr( "Color Ramp" ), e );
117 break;
118
120 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"mIconFieldText.svg"_s ), tr( "Text Format" ), e );
121 break;
122
124 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"labelingSingle.svg"_s ), tr( "Label Settings" ), e );
125 break;
126
128 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"legend.svg"_s ), tr( "Legend Patch Shape" ), e );
129 break;
130
132 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"3d.svg"_s ), tr( "3D Symbol" ), e );
133 break;
134
137 break;
138 }
139 }
140 mComboSaveAs->setCurrentIndex( 0 );
141 }
142}
143
145{
146 return mName->text();
147}
148
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 ( QgsStyle *style = qobject_cast<QgsStyle *>( mComboBoxDestination->model()->data( mComboBoxDestination->model()->index( mComboBoxDestination->currentIndex(), 0, QModelIndex() ), static_cast<int>( QgsProjectStyleDatabaseModel::CustomRole::Style ) ).value<QObject *>() ) )
175 {
176 return style;
177 }
178 else
179 {
180 return QgsStyle::defaultStyle();
181 }
182}
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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:224
List model representing the style databases associated with a QgsProject.
void setShowDefaultStyle(bool show)
Sets whether the default style should also be included in the model.
A proxy model for filtering QgsProjectStyleDatabaseModel.
@ FilterHideReadOnly
Hide read-only style databases.
void setFilters(QgsProjectStyleDatabaseProxyModel::Filters filters)
Sets the current filters used for filtering available styles.
static QgsProject * instance()
Returns the QgsProject singleton instance.
bool isFavorite() const
Returns true if the favorite is checked for the symbol.
QString name() const
Returns the entered name for the new symbol.
QgsStyle::StyleEntity selectedType() const
Returns the type of style entity to save.
void setDefaultTags(const QString &tags)
Sets the default tags for the newly created item.
QgsStyleSaveDialog(QWidget *parent=nullptr, QgsStyle::StyleEntity type=QgsStyle::SymbolEntity)
Constructor for QgsSymbolSaveDialog.
QString tags() const
Returns any tags entered for the new symbol (as a comma separated value list).
QgsStyle * destinationStyle()
Returns the destination style database.
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition qgsstyle.h:89
QStringList tags() const
Returns a list of all tags in the style database.
StyleEntity
Enum for Entities involved in a style.
Definition qgsstyle.h:205
@ LabelSettingsEntity
Label settings.
Definition qgsstyle.h:211
@ TextFormatEntity
Text formats.
Definition qgsstyle.h:210
@ SmartgroupEntity
Smart groups.
Definition qgsstyle.h:209
@ Symbol3DEntity
3D symbol entity
Definition qgsstyle.h:213
@ SymbolEntity
Symbols.
Definition qgsstyle.h:206
@ TagEntity
Tags.
Definition qgsstyle.h:207
@ ColorrampEntity
Color ramps.
Definition qgsstyle.h:208
@ LegendPatchShapeEntity
Legend patch shape.
Definition qgsstyle.h:212
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:150