QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
|
Represents a relationship between two vector layers. More...
#include <qgsrelation.h>
Classes | |
class | FieldPair |
Defines a relation between matching fields of the two involved tables of a relation. More... | |
Public Member Functions | |
QgsRelation () | |
Default constructor. | |
QgsRelation (const QgsRelation &other) | |
Copies a relation. | |
QgsRelation (const QgsRelationContext &context) | |
Constructor with context. | |
~QgsRelation () | |
void | addFieldPair (const FieldPair &fieldPair) |
Add a field pair which is part of this relation The first element of each pair are the field names of the foreign key. | |
void | addFieldPair (const QString &referencingField, const QString &referencedField) |
Add a field pair which is part of this relation The first element of each pair are the field names of the foreign key. | |
QList< QgsRelation::FieldPair > | fieldPairs () const |
Returns the field pairs which form this relation The first element of each pair are the field names of the foreign key. | |
void | generateId () |
Generate a (project-wide) unique id for this relation. | |
QgsFeature | getReferencedFeature (const QgsFeature &feature) const |
Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature. | |
QgsFeatureRequest | getReferencedFeatureRequest (const QgsAttributes &attributes) const |
Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature. | |
QgsFeatureRequest | getReferencedFeatureRequest (const QgsFeature &feature) const |
Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature. | |
QgsFeatureIterator | getRelatedFeatures (const QgsFeature &feature) const |
Creates an iterator which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature. | |
QString | getRelatedFeaturesFilter (const QgsFeature &feature) const |
Returns a filter expression which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature. | |
QgsFeatureRequest | getRelatedFeaturesRequest (const QgsFeature &feature) const |
Creates a request to return all the features on the referencing (child) layer which have a foreign key pointing to the provided feature. | |
bool | hasEqualDefinition (const QgsRelation &other) const |
Compares the two QgsRelation, ignoring the name and the ID. | |
QString | id () const |
A (project-wide) unique id for this relation. | |
bool | isValid () const |
Returns the validity of this relation. | |
QString | name () const |
Returns a human readable name for this relation. | |
QgsRelation & | operator= (const QgsRelation &other) |
Copies a relation. | |
QgsPolymorphicRelation | polymorphicRelation () const |
Returns the parent polymorphic relation. | |
QString | polymorphicRelationId () const |
Returns the parent polymorphic relation id. | |
QgsAttributeList | referencedFields () const |
Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer. | |
QgsVectorLayer * | referencedLayer () const |
Access the referenced (parent) layer. | |
QString | referencedLayerId () const |
Access the referenced (parent) layer's id. | |
QgsAttributeList | referencingFields () const |
Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer. | |
bool | referencingFieldsAllowNull () const |
Returns true if none of the referencing fields has a NOT NULL constraint. | |
QgsVectorLayer * | referencingLayer () const |
Access the referencing (child) layer This is the layer which has the field(s) which point to another layer. | |
QString | referencingLayerId () const |
Access the referencing (child) layer's id This is the layer which has the field(s) which point to another layer. | |
Q_INVOKABLE QString | resolveReferencedField (const QString &referencingField) const |
Gets the referenced field counterpart given a referencing field. | |
Q_INVOKABLE QString | resolveReferencingField (const QString &referencedField) const |
Gets the referencing field counterpart given a referenced field. | |
void | setId (const QString &id) |
Set an id for this relation. | |
void | setName (const QString &name) |
Set a name for this relation. | |
void | setPolymorphicRelationId (const QString &polymorphicRelationId) |
Sets the parent polymorphic relation id. | |
void | setReferencedLayer (const QString &id) |
Set the referenced (parent) layer id. | |
void | setReferencingLayer (const QString &id) |
Set the referencing (child) layer id. | |
void | setStrength (Qgis::RelationshipStrength strength) |
Set a strength for this relation. | |
Qgis::RelationshipStrength | strength () const |
Returns the relation strength as a string. | |
Qgis::RelationshipType | type () const |
Returns the type of the relation. | |
void | updateRelationStatus () |
Updates the validity status of this relation. | |
QString | validationError () const |
Returns a user-friendly explanation for why the relationship is invalid. | |
void | writeXml (QDomNode &node, QDomDocument &doc) const |
Writes a relation to an XML structure. | |
Static Public Member Functions | |
static QString | cardinalityToDisplayString (Qgis::RelationshipCardinality cardinality) |
Returns a user-friendly translated string representing a relationship cardinality. | |
static QgsRelation | createFromXml (const QDomNode &node, QgsReadWriteContext &context, const QgsRelationContext &relationContext=QgsRelationContext()) |
Creates a relation from an XML structure. | |
static QString | strengthToDisplayString (Qgis::RelationshipStrength strength) |
Returns a user-friendly translated string representing a relationship strength. | |
Properties | |
QString | id |
bool | isValid |
QString | name |
QgsPolymorphicRelation | polymorphicRelation |
QString | polymorphicRelationId |
QgsVectorLayer * | referencedLayer |
QgsVectorLayer * | referencingLayer |
Represents a relationship between two vector layers.
Definition at line 43 of file qgsrelation.h.
QgsRelation::QgsRelation | ( | ) |
|
default |
QgsRelation::QgsRelation | ( | const QgsRelationContext & | context | ) |
Constructor with context.
Creates an invalid relation.
Definition at line 33 of file qgsrelation.cpp.
QgsRelation::QgsRelation | ( | const QgsRelation & | other | ) |
Copies a relation.
This makes a shallow copy, relations are implicitly shared and only duplicated when the copy is changed.
Definition at line 41 of file qgsrelation.cpp.
void QgsRelation::addFieldPair | ( | const FieldPair & | fieldPair | ) |
Add a field pair which is part of this relation The first element of each pair are the field names of the foreign key.
The second element of each pair are the field names of the matching primary key.
fieldPair | A pair of two strings |
Definition at line 182 of file qgsrelation.cpp.
void QgsRelation::addFieldPair | ( | const QString & | referencingField, |
const QString & | referencedField | ||
) |
Add a field pair which is part of this relation The first element of each pair are the field names of the foreign key.
The second element of each pair are the field names of the matching primary key.
referencingField | The field name on the referencing (child) layer (FK) |
referencedField | The field name on the referenced (parent) layer (PK) |
Definition at line 175 of file qgsrelation.cpp.
|
static |
Returns a user-friendly translated string representing a relationship cardinality.
Definition at line 523 of file qgsrelation.cpp.
|
static |
Creates a relation from an XML structure.
Used for reading .qgs projects.
node | The dom node containing the relation information |
context | to pass project translator |
relationContext | a relation context |
Definition at line 54 of file qgsrelation.cpp.
QList< QgsRelation::FieldPair > QgsRelation::fieldPairs | ( | ) | const |
Returns the field pairs which form this relation The first element of each pair are the field names of the foreign key.
The second element of each pair are the field names of the matching primary key.
Definition at line 331 of file qgsrelation.cpp.
void QgsRelation::generateId | ( | ) |
Generate a (project-wide) unique id for this relation.
Definition at line 297 of file qgsrelation.cpp.
QgsFeature QgsRelation::getReferencedFeature | ( | const QgsFeature & | feature | ) | const |
Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.
feature | A feature from the referencing (child) layer |
Definition at line 273 of file qgsrelation.cpp.
QgsFeatureRequest QgsRelation::getReferencedFeatureRequest | ( | const QgsAttributes & | attributes | ) | const |
Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.
attributes | An attribute vector containing the foreign key |
Definition at line 240 of file qgsrelation.cpp.
QgsFeatureRequest QgsRelation::getReferencedFeatureRequest | ( | const QgsFeature & | feature | ) | const |
Creates a request to return the feature on the referenced (parent) layer which is referenced by the provided feature.
feature | A feature from the referencing (child) layer |
Definition at line 268 of file qgsrelation.cpp.
QgsFeatureIterator QgsRelation::getRelatedFeatures | ( | const QgsFeature & | feature | ) | const |
Creates an iterator which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.
feature | A feature from the referenced (parent) layer |
Definition at line 189 of file qgsrelation.cpp.
QString QgsRelation::getRelatedFeaturesFilter | ( | const QgsFeature & | feature | ) | const |
Returns a filter expression which returns all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.
feature | A feature from the referenced (parent) layer |
Definition at line 204 of file qgsrelation.cpp.
QgsFeatureRequest QgsRelation::getRelatedFeaturesRequest | ( | const QgsFeature & | feature | ) | const |
Creates a request to return all the features on the referencing (child) layer which have a foreign key pointing to the provided feature.
feature | A feature from the referenced (parent) layer |
Definition at line 194 of file qgsrelation.cpp.
bool QgsRelation::hasEqualDefinition | ( | const QgsRelation & | other | ) | const |
Compares the two QgsRelation, ignoring the name and the ID.
other | The other relation |
true
if they are similar Definition at line 411 of file qgsrelation.cpp.
QString QgsRelation::id | ( | ) | const |
A (project-wide) unique id for this relation.
Definition at line 292 of file qgsrelation.cpp.
bool QgsRelation::isValid | ( | ) | const |
Returns the validity of this relation.
Don't use the information if it's not valid. A relation is considered valid if both referenced and referencig layers are valid.
true
if the relation is validDefinition at line 379 of file qgsrelation.cpp.
QString QgsRelation::name | ( | ) | const |
Returns a human readable name for this relation.
Mostly used as title for the children.
Definition at line 282 of file qgsrelation.cpp.
QgsRelation & QgsRelation::operator= | ( | const QgsRelation & | other | ) |
Copies a relation.
This makes a shallow copy, relations are implicitly shared and only duplicated when the copy is changed.
Definition at line 47 of file qgsrelation.cpp.
QgsPolymorphicRelation QgsRelation::polymorphicRelation | ( | ) | const |
Returns the parent polymorphic relation.
If the relation is a normal relation, an invalid polymorphic relation is returned.
Definition at line 507 of file qgsrelation.cpp.
QString QgsRelation::polymorphicRelationId | ( | ) | const |
Returns the parent polymorphic relation id.
If the relation is a normal relation, a null string is returned.
Definition at line 502 of file qgsrelation.cpp.
QgsAttributeList QgsRelation::referencedFields | ( | ) | const |
Returns a list of attributes used to form the referenced fields (most likely primary key) on the referenced (parent) layer.
Definition at line 336 of file qgsrelation.cpp.
QgsVectorLayer * QgsRelation::referencedLayer | ( | ) | const |
Access the referenced (parent) layer.
Definition at line 326 of file qgsrelation.cpp.
QString QgsRelation::referencedLayerId | ( | ) | const |
Access the referenced (parent) layer's id.
Definition at line 321 of file qgsrelation.cpp.
QgsAttributeList QgsRelation::referencingFields | ( | ) | const |
Returns a list of attributes used to form the referencing fields (foreign key) on the referencing (child) layer.
Definition at line 347 of file qgsrelation.cpp.
bool QgsRelation::referencingFieldsAllowNull | ( | ) | const |
Returns true
if none of the referencing fields has a NOT NULL constraint.
Definition at line 359 of file qgsrelation.cpp.
QgsVectorLayer * QgsRelation::referencingLayer | ( | ) | const |
Access the referencing (child) layer This is the layer which has the field(s) which point to another layer.
Definition at line 316 of file qgsrelation.cpp.
QString QgsRelation::referencingLayerId | ( | ) | const |
Access the referencing (child) layer's id This is the layer which has the field(s) which point to another layer.
Definition at line 311 of file qgsrelation.cpp.
QString QgsRelation::resolveReferencedField | ( | const QString & | referencingField | ) | const |
Gets the referenced field counterpart given a referencing field.
Definition at line 416 of file qgsrelation.cpp.
QString QgsRelation::resolveReferencingField | ( | const QString & | referencedField | ) | const |
Gets the referencing field counterpart given a referenced field.
Definition at line 426 of file qgsrelation.cpp.
void QgsRelation::setId | ( | const QString & | id | ) |
Set an id for this relation.
Definition at line 138 of file qgsrelation.cpp.
void QgsRelation::setName | ( | const QString & | name | ) |
Set a name for this relation.
Definition at line 146 of file qgsrelation.cpp.
void QgsRelation::setPolymorphicRelationId | ( | const QString & | polymorphicRelationId | ) |
Sets the parent polymorphic relation id.
Definition at line 496 of file qgsrelation.cpp.
void QgsRelation::setReferencedLayer | ( | const QString & | id | ) |
Set the referenced (parent) layer id.
This layer will be searched in the registry.
Definition at line 167 of file qgsrelation.cpp.
void QgsRelation::setReferencingLayer | ( | const QString & | id | ) |
Set the referencing (child) layer id.
This layer will be searched in the registry.
Definition at line 159 of file qgsrelation.cpp.
void QgsRelation::setStrength | ( | Qgis::RelationshipStrength | strength | ) |
Set a strength for this relation.
Definition at line 153 of file qgsrelation.cpp.
Qgis::RelationshipStrength QgsRelation::strength | ( | ) | const |
Returns the relation strength as a string.
Definition at line 287 of file qgsrelation.cpp.
|
static |
Returns a user-friendly translated string representing a relationship strength.
Definition at line 539 of file qgsrelation.cpp.
Qgis::RelationshipType QgsRelation::type | ( | ) | const |
void QgsRelation::updateRelationStatus | ( | ) |
Updates the validity status of this relation.
Will be called internally whenever a member is changed.
Definition at line 436 of file qgsrelation.cpp.
QString QgsRelation::validationError | ( | ) | const |
Returns a user-friendly explanation for why the relationship is invalid.
Returns an empty string if the relationship isValid().
Definition at line 384 of file qgsrelation.cpp.
void QgsRelation::writeXml | ( | QDomNode & | node, |
QDomDocument & | doc | ||
) | const |
Writes a relation to an XML structure.
Used for saving .qgs projects
node | The parent node in which the relation will be created |
doc | The document in which the relation will be saved |
Definition at line 118 of file qgsrelation.cpp.
|
readwrite |
Definition at line 47 of file qgsrelation.h.
|
read |
Definition at line 51 of file qgsrelation.h.
|
readwrite |
Definition at line 50 of file qgsrelation.h.
|
read |
Definition at line 53 of file qgsrelation.h.
|
readwrite |
Definition at line 52 of file qgsrelation.h.
|
read |
Definition at line 49 of file qgsrelation.h.
|
read |
Definition at line 48 of file qgsrelation.h.