QGIS API Documentation  2.14.0-Essen
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 
45  {
46  public:
47 
48  bool operator==( const PresetRecord& other ) const
49  {
50  return mVisibleLayerIDs.toSet() == other.mVisibleLayerIDs.toSet()
51  && mPerLayerCheckedLegendSymbols == other.mPerLayerCheckedLegendSymbols
52  && mPerLayerCurrentStyle == other.mPerLayerCurrentStyle;
53  }
54  bool operator!=( const PresetRecord& other ) const
55  {
56  return !( *this == other );
57  }
58 
67  };
68 
70 
75  bool hasPreset( const QString& name ) const;
76 
82  void insert( const QString& name, const PresetRecord& state );
83 
89  void update( const QString& name, const PresetRecord& state );
90 
94  void removePreset( const QString& name );
95 
97  void clear();
98 
100  QStringList presets() const;
101 
105  PresetRecord presetState( const QString& name ) const { return mPresets[name]; }
106 
112  QStringList presetVisibleLayers( const QString& name ) const;
113 
118  void applyPresetCheckedLegendNodesToLayer( const QString& name, const QString& layerID );
119 
123  QMap<QString, QString> presetStyleOverrides( const QString& name );
124 
129  void readXML( const QDomDocument& doc );
130 
135  void writeXML( QDomDocument& doc );
136 
142  static void addVisibleLayersToPreset( QgsLayerTreeGroup* parent, PresetRecord& rec );
143 
144  signals:
145 
148  void presetsChanged();
149 
150  protected slots:
151 
154  void registryLayersRemoved( const QStringList& layerIDs );
155 
157  void layerStyleRenamed( const QString& oldName, const QString& newName );
158 
159  protected:
160 
163  void reconnectToLayersStyleManager();
164 
166  PresetRecordMap mPresets;
167 };
168 
169 
170 #endif // QGSVISIBILITYPRESETCOLLECTION_H
Layer tree group node serves as a container for layers and further groups.
QSet< T > toSet() const
PresetRecord presetState(const QString &name) const
Returns the recorded state of a preset.
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.
bool operator!=(const PresetRecord &other) const
Individual preset record of visible layers and styles.
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...
bool operator==(const PresetRecord &other) const