QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
70  break;
71  }
72 
73  if ( possibleEntities.size() < 2 )
74  {
75  mLabelSaveAs->hide();
76  mComboSaveAs->hide();
77  }
78  else
79  {
80  for ( QgsStyle::StyleEntity e : qgis::as_const( possibleEntities ) )
81  {
82  switch ( e )
83  {
85  mComboSaveAs->addItem( tr( "Symbol" ), e );
86  break;
87 
89  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "styleicons/color.svg" ) ), tr( "Color Ramp" ), e );
90  break;
91 
93  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconFieldText.svg" ) ), tr( "Text Format" ), e );
94  break;
95 
97  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingSingle.svg" ) ), tr( "Label Settings" ), e );
98  break;
99 
101  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "legend.svg" ) ), tr( "Legend Patch Shape" ), e );
102  break;
103 
104  case QgsStyle::TagEntity:
106  break;
107  }
108  }
109  mComboSaveAs->setCurrentIndex( 0 );
110  }
111 }
112 
114 {
115  return mName->text();
116 }
117 
118 void QgsStyleSaveDialog::setDefaultTags( const QString &tags )
119 {
120  mTags->setCurrentText( tags );
121 }
122 
124 {
125  return mTags->currentText();
126 }
127 
129 {
130  return mFavorite->isChecked();
131 }
132 
134 {
135  if ( mComboSaveAs->count() > 0 )
136  return static_cast< QgsStyle::StyleEntity >( mComboSaveAs->currentData().toInt() );
137  else
138  return mType;
139 }
QgsStyle::ColorrampEntity
@ ColorrampEntity
Color ramps.
Definition: qgsstyle.h:182
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Definition: qgsapplication.cpp:605
QgsStyleSaveDialog::setDefaultTags
void setDefaultTags(const QString &tags)
Sets the default tags for the newly created item.
Definition: qgsstylesavedialog.cpp:118
qgsgui.h
QgsStyleSaveDialog::QgsStyleSaveDialog
QgsStyleSaveDialog(QWidget *parent=nullptr, QgsStyle::StyleEntity type=QgsStyle::SymbolEntity)
Constructor for QgsSymbolSaveDialog.
Definition: qgsstylesavedialog.cpp:28
qgis.h
QgsStyle::LegendPatchShapeEntity
@ LegendPatchShapeEntity
Legend patch shape (since QGIS 3.14)
Definition: qgsstyle.h:186
qgsstylesavedialog.h
QgsStyle::SymbolEntity
@ SymbolEntity
Symbols.
Definition: qgsstyle.h:180
QgsStyle::TagEntity
@ TagEntity
Tags.
Definition: qgsstyle.h:181
QgsStyle::LabelSettingsEntity
@ LabelSettingsEntity
Label settings.
Definition: qgsstyle.h:185
QgsStyle::defaultStyle
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:111
qgsapplication.h
QgsGui::enableAutoGeometryRestore
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:133
QgsStyleSaveDialog::name
QString name() const
Returns the entered name for the new symbol.
Definition: qgsstylesavedialog.cpp:113
QgsStyleSaveDialog::selectedType
QgsStyle::StyleEntity selectedType() const
Returns the type of style entity to save.
Definition: qgsstylesavedialog.cpp:133
QgsStyle::tags
QStringList tags() const
Returns a list of all tags in the style database.
Definition: qgsstyle.cpp:1185
QgsStyle::SmartgroupEntity
@ SmartgroupEntity
Smart groups.
Definition: qgsstyle.h:183
QgsStyleSaveDialog::isFavorite
bool isFavorite() const
Returns true if the favorite is checked for the symbol.
Definition: qgsstylesavedialog.cpp:128
QgsStyleSaveDialog::tags
QString tags() const
Returns any tags entered for the new symbol (as a comma separated value list).
Definition: qgsstylesavedialog.cpp:123
qgsstyle.h
QgsStyle::TextFormatEntity
@ TextFormatEntity
Text formats.
Definition: qgsstyle.h:184
QgsStyle::StyleEntity
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:178