2014-01-27 09:22:24 +01:00
|
|
|
/**
|
|
|
|
* This class manages a set of relations between layers.
|
|
|
|
*/
|
|
|
|
class QgsRelationManager : QObject
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include "qgsrelationmanager.h"
|
|
|
|
%End
|
|
|
|
public:
|
2016-05-17 07:33:50 +10:00
|
|
|
|
|
|
|
/** Constructor for QgsRelationManager.
|
|
|
|
* @param project associated project (used to notify project of changes)
|
|
|
|
*/
|
|
|
|
explicit QgsRelationManager( QgsProject *project = nullptr );
|
2014-01-27 09:22:24 +01:00
|
|
|
|
2015-02-03 02:21:52 +01:00
|
|
|
/**
|
|
|
|
* Will set the specified relations and remove any relation currently set.
|
|
|
|
*
|
|
|
|
* @param relations A list of relations to set.
|
|
|
|
*/
|
2014-01-27 09:22:24 +01:00
|
|
|
void setRelations( const QList<QgsRelation>& relations );
|
2015-02-03 02:21:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get access to the relations managed by this class.
|
|
|
|
*
|
|
|
|
* @return A QMap where the key is the relation id, the value the relation object.
|
|
|
|
*/
|
2017-01-14 13:46:26 +10:00
|
|
|
QMap<QString, QgsRelation> relations() const;
|
2015-02-03 02:21:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a relation.
|
|
|
|
*
|
|
|
|
* @param relation The relation to add.
|
|
|
|
*/
|
2014-01-27 09:22:24 +01:00
|
|
|
void addRelation( const QgsRelation& relation );
|
2015-02-03 02:21:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a relation.
|
|
|
|
*
|
|
|
|
* @param id The id of the relation to remove.
|
|
|
|
*/
|
2014-09-19 09:38:05 +02:00
|
|
|
void removeRelation( const QString& id );
|
2015-02-03 02:21:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a relation.
|
|
|
|
*
|
|
|
|
* @param relation The relation to remove.
|
|
|
|
*/
|
2014-01-27 09:22:24 +01:00
|
|
|
void removeRelation( const QgsRelation& relation );
|
2015-02-03 02:21:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get access to a relation by its id.
|
|
|
|
*
|
|
|
|
* @param id The id to search for
|
|
|
|
*
|
|
|
|
* @return A relation. Invalid if not found.
|
2016-05-17 07:33:50 +10:00
|
|
|
* @see relationsByName()
|
2015-02-03 02:21:52 +01:00
|
|
|
*/
|
2014-01-27 09:22:24 +01:00
|
|
|
QgsRelation relation( const QString& id ) const;
|
2015-02-03 02:21:52 +01:00
|
|
|
|
2016-05-17 07:33:50 +10:00
|
|
|
/** Returns a list of relations with matching names.
|
|
|
|
* @param name relation name to search for. Searching is case insensitive.
|
|
|
|
* @returns a list of matching relations
|
|
|
|
* @note added in QGIS 2.16
|
|
|
|
* @see relation()
|
|
|
|
*/
|
|
|
|
QList<QgsRelation> relationsByName( const QString& name ) const;
|
|
|
|
|
2015-02-03 02:21:52 +01:00
|
|
|
/**
|
|
|
|
* Remove any relation managed by this class.
|
|
|
|
*/
|
2014-01-27 09:22:24 +01:00
|
|
|
void clear();
|
|
|
|
|
2015-02-03 02:21:52 +01:00
|
|
|
/**
|
|
|
|
* Get all relations where the specified layer (and field) is the referencing part (i.e. the child table with the foreign key).
|
|
|
|
*
|
|
|
|
* @param layer The layer which should be searched for.
|
|
|
|
* @param fieldIdx The field which should be part of the foreign key. If not set will return all relations.
|
|
|
|
*
|
|
|
|
* @return A list of relations matching the given layer and fieldIdx.
|
|
|
|
*/
|
2016-07-11 12:06:06 +10:00
|
|
|
QList<QgsRelation> referencingRelations( const QgsVectorLayer *layer = 0, int fieldIdx = -2 ) const;
|
2015-02-03 02:21:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all relations where this layer is the referenced part (i.e. the parent table with the primary key being referenced from another layer).
|
|
|
|
*
|
|
|
|
* @param layer The layer which should be searched for.
|
|
|
|
*
|
|
|
|
* @return A list of relations where the specified layer is the referenced part.
|
|
|
|
*/
|
2014-01-27 09:22:24 +01:00
|
|
|
QList<QgsRelation> referencedRelations( QgsVectorLayer *layer = 0 ) const;
|
|
|
|
|
2016-09-26 13:51:37 +02:00
|
|
|
/**
|
|
|
|
* Discover all the relations available from the current layers.
|
|
|
|
*
|
|
|
|
* @param existingRelations the existing relations to filter them out
|
|
|
|
* @param layers the current layers
|
|
|
|
* @return the list of discovered relations
|
|
|
|
* @note added in QGIS 3.0
|
|
|
|
*/
|
|
|
|
static QList<QgsRelation> discoverRelations( const QList<QgsRelation>& existingRelations, const QList<QgsVectorLayer*>& layers );
|
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
signals:
|
2015-07-29 11:52:14 +02:00
|
|
|
/** This signal is emitted when the relations were loaded after reading a project */
|
2014-01-27 09:22:24 +01:00
|
|
|
void relationsLoaded();
|
2014-11-13 23:13:13 +01:00
|
|
|
|
2014-09-20 22:12:26 +10:00
|
|
|
/**
|
|
|
|
* Emitted when relations are added or removed to the manager.
|
|
|
|
* @note added in QGIS 2.5
|
|
|
|
*/
|
|
|
|
void changed();
|
2014-01-27 09:22:24 +01:00
|
|
|
};
|