QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
symbology
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 "
qgsapplication.h
"
22
#include "
qgsgui.h
"
23
#include "
qgsproject.h
"
24
#include "
qgsprojectstylesettings.h
"
25
#include "
qgsstyle.h
"
26
27
#include <QCheckBox>
28
#include <QLineEdit>
29
#include <QString>
30
31
#include "moc_qgsstylesavedialog.cpp"
32
33
using namespace
Qt::StringLiterals;
34
35
QgsStyleSaveDialog::QgsStyleSaveDialog
( QWidget *parent,
QgsStyle::StyleEntity
type )
36
: QDialog( parent )
37
, mType( type )
38
{
39
setupUi(
this
);
40
41
QgsGui::enableAutoGeometryRestore
(
this
);
42
43
QStringList defaultTags =
QgsStyle::defaultStyle
()->
tags
();
44
defaultTags.sort( Qt::CaseInsensitive );
45
mTags->addItems( defaultTags );
46
47
QList<QgsStyle::StyleEntity> possibleEntities;
48
switch
( type )
49
{
50
case
QgsStyle::SymbolEntity
:
51
this->setWindowTitle( tr(
"Save New Symbol"
) );
52
possibleEntities <<
QgsStyle::SymbolEntity
;
53
break
;
54
55
case
QgsStyle::ColorrampEntity
:
56
this->setWindowTitle( tr(
"Save New Color Ramp"
) );
57
possibleEntities <<
QgsStyle::ColorrampEntity
;
58
break
;
59
60
case
QgsStyle::TextFormatEntity
:
61
this->setWindowTitle( tr(
"Save New Text Format"
) );
62
possibleEntities <<
QgsStyle::TextFormatEntity
;
63
break
;
64
65
case
QgsStyle::LabelSettingsEntity
:
66
this->setWindowTitle( tr(
"Save New Label Settings"
) );
67
possibleEntities <<
QgsStyle::LabelSettingsEntity
<<
QgsStyle::TextFormatEntity
;
68
break
;
69
70
case
QgsStyle::LegendPatchShapeEntity
:
71
this->setWindowTitle( tr(
"Save New Legend Patch Shape"
) );
72
possibleEntities <<
QgsStyle::LegendPatchShapeEntity
;
73
break
;
74
75
case
QgsStyle::Symbol3DEntity
:
76
this->setWindowTitle( tr(
"Save New 3D Symbol"
) );
77
possibleEntities <<
QgsStyle::Symbol3DEntity
<<
QgsStyle::MaterialSettingsEntity
;
78
break
;
79
80
case
QgsStyle::MaterialSettingsEntity
:
81
this->setWindowTitle( tr(
"Save New Material Settings"
) );
82
possibleEntities <<
QgsStyle::MaterialSettingsEntity
;
83
break
;
84
85
case
QgsStyle::TagEntity
:
86
case
QgsStyle::SmartgroupEntity
:
87
break
;
88
}
89
90
QgsProjectStyleDatabaseModel
*projectStyleModel =
new
QgsProjectStyleDatabaseModel
(
QgsProject::instance
()->styleSettings(),
this
);
91
QgsProjectStyleDatabaseProxyModel
*styleProxyModel =
new
QgsProjectStyleDatabaseProxyModel
( projectStyleModel,
this
);
92
styleProxyModel->
setFilters
(
QgsProjectStyleDatabaseProxyModel::Filter::FilterHideReadOnly
);
93
94
if
( styleProxyModel->rowCount( QModelIndex() ) == 0 )
95
{
96
mLabelDestination->hide();
97
mComboBoxDestination->hide();
98
}
99
else
100
{
101
projectStyleModel->
setShowDefaultStyle
(
true
);
102
mComboBoxDestination->setModel( styleProxyModel );
103
}
104
105
if
( possibleEntities.size() < 2 )
106
{
107
mLabelSaveAs->hide();
108
mComboSaveAs->hide();
109
}
110
else
111
{
112
for
(
QgsStyle::StyleEntity
e : std::as_const( possibleEntities ) )
113
{
114
switch
( e )
115
{
116
case
QgsStyle::SymbolEntity
:
117
mComboSaveAs->addItem( tr(
"Symbol"
), e );
118
break
;
119
120
case
QgsStyle::ColorrampEntity
:
121
mComboSaveAs->addItem(
QgsApplication::getThemeIcon
( u
"styleicons/color.svg"
_s ), tr(
"Color Ramp"
), e );
122
break
;
123
124
case
QgsStyle::TextFormatEntity
:
125
mComboSaveAs->addItem(
QgsApplication::getThemeIcon
( u
"mIconFieldText.svg"
_s ), tr(
"Text Format"
), e );
126
break
;
127
128
case
QgsStyle::LabelSettingsEntity
:
129
mComboSaveAs->addItem(
QgsApplication::getThemeIcon
( u
"labelingSingle.svg"
_s ), tr(
"Label Settings"
), e );
130
break
;
131
132
case
QgsStyle::LegendPatchShapeEntity
:
133
mComboSaveAs->addItem(
QgsApplication::getThemeIcon
( u
"legend.svg"
_s ), tr(
"Legend Patch Shape"
), e );
134
break
;
135
136
case
QgsStyle::Symbol3DEntity
:
137
mComboSaveAs->addItem(
QgsApplication::getThemeIcon
( u
"3d.svg"
_s ), tr(
"3D Symbol"
), e );
138
break
;
139
140
case
QgsStyle::MaterialSettingsEntity
:
141
mComboSaveAs->addItem(
QgsApplication::getThemeIcon
( u
"3d.svg"
_s ), tr(
"Material"
), e );
142
break
;
143
144
case
QgsStyle::TagEntity
:
145
case
QgsStyle::SmartgroupEntity
:
146
break
;
147
}
148
}
149
mComboSaveAs->setCurrentIndex( 0 );
150
}
151
}
152
153
QString
QgsStyleSaveDialog::name
()
const
154
{
155
return
mName->text();
156
}
157
158
void
QgsStyleSaveDialog::setDefaultTags
(
const
QString &
tags
)
159
{
160
mTags->setCurrentText(
tags
);
161
}
162
163
QString
QgsStyleSaveDialog::tags
()
const
164
{
165
return
mTags->currentText();
166
}
167
168
bool
QgsStyleSaveDialog::isFavorite
()
const
169
{
170
return
mFavorite->isChecked();
171
}
172
173
QgsStyle::StyleEntity
QgsStyleSaveDialog::selectedType
()
const
174
{
175
if
( mComboSaveAs->count() > 0 )
176
return
static_cast<
QgsStyle::StyleEntity
>
( mComboSaveAs->currentData().toInt() );
177
else
178
return
mType;
179
}
180
181
QgsStyle
*
QgsStyleSaveDialog::destinationStyle
()
182
{
183
if
(
QgsStyle
*style = qobject_cast<QgsStyle *>(
184
mComboBoxDestination->model()
185
->data( mComboBoxDestination->model()->index( mComboBoxDestination->currentIndex(), 0, QModelIndex() ),
static_cast<
int
>
(
QgsProjectStyleDatabaseModel::CustomRole::Style
) )
186
.value<QObject *>()
187
) )
188
{
189
return
style;
190
}
191
else
192
{
193
return
QgsStyle::defaultStyle
();
194
}
195
}
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition
qgsapplication.cpp:904
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:225
QgsProjectStyleDatabaseModel
List model representing the style databases associated with a QgsProject.
Definition
qgsprojectstylesettings.h:371
QgsProjectStyleDatabaseModel::CustomRole::Style
@ Style
Style object.
Definition
qgsprojectstylesettings.h:385
QgsProjectStyleDatabaseModel::setShowDefaultStyle
void setShowDefaultStyle(bool show)
Sets whether the default style should also be included in the model.
Definition
qgsprojectstylesettings.cpp:707
QgsProjectStyleDatabaseProxyModel
A proxy model for filtering QgsProjectStyleDatabaseModel.
Definition
qgsprojectstylesettings.h:451
QgsProjectStyleDatabaseProxyModel::Filter::FilterHideReadOnly
@ FilterHideReadOnly
Hide read-only style databases.
Definition
qgsprojectstylesettings.h:458
QgsProjectStyleDatabaseProxyModel::setFilters
void setFilters(QgsProjectStyleDatabaseProxyModel::Filters filters)
Sets the current filters used for filtering available styles.
Definition
qgsprojectstylesettings.cpp:823
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition
qgsproject.cpp:490
QgsStyleSaveDialog::isFavorite
bool isFavorite() const
Returns true if the favorite is checked for the symbol.
Definition
qgsstylesavedialog.cpp:168
QgsStyleSaveDialog::name
QString name() const
Returns the entered name for the new symbol.
Definition
qgsstylesavedialog.cpp:153
QgsStyleSaveDialog::selectedType
QgsStyle::StyleEntity selectedType() const
Returns the type of style entity to save.
Definition
qgsstylesavedialog.cpp:173
QgsStyleSaveDialog::setDefaultTags
void setDefaultTags(const QString &tags)
Sets the default tags for the newly created item.
Definition
qgsstylesavedialog.cpp:158
QgsStyleSaveDialog::QgsStyleSaveDialog
QgsStyleSaveDialog(QWidget *parent=nullptr, QgsStyle::StyleEntity type=QgsStyle::SymbolEntity)
Constructor for QgsSymbolSaveDialog.
Definition
qgsstylesavedialog.cpp:35
QgsStyleSaveDialog::tags
QString tags() const
Returns any tags entered for the new symbol (as a comma separated value list).
Definition
qgsstylesavedialog.cpp:163
QgsStyleSaveDialog::destinationStyle
QgsStyle * destinationStyle()
Returns the destination style database.
Definition
qgsstylesavedialog.cpp:181
QgsStyle
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition
qgsstyle.h:91
QgsStyle::tags
QStringList tags() const
Returns a list of all tags in the style database.
Definition
qgsstyle.cpp:1612
QgsStyle::StyleEntity
StyleEntity
Enum for Entities involved in a style.
Definition
qgsstyle.h:206
QgsStyle::LabelSettingsEntity
@ LabelSettingsEntity
Label settings.
Definition
qgsstyle.h:212
QgsStyle::TextFormatEntity
@ TextFormatEntity
Text formats.
Definition
qgsstyle.h:211
QgsStyle::SmartgroupEntity
@ SmartgroupEntity
Smart groups.
Definition
qgsstyle.h:210
QgsStyle::Symbol3DEntity
@ Symbol3DEntity
3D symbol entity
Definition
qgsstyle.h:214
QgsStyle::SymbolEntity
@ SymbolEntity
Symbols.
Definition
qgsstyle.h:207
QgsStyle::TagEntity
@ TagEntity
Tags.
Definition
qgsstyle.h:208
QgsStyle::ColorrampEntity
@ ColorrampEntity
Color ramps.
Definition
qgsstyle.h:209
QgsStyle::LegendPatchShapeEntity
@ LegendPatchShapeEntity
Legend patch shape.
Definition
qgsstyle.h:213
QgsStyle::MaterialSettingsEntity
@ MaterialSettingsEntity
Material settings.
Definition
qgsstyle.h:215
QgsStyle::defaultStyle
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition
qgsstyle.cpp:164
qgis.h
qgsapplication.h
qgsgui.h
qgsproject.h
qgsprojectstylesettings.h
qgsstyle.h
qgsstylesavedialog.h
Generated on
for QGIS API Documentation by
1.17.0