/
qgsmaplayerdependency.h
102 lines (86 loc) · 3.29 KB
/
qgsmaplayerdependency.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/***************************************************************************
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 "qgis_core.h"
#include <QString>
/**
* \ingroup core
* \brief 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
*
* \since 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( const QString &layerId, Type type = DataDependency, Origin origin = FromUser )
: mType( type )
, mOrigin( origin )
, mLayerId( layerId )
{}
//! Returns the dependency type
Type type() const { return mType; }
//! Returns the dependency origin
Origin origin() const { return mOrigin; }
//! Returns the ID of the layer this dependency depends on
QString layerId() const { return mLayerId; }
// TODO c++20 - replace with = default
//! Comparison operator
bool operator==( const QgsMapLayerDependency &other ) const
{
return layerId() == other.layerId() && origin() == other.origin() && type() == other.type();
}
#ifdef SIP_RUN
//! hash operator
long __hash__() const;
% MethodCode
sipRes = qHash( *sipCpp );
% End
#endif
private:
Type mType;
Origin mOrigin;
QString mLayerId;
};
#ifndef SIP_RUN
/**
* 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
#endif