24 : mReferencingLayer( NULL )
25 , mReferencedLayer( NULL )
32 QDomElement elem = node.toElement();
34 if ( elem.tagName() !=
"relation" )
36 QgsLogger::warning( QApplication::translate(
"QgsRelation",
"Cannot create relation. Unexpected tag '%1'" ).arg( elem.tagName() ) );
43 QString
id = elem.attribute(
"id" );
44 QString
name = elem.attribute(
"name" );
51 if ( NULL == referencingLayer )
53 QgsLogger::warning( QApplication::translate(
"QgsRelation",
"Relation defined for layer '%1' which does not exist." ).arg( referencingLayerId ) );
57 QgsLogger::warning( QApplication::translate(
"QgsRelation",
"Relation defined for layer '%1' which is not of type VectorLayer." ).arg( referencingLayerId ) );
60 if ( NULL == referencedLayer )
62 QgsLogger::warning( QApplication::translate(
"QgsRelation",
"Relation defined for layer '%1' which does not exist." ).arg( referencedLayerId ) );
66 QgsLogger::warning( QApplication::translate(
"QgsRelation",
"Relation defined for layer '%1' which is not of type VectorLayer." ).arg( referencedLayerId ) );
73 relation.mRelationId =
id;
74 relation.mRelationName =
name;
76 QDomNodeList references = elem.elementsByTagName(
"fieldRef" );
77 for (
int i = 0; i < references.size(); ++i )
79 QDomElement refEl = references.at( i ).toElement();
81 QString referencingField = refEl.attribute(
"referencingField" );
82 QString referencedField = refEl.attribute(
"referencedField" );
84 relation.
addFieldPair( referencingField, referencedField );
94 QDomElement elem = doc.createElement(
"relation" );
95 elem.setAttribute(
"id", mRelationId );
96 elem.setAttribute(
"name", mRelationName );
97 elem.setAttribute(
"referencingLayer", mReferencingLayerId );
98 elem.setAttribute(
"referencedLayer", mReferencedLayerId );
100 foreach (
FieldPair fields, mFieldPairs )
102 QDomElement referenceElem = doc.createElement(
"fieldRef" );
103 referenceElem.setAttribute(
"referencingField", fields.first );
104 referenceElem.setAttribute(
"referencedField", fields.second );
105 elem.appendChild( referenceElem );
108 node.appendChild( elem );
118 mRelationName =
name;
123 mReferencingLayerId =
id;
130 mReferencedLayerId =
id;
137 mFieldPairs <<
FieldPair( referencingField, referencedField );
143 mFieldPairs << fieldPair;
154 QStringList conditions;
161 switch ( referencingField.
type() )
163 case QVariant::String:
177 QgsDebugMsg( QString(
"Filter conditions: '%1'" ).arg( conditions.join(
" AND " ) ) );
186 return mRelationName;
196 return mReferencingLayerId;
201 return mReferencingLayer;
206 return mReferencedLayerId;
211 return mReferencedLayer;
228 mReferencingLayer = qobject_cast<
QgsVectorLayer*>( mapLayers[mReferencingLayerId] );
229 mReferencedLayer = qobject_cast<
QgsVectorLayer*>( mapLayers[mReferencedLayerId] );
233 if ( !mReferencedLayer || !mReferencingLayer )
239 if ( mFieldPairs.count() < 1 )
244 Q_FOREACH (
const FieldPair& fieldPair, mFieldPairs )
247 || -1 == mReferencedLayer->fieldNameIndex( fieldPair.second ) )