28 connect( project, SIGNAL( readProject(
const QDomDocument& ) ), SLOT( readProject(
const QDomDocument& ) ) );
29 connect( project, SIGNAL( writeProject( QDomDocument& ) ), SLOT( writeProject( QDomDocument& ) ) );
55 mProject->
dirty(
true );
61 mRelations.remove(
id );
67 mRelations.remove( relation.
id() );
73 return mRelations.value(
id );
86 return mRelations.values();
97 bool containsField =
false;
102 containsField =
true;
107 if ( !containsField )
112 relations.append( rel );
123 return mRelations.values();
132 relations.append( rel );
139 void QgsRelationManager::readProject(
const QDomDocument & doc )
143 QDomNodeList nodes = doc.elementsByTagName(
"relations" );
146 QDomNode node = nodes.item( 0 );
147 QDomNodeList relationNodes = node.childNodes();
148 int relCount = relationNodes.count();
149 for (
int i = 0; i < relCount; ++i )
156 QgsDebugMsg(
"No relations data present in this document" );
163 void QgsRelationManager::writeProject( QDomDocument & doc )
165 QDomNodeList nl = doc.elementsByTagName(
"qgis" );
168 QgsDebugMsg(
"Unable to find qgis element in project file" );
171 QDomNode qgisNode = nl.item( 0 );
173 QDomElement relationsNode = doc.createElement(
"relations" );
174 qgisNode.appendChild( relationsNode );
178 relation.
writeXML( relationsNode, doc );
182 void QgsRelationManager::layersRemoved(
const QStringList& layers )
184 bool relationsChanged =
false;
185 Q_FOREACH (
const QString& layer, layers )
187 QMapIterator<QString, QgsRelation> it( mRelations );
189 while ( it.hasNext() )
193 if ( it.value().referencedLayerId() == layer
194 || it.value().referencingLayerId() == layer )
196 mRelations.remove( it.key() );
197 relationsChanged =
true;
201 if ( relationsChanged )
bool isValid() const
Returns the validity of this relation.
static QgsMapLayerRegistry * instance()
QgsVectorLayer * referencedLayer() const
Access the referenced (parent) layer.
static QgsRelation createFromXML(const QDomNode &node)
Creates a relation from an XML structure.
void writeXML(QDomNode &node, QDomDocument &doc) const
Writes a relation to an XML structure.
void clear()
Remove any relation managed by this class.
void setRelations(const QList< QgsRelation > &relations)
Will set the specified relations and remove any relation currently set.
QList< QgsRelation > referencedRelations(QgsVectorLayer *layer=0) const
Get all relations where this layer is the referenced part (i.e.
const QMap< QString, QgsRelation > & relations() const
Get access to the relations managed by this class.
Defines a relation between matchin fields of the two involved tables of a relation.
QgsRelation relation(const QString &id) const
Get access to a relation by its id.
const QString & id() const
The id.
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
Reads and writes project states.
QList< QgsRelation > referencingRelations(QgsVectorLayer *layer=0, int fieldIdx=-2) const
Get all relations where the specified layer (and field) is the referencing part (i.e.
QgsRelationManager(QgsProject *project)
void relationsLoaded()
this signal is emitted when the relations were loaded after reading a project
const QString & referencingField() const
Get the name of the referencing field.
void changed()
Emitted when relations are added or removed to the manager.
QList< FieldPair > fieldPairs() const
Returns the field pairs which form this relation The first element of each pair are the field names f...
void removeRelation(const QString &id)
Remove a relation.
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
void addRelation(const QgsRelation &relation)
Add a relation.