QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgssubsetstringeditorproviderregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssubsetstringeditorproviderregistry.cpp
3 ----------------------------------------
4 Date : 15-Nov-2020
5 Copyright : (C) 2020 by Even Rouault
6 Email : even.rouault at spatials.com
7****************************************************************************/
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18
19#include <memory>
20
22#include "qgsquerybuilder.h"
24
26
31
32QList<QgsSubsetStringEditorProvider *> QgsSubsetStringEditorProviderRegistry::providers()
33{
34 return mProviders;
35}
36
38{
39 mProviders.append( provider );
40}
41
43{
44 const int index = mProviders.indexOf( provider );
45 if ( index >= 0 )
46 {
47 delete mProviders.takeAt( index );
48 return true;
49 }
50 return false;
51}
52
53
55{
56 if ( !providerGuiRegistry )
57 return;
58
59 const QStringList providersList = providerGuiRegistry->providerList();
60 for ( const QString &key : providersList )
61 {
62 const QList<QgsSubsetStringEditorProvider *> providerList = providerGuiRegistry->subsetStringEditorProviders( key );
63 // the function is a factory - we keep ownership of the returned providers
64 for ( auto provider : providerList )
65 {
66 addProvider( provider );
67 }
68 }
69}
70
72{
73 const QList<QgsSubsetStringEditorProvider *> providerList = providers();
74 for ( const auto provider : providerList )
75 {
76 if ( provider->name() == name )
77 {
78 return provider;
79 }
80 }
81 return nullptr;
82}
83
84QList<QgsSubsetStringEditorProvider *> QgsSubsetStringEditorProviderRegistry::providersByKey( const QString &providerKey )
85{
86 QList<QgsSubsetStringEditorProvider *> result;
87 const QList<QgsSubsetStringEditorProvider *> providerList = providers();
88 for ( const auto provider : providerList )
89 {
90 if ( provider->providerKey() == providerKey )
91 {
92 result << provider;
93 }
94 }
95 return result;
96}
97
99{
100 const QList<QgsSubsetStringEditorProvider *> providerList = providers();
101 QgsSubsetStringEditorProvider *bestProviderCandidate = nullptr;
102 // Loop over providers to find one that can handle the layer.
103 // And prefer one that will also indicate to handle the storage type.
104 for ( const auto provider : providerList )
105 {
106 if ( provider->canHandleLayer( layer ) )
107 {
108 if ( provider->canHandleLayerStorageType( layer ) )
109 {
110 return provider->createDialog( layer, parent, fl );
111 }
112 bestProviderCandidate = provider;
113 }
114 }
115 if ( bestProviderCandidate )
116 {
117 return bestProviderCandidate->createDialog( layer, parent, fl );
118 }
119
120 return new QgsQueryBuilder( layer, parent, fl );
121}
A registry / canonical manager of GUI parts of data providers.
virtual QList< QgsSubsetStringEditorProvider * > subsetStringEditorProviders(const QString &providerKey)
Returns all subset string editor providers registered in provider with providerKey.
QStringList providerList() const
Returns list of available providers by their keys.
Query Builder for layers.
Interface for a dialog that can edit subset strings.
QgsSubsetStringEditorInterface * createDialog(QgsVectorLayer *layer, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Creates a new dialog to edit the subset string of the provided layer.
bool removeProvider(QgsSubsetStringEditorProvider *provider)
Remove provider implementation from the list (provider object is deleted).
QgsSubsetStringEditorProvider * providerByName(const QString &name)
Returns a provider by name or nullptr if not found.
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
QList< QgsSubsetStringEditorProvider * > providersByKey(const QString &providerKey)
Returns a (possibly empty) list of providers by data providerkey.
void addProvider(QgsSubsetStringEditorProvider *provider)
Add a provider implementation. Takes ownership of the object.
QList< QgsSubsetStringEditorProvider * > providers()
Gets list of available providers.
An interface for widgets which edit a subset string.
virtual QgsSubsetStringEditorInterface * createDialog(QgsVectorLayer *layer, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)=0
Creates a new dialog to edit the subset string of the provided layer.
Represents a vector layer which manages a vector based dataset.