QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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#include "moc_qgsstylesavedialog.cpp"
20
21#include "qgis.h"
22#include "qgsstyle.h"
23#include "qgsgui.h"
24#include "qgsapplication.h"
25#include "qgsproject.h"
27
28#include <QLineEdit>
29#include <QCheckBox>
30
32 : QDialog( parent )
33 , mType( type )
34{
35 setupUi( this );
36
38
39 QStringList defaultTags = QgsStyle::defaultStyle()->tags();
40 defaultTags.sort( Qt::CaseInsensitive );
41 mTags->addItems( defaultTags );
42
43 QList< QgsStyle::StyleEntity > possibleEntities;
44 switch ( type )
45 {
47 this->setWindowTitle( tr( "Save New Symbol" ) );
48 possibleEntities << QgsStyle::SymbolEntity;
49 break;
50
52 this->setWindowTitle( tr( "Save New Color Ramp" ) );
53 possibleEntities << QgsStyle::ColorrampEntity;
54 break;
55
57 this->setWindowTitle( tr( "Save New Text Format" ) );
58 possibleEntities << QgsStyle::TextFormatEntity;
59 break;
60
62 this->setWindowTitle( tr( "Save New Label Settings" ) );
64 break;
65
67 this->setWindowTitle( tr( "Save New Legend Patch Shape" ) );
68 possibleEntities << QgsStyle::LegendPatchShapeEntity;
69 break;
70
72 this->setWindowTitle( tr( "Save New 3D Symbol" ) );
73 possibleEntities << QgsStyle::Symbol3DEntity;
74 break;
75
78 break;
79 }
80
81 QgsProjectStyleDatabaseModel *projectStyleModel = new QgsProjectStyleDatabaseModel( QgsProject::instance()->styleSettings(), this );
82 QgsProjectStyleDatabaseProxyModel *styleProxyModel = new QgsProjectStyleDatabaseProxyModel( projectStyleModel, this );
84
85 if ( styleProxyModel->rowCount( QModelIndex() ) == 0 )
86 {
87 mLabelDestination->hide();
88 mComboBoxDestination->hide();
89 }
90 else
91 {
92 projectStyleModel->setShowDefaultStyle( true );
93 mComboBoxDestination->setModel( styleProxyModel );
94 }
95
96 if ( possibleEntities.size() < 2 )
97 {
98 mLabelSaveAs->hide();
99 mComboSaveAs->hide();
100 }
101 else
102 {
103 for ( QgsStyle::StyleEntity e : std::as_const( possibleEntities ) )
104 {
105 switch ( e )
106 {
108 mComboSaveAs->addItem( tr( "Symbol" ), e );
109 break;
110
112 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "styleicons/color.svg" ) ), tr( "Color Ramp" ), e );
113 break;
114
116 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconFieldText.svg" ) ), tr( "Text Format" ), e );
117 break;
118
120 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingSingle.svg" ) ), tr( "Label Settings" ), e );
121 break;
122
124 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "legend.svg" ) ), tr( "Legend Patch Shape" ), e );
125 break;
126
128 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "3d.svg" ) ), tr( "3D Symbol" ), e );
129 break;
130
133 break;
134 }
135 }
136 mComboSaveAs->setCurrentIndex( 0 );
137 }
138}
139
141{
142 return mName->text();
143}
144
145void QgsStyleSaveDialog::setDefaultTags( const QString &tags )
146{
147 mTags->setCurrentText( tags );
148}
149
151{
152 return mTags->currentText();
153}
154
156{
157 return mFavorite->isChecked();
158}
159
161{
162 if ( mComboSaveAs->count() > 0 )
163 return static_cast< QgsStyle::StyleEntity >( mComboSaveAs->currentData().toInt() );
164 else
165 return mType;
166}
167
169{
170 if ( QgsStyle *style = qobject_cast< QgsStyle * >( mComboBoxDestination->model()->data( mComboBoxDestination->model()->index( mComboBoxDestination->currentIndex(), 0, QModelIndex() ), static_cast< int >( QgsProjectStyleDatabaseModel::CustomRole::Style ) ).value< QObject * >() ) )
171 {
172 return style;
173 }
174 else
175 {
176 return QgsStyle::defaultStyle();
177 }
178}
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:209
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.
QStringList tags() const
Returns a list of all tags in the style database.
StyleEntity
Enum for Entities involved in a style.
Definition qgsstyle.h:203
@ LabelSettingsEntity
Label settings.
Definition qgsstyle.h:209
@ TextFormatEntity
Text formats.
Definition qgsstyle.h:208
@ SmartgroupEntity
Smart groups.
Definition qgsstyle.h:207
@ Symbol3DEntity
3D symbol entity
Definition qgsstyle.h:211
@ SymbolEntity
Symbols.
Definition qgsstyle.h:204
@ TagEntity
Tags.
Definition qgsstyle.h:205
@ ColorrampEntity
Color ramps.
Definition qgsstyle.h:206
@ LegendPatchShapeEntity
Legend patch shape.
Definition qgsstyle.h:210
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:146