|
| 1 | +/*************************************************************************** |
| 2 | + qgsmaplayerstylemanager.h |
| 3 | + -------------------------------------- |
| 4 | + Date : January 2015 |
| 5 | + Copyright : (C) 2015 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 | + |
1 | 16 | #ifndef QGSMAPLAYERSTYLEMANAGER_H |
2 | 17 | #define QGSMAPLAYERSTYLEMANAGER_H |
3 | 18 |
|
4 | 19 |
|
5 | 20 | class QgsMapLayer; |
6 | 21 |
|
7 | | - |
8 | 22 | #include <QByteArray> |
9 | 23 | #include <QMap> |
10 | 24 | #include <QStringList> |
11 | 25 |
|
12 | 26 | class QDomElement; |
13 | 27 |
|
14 | | -/** stores style information (renderer, transparency, labeling, diagrams etc.) applicable to a map layer */ |
15 | | -class QgsMapLayerStyle |
| 28 | +/** |
| 29 | + * Stores style information (renderer, transparency, labeling, diagrams etc.) applicable to a map layer. |
| 30 | + * |
| 31 | + * Stored data are considered as opaque - it is not possible to access them directly or modify them - it is |
| 32 | + * only possible to read or write layer's current style. |
| 33 | + * |
| 34 | + * @note added in 2.8 |
| 35 | + */ |
| 36 | +class CORE_EXPORT QgsMapLayerStyle |
16 | 37 | { |
17 | 38 | public: |
18 | | - QgsMapLayerStyle(); // consutrct invalid style |
| 39 | + //! construct invalid style |
| 40 | + QgsMapLayerStyle(); |
19 | 41 |
|
| 42 | + //! Tell whether the style is valid (i.e. there is something stored in it) |
20 | 43 | bool isValid() const; |
21 | 44 |
|
22 | | - QString dump() const; // for debugging only |
| 45 | + //! Return information about the style - for debugging purposes only |
| 46 | + QString dump() const; |
23 | 47 |
|
24 | | - void loadFromLayer( QgsMapLayer* layer ); |
25 | | - void applyToLayer( QgsMapLayer* layer ) const; |
| 48 | + //! Store layer's active style information in the instance |
| 49 | + void readFromLayer( QgsMapLayer* layer ); |
| 50 | + //! Apply stored layer's style information to the layer |
| 51 | + void writeToLayer( QgsMapLayer* layer ) const; |
26 | 52 |
|
| 53 | + //! Read style configuration (for project file reading) |
27 | 54 | void readXml( const QDomElement& styleElement ); |
| 55 | + //! Write style configuration (for project file writing) |
28 | 56 | void writeXml( QDomElement& styleElement ) const; |
29 | 57 |
|
30 | 58 | private: |
31 | 59 | QByteArray mXmlData; |
32 | 60 | }; |
33 | 61 |
|
34 | 62 |
|
35 | | -/** Management of styles for use with one map layer */ |
36 | | -class QgsMapLayerStyleManager |
| 63 | +/** |
| 64 | + * Management of styles for use with one map layer. Stored styles are identified by their names. The manager |
| 65 | + * always keep track of which style of the stored ones is currently active. When the current style is changed, |
| 66 | + * the new style is applied to the associated layer. |
| 67 | + * |
| 68 | + * The class takes care of updating itself when the layer's current style configuration changes. |
| 69 | + * When some of layer style's properties change (e.g. transparency / colors), the style manager will |
| 70 | + * record them in the currently active style without any extra effort required. |
| 71 | + * |
| 72 | + * When an instance is created, it creates "default" style (with empty name) recorded from the associated map layer |
| 73 | + * and it is set as the current style. |
| 74 | + * |
| 75 | + * The instance must always contain at least one style. If no extra styles are wanted, the style manager should get |
| 76 | + * disabled in QgsMapLayer instance. |
| 77 | + * |
| 78 | + * @note added in 2.8 |
| 79 | + */ |
| 80 | +class CORE_EXPORT QgsMapLayerStyleManager |
37 | 81 | { |
38 | 82 | public: |
| 83 | + //! Construct a style manager associated with a map layer (must not be null) |
39 | 84 | QgsMapLayerStyleManager( QgsMapLayer* layer ); |
40 | 85 |
|
| 86 | + //! Read configuration (for project loading) |
41 | 87 | void readXml( const QDomElement& mgrElement ); |
| 88 | + //! Write configuration (for project saving) |
42 | 89 | void writeXml( QDomElement& mgrElement ) const; |
43 | 90 |
|
| 91 | + //! Return list of all defined style names |
44 | 92 | QStringList styles() const; |
| 93 | + //! Return data of a stored style - accessed by its unique name |
45 | 94 | QgsMapLayerStyle style( const QString& name ) const; |
46 | 95 |
|
| 96 | + //! Add a style with given name and data |
| 97 | + //! @return true on success (name is unique and style is valid) |
47 | 98 | bool addStyle( const QString& name, const QgsMapLayerStyle& style ); |
48 | 99 | //! Add style by cloning the current one |
| 100 | + //! @return true on success |
49 | 101 | bool addStyleFromLayer( const QString& name ); |
| 102 | + //! Remove a stored style |
| 103 | + //! @return true on success (style exists and it is not the last one) |
50 | 104 | bool removeStyle( const QString& name ); |
51 | 105 |
|
| 106 | + //! Return name of the current style |
52 | 107 | QString currentStyle() const; |
53 | | - bool setCurrentStyle( const QString& name ); // applies to the mLayer! (+ sync previous style) |
| 108 | + //! Set a different style as the current style - will apply it to the layer |
| 109 | + //! @return true on success |
| 110 | + bool setCurrentStyle( const QString& name ); |
54 | 111 |
|
55 | 112 | private: |
56 | 113 | void syncCurrentStyle(); |
|
0 commit comments