A new class QgsMapLayerDependency allows to represent different kinds of dependencies between layers.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class QgsMapLayerDependency | ||
{ | ||
%TypeHeaderCode | ||
#include "qgsmaplayerdependency.h" | ||
%End | ||
public: | ||
//! Type of dependency | ||
enum Type | ||
{ | ||
PresenceDependency = 1, // The layer must be already present (in the registry) for this dependency to be resolved | ||
DataDependency = 2 // The layer may be invalidated by data changes on another layer | ||
}; | ||
|
||
//! Origin of the dependency | ||
enum Origin | ||
{ | ||
FromProvider = 0, // Dependency given by the provider, the user cannot change it | ||
FromUser = 1 // Dependency given by the user | ||
}; | ||
|
||
//! Standard constructor | ||
QgsMapLayerDependency( QString layerId, Type type = DataDependency, Origin origin = FromUser ); | ||
|
||
//! Return the dependency type | ||
Type type() const; | ||
|
||
//! Return the dependency origin | ||
Origin origin() const; | ||
|
||
//! Return the ID of the layer this dependency depends on | ||
QString layerId() const; | ||
|
||
bool operator==( const QgsMapLayerDependency& other ) const; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -32,6 +32,7 @@ | ||
#include "qgsrectangle.h" | ||
#include "qgscoordinatereferencesystem.h" | ||
#include "qgsrendercontext.h" | ||
#include "qgsmaplayerdependency.h" | ||
|
||
class QgsMapLayerLegend; | ||
class QgsMapLayerRenderer; | ||
@@ -700,20 +701,29 @@ class CORE_EXPORT QgsMapLayer : public QObject | ||
|
||
/** | ||
* Sets the list of layers that may modify data/geometries of this layer when modified. | ||
* @see dataDependencies | ||
* @see dependencies() | ||
* | ||
* @param layersIds IDs of the layers that this layer depends on | ||
* @returns false if a dependency cycle has been detected (the change dependency set is not changed in that case) | ||
*/ | ||
virtual bool setDataDependencies( const QSet<QString>& layersIds ); | ||
|
||
/** | ||
* Gets the list of layers that may modify data/geometries of this layer when modified. | ||
* @see setDataDependencies | ||
* Sets the list of layers that may modify data/geometries of this layer when modified. | ||
* @see dependencies() | ||
* | ||
* @param layers set of QgsMapLayerDependency. Only user-defined dependencies will be added | ||
* @returns false if a dependency cycle has been detected (the change dependency set is not changed in that case) | ||
*/ | ||
bool setDataDependencies( const QSet<QgsMapLayerDependency>& layers ); | ||
This comment has been minimized.
Sorry, something went wrong.
m-kuhn
Member
|
||
|
||
/** | ||
* Gets the list of dependencies. This includes data dependencies set by the user (@see setDataDependencies) | ||
* as well as dependencies given by the provider | ||
* | ||
* @returns IDs of the layers that this layer depends on | ||
* @returns a set of QgsMapLayerDependency | ||
*/ | ||
virtual QSet<QString> dataDependencies() const; | ||
virtual QSet<QgsMapLayerDependency> dependencies() const; | ||
|
||
signals: | ||
|
||
@@ -854,10 +864,10 @@ class CORE_EXPORT QgsMapLayer : public QObject | ||
QgsError mError; | ||
|
||
//! List of layers that may modify this layer on modification | ||
QSet<QString> mDataDependencies; | ||
QSet<QgsMapLayerDependency> mDataDependencies; | ||
|
||
//! Checks whether a new set of data dependencies will introduce a cycle | ||
bool hasDataDependencyCycle( const QSet<QString>& layersIds ) const; | ||
bool hasDataDependencyCycle( const QSet<QgsMapLayerDependency>& layers ) const; | ||
|
||
private: | ||
/** | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
/*************************************************************************** | ||
qgsmaplayerdependency.h - description | ||
------------------- | ||
begin : September 2016 | ||
copyright : (C) 2016 by Hugo Mercier | ||
email : hugo dot mercier at oslandia dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSMAPLAYERDEPENDENCY_H | ||
#define QGSMAPLAYERDEPENDENCY_H | ||
|
||
#include <QString> | ||
|
||
/** \ingroup core | ||
* This class models dependencies with or between map layers. | ||
* A dependency is defined by a layer ID, a type and an origin. | ||
* The two combinations of type/origin that are currently supported are: | ||
* - PresenceDependency && FromProvider: virtual layers for instance which may depend on other layers already loaded to work | ||
* - DataDependency && FromUser: dependencies given by the user, mainly to represent database triggers | ||
* | ||
* @note added in QGIS 3.0 | ||
*/ | ||
class CORE_EXPORT QgsMapLayerDependency | ||
{ | ||
public: | ||
//! Type of dependency | ||
enum Type | ||
{ | ||
PresenceDependency = 1, //< The layer must be already present (in the registry) for this dependency to be resolved | ||
DataDependency = 2 //< The layer may be invalidated by data changes on another layer | ||
}; | ||
|
||
//! Origin of the dependency | ||
enum Origin | ||
{ | ||
FromProvider = 0, //< Dependency given by the provider, the user cannot change it | ||
FromUser = 1 //< Dependency given by the user | ||
}; | ||
|
||
//! Standard constructor | ||
QgsMapLayerDependency( QString layerId, Type type = DataDependency, Origin origin = FromUser ) : | ||
mType( type ), | ||
mOrigin( origin ), | ||
mLayerId( layerId ) | ||
{} | ||
|
||
//! Return the dependency type | ||
Type type() const { return mType; } | ||
|
||
//! Return the dependency origin | ||
Origin origin() const { return mOrigin; } | ||
|
||
//! Return the ID of the layer this dependency depends on | ||
QString layerId() const { return mLayerId; } | ||
|
||
//! Comparison operator | ||
bool operator==( const QgsMapLayerDependency& other ) const | ||
{ | ||
return layerId() == other.layerId() && origin() == other.origin() && type() == other.type(); | ||
} | ||
private: | ||
Type mType; | ||
Origin mOrigin; | ||
QString mLayerId; | ||
}; | ||
|
||
/** | ||
* global qHash function for QgsMapLayerDependency, so that it can be used in a QSet | ||
*/ | ||
inline uint qHash( const QgsMapLayerDependency& dep ) | ||
{ | ||
return qHash( dep.layerId() ) + dep.origin() + dep.type(); | ||
} | ||
|
||
#endif |
1 comment
on commit 0749ba4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature, I'm sure I'll want to use it soon :)
It would also be good to send a signal when this is set so the rest of the world can subscribe to notifications.
I always do setters like this: