-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgslegendmodel.h
88 lines (70 loc) · 3.18 KB
/
qgslegendmodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/***************************************************************************
qgslegendmodel.h - description
-----------------
begin : June 2008
copyright : (C) 2008 by Marco Hugentobler
email : marco dot hugentobler at karto dot baug dot ethz dot ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSLEGENDMODEL_H
#define QGSLEGENDMODEL_H
#include <QStandardItemModel>
#include <QStringList>
#include <QSet>
class QDomDocument;
class QDomElement;
class QgsMapLayer;
class QgsSymbol;
/** \ingroup MapComposer
* A model that provides layers as root items. The classification items are
* children of the layer items.
*/
class CORE_EXPORT QgsLegendModel: public QStandardItemModel
{
Q_OBJECT
public:
QgsLegendModel();
~QgsLegendModel();
void setLayerSet( const QStringList& layerIds );
/**Tries to automatically update a model entry (e.g. a whole layer or only a single item)*/
void updateItem( QStandardItem* item );
/**Updates the whole symbology of a layer*/
void updateLayer( QStandardItem* layerItem );
/**Tries to update a single classification item*/
void updateVectorClassificationItem( QStandardItem* classificationItem, QgsSymbol* symbol, QString itemText );
void updateRasterClassificationItem( QStandardItem* classificationItem );
bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const;
bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc );
public slots:
void removeLayer( const QString& layerId );
void addLayer( QgsMapLayer* theMapLayer );
signals:
void layersChanged();
private:
/**Adds classification items of vector layers
@return 0 in case of success*/
int addVectorLayerItems( QStandardItem* layerItem, QgsMapLayer* vlayer );
/**Adds item of raster layer
@return 0 in case of success*/
int addRasterLayerItem( QStandardItem* layerItem, QgsMapLayer* rlayer );
/**Insert a symbol into QgsLegendModel symbol storage*/
void insertSymbol( QgsSymbol* s );
/**Removes and deletes a symbol*/
void removeSymbol( QgsSymbol* s );
/**Removes and deletes all stored symbols*/
void removeAllSymbols();
/**Creates a model item for a vector symbol. The calling function takes ownership*/
QStandardItem* itemFromSymbol( QgsSymbol* s, int opacity );
/**Keep track of copied symbols to delete them if not used anymore*/
QSet<QgsSymbol*> mSymbols;
protected:
QStringList mLayerIds;
};
#endif