QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
30#include "moc_qgsstylesavedialog.cpp"
31
33 : QDialog( parent )
34 , mType( type )
35{
36 setupUi( this );
37
39
40 QStringList defaultTags = QgsStyle::defaultStyle()->tags();
41 defaultTags.sort( Qt::CaseInsensitive );
42 mTags->addItems( defaultTags );
43
44 QList<QgsStyle::StyleEntity> possibleEntities;
45 switch ( type )
46 {
48 this->setWindowTitle( tr( "Save New Symbol" ) );
49 possibleEntities << QgsStyle::SymbolEntity;
50 break;
51
53 this->setWindowTitle( tr( "Save New Color Ramp" ) );
54 possibleEntities << QgsStyle::ColorrampEntity;
55 break;
56
58 this->setWindowTitle( tr( "Save New Text Format" ) );
59 possibleEntities << QgsStyle::TextFormatEntity;
60 break;
61
63 this->setWindowTitle( tr( "Save New Label Settings" ) );
65 break;
66
68 this->setWindowTitle( tr( "Save New Legend Patch Shape" ) );
69 possibleEntities << QgsStyle::LegendPatchShapeEntity;
70 break;
71
73 this->setWindowTitle( tr( "Save New 3D Symbol" ) );
74 possibleEntities << QgsStyle::Symbol3DEntity;
75 break;
76
79 break;
80 }
81
82 QgsProjectStyleDatabaseModel *projectStyleModel = new QgsProjectStyleDatabaseModel( QgsProject::instance()->styleSettings(), this );
83 QgsProjectStyleDatabaseProxyModel *styleProxyModel = new QgsProjectStyleDatabaseProxyModel( projectStyleModel, this );
85
86 if ( styleProxyModel->rowCount( QModelIndex() ) == 0 )
87 {
88 mLabelDestination->hide();
89 mComboBoxDestination->hide();
90 }
91 else
92 {
93 projectStyleModel->setShowDefaultStyle( true );
94 mComboBoxDestination->setModel( styleProxyModel );
95 }
96
97 if ( possibleEntities.size() < 2 )
98 {
99 mLabelSaveAs->hide();
100 mComboSaveAs->hide();
101 }
102 else
103 {
104 for ( QgsStyle::StyleEntity e : std::as_const( possibleEntities ) )
105 {
106 switch ( e )
107 {
109 mComboSaveAs->addItem( tr( "Symbol" ), e );
110 break;
111
113 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "styleicons/color.svg" ) ), tr( "Color Ramp" ), e );
114 break;
115
117 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconFieldText.svg" ) ), tr( "Text Format" ), e );
118 break;
119
121 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingSingle.svg" ) ), tr( "Label Settings" ), e );
122 break;
123
125 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "legend.svg" ) ), tr( "Legend Patch Shape" ), e );
126 break;
127
129 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "3d.svg" ) ), tr( "3D Symbol" ), e );
130 break;
131
134 break;
135 }
136 }
137 mComboSaveAs->setCurrentIndex( 0 );
138 }
139}
140
142{
143 return mName->text();
144}
145
147{
148 mTags->setCurrentText( tags );
149}
150
152{
153 return mTags->currentText();
154}
155
157{
158 return mFavorite->isChecked();
159}
160
162{
163 if ( mComboSaveAs->count() > 0 )
164 return static_cast<QgsStyle::StyleEntity>( mComboSaveAs->currentData().toInt() );
165 else
166 return mType;
167}
168
170{
171 if ( QgsStyle *style = qobject_cast<QgsStyle *>( mComboBoxDestination->model()->data( mComboBoxDestination->model()->index( mComboBoxDestination->currentIndex(), 0, QModelIndex() ), static_cast<int>( QgsProjectStyleDatabaseModel::CustomRole::Style ) ).value<QObject *>() ) )
172 {
173 return style;
174 }
175 else
176 {
177 return QgsStyle::defaultStyle();
178 }
179}
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:221
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:88
QStringList tags() const
Returns a list of all tags in the style database.
StyleEntity
Enum for Entities involved in a style.
Definition qgsstyle.h:204
@ LabelSettingsEntity
Label settings.
Definition qgsstyle.h:210
@ TextFormatEntity
Text formats.
Definition qgsstyle.h:209
@ SmartgroupEntity
Smart groups.
Definition qgsstyle.h:208
@ Symbol3DEntity
3D symbol entity
Definition qgsstyle.h:212
@ SymbolEntity
Symbols.
Definition qgsstyle.h:205
@ TagEntity
Tags.
Definition qgsstyle.h:206
@ ColorrampEntity
Color ramps.
Definition qgsstyle.h:207
@ LegendPatchShapeEntity
Legend patch shape.
Definition qgsstyle.h:211
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:147