QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
25 #include <QLineEdit>
26 #include <QCheckBox>
27 
29  : QDialog( parent )
30  , mType( type )
31 {
32  setupUi( this );
33 
35 
36  QStringList defaultTags = QgsStyle::defaultStyle()->tags();
37  defaultTags.sort( Qt::CaseInsensitive );
38  mTags->addItems( defaultTags );
39 
40  QList< QgsStyle::StyleEntity > possibleEntities;
41  switch ( type )
42  {
44  this->setWindowTitle( tr( "Save New Symbol" ) );
45  possibleEntities << QgsStyle::SymbolEntity;
46  break;
47 
49  this->setWindowTitle( tr( "Save New Color Ramp" ) );
50  possibleEntities << QgsStyle::ColorrampEntity;
51  break;
52 
54  this->setWindowTitle( tr( "Save New Text Format" ) );
55  possibleEntities << QgsStyle::TextFormatEntity;
56  break;
57 
59  this->setWindowTitle( tr( "Save New Label Settings" ) );
61  break;
62 
64  this->setWindowTitle( tr( "Save New Legend Patch Shape" ) );
65  possibleEntities << QgsStyle::LegendPatchShapeEntity;
66  break;
67 
69  this->setWindowTitle( tr( "Save New 3D Symbol" ) );
70  possibleEntities << QgsStyle::Symbol3DEntity;
71  break;
72 
75  break;
76  }
77 
78  if ( possibleEntities.size() < 2 )
79  {
80  mLabelSaveAs->hide();
81  mComboSaveAs->hide();
82  }
83  else
84  {
85  for ( QgsStyle::StyleEntity e : std::as_const( possibleEntities ) )
86  {
87  switch ( e )
88  {
90  mComboSaveAs->addItem( tr( "Symbol" ), e );
91  break;
92 
94  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "styleicons/color.svg" ) ), tr( "Color Ramp" ), e );
95  break;
96 
98  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconFieldText.svg" ) ), tr( "Text Format" ), e );
99  break;
100 
102  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingSingle.svg" ) ), tr( "Label Settings" ), e );
103  break;
104 
106  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "legend.svg" ) ), tr( "Legend Patch Shape" ), e );
107  break;
108 
110  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "3d.svg" ) ), tr( "3D Symbol" ), e );
111  break;
112 
113  case QgsStyle::TagEntity:
115  break;
116  }
117  }
118  mComboSaveAs->setCurrentIndex( 0 );
119  }
120 }
121 
123 {
124  return mName->text();
125 }
126 
127 void QgsStyleSaveDialog::setDefaultTags( const QString &tags )
128 {
129  mTags->setCurrentText( tags );
130 }
131 
133 {
134  return mTags->currentText();
135 }
136 
138 {
139  return mFavorite->isChecked();
140 }
141 
143 {
144  if ( mComboSaveAs->count() > 0 )
145  return static_cast< QgsStyle::StyleEntity >( mComboSaveAs->currentData().toInt() );
146  else
147  return mType;
148 }
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:156
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).
QStringList tags() const
Returns a list of all tags in the style database.
Definition: qgsstyle.cpp:1403
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:131