QGIS API Documentation  2.99.0-Master (0a63d1f)
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 
20 #include "qgis_core.h"
23 #include <QObject>
24 #include <QDomNode>
25 #include <QMap>
26 
27 class QgsComposition;
28 class QPainter;
29 class QgsDataDefined;
30 
34 class CORE_EXPORT QgsComposerObject: public QObject, public QgsExpressionContextGenerator
35 {
36  Q_OBJECT
37  public:
38 
42  {
43  NoProperty = 0,
46  //composer page properties
52  //general composer item properties
62  //composer map
72  //composer picture
74  //html item
75  SourceUrl
76  };
77 
83  {
84  EvaluatedValue = 0,
85  OriginalValue
86  };
87 
91  QgsComposerObject( QgsComposition* composition );
92  virtual ~QgsComposerObject();
93 
97  const QgsComposition* composition() const { return mComposition; }
98 
100  QgsComposition* composition() { return mComposition; }
101 
106  virtual bool writeXml( QDomElement& elem, QDomDocument & doc ) const;
107 
112  virtual bool readXml( const QDomElement& itemElem, const QDomDocument& doc );
113 
118  QgsDataDefined* dataDefinedProperty( const DataDefinedProperty property ) const;
119 
128  void setDataDefinedProperty( const DataDefinedProperty property, const bool active, const bool useExpression, const QString &expression, const QString &field );
129 
138  void setCustomProperty( const QString &key, const QVariant &value );
139 
149  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
150 
158  void removeCustomProperty( const QString &key );
159 
166  QStringList customProperties() const;
167 
173 
174  public slots:
175 
177  virtual void repaint();
178 
187  virtual void refreshDataDefinedProperty( const DataDefinedProperty property = AllProperties, const QgsExpressionContext* context = nullptr );
188 
189  protected:
190 
192 
194  QMap< QgsComposerObject::DataDefinedProperty, QString > mDataDefinedNames;
195 
198 
207  bool dataDefinedEvaluate( const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue, const QgsExpressionContext& context = QgsExpressionContext() ) const;
208 
209  signals:
210 
214  void itemChanged();
215 
216  private slots:
217 
221  void prepareDataDefinedExpressions() const;
222 
223  private:
224 
226  //mutable since expressions in data defineds need to be preparable
227  mutable QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* > mDataDefinedProperties;
228 
229  friend class TestQgsComposerObject;
230 };
231 
232 #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...
Layer and style map theme.
Map extent x maximum.
Map extent x minimum.
DataDefinedProperty
Data defined properties for different item types.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Map extent y minimum.
QgsComposition * composition()
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
Graphics scene for map printing.
Abstract interface for generating an expression context.
Map extent y maximum.
QgsComposition * mComposition
const QgsComposition * composition() const
Returns the composition the item is attached to.
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Number of pages in composition.
Page number for item placement.
Dummy property with no effect on item.
Preset paper size for composition.
All properties for item.