|
| 1 | + |
| 2 | +/** |
| 3 | + * The QgsLegendRendererItem class is abstract interface for legend items |
| 4 | + * returned from QgsMapLayerLegend implementation. |
| 5 | + * |
| 6 | + * The objects are used in QgsLayerTreeModel. Custom implementations may offer additional interactivity |
| 7 | + * and customized look. |
| 8 | + * |
| 9 | + * @note added in 2.6 |
| 10 | + */ |
| 11 | +class QgsLayerTreeModelLegendNode : QObject |
| 12 | +{ |
| 13 | +%TypeHeaderCode |
| 14 | +#include <qgsmaplayerlegend.h> |
| 15 | +%End |
| 16 | + |
| 17 | + public: |
| 18 | + |
| 19 | + /** Return pointer to the parent layer node */ |
| 20 | + QgsLayerTreeLayer* parent() const; |
| 21 | + |
| 22 | + /** Return item flags associated with the item. Default implementation returns Qt::ItemIsEnabled. */ |
| 23 | + virtual Qt::ItemFlags flags() const; |
| 24 | + |
| 25 | + /** Return data associated with the item. Must be implemented in derived class. */ |
| 26 | + virtual QVariant data( int role ) const = 0; |
| 27 | + |
| 28 | + /** Set some data associated with the item. Default implementation does nothing and returns false. */ |
| 29 | + virtual bool setData( const QVariant& value, int role ); |
| 30 | + |
| 31 | + protected: |
| 32 | + /** Construct the node with pointer to its parent layer node */ |
| 33 | + explicit QgsLayerTreeModelLegendNode( QgsLayerTreeLayer* nodeL ); |
| 34 | +}; |
| 35 | + |
| 36 | + |
| 37 | +/** |
| 38 | + * Implementation of legend node interface for displaying preview of vector symbols and their labels |
| 39 | + * and allowing interaction with the symbol / renderer. |
| 40 | + * |
| 41 | + * @note added in 2.6 |
| 42 | + */ |
| 43 | +class QgsSymbolV2LegendNode : QgsLayerTreeModelLegendNode |
| 44 | +{ |
| 45 | +%TypeHeaderCode |
| 46 | +#include <qgsmaplayerlegend.h> |
| 47 | +%End |
| 48 | + public: |
| 49 | + QgsSymbolV2LegendNode( QgsLayerTreeLayer* nodeLayer, QgsSymbolV2* symbol, const QString& label, int rendererRef = -1 ); |
| 50 | + |
| 51 | + virtual Qt::ItemFlags flags() const; |
| 52 | + virtual QVariant data( int role ) const; |
| 53 | + virtual bool setData( const QVariant& value, int role ); |
| 54 | +}; |
| 55 | + |
| 56 | + |
| 57 | +/** |
| 58 | + * Implementation of legend node interface for displaying arbitrary label with icon. |
| 59 | + * |
| 60 | + * @note added in 2.6 |
| 61 | + */ |
| 62 | +class QgsSimpleLegendNode : QgsLayerTreeModelLegendNode |
| 63 | +{ |
| 64 | +%TypeHeaderCode |
| 65 | +#include <qgsmaplayerlegend.h> |
| 66 | +%End |
| 67 | + public: |
| 68 | + QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon = QIcon() ); |
| 69 | + |
| 70 | + virtual QVariant data( int role ) const; |
| 71 | +}; |
| 72 | + |
| 73 | + |
| 74 | +/** |
| 75 | + * The QgsMapLayerLegend class is abstract interface for implementations |
| 76 | + * of legends for one map layer. |
| 77 | + * |
| 78 | + * @note added in 2.6 |
| 79 | + */ |
| 80 | +class QgsMapLayerLegend : QObject |
| 81 | +{ |
| 82 | +%TypeHeaderCode |
| 83 | +#include <qgsmaplayerlegend.h> |
| 84 | +%End |
| 85 | + |
| 86 | + public: |
| 87 | + explicit QgsMapLayerLegend( QObject *parent /TransferThis/ = 0 ); |
| 88 | + |
| 89 | + // TODO: type, load/save settings |
| 90 | + |
| 91 | + /** |
| 92 | + * Return list of legend nodes to be used for a particular layer tree layer node. |
| 93 | + * Ownership is transferred to the caller. |
| 94 | + */ |
| 95 | + virtual QList<QgsLayerTreeModelLegendNode*> createLayerTreeModelLegendNodes( QgsLayerTreeLayer* nodeLayer ) = 0 /Factory/; |
| 96 | + |
| 97 | + // TODO: support for layer tree view delegates |
| 98 | + |
| 99 | + // TODO: support for legend renderer |
| 100 | + |
| 101 | + |
| 102 | + //! Create new legend implementation for vector layer |
| 103 | + static QgsMapLayerLegend* defaultVectorLegend( QgsVectorLayer* vl ) /Factory/; |
| 104 | + |
| 105 | + //! Create new legend implementation for raster layer |
| 106 | + static QgsMapLayerLegend* defaultRasterLegend( QgsRasterLayer* rl ) /Factory/; |
| 107 | + |
| 108 | + //! Create new legend implementation for raster layer |
| 109 | + static QgsMapLayerLegend* defaultPluginLegend( QgsPluginLayer* pl ) /Factory/; |
| 110 | + |
| 111 | + signals: |
| 112 | + //! Emitted when existing items/nodes got invalid and should be replaced by new ones |
| 113 | + void itemsChanged(); |
| 114 | +}; |
| 115 | + |
| 116 | + |
| 117 | +/** Default legend implementation for vector layers |
| 118 | + * @note added in 2.6 |
| 119 | + */ |
| 120 | +class QgsDefaultVectorLayerLegend : QgsMapLayerLegend |
| 121 | +{ |
| 122 | +%TypeHeaderCode |
| 123 | +#include <qgsmaplayerlegend.h> |
| 124 | +%End |
| 125 | + public: |
| 126 | + explicit QgsDefaultVectorLayerLegend( QgsVectorLayer* vl ); |
| 127 | + |
| 128 | + virtual QList<QgsLayerTreeModelLegendNode*> createLayerTreeModelLegendNodes( QgsLayerTreeLayer* nodeLayer ) /Factory/; |
| 129 | + |
| 130 | +}; |
| 131 | + |
| 132 | + |
| 133 | +/** Default legend implementation for raster layers |
| 134 | + * @note added in 2.6 |
| 135 | + */ |
| 136 | +class QgsDefaultRasterLayerLegend : QgsMapLayerLegend |
| 137 | +{ |
| 138 | +%TypeHeaderCode |
| 139 | +#include <qgsmaplayerlegend.h> |
| 140 | +%End |
| 141 | + public: |
| 142 | + explicit QgsDefaultRasterLayerLegend( QgsRasterLayer* rl ); |
| 143 | + |
| 144 | + virtual QList<QgsLayerTreeModelLegendNode*> createLayerTreeModelLegendNodes( QgsLayerTreeLayer* nodeLayer ) /Factory/; |
| 145 | + |
| 146 | +}; |
| 147 | + |
| 148 | + |
| 149 | +/** Default legend implementation for plugin layers |
| 150 | + * @note added in 2.6 |
| 151 | + */ |
| 152 | +class QgsDefaultPluginLayerLegend : QgsMapLayerLegend |
| 153 | +{ |
| 154 | +%TypeHeaderCode |
| 155 | +#include <qgsmaplayerlegend.h> |
| 156 | +%End |
| 157 | + public: |
| 158 | + explicit QgsDefaultPluginLayerLegend( QgsPluginLayer* pl ); |
| 159 | + |
| 160 | + virtual QList<QgsLayerTreeModelLegendNode*> createLayerTreeModelLegendNodes( QgsLayerTreeLayer* nodeLayer ) /Factory/; |
| 161 | + |
| 162 | +}; |
| 163 | + |
0 commit comments