QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
65  break;
66  }
67 
68  if ( possibleEntities.size() < 2 )
69  {
70  mLabelSaveAs->hide();
71  mComboSaveAs->hide();
72  }
73  else
74  {
75  for ( QgsStyle::StyleEntity e : qgis::as_const( possibleEntities ) )
76  {
77  switch ( e )
78  {
80  mComboSaveAs->addItem( tr( "Symbol" ), e );
81  break;
82 
84  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "styleicons/color.svg" ) ), tr( "Color Ramp" ), e );
85  break;
86 
88  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconFieldText.svg" ) ), tr( "Text Format" ), e );
89  break;
90 
92  mComboSaveAs->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingSingle.svg" ) ), tr( "Label Settings" ), e );
93  break;
94 
97  break;
98  }
99  }
100  mComboSaveAs->setCurrentIndex( 0 );
101  }
102 }
103 
105 {
106  return mName->text();
107 }
108 
110 {
111  mTags->setCurrentText( tags );
112 }
113 
115 {
116  return mTags->currentText();
117 }
118 
120 {
121  return mFavorite->isChecked();
122 }
123 
125 {
126  if ( mComboSaveAs->count() > 0 )
127  return static_cast< QgsStyle::StyleEntity >( mComboSaveAs->currentData().toInt() );
128  else
129  return mType;
130 }
QString tags() const
Returns any tags entered for the new symbol (as a comma separated value list).
QString name() const
Returns the entered name for the new symbol.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:74
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:177
QgsStyleSaveDialog(QWidget *parent=nullptr, QgsStyle::StyleEntity type=QgsStyle::SymbolEntity)
Constructor for QgsSymbolSaveDialog.
void setDefaultTags(const QString &tags)
Sets the default tags for the newly created item.
QStringList tags() const
Returns a list of all tags in the style database.
Definition: qgsstyle.cpp:1032
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:127
bool isFavorite() const
Returns true if the favorite is checked for the symbol.
QgsStyle::StyleEntity selectedType() const
Returns the type of style entity to save.