|
QGIS API Documentation
master-59fd5e0
|
00001 /*************************************************************************** 00002 qgscomposerlegenditem.h - description 00003 ------------------------ 00004 begin : May 2010 00005 copyright : (C) 2010 by Marco Hugentobler 00006 email : marco dot hugentobler at sourcepole dot ch 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef QGSCOMPOSERLEGENDITEM_H 00019 #define QGSCOMPOSERLEGENDITEM_H 00020 00021 #include "qgscomposerlegendstyle.h" 00022 #include <QStandardItem> 00023 class QDomDocument; 00024 class QDomElement; 00025 00027 class CORE_EXPORT QgsComposerLegendItem: public QStandardItem 00028 { 00029 public: 00030 QgsComposerLegendItem( QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined ); 00031 QgsComposerLegendItem( const QString& text, QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined ); 00032 QgsComposerLegendItem( const QIcon& icon, const QString& text, QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined ); 00033 virtual ~QgsComposerLegendItem(); 00034 00035 enum ItemType 00036 { 00037 GroupItem = QStandardItem::UserType, 00038 LayerItem, 00039 SymbologyV2Item, 00040 RasterSymbolItem, 00041 StyleItem 00042 }; 00043 00044 virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const = 0; 00048 virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) = 0; 00049 00050 virtual ItemType itemType() const = 0; 00051 virtual QStandardItem* clone() const = 0; 00052 00053 QgsComposerLegendStyle::Style style() const { return mStyle; } 00054 void setStyle( QgsComposerLegendStyle::Style style ) { mStyle = style; } 00055 00056 // Get text defined by user 00057 virtual QString userText() const { return mUserText; } 00058 // Set text defined by user 00059 virtual void setUserText( const QString & text ) { mUserText = text; } 00060 00061 00062 protected: 00063 void writeXMLChildren( QDomElement& elem, QDomDocument& doc ) const; 00064 00065 QgsComposerLegendStyle::Style mStyle; 00066 00067 // User defined text 00068 QString mUserText; 00069 }; 00070 00071 00072 class QgsSymbolV2; 00073 00074 class CORE_EXPORT QgsComposerSymbolV2Item: public QgsComposerLegendItem 00075 { 00076 public: 00077 QgsComposerSymbolV2Item(); 00078 QgsComposerSymbolV2Item( const QString& text ); 00079 QgsComposerSymbolV2Item( const QIcon& icon, const QString& text ); 00080 virtual ~QgsComposerSymbolV2Item(); 00081 00082 virtual QStandardItem* clone() const; 00083 00084 virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const; 00085 virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ); 00086 00088 void setSymbolV2( QgsSymbolV2* s ); 00089 QgsSymbolV2* symbolV2() {return mSymbolV2;} 00090 00091 ItemType itemType() const { return SymbologyV2Item; } 00092 00093 private: 00094 QgsSymbolV2* mSymbolV2; 00095 }; 00096 00097 class CORE_EXPORT QgsComposerRasterSymbolItem: public QgsComposerLegendItem 00098 { 00099 public: 00100 QgsComposerRasterSymbolItem(); 00101 QgsComposerRasterSymbolItem( const QString& text ); 00102 QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text ); 00103 virtual ~QgsComposerRasterSymbolItem(); 00104 00105 virtual QStandardItem* clone() const; 00106 00107 virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const; 00108 virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ); 00109 00110 void setLayerID( const QString& id ) { mLayerID = id; } 00111 QString layerID() const { return mLayerID; } 00112 ItemType itemType() const { return RasterSymbolItem; } 00113 00114 void setColor( const QColor& c ) { mColor = c; } 00115 QColor color() const { return mColor; } 00116 00117 private: 00118 QString mLayerID; 00119 QColor mColor; 00120 }; 00121 00122 class CORE_EXPORT QgsComposerLayerItem: public QgsComposerLegendItem 00123 { 00124 public: 00125 QgsComposerLayerItem(); 00126 QgsComposerLayerItem( const QString& text ); 00127 virtual ~QgsComposerLayerItem(); 00128 virtual QStandardItem* clone() const; 00129 00130 virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const; 00131 virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ); 00132 00133 ItemType itemType() const { return LayerItem; } 00134 00135 void setLayerID( const QString& id ) { mLayerID = id; } 00136 QString layerID() const { return mLayerID; } 00137 00138 void setShowFeatureCount( bool show ) { mShowFeatureCount = show; } 00139 bool showFeatureCount() const { return mShowFeatureCount; } 00140 00141 void setDefaultStyle(); 00142 00143 private: 00144 QString mLayerID; 00145 // Show vector feature counts 00146 bool mShowFeatureCount; 00147 }; 00148 00149 class CORE_EXPORT QgsComposerGroupItem: public QgsComposerLegendItem 00150 { 00151 public: 00152 QgsComposerGroupItem(); 00153 QgsComposerGroupItem( const QString& text ); 00154 virtual ~QgsComposerGroupItem(); 00155 virtual QStandardItem* clone() const; 00156 00157 virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const; 00158 virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ); 00159 00160 ItemType itemType() const { return GroupItem; } 00161 }; 00162 00163 class CORE_EXPORT QgsComposerStyleItem: public QStandardItem 00164 { 00165 public: 00166 QgsComposerStyleItem( ); 00167 QgsComposerStyleItem( QgsComposerLegendItem *item ); 00168 ~QgsComposerStyleItem(); 00169 }; 00170 00171 #endif // QGSCOMPOSERLEGENDITEM_H