QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "moc_qgsprofilesourceregistry.cpp"
21
26
28{
29 qDeleteAll( mSources );
30}
31
32QList< QgsAbstractProfileSource * > QgsProfileSourceRegistry::profileSources() const
33{
34 return mSources;
35}
36
38{
39
40 if ( mSources.contains( profileSource ) )
41 {
42 return false;
43 }
44
45 for ( const auto &source : std::as_const( mSources ) )
46 {
47 if ( source->profileSourceId() == profileSource->profileSourceId() )
48 {
49 QgsDebugError( QStringLiteral( "A profile source with the same ID (%1) already exists" ).arg( profileSource->profileSourceId() ) );
50 return false;
51 }
52 }
53
54 mSources.append( profileSource );
55 emit profileSourceRegistered( profileSource->profileSourceId(), profileSource->profileSourceName() );
56 return true;
57}
58
60{
61 const int index = mSources.indexOf( profileSource );
62 if ( index >= 0 )
63 {
64 const QString id = profileSource->profileSourceId();
65 delete mSources.takeAt( index );
67 return true;
68 }
69 return false;
70}
71
73{
74 for ( auto it = mSources.begin(); it != mSources.end(); ++it )
75 {
76 if ( ( *it )->profileSourceId() == sourceId )
77 {
78 const int index = mSources.indexOf( *it );
79 delete mSources.takeAt( index );
80 emit profileSourceUnregistered( sourceId );
81 return true;
82 }
83 }
84 return false;
85}
86
88{
89 for ( QgsAbstractProfileSource *source : mSources )
90 {
91 if ( source->profileSourceId() == sourceId )
92 return source;
93 }
94
95 return nullptr;
96}
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:57