QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
28
30{
31 qDeleteAll( mSources );
32}
33
34QList< QgsAbstractProfileSource * > QgsProfileSourceRegistry::profileSources() const
35{
36 return mSources;
37}
38
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
61{
62 const int index = mSources.indexOf( profileSource );
63 if ( index >= 0 )
64 {
65 const QString id = profileSource->profileSourceId();
66 delete mSources.takeAt( index );
68 return true;
69 }
70 return false;
71}
72
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
89{
90 for ( QgsAbstractProfileSource *source : mSources )
91 {
92 if ( source->profileSourceId() == sourceId )
93 return source;
94 }
95
96 return nullptr;
97}
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