QGIS API Documentation  2.99.0-Master (c558d51)
qgseditorwidgetregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgseditorwidgetregistry.h
3  --------------------------------------
4  Date : 24.4.2013
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias 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  ***************************************************************************/
15 
16 #ifndef QGSEDITORWIDGETREGISTRY_H
17 #define QGSEDITORWIDGETREGISTRY_H
18 
19 #include <QObject>
20 #include <QMap>
21 #include "qgseditorwidgetconfig.h"
22 #include "qgseditorwidgetfactory.h"
25 
26 class QgsMapLayer;
27 class QDomNode;
28 class QgsMapCanvas;
29 class QgsMessageBar;
33 class QgsVectorLayer;
34 
35 
39 class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
40 {
41  Q_OBJECT
42 
43  public:
44 
51  static QgsEditorWidgetRegistry* instance();
52 
63  static void initEditors( QgsMapCanvas* mapCanvas = nullptr, QgsMessageBar* messageBar = nullptr );
64 
71 
80  QgsEditorWidgetSetup findBest( const QgsVectorLayer* vl, const QString& fieldName ) const;
81 
96  QgsEditorWidgetWrapper* create( const QString& widgetId,
97  QgsVectorLayer* vl,
98  int fieldIdx,
99  const QgsEditorWidgetConfig& config,
100  QWidget* editor,
101  QWidget* parent,
103 
117  int fieldIdx,
118  QWidget* editor,
119  QWidget* parent,
121 
122  QgsSearchWidgetWrapper* createSearchWidget( const QString& widgetId,
123  QgsVectorLayer* vl,
124  int fieldIdx,
125  const QgsEditorWidgetConfig& config,
126  QWidget* parent,
128 
139  QgsEditorConfigWidget* createConfigWidget( const QString& widgetId, QgsVectorLayer* vl, int fieldIdx, QWidget* parent );
140 
148  QString name( const QString& widgetId );
149 
155  const QMap<QString, QgsEditorWidgetFactory*>& factories();
156 
162  QgsEditorWidgetFactory* factory( const QString& widgetId );
163 
172  bool registerWidget( const QString& widgetId, QgsEditorWidgetFactory* widgetFactory );
173 
179  void registerAutoConfPlugin( QgsEditorWidgetAutoConfPlugin* plugin ) { mAutoConf.registerPlugin( plugin ); }
180 
181  protected:
183 
184  private slots:
185 
191  void readMapLayer( QgsMapLayer* mapLayer, const QDomElement& layerElem );
192 
200  void writeMapLayer( QgsMapLayer* mapLayer, QDomElement& layerElem, QDomDocument& doc ) const;
201 
207  void mapLayerAdded( QgsMapLayer* mapLayer );
208 
214  void mapLayerWillBeRemoved( QgsMapLayer* mapLayer );
215 
223  void readSymbology( const QDomElement& element, QString& errorMessage );
224 
233  void writeSymbology( QDomElement& element, QDomDocument& doc, QString& errorMessage );
234 
235  private:
236  QString findSuitableWrapper( QWidget* editor , const QString& defaultWidget );
237 
238  QMap<QString, QgsEditorWidgetFactory*> mWidgetFactories;
239  QMap<const char*, QPair<int, QString> > mFactoriesByType;
240  QgsEditorWidgetAutoConf mAutoConf;
241 };
242 
243 #endif // QGSEDITORWIDGETREGISTRY_H
void registerAutoConfPlugin(QgsEditorWidgetAutoConfPlugin *plugin)
Register a new auto-conf plugin.
Manages an editor widget Widget and wrapper share the same parent.
Base class for all map layer types.
Definition: qgsmaplayer.h:49
This class should be subclassed for every configurable editor widget type.
This class manages all known edit widget factories.
This class contains context information for attribute editor widgets.
Manages an editor widget Widget and wrapper share the same parent.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:42
Base class for plugins allowing to pick automatically a widget type for editing fields.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:106
QVariantMap QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
Every attribute editor widget needs a factory, which inherits this class.
Holder for the widget type and its configuration for a field.
Represents a vector layer which manages a vector based data sets.