QGIS API Documentation 3.99.0-Master (e9821da5c6b)
Loading...
Searching...
No Matches
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 ***************************************************************************/
16
18#include "qgslogger.h"
19
20#include <QString>
21
22#include "moc_qgsprofilesourceregistry.cpp"
23
24using namespace Qt::StringLiterals;
25
30
32{
33 qDeleteAll( mSources );
34}
35
36QList< QgsAbstractProfileSource * > QgsProfileSourceRegistry::profileSources() const
37{
38 return mSources;
39}
40
42{
43
44 if ( mSources.contains( profileSource ) )
45 {
46 return false;
47 }
48
49 for ( const auto &source : std::as_const( mSources ) )
50 {
51 if ( source->profileSourceId() == profileSource->profileSourceId() )
52 {
53 QgsDebugError( u"A profile source with the same ID (%1) already exists"_s.arg( profileSource->profileSourceId() ) );
54 return false;
55 }
56 }
57
58 mSources.append( profileSource );
59 emit profileSourceRegistered( profileSource->profileSourceId(), profileSource->profileSourceName() );
60 return true;
61}
62
64{
65 const int index = mSources.indexOf( profileSource );
66 if ( index >= 0 )
67 {
68 const QString id = profileSource->profileSourceId();
69 delete mSources.takeAt( index );
71 return true;
72 }
73 return false;
74}
75
77{
78 for ( auto it = mSources.begin(); it != mSources.end(); ++it )
79 {
80 if ( ( *it )->profileSourceId() == sourceId )
81 {
82 const int index = mSources.indexOf( *it );
83 delete mSources.takeAt( index );
84 emit profileSourceUnregistered( sourceId );
85 return true;
86 }
87 }
88 return false;
89}
90
92{
93 for ( QgsAbstractProfileSource *source : mSources )
94 {
95 if ( source->profileSourceId() == sourceId )
96 return source;
97 }
98
99 return nullptr;
100}
Interface for classes which can generate elevation profiles.
virtual QString profileSourceId() const
Returns a unique identifier for this profile source.
virtual QString profileSourceName() const
Returns a name for displaying this profile source in the elevation profile layer tree.
QgsAbstractProfileSource * findSourceById(const QString &sourceId) const
Finds a registered profile source by id.
void profileSourceUnregistered(const QString &sourceId)
Signal emitted once a profile source is unregistered.
Q_DECL_DEPRECATED bool unregisterProfileSource(QgsAbstractProfileSource *source)
Unregisters a profile source and destroys its instance.
bool registerProfileSource(QgsAbstractProfileSource *source)
Registers a profile source and takes ownership of it.
QList< QgsAbstractProfileSource * > profileSources() const
Returns a list of registered profile sources.
QgsProfileSourceRegistry()
Constructor - creates a registry of profile sources.
void profileSourceRegistered(const QString &sourceId, const QString &sourceName)
Signal emitted once a profile source is registered.
#define QgsDebugError(str)
Definition qgslogger.h:59