QGIS API Documentation
2.2.0-Valmiera
|
#include <qgsrelation.h>
Classes | |
class | FieldPair |
Defines a relation between matchin fields of the two involved tables of a relation. More... |
Public Member Functions | |
QgsRelation () | |
Default constructor. | |
void | writeXML (QDomNode &node, QDomDocument &doc) const |
Writes a relation to an XML structure. | |
void | setRelationId (QString id) |
Set a name for this relation. | |
void | setRelationName (QString name) |
Set a name for this relation. | |
void | setReferencingLayer (QString id) |
Set the referencing layer id. | |
void | setReferencedLayer (QString id) |
Set the referenced layer id. | |
void | addFieldPair (QString referencingField, QString referencedField) |
Add a field pairs which is part of this relation The first element of each pair are the field names fo the foreign key. | |
void | addFieldPair (FieldPair fieldPair) |
Add a field pairs which is part of this relation The first element of each pair are the field names fo the foreign key. | |
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. | |
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. | |
const QString | name () const |
const QString & | id () const |
The id. | |
QString | referencingLayerId () const |
Access the referencing (child) layer's id This is the layer which has the field(s) which point to another layer. | |
QgsVectorLayer * | referencingLayer () const |
Access the referencing (child) layer This is the layer which has the field(s) which point to another layer. | |
QString | referencedLayerId () const |
Access the referenced (parent) layer's id. | |
QgsVectorLayer * | referencedLayer () const |
Access the referenced (parent) layer. | |
QList< FieldPair > | fieldPairs () const |
Returns the field pairs which form this relation The first element of each pair are the field names fo the foreign key. | |
bool | isValid () const |
Returns the validity of this relation. |
Static Public Member Functions | |
static QgsRelation | createFromXML (const QDomNode &node) |
Creates a relation from an XML structure. |
Protected Member Functions | |
void | updateRelationStatus () |
void | runChecks () |
Private Attributes | |
QString | mRelationId |
Unique Id. | |
QString | mRelationName |
Human redable name. | |
QString | mReferencingLayerId |
The child layer. | |
QgsVectorLayer * | mReferencingLayer |
The child layer. | |
QString | mReferencedLayerId |
The parent layer id. | |
QgsVectorLayer * | mReferencedLayer |
The parent layer. | |
QList< FieldPair > | mFieldPairs |
A list of fields which define the relation. | |
bool | mValid |
Definition at line 28 of file qgsrelation.h.
QgsRelation::QgsRelation | ( | ) |
void QgsRelation::addFieldPair | ( | QString | referencingField, |
QString | referencedField | ||
) |
Add a field pairs which is part of 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.
referencingField | The field name on the referencing layer (FK) |
referencedField | The field name on the referenced layer (PK) |
Definition at line 135 of file qgsrelation.cpp.
References mFieldPairs, and updateRelationStatus().
Referenced by createFromXML(), and QgsRelationManagerDialog::on_mBtnAddRelation_clicked().
void QgsRelation::addFieldPair | ( | QgsRelation::FieldPair | fieldPair | ) |
Add a field pairs which is part of 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.
fieldPair | A pair of two strings |
Definition at line 141 of file qgsrelation.cpp.
References mFieldPairs, and updateRelationStatus().
|
static |
Creates a relation from an XML structure.
Used for reading .qgs projects.
node | The dom node containing the relation information |
Definition at line 30 of file qgsrelation.cpp.
References addFieldPair(), id(), QgsMapLayerRegistry::instance(), QgsMapLayerRegistry::mapLayers(), mReferencedLayer, mReferencedLayerId, mReferencingLayer, mReferencingLayerId, mRelationId, mRelationName, name(), referencedLayer(), referencedLayerId(), referencingLayer(), referencingLayerId(), QgsMapLayer::type(), updateRelationStatus(), QgsMapLayer::VectorLayer, and QgsLogger::warning().
Referenced by QgsRelationManager::readProject().
QList< QgsRelation::FieldPair > QgsRelation::fieldPairs | ( | ) | 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.
Definition at line 214 of file qgsrelation.cpp.
References mFieldPairs.
Referenced by QgsRelationManagerDialog::addRelation(), QgsRelationEditorWidget::on_mAddFeatureButton_clicked(), QgsRelationEditorWidget::on_mLinkFeatureButton_clicked(), QgsRelationEditorWidget::on_mUnlinkFeatureButton_clicked(), and QgsRelationManager::referencingRelations().
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 147 of file qgsrelation.cpp.
References QgsVectorLayer::getFeatures(), getRelatedFeaturesRequest(), and referencingLayer().
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 152 of file qgsrelation.cpp.
References QgsFields::at(), QgsFeature::attribute(), QgsFields::indexFromName(), mFieldPairs, QgsVectorLayer::pendingFields(), QgsDebugMsg, QgsRelation::FieldPair::referencedField(), QgsRelation::FieldPair::referencingField(), referencingLayer(), QgsFeatureRequest::setFilterExpression(), and QgsField::type().
Referenced by QgsRelationEditorWidget::createRelationEditor(), and getRelatedFeatures().
const QString & QgsRelation::id | ( | ) | const |
The id.
Definition at line 189 of file qgsrelation.cpp.
References mRelationId.
Referenced by QgsRelationManagerDialog::addRelation(), QgsRelationManager::addRelation(), createFromXML(), QgsAttributeDialog::init(), QgsRelationManagerDialog::on_mBtnAddRelation_clicked(), QgsRelationManager::removeRelation(), setReferencedLayer(), setReferencingLayer(), setRelationId(), and QgsAttributeEditorRelation::toDomElement().
bool QgsRelation::isValid | ( | ) | const |
Returns the validity of this relation.
Don't use the information if it's not valid.
Definition at line 219 of file qgsrelation.cpp.
References mValid.
Referenced by QgsRelationManager::addRelation(), QgsAttributeDialog::init(), and QgsAttributeEditorRelation::init().
const QString QgsRelation::name | ( | ) | const |
Definition at line 184 of file qgsrelation.cpp.
References mRelationName.
Referenced by QgsRelationManagerDialog::addRelation(), createFromXML(), and setRelationName().
QgsVectorLayer * QgsRelation::referencedLayer | ( | ) | const |
Access the referenced (parent) layer.
Definition at line 209 of file qgsrelation.cpp.
References mReferencedLayer.
Referenced by QgsRelationManagerDialog::addRelation(), createFromXML(), and QgsRelationManager::referencedRelations().
QString QgsRelation::referencedLayerId | ( | ) | const |
Access the referenced (parent) layer's id.
Definition at line 204 of file qgsrelation.cpp.
References mReferencedLayerId.
Referenced by createFromXML().
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 199 of file qgsrelation.cpp.
References mReferencingLayer.
Referenced by QgsRelationManagerDialog::addRelation(), createFromXML(), QgsRelationEditorWidget::createRelationEditor(), getRelatedFeatures(), getRelatedFeaturesRequest(), QgsRelationEditorWidget::on_mAddFeatureButton_clicked(), QgsRelationEditorWidget::on_mDeleteFeatureButton_clicked(), QgsRelationEditorWidget::on_mLinkFeatureButton_clicked(), QgsRelationEditorWidget::on_mToggleEditingButton_toggled(), QgsRelationEditorWidget::on_mUnlinkFeatureButton_clicked(), QgsRelationEditorWidget::QgsRelationEditorWidget(), QgsRelationEditorWidget::referencingLayerEditingToggled(), and QgsRelationManager::referencingRelations().
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 194 of file qgsrelation.cpp.
References mReferencingLayerId.
Referenced by createFromXML().
|
protected |
Definition at line 255 of file qgsrelation.cpp.
void QgsRelation::setReferencedLayer | ( | QString | id | ) |
Set the referenced layer id.
This layer will be searched in the registry.
id |
Definition at line 128 of file qgsrelation.cpp.
References id(), mReferencedLayerId, and updateRelationStatus().
Referenced by QgsRelationManagerDialog::on_mBtnAddRelation_clicked().
void QgsRelation::setReferencingLayer | ( | QString | id | ) |
Set the referencing layer id.
This layer will be searched in the registry.
id |
Definition at line 121 of file qgsrelation.cpp.
References id(), mReferencingLayerId, and updateRelationStatus().
Referenced by QgsRelationManagerDialog::on_mBtnAddRelation_clicked().
void QgsRelation::setRelationId | ( | QString | id | ) |
Set a name for this relation.
id |
Definition at line 111 of file qgsrelation.cpp.
References id(), and mRelationId.
Referenced by QgsRelationManagerDialog::on_mBtnAddRelation_clicked().
void QgsRelation::setRelationName | ( | QString | name | ) |
Set a name for this relation.
name |
Definition at line 116 of file qgsrelation.cpp.
References mRelationName, and name().
Referenced by QgsRelationManagerDialog::on_mBtnAddRelation_clicked(), and QgsRelationManagerDialog::relations().
|
protected |
Definition at line 224 of file qgsrelation.cpp.
References QgsVectorLayer::fieldNameIndex(), QgsMapLayerRegistry::instance(), QgsMapLayerRegistry::mapLayers(), mFieldPairs, mReferencedLayer, mReferencedLayerId, mReferencingLayer, mReferencingLayerId, and mValid.
Referenced by addFieldPair(), createFromXML(), setReferencedLayer(), and setReferencingLayer().
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 92 of file qgsrelation.cpp.
References mFieldPairs, mReferencedLayerId, mReferencingLayerId, mRelationId, and mRelationName.
Referenced by QgsRelationManager::writeProject().
|
private |
A list of fields which define the relation.
In most cases there will be only one value, but multiple values are supported for composited foreign keys. The first field is on the referencing layer, the second on the referenced
Definition at line 219 of file qgsrelation.h.
Referenced by addFieldPair(), fieldPairs(), getRelatedFeaturesRequest(), updateRelationStatus(), and writeXML().
|
private |
The parent layer.
Definition at line 214 of file qgsrelation.h.
Referenced by createFromXML(), referencedLayer(), and updateRelationStatus().
|
private |
The parent layer id.
Definition at line 212 of file qgsrelation.h.
Referenced by createFromXML(), referencedLayerId(), setReferencedLayer(), updateRelationStatus(), and writeXML().
|
private |
The child layer.
Definition at line 210 of file qgsrelation.h.
Referenced by createFromXML(), referencingLayer(), and updateRelationStatus().
|
private |
The child layer.
Definition at line 208 of file qgsrelation.h.
Referenced by createFromXML(), referencingLayerId(), setReferencingLayer(), updateRelationStatus(), and writeXML().
|
private |
Unique Id.
Definition at line 204 of file qgsrelation.h.
Referenced by createFromXML(), id(), setRelationId(), and writeXML().
|
private |
Human redable name.
Definition at line 206 of file qgsrelation.h.
Referenced by createFromXML(), name(), setRelationName(), and writeXML().
|
private |
Definition at line 221 of file qgsrelation.h.
Referenced by isValid(), and updateRelationStatus().