2013-10-04 14:47:59 +02:00
|
|
|
/***************************************************************************
|
|
|
|
qgsrelation.sip
|
|
|
|
--------------------------------------
|
|
|
|
Date : 29.4.2013
|
|
|
|
Copyright : (C) 2013 Matthias Kuhn
|
2015-08-30 12:59:30 +02:00
|
|
|
Email : matthias at opengis dot ch
|
2013-10-04 14:47:59 +02:00
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
class QgsRelation
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsrelation.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
|
|
|
|
QgsRelation();
|
2016-07-19 11:45:47 +10:00
|
|
|
static QgsRelation createFromXml( const QDomNode& node );
|
2013-10-04 14:47:59 +02:00
|
|
|
|
2016-07-19 11:45:47 +10:00
|
|
|
void writeXml( QDomNode& node, QDomDocument& doc ) const;
|
2013-10-04 14:47:59 +02:00
|
|
|
|
2017-02-17 16:50:43 +01:00
|
|
|
void setId( const QString& id );
|
2013-10-04 14:47:59 +02:00
|
|
|
|
2017-02-17 16:50:43 +01:00
|
|
|
void setName( const QString& name );
|
2013-10-04 14:47:59 +02:00
|
|
|
|
2015-10-07 11:55:34 +11:00
|
|
|
void setReferencingLayer( const QString& id );
|
2013-10-04 14:47:59 +02:00
|
|
|
|
2015-10-07 11:55:34 +11:00
|
|
|
void setReferencedLayer( const QString& id );
|
|
|
|
void addFieldPair( const QString& referencingField, const QString& referencedField );
|
2016-02-02 19:46:18 +11:00
|
|
|
// void addFieldPair( const FieldPair& fieldPair );
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2013-10-04 14:47:59 +02:00
|
|
|
QgsFeatureIterator getRelatedFeatures( const QgsFeature& feature ) const;
|
|
|
|
|
|
|
|
QgsFeatureRequest getRelatedFeaturesRequest( const QgsFeature& feature ) const;
|
[FEATURE] Aggregates for expressions
This commit adds a number of different forms of aggregates to
the expression engine.
1. Aggregates within the current layer, eg sum("passengers")
Supports sub expressions (ie sum("passengers"/2) ), group by
( sum("passengers", group_by:="line_segment") ), and optional
filters ( sum("passengers", filter:= "station_class" > 3 ) )
2. Relational aggregates, which calculate an aggregate over
all matching child features from a relation, eg
relation_aggregate( 'my_relation', 'mean', "some_child_field" )
3. A summary aggregate function, for calculating aggregates
on other layers. Eg aggregate('rail_station_layer','sum',"passengers")
The summary aggregate function supports an optional filter,
making it possible to calculate things like:
aggregate('rail_stations','sum',"passengers",
intersects(@atlas_geometry, $geometry ) )
for calculating the total number of passengers for the stations
inside the current atlas feature
In all cases the calculations are cached inside the expression
context, so they only need to be calculated once for each
set of expression evaluations.
Sponsored by Kanton of Zug, Switzerland
2016-05-16 17:30:07 +10:00
|
|
|
QString getRelatedFeaturesFilter( const QgsFeature& feature ) const;
|
2016-02-14 03:50:23 +01:00
|
|
|
QgsFeatureRequest getReferencedFeatureRequest( const QgsAttributes& attributes ) const;
|
2015-07-24 16:54:29 +02:00
|
|
|
QgsFeatureRequest getReferencedFeatureRequest( const QgsFeature& feature ) const;
|
2016-02-14 03:50:23 +01:00
|
|
|
QgsFeature getReferencedFeature( const QgsFeature& feature ) const;
|
2015-07-24 16:54:29 +02:00
|
|
|
QString name() const;
|
|
|
|
|
|
|
|
QString id() const;
|
2013-10-04 14:47:59 +02:00
|
|
|
|
2016-09-26 13:51:37 +02:00
|
|
|
void generateId();
|
|
|
|
|
2013-10-04 14:47:59 +02:00
|
|
|
QString referencingLayerId() const;
|
|
|
|
|
|
|
|
QgsVectorLayer* referencingLayer() const;
|
|
|
|
|
|
|
|
QString referencedLayerId() const;
|
|
|
|
|
|
|
|
QgsVectorLayer* referencedLayer() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the field pairs which form this relation
|
|
|
|
* The first element of each pair are the field names fo the foreign key.
|
|
|
|
* The second element of each pair are the field names of the matching primary key.
|
|
|
|
*
|
|
|
|
* @return The fields forming the relation
|
|
|
|
*/
|
|
|
|
QMap< QString, QString > fieldPairs() const;
|
|
|
|
%MethodCode
|
2014-08-18 14:56:15 +02:00
|
|
|
const QList< QgsRelation::FieldPair >& pairs = sipCpp->fieldPairs();
|
|
|
|
sipRes = new QMap< QString, QString >();
|
2013-10-04 14:47:59 +02:00
|
|
|
Q_FOREACH( const QgsRelation::FieldPair& pair, pairs )
|
|
|
|
{
|
|
|
|
sipRes->insert( pair.first, pair.second );
|
|
|
|
}
|
|
|
|
%End
|
|
|
|
|
2015-11-30 14:42:29 +01:00
|
|
|
QgsAttributeList referencedFields() const;
|
|
|
|
|
|
|
|
QgsAttributeList referencingFields() const;
|
|
|
|
|
2013-10-04 14:47:59 +02:00
|
|
|
bool isValid() const;
|
2016-09-26 13:51:37 +02:00
|
|
|
bool hasEqualDefinition( const QgsRelation& other ) const;
|
|
|
|
|
2017-02-20 09:00:50 +01:00
|
|
|
QString resolveReferencedField( const QString& referencingField ) const;
|
|
|
|
QString resolveReferencingField( const QString& referencedField ) const;
|
2013-10-04 14:47:59 +02:00
|
|
|
};
|