QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
elevation
qgsprofilesourceregistry.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsprofilesourceregistry.cpp
3
--------------------------------------
4
Date : April 2024
5
Copyright : (C) 2024 by Germán Carrillo
6
Email : german at opengis dot ch
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
#include "
qgsprofilesourceregistry.h
"
16
17
#include "
qgsabstractprofilesource.h
"
18
#include "
qgslogger.h
"
19
20
#include <QString>
21
22
#include "moc_qgsprofilesourceregistry.cpp"
23
24
using namespace
Qt::StringLiterals;
25
26
QgsProfileSourceRegistry::QgsProfileSourceRegistry
()
27
{}
28
29
QgsProfileSourceRegistry::~QgsProfileSourceRegistry
()
30
{
31
qDeleteAll( mSources );
32
}
33
34
QList< QgsAbstractProfileSource * >
QgsProfileSourceRegistry::profileSources
()
const
35
{
36
return
mSources;
37
}
38
39
bool
QgsProfileSourceRegistry::registerProfileSource
(
QgsAbstractProfileSource
*profileSource )
40
{
41
if
( mSources.contains( profileSource ) )
42
{
43
return
false
;
44
}
45
46
for
(
const
auto
&source : std::as_const( mSources ) )
47
{
48
if
( source->profileSourceId() == profileSource->
profileSourceId
() )
49
{
50
QgsDebugError
( u
"A profile source with the same ID (%1) already exists"
_s.arg( profileSource->
profileSourceId
() ) );
51
return
false
;
52
}
53
}
54
55
mSources.append( profileSource );
56
emit
profileSourceRegistered
( profileSource->
profileSourceId
(), profileSource->
profileSourceName
() );
57
return
true
;
58
}
59
60
bool
QgsProfileSourceRegistry::unregisterProfileSource
(
QgsAbstractProfileSource
*profileSource )
61
{
62
const
int
index = mSources.indexOf( profileSource );
63
if
( index >= 0 )
64
{
65
const
QString
id
= profileSource->
profileSourceId
();
66
delete
mSources.takeAt( index );
67
emit
profileSourceUnregistered
(
id
);
68
return
true
;
69
}
70
return
false
;
71
}
72
73
bool
QgsProfileSourceRegistry::unregisterProfileSource
(
const
QString &sourceId )
74
{
75
for
(
auto
it = mSources.begin(); it != mSources.end(); ++it )
76
{
77
if
( ( *it )->profileSourceId() == sourceId )
78
{
79
const
int
index = mSources.indexOf( *it );
80
delete
mSources.takeAt( index );
81
emit
profileSourceUnregistered
( sourceId );
82
return
true
;
83
}
84
}
85
return
false
;
86
}
87
88
QgsAbstractProfileSource
*
QgsProfileSourceRegistry::findSourceById
(
const
QString &sourceId )
const
89
{
90
for
(
QgsAbstractProfileSource
*source : mSources )
91
{
92
if
( source->profileSourceId() == sourceId )
93
return
source;
94
}
95
96
return
nullptr
;
97
}
QgsAbstractProfileSource
Interface for classes which can generate elevation profiles.
Definition
qgsabstractprofilesource.h:35
QgsAbstractProfileSource::profileSourceId
virtual QString profileSourceId() const
Returns a unique identifier for this profile source.
Definition
qgsabstractprofilesource.h:57
QgsAbstractProfileSource::profileSourceName
virtual QString profileSourceName() const
Returns a name for displaying this profile source in the elevation profile layer tree.
Definition
qgsabstractprofilesource.h:66
QgsProfileSourceRegistry::findSourceById
QgsAbstractProfileSource * findSourceById(const QString &sourceId) const
Finds a registered profile source by id.
Definition
qgsprofilesourceregistry.cpp:88
QgsProfileSourceRegistry::profileSourceUnregistered
void profileSourceUnregistered(const QString &sourceId)
Signal emitted once a profile source is unregistered.
QgsProfileSourceRegistry::~QgsProfileSourceRegistry
~QgsProfileSourceRegistry() override
Definition
qgsprofilesourceregistry.cpp:29
QgsProfileSourceRegistry::unregisterProfileSource
Q_DECL_DEPRECATED bool unregisterProfileSource(QgsAbstractProfileSource *source)
Unregisters a profile source and destroys its instance.
Definition
qgsprofilesourceregistry.cpp:60
QgsProfileSourceRegistry::registerProfileSource
bool registerProfileSource(QgsAbstractProfileSource *source)
Registers a profile source and takes ownership of it.
Definition
qgsprofilesourceregistry.cpp:39
QgsProfileSourceRegistry::profileSources
QList< QgsAbstractProfileSource * > profileSources() const
Returns a list of registered profile sources.
Definition
qgsprofilesourceregistry.cpp:34
QgsProfileSourceRegistry::QgsProfileSourceRegistry
QgsProfileSourceRegistry()
Constructor - creates a registry of profile sources.
Definition
qgsprofilesourceregistry.cpp:26
QgsProfileSourceRegistry::profileSourceRegistered
void profileSourceRegistered(const QString &sourceId, const QString &sourceName)
Signal emitted once a profile source is registered.
qgsabstractprofilesource.h
qgslogger.h
QgsDebugError
#define QgsDebugError(str)
Definition
qgslogger.h:71
qgsprofilesourceregistry.h
Generated on
for QGIS API Documentation by
1.17.0