QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 "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 QgsProjectStyleDatabaseModel *projectStyleModel = new QgsProjectStyleDatabaseModel( QgsProject::instance()->styleSettings(), this );
81 QgsProjectStyleDatabaseProxyModel *styleProxyModel = new QgsProjectStyleDatabaseProxyModel( projectStyleModel, this );
83
84 if ( styleProxyModel->rowCount( QModelIndex() ) == 0 )
85 {
86 mLabelDestination->hide();
87 mComboBoxDestination->hide();
88 }
89 else
90 {
91 projectStyleModel->setShowDefaultStyle( true );
92 mComboBoxDestination->setModel( styleProxyModel );
93 }
94
95 if ( possibleEntities.size() < 2 )
96 {
97 mLabelSaveAs->hide();
98 mComboSaveAs->hide();
99 }
100 else
101 {
102 for ( QgsStyle::StyleEntity e : std::as_const( possibleEntities ) )
103 {
104 switch ( e )
105 {
107 mComboSaveAs->addItem( tr( "Symbol" ), e );
108 break;
109
111 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "styleicons/color.svg" ) ), tr( "Color Ramp" ), e );
112 break;
113
115 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconFieldText.svg" ) ), tr( "Text Format" ), e );
116 break;
117
119 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingSingle.svg" ) ), tr( "Label Settings" ), e );
120 break;
121
123 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "legend.svg" ) ), tr( "Legend Patch Shape" ), e );
124 break;
125
127 mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "3d.svg" ) ), tr( "3D Symbol" ), e );
128 break;
129
132 break;
133 }
134 }
135 mComboSaveAs->setCurrentIndex( 0 );
136 }
137}
138
140{
141 return mName->text();
142}
143
144void QgsStyleSaveDialog::setDefaultTags( const QString &tags )
145{
146 mTags->setCurrentText( tags );
147}
148
150{
151 return mTags->currentText();
152}
153
155{
156 return mFavorite->isChecked();
157}
158
160{
161 if ( mComboSaveAs->count() > 0 )
162 return static_cast< QgsStyle::StyleEntity >( mComboSaveAs->currentData().toInt() );
163 else
164 return mType;
165}
166
168{
169 if ( QgsStyle *style = qobject_cast< QgsStyle * >( mComboBoxDestination->model()->data( mComboBoxDestination->model()->index( mComboBoxDestination->currentIndex(), 0, QModelIndex() ), QgsProjectStyleDatabaseModel::StyleRole ).value< QObject * >() ) )
170 {
171 return style;
172 }
173 else
174 {
175 return QgsStyle::defaultStyle();
176 }
177}
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:194
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.
void setFilters(QgsProjectStyleDatabaseProxyModel::Filters filters)
Sets the current filters used for filtering available styles.
@ FilterHideReadOnly
Hide read-only style databases.
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:179
@ LabelSettingsEntity
Label settings.
Definition qgsstyle.h:185
@ TextFormatEntity
Text formats.
Definition qgsstyle.h:184
@ SmartgroupEntity
Smart groups.
Definition qgsstyle.h:183
@ Symbol3DEntity
3D symbol entity (since QGIS 3.14)
Definition qgsstyle.h:187
@ SymbolEntity
Symbols.
Definition qgsstyle.h:180
@ TagEntity
Tags.
Definition qgsstyle.h:181
@ ColorrampEntity
Color ramps.
Definition qgsstyle.h:182
@ LegendPatchShapeEntity
Legend patch shape (since QGIS 3.14)
Definition qgsstyle.h:186
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition qgsstyle.cpp:145