QGIS API Documentation  2.14.0-Essen
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 
99  QgsComposition* composition() { return mComposition; }
100 
105  virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
106 
111  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
112 
117  QgsDataDefined* dataDefinedProperty( const DataDefinedProperty property ) const;
118 
127  void setDataDefinedProperty( const DataDefinedProperty property, const bool active, const bool useExpression, const QString &expression, const QString &field );
128 
137  void setCustomProperty( const QString &key, const QVariant &value );
138 
148  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
149 
157  void removeCustomProperty( const QString &key );
158 
165  QStringList customProperties() const;
166 
171  virtual QgsExpressionContext* createExpressionContext() const;
172 
173  public slots:
174 
176  virtual void repaint();
177 
186  virtual void refreshDataDefinedProperty( const DataDefinedProperty property = AllProperties, const QgsExpressionContext* context = nullptr );
187 
188  protected:
189 
191 
194 
197 
206  bool dataDefinedEvaluate( const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue, const QgsExpressionContext& context = QgsExpressionContext() ) const;
207 
208  signals:
212  void itemChanged();
213 
214  private slots:
218  void prepareDataDefinedExpressions() const;
219 
220  private:
221 
223  //mutable since expressions in data defineds need to be preparable
225 
226  friend class TestQgsComposerObject;
227 };
228 
229 #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...