QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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" ) );
78 break;
79
81 this->setWindowTitle( tr( "Save New Material Settings" ) );
82 possibleEntities << QgsStyle::MaterialSettingsEntity;
83 break;
84
87 break;
88 }
89
90 QgsProjectStyleDatabaseModel *projectStyleModel = new QgsProjectStyleDatabaseModel( QgsProject::instance()->styleSettings(), this );
91 QgsProjectStyleDatabaseProxyModel *styleProxyModel = new QgsProjectStyleDatabaseProxyModel( projectStyleModel, this );
93
94 if ( styleProxyModel->rowCount( QModelIndex() ) == 0 )
95 {
96 mLabelDestination->hide();
97 mComboBoxDestination->hide();
98 }
99 else
100 {
101 projectStyleModel->setShowDefaultStyle( true );
102 mComboBoxDestination->setModel( styleProxyModel );
103 }
104
105 if ( possibleEntities.size() < 2 )
106 {
107 mLabelSaveAs->hide();
108 mComboSaveAs->hide();
109 }
110 else
111 {
112 for ( QgsStyle::StyleEntity e : std::as_const( possibleEntities ) )
113 {
114 switch ( e )
115 {
117 mComboSaveAs->addItem( tr( "Symbol" ), e );
118 break;
119
121 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"styleicons/color.svg"_s ), tr( "Color Ramp" ), e );
122 break;
123
125 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"mIconFieldText.svg"_s ), tr( "Text Format" ), e );
126 break;
127
129 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"labelingSingle.svg"_s ), tr( "Label Settings" ), e );
130 break;
131
133 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"legend.svg"_s ), tr( "Legend Patch Shape" ), e );
134 break;
135
137 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"3d.svg"_s ), tr( "3D Symbol" ), e );
138 break;
139
141 mComboSaveAs->addItem( QgsApplication::getThemeIcon( u"3d.svg"_s ), tr( "Material" ), e );
142 break;
143
146 break;
147 }
148 }
149 mComboSaveAs->setCurrentIndex( 0 );
150 }
151}
152
154{
155 return mName->text();
156}
157
159{
160 mTags->setCurrentText( tags );
161}
162
164{
165 return mTags->currentText();
166}
167
169{
170 return mFavorite->isChecked();
171}
172
174{
175 if ( mComboSaveAs->count() > 0 )
176 return static_cast<QgsStyle::StyleEntity>( mComboSaveAs->currentData().toInt() );
177 else
178 return mType;
179}
180
182{
183 if ( QgsStyle *style = qobject_cast<QgsStyle *>(
184 mComboBoxDestination->model()
185 ->data( mComboBoxDestination->model()->index( mComboBoxDestination->currentIndex(), 0, QModelIndex() ), static_cast<int>( QgsProjectStyleDatabaseModel::CustomRole::Style ) )
186 .value<QObject *>()
187 ) )
188 {
189 return style;
190 }
191 else
192 {
193 return QgsStyle::defaultStyle();
194 }
195}
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:91
QStringList tags() const
Returns a list of all tags in the style database.
StyleEntity
Enum for Entities involved in a style.
Definition qgsstyle.h:206
@ LabelSettingsEntity
Label settings.
Definition qgsstyle.h:212
@ TextFormatEntity
Text formats.
Definition qgsstyle.h:211
@ SmartgroupEntity
Smart groups.
Definition qgsstyle.h:210
@ Symbol3DEntity
3D symbol entity
Definition qgsstyle.h:214
@ SymbolEntity
Symbols.
Definition qgsstyle.h:207
@ TagEntity
Tags.
Definition qgsstyle.h:208
@ ColorrampEntity
Color ramps.
Definition qgsstyle.h:209
@ LegendPatchShapeEntity
Legend patch shape.
Definition qgsstyle.h:213
@ MaterialSettingsEntity
Material settings.
Definition qgsstyle.h:215
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:164