QGIS API Documentation 3.41.0-Master (3440c17df1d)
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
20#include "qgsquerybuilder.h"
21
22#include <memory>
23
25
30
31QList<QgsSubsetStringEditorProvider *> QgsSubsetStringEditorProviderRegistry::providers()
32{
33 return mProviders;
34}
35
37{
38 mProviders.append( provider );
39}
40
42{
43 const int index = mProviders.indexOf( provider );
44 if ( index >= 0 )
45 {
46 delete mProviders.takeAt( index );
47 return true;
48 }
49 return false;
50}
51
52
54{
55 if ( !providerGuiRegistry )
56 return;
57
58 const QStringList providersList = providerGuiRegistry->providerList();
59 for ( const QString &key : providersList )
60 {
61 const QList<QgsSubsetStringEditorProvider *> providerList = providerGuiRegistry->subsetStringEditorProviders( key );
62 // the function is a factory - we keep ownership of the returned providers
63 for ( auto provider : providerList )
64 {
65 addProvider( provider );
66 }
67 }
68}
69
71{
72 const QList<QgsSubsetStringEditorProvider *> providerList = providers();
73 for ( const auto provider : providerList )
74 {
75 if ( provider->name() == name )
76 {
77 return provider;
78 }
79 }
80 return nullptr;
81}
82
83QList<QgsSubsetStringEditorProvider *> QgsSubsetStringEditorProviderRegistry::providersByKey( const QString &providerKey )
84{
85 QList<QgsSubsetStringEditorProvider *> result;
86 const QList<QgsSubsetStringEditorProvider *> providerList = providers();
87 for ( const auto provider : providerList )
88 {
89 if ( provider->providerKey() == providerKey )
90 {
91 result << provider;
92 }
93 }
94 return result;
95}
96
98{
99 const QList<QgsSubsetStringEditorProvider *> providerList = providers();
100 QgsSubsetStringEditorProvider *bestProviderCandidate = nullptr;
101 // Loop over providers to find one that can handle the layer.
102 // And prefer one that will also indicate to handle the storage type.
103 for ( const auto provider : providerList )
104 {
105 if ( provider->canHandleLayer( layer ) )
106 {
107 if ( provider->canHandleLayerStorageType( layer ) )
108 {
109 return provider->createDialog( layer, parent, fl );
110 }
111 bestProviderCandidate = provider;
112 }
113 }
114 if ( bestProviderCandidate )
115 {
116 return bestProviderCandidate->createDialog( layer, parent, fl );
117 }
118
119 return new QgsQueryBuilder( layer, parent, fl );
120}
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.
This is the interface for those who want to provide a dialog to 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 data sets.