QGIS API Documentation  2.12.0-Lyon
qgscomposerobject.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerobject.h
3  -------------------
4  begin : July 2014
5  copyright : (C) 2014 by Nyall Dawson,Radim Blazek
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSCOMPOSEROBJECT_H
18 #define QGSCOMPOSEROBJECT_H
19 
21 #include "qgsexpressioncontext.h"
22 #include <QObject>
23 #include <QDomNode>
24 #include <QMap>
25 
26 class QgsComposition;
27 class QPainter;
28 class QgsDataDefined;
29 
33 class CORE_EXPORT QgsComposerObject: public QObject
34 {
35  Q_OBJECT
36  public:
37 
41  {
42  NoProperty = 0,
45  //composer page properties
51  //general composer item properties
61  //composer map
71  //composer picture
73  //html item
74  SourceUrl
75  };
76 
82  {
83  EvaluatedValue = 0,
84  OriginalValue
85  };
86 
90  QgsComposerObject( QgsComposition* composition );
91  virtual ~QgsComposerObject();
92 
96  const QgsComposition* composition() const { return mComposition; }
97  QgsComposition* composition() { return mComposition; }
98 
103  virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
104 
109  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
110 
115  QgsDataDefined* dataDefinedProperty( const DataDefinedProperty property ) const;
116 
125  void setDataDefinedProperty( const DataDefinedProperty property, const bool active, const bool useExpression, const QString &expression, const QString &field );
126 
135  void setCustomProperty( const QString &key, const QVariant &value );
136 
146  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
147 
155  void removeCustomProperty( const QString &key );
156 
163  QStringList customProperties() const;
164 
169  virtual QgsExpressionContext* createExpressionContext() const;
170 
171  public slots:
172 
174  virtual void repaint();
175 
184  virtual void refreshDataDefinedProperty( const DataDefinedProperty property = AllProperties, const QgsExpressionContext* context = 0 );
185 
186  protected:
187 
189 
192 
195 
204  bool dataDefinedEvaluate( const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue, const QgsExpressionContext& context = QgsExpressionContext() ) const;
205 
206  signals:
210  void itemChanged();
211 
212  private slots:
216  void prepareDataDefinedExpressions() const;
217 
218  private:
219 
221  //mutable since expressions in data defineds need to be preparable
223 
224  friend class TestQgsComposerObject;
225 };
226 
227 #endif
A base class for objects which belong to a map composition.
A container class for data source field mapping or expression.
QgsObjectCustomProperties mCustomProperties
Custom properties for object.
QMap< QgsComposerObject::DataDefinedProperty, QString > mDataDefinedNames
Map of data defined properties for the item to string name to use when exporting item to xml...
DataDefinedProperty
Data defined properties for different item types.
const QgsComposition * composition() const
Returns the composition the item is attached to.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsComposition * composition()
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
Graphics scene for map printing.
QgsComposition * mComposition
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...