2013-05-15 04:39:23 -06:00
|
|
|
/** \ingroup core
|
|
|
|
* \class QgsDataDefined
|
|
|
|
* A container class for data source field mapping or expression.
|
2015-05-08 16:25:39 +10:00
|
|
|
* \note QgsDataDefined objects are implicitly shared.
|
2013-05-15 04:39:23 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
class QgsDataDefined
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsdatadefined.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Construct a new data defined object
|
|
|
|
*
|
|
|
|
* @param active Whether the current data defined is active
|
|
|
|
* @param useexpr Whether to use expression instead of field
|
|
|
|
* @param expr Expression string
|
|
|
|
* @param field Field name string
|
|
|
|
*/
|
|
|
|
QgsDataDefined( bool active = false,
|
|
|
|
bool useexpr = false,
|
|
|
|
const QString& expr = QString(),
|
|
|
|
const QString& field = QString() );
|
|
|
|
|
2015-01-20 12:14:16 +01:00
|
|
|
/**
|
2015-04-27 09:45:13 +10:00
|
|
|
* Construct a new data defined object, analysing the expression to determine
|
|
|
|
* if it's a simple field reference or an expression.
|
2015-01-20 12:14:16 +01:00
|
|
|
* @param expression can be null
|
|
|
|
*/
|
2015-04-27 09:45:13 +10:00
|
|
|
explicit QgsDataDefined( const QgsExpression * expression );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new data defined object, analysing the string to determine
|
|
|
|
* if it's a simple field reference or an expression
|
|
|
|
* @param string field reference or an expression, can be empty
|
|
|
|
* @note added in QGIS 2.9
|
|
|
|
*/
|
|
|
|
explicit QgsDataDefined( const QString& string );
|
2015-01-20 12:14:16 +01:00
|
|
|
|
2015-04-22 06:00:59 +10:00
|
|
|
/**
|
|
|
|
* Copy constructor. Note that copies of data defined objects with expressions
|
|
|
|
* will not be prepared.
|
|
|
|
*/
|
|
|
|
QgsDataDefined( const QgsDataDefined& other );
|
|
|
|
|
2015-05-06 16:47:06 +10:00
|
|
|
/** Creates a QgsDataDefined from a decoded QgsStringMap.
|
|
|
|
* @param map string map encoding of QgsDataDefined
|
|
|
|
* @param baseName base name for values in the string map
|
|
|
|
* @returns new QgsDataDefined if string map was successfully interpreted
|
|
|
|
* @see toMap
|
|
|
|
* @note added in QGIS 2.9
|
|
|
|
*/
|
|
|
|
static QgsDataDefined* fromMap( const QgsStringMap& map, const QString& baseName = QString() );
|
|
|
|
|
2015-04-27 09:45:13 +10:00
|
|
|
virtual ~QgsDataDefined();
|
2014-11-21 01:17:21 +01:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns whether the data defined container is set to all the default
|
2014-11-20 21:20:39 +11:00
|
|
|
* values, ie, disabled, with empty expression and no assigned field
|
|
|
|
* @returns true if data defined container is set to default values
|
|
|
|
* @note added in QGIS 2.7
|
|
|
|
*/
|
2014-11-21 01:17:21 +01:00
|
|
|
bool hasDefaultValues() const;
|
2013-05-15 04:39:23 -06:00
|
|
|
|
|
|
|
bool isActive() const;
|
|
|
|
void setActive( bool active );
|
|
|
|
|
2015-08-06 13:07:32 +10:00
|
|
|
/**
|
|
|
|
* Returns if the field or the expression part is active.
|
|
|
|
*
|
|
|
|
* @return True if it is in expression mode.
|
|
|
|
*/
|
2013-05-15 04:39:23 -06:00
|
|
|
bool useExpression() const;
|
2015-08-05 13:50:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controls if the field or the expression part is active.
|
|
|
|
* For QGIS<=2.10 it is mandatory to call this after {@link setExpressionString}
|
|
|
|
* or {@link setField}.
|
|
|
|
*
|
|
|
|
* @param use True if it should be set to expression mode.
|
|
|
|
*/
|
2013-05-15 04:39:23 -06:00
|
|
|
void setUseExpression( bool use );
|
|
|
|
|
2015-08-06 13:07:32 +10:00
|
|
|
/**
|
|
|
|
* Returns the expression string of this QgsDataDefined.
|
|
|
|
*
|
|
|
|
* @return An expression
|
|
|
|
*
|
|
|
|
* @see field()
|
|
|
|
* @see expressionOrField()
|
|
|
|
*/
|
2013-05-15 04:39:23 -06:00
|
|
|
QString expressionString() const;
|
2015-08-05 13:50:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the expression for this QgsDataDefined.
|
|
|
|
* Will also set useExpression to true.
|
|
|
|
*
|
|
|
|
* @param expr The expression to set
|
|
|
|
*
|
|
|
|
* @see setField
|
|
|
|
*/
|
2013-05-15 04:39:23 -06:00
|
|
|
void setExpressionString( const QString& expr );
|
2015-08-05 13:50:00 +02:00
|
|
|
|
2015-08-06 13:07:32 +10:00
|
|
|
/**
|
|
|
|
* Returns an expression which represents a single field if useExpression returns false, otherwise
|
|
|
|
* returns the current expression string.
|
|
|
|
* @return An expression
|
|
|
|
*
|
|
|
|
* @note added in 2.12
|
|
|
|
*/
|
2015-08-05 13:50:00 +02:00
|
|
|
QString expressionOrField() const;
|
2013-05-15 04:39:23 -06:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
//! @note not available in python bindings
|
2013-05-15 04:39:23 -06:00
|
|
|
//QMap<QString, QVariant> expressionParams() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! @note not available in python bindings
|
2013-05-15 04:39:23 -06:00
|
|
|
//void setExpressionParams( QMap<QString, QVariant> params );
|
2015-10-07 11:55:34 +11:00
|
|
|
void insertExpressionParam( const QString& key, const QVariant& param );
|
2013-05-15 04:39:23 -06:00
|
|
|
|
2015-04-22 06:00:59 +10:00
|
|
|
/** Prepares the expression using a vector layer
|
|
|
|
* @param layer vector layer
|
|
|
|
* @returns true if expression was successfully prepared
|
2015-12-07 21:54:40 +11:00
|
|
|
* @deprecated use QgsExpressionContext variant instead
|
2015-04-22 06:00:59 +10:00
|
|
|
*/
|
2015-08-13 10:23:28 +10:00
|
|
|
bool prepareExpression( QgsVectorLayer* layer ) /Deprecated/;
|
2015-04-22 06:00:59 +10:00
|
|
|
|
|
|
|
/** Prepares the expression using a fields collection
|
|
|
|
* @param fields
|
|
|
|
* @returns true if expression was successfully prepared
|
|
|
|
* @note added in QGIS 2.9
|
2015-12-07 21:54:40 +11:00
|
|
|
* @deprecated use QgsExpressionContext variant instead
|
2015-04-22 06:00:59 +10:00
|
|
|
*/
|
2015-08-13 10:23:28 +10:00
|
|
|
bool prepareExpression( const QgsFields &fields ) /Deprecated/;
|
|
|
|
|
|
|
|
/** Prepares the expression using an expression context.
|
|
|
|
* @param context expression context
|
|
|
|
* @returns true if expression was successfully prepared
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
bool prepareExpression( const QgsExpressionContext &context = QgsExpressionContext() );
|
2015-04-22 06:00:59 +10:00
|
|
|
|
|
|
|
/** Returns whether the data defined object's expression is prepared
|
|
|
|
* @returns true if expression is prepared
|
|
|
|
*/
|
2013-05-15 04:39:23 -06:00
|
|
|
bool expressionIsPrepared() const;
|
|
|
|
|
|
|
|
QgsExpression* expression();
|
2015-05-06 16:47:06 +10:00
|
|
|
|
|
|
|
/** Returns the columns referenced by the QgsDataDefined
|
|
|
|
* @param layer vector layer, used for preparing the expression if required
|
2015-12-07 21:54:40 +11:00
|
|
|
* @deprecated use QgsExpressionContext variant instead
|
2015-05-06 16:47:06 +10:00
|
|
|
*/
|
2015-08-13 10:23:28 +10:00
|
|
|
QStringList referencedColumns( QgsVectorLayer* layer ) /Deprecated/;
|
2013-05-15 04:39:23 -06:00
|
|
|
|
2015-05-06 16:47:06 +10:00
|
|
|
/** Returns the columns referenced by the QgsDataDefined
|
|
|
|
* @param fields vector layer, used for preparing the expression if required
|
|
|
|
* @note added in QGIS 2.9
|
2015-12-07 21:54:40 +11:00
|
|
|
* @deprecated use QgsExpressionContext variant instead
|
2015-05-06 16:47:06 +10:00
|
|
|
*/
|
2015-08-13 10:23:28 +10:00
|
|
|
QStringList referencedColumns( const QgsFields& fields ) /Deprecated/;
|
|
|
|
|
|
|
|
/** Returns the columns referenced by the QgsDataDefined
|
|
|
|
* @param context expression context, used for preparing the expression if required
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
QStringList referencedColumns( const QgsExpressionContext& context = QgsExpressionContext() );
|
2015-05-06 16:47:06 +10:00
|
|
|
|
2015-08-06 13:07:32 +10:00
|
|
|
/**
|
|
|
|
* Get the field which this QgsDataDefined represents. Be aware that this may return
|
|
|
|
* a field name which may not be active if useExpression is true.
|
|
|
|
*
|
|
|
|
* @return A fieldname
|
|
|
|
*
|
|
|
|
* @see expressionOrField()
|
|
|
|
*/
|
2013-05-15 04:39:23 -06:00
|
|
|
QString field() const;
|
2015-08-05 13:50:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the field name which this QgsDataDefined represents.
|
|
|
|
* Will set useExpression to false.
|
|
|
|
*
|
|
|
|
* @param field
|
|
|
|
*/
|
2013-05-15 04:39:23 -06:00
|
|
|
void setField( const QString& field );
|
|
|
|
|
2015-05-06 16:47:06 +10:00
|
|
|
/** Encodes the QgsDataDefined into a string map.
|
|
|
|
* @param baseName optional base name for values in the string map. Can be used
|
|
|
|
* to differentiate multiple QgsDataDefineds encoded in the same string map.
|
|
|
|
* @see fromMap
|
|
|
|
*/
|
2015-05-08 16:25:39 +10:00
|
|
|
QMap< QString, QString > toMap( const QString& baseName = QString() ) const;
|
2014-12-30 22:06:00 +01:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns a DOM element containing the properties of the data defined container.
|
2015-02-03 02:21:52 +01:00
|
|
|
* @param document DOM document
|
2014-12-10 19:20:53 +11:00
|
|
|
* @param elementName name for DOM element
|
|
|
|
* @returns DOM element corresponding to data defined container
|
|
|
|
* @note added in QGIS 2.7
|
|
|
|
* @see setFromXmlElement
|
|
|
|
*/
|
|
|
|
QDomElement toXmlElement( QDomDocument &document, const QString &elementName ) const;
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets the properties of the data defined container from an XML element. Calling
|
2014-12-10 19:20:53 +11:00
|
|
|
* this will overwrite all the current properties of the container.
|
|
|
|
* @param element DOM element
|
|
|
|
* @returns true if properties were successfully read from element
|
|
|
|
* @note added in QGIS 2.7
|
|
|
|
* @see toXmlElement
|
|
|
|
*/
|
|
|
|
bool setFromXmlElement( const QDomElement& element );
|
2014-12-30 22:06:00 +01:00
|
|
|
|
2014-12-12 06:20:58 +11:00
|
|
|
bool operator==( const QgsDataDefined &other ) const;
|
|
|
|
bool operator!=( const QgsDataDefined &other ) const;
|
2013-05-15 04:39:23 -06:00
|
|
|
|
|
|
|
};
|