QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsvisibilitypresetcollection.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvisibilitypresetcollection.h
3  --------------------------------------
4  Date : September 2014
5  Copyright : (C) 2014 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSVISIBILITYPRESETCOLLECTION_H
17 #define QGSVISIBILITYPRESETCOLLECTION_H
18 
19 #include <QMap>
20 #include <QObject>
21 #include <QSet>
22 #include <QStringList>
23 
24 class QDomDocument;
25 class QgsLayerTreeNode;
26 class QgsLayerTreeGroup;
27 
36 class CORE_EXPORT QgsVisibilityPresetCollection : public QObject
37 {
38  Q_OBJECT
39 
40  public:
41 
46  {
47  public:
48 
49  bool operator==( const PresetRecord& other ) const
50  {
51  return mVisibleLayerIDs.toSet() == other.mVisibleLayerIDs.toSet()
52  && mPerLayerCheckedLegendSymbols == other.mPerLayerCheckedLegendSymbols
53  && mPerLayerCurrentStyle == other.mPerLayerCurrentStyle;
54  }
55  bool operator!=( const PresetRecord& other ) const
56  {
57  return !( *this == other );
58  }
59 
68  };
69 
71 
76  bool hasPreset( const QString& name ) const;
77 
83  void insert( const QString& name, const PresetRecord& state );
84 
90  void update( const QString& name, const PresetRecord& state );
91 
95  void removePreset( const QString& name );
96 
98  void clear();
99 
101  QStringList presets() const;
102 
106  PresetRecord presetState( const QString& name ) const { return mPresets[name]; }
107 
113  QStringList presetVisibleLayers( const QString& name ) const;
114 
119  void applyPresetCheckedLegendNodesToLayer( const QString& name, const QString& layerID );
120 
124  QMap<QString, QString> presetStyleOverrides( const QString& name );
125 
130  void readXML( const QDomDocument& doc );
131 
136  void writeXML( QDomDocument& doc );
137 
143  static void addVisibleLayersToPreset( QgsLayerTreeGroup* parent, PresetRecord& rec );
144 
145  signals:
146 
149  void presetsChanged();
150 
151  protected slots:
152 
155  void registryLayersRemoved( const QStringList& layerIDs );
156 
158  void layerStyleRenamed( const QString& oldName, const QString& newName );
159 
160  protected:
161 
164  void reconnectToLayersStyleManager();
165 
167  PresetRecordMap mPresets;
168 };
169 
170 
171 #endif // QGSVISIBILITYPRESETCOLLECTION_H
Layer tree group node serves as a container for layers and further groups.
bool operator==(const PresetRecord &other) const
QSet< T > toSet() const
QMap< QString, PresetRecord > PresetRecordMap
QMap< QString, QString > mPerLayerCurrentStyle
For layers that use multiple styles - which one is currently selected.
QStringList mVisibleLayerIDs
Ordered list of layers that are visible.
This class is a base class for nodes in a layer tree.
PresetRecord presetState(const QString &name) const
Returns the recorded state of a preset.
Individual preset record of visible layers and styles.
bool operator!=(const PresetRecord &other) const
Container class that allows storage of visibility presets consisting of visible map layers and layer ...
QMap< QString, QSet< QString > > mPerLayerCheckedLegendSymbols
For layers that have checkable legend symbols and not all symbols are checked - list which ones are...