QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsrelationreferencefactory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelationreferencefactory.cpp
3  --------------------------------------
4  Date : 29.5.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 #include "qgsproject.h"
18 
19 #include "qgsfeatureiterator.h"
20 #include "qgsrelation.h"
21 #include "qgsrelationmanager.h"
26 #include "qgslogger.h"
27 
29  : QgsEditorWidgetFactory( name )
30  , mCanvas( canvas )
31  , mMessageBar( messageBar )
32 {
33 }
34 
35 QgsEditorWidgetWrapper *QgsRelationReferenceFactory::create( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const
36 {
37  return new QgsRelationReferenceWidgetWrapper( vl, fieldIdx, editor, mCanvas, mMessageBar, parent );
38 }
39 
41 {
42  return new QgsRelationReferenceSearchWidgetWrapper( vl, fieldIdx, mCanvas, parent );
43 }
44 
46 {
47  return new QgsRelationReferenceConfigDlg( vl, fieldIdx, parent );
48 }
49 
51 {
52  QHash<const char *, int> map = QHash<const char *, int>();
53  map.insert( QgsRelationReferenceWidget::staticMetaObject.className(), 10 );
54  return map;
55 }
56 
57 unsigned int QgsRelationReferenceFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
58 {
59  const QList<QgsRelation> relations = vl->referencingRelations( fieldIdx );
60  return !relations.isEmpty() ? 21 /*A bit stronger than the range widget*/ : 5;
61 }
QgsEditorConfigWidget
This class should be subclassed for every configurable editor widget type.
Definition: qgseditorconfigwidget.h:39
QgsEditorWidgetFactory
Every attribute editor widget needs a factory, which inherits this class.
Definition: qgseditorwidgetfactory.h:43
QgsRelationReferenceSearchWidgetWrapper
Wraps a relation reference search widget.
Definition: qgsrelationreferencesearchwidgetwrapper.h:40
QgsRelationReferenceConfigDlg
Definition: qgsrelationreferenceconfigdlg.h:34
qgsfeatureiterator.h
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
QgsSearchWidgetWrapper
Shows a search widget on a filter form.
Definition: qgssearchwidgetwrapper.h:86
QgsRelationReferenceFactory::configWidget
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
Definition: qgsrelationreferencefactory.cpp:45
QgsRelationReferenceFactory::supportedWidgetTypes
QHash< const char *, int > supportedWidgetTypes() override
Returns a list of widget types which this editor widget supports.
Definition: qgsrelationreferencefactory.cpp:50
QgsRelationReferenceFactory::QgsRelationReferenceFactory
QgsRelationReferenceFactory(const QString &name, QgsMapCanvas *canvas, QgsMessageBar *messageBar)
Definition: qgsrelationreferencefactory.cpp:28
QgsEditorWidgetWrapper
Manages an editor widget Widget and wrapper share the same parent.
Definition: qgseditorwidgetwrapper.h:48
qgsrelationreferencefactory.h
QgsRelationReferenceFactory::create
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
Definition: qgsrelationreferencefactory.cpp:35
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
QgsVectorLayer::referencingRelations
QList< QgsRelation > referencingRelations(int idx) const
Returns the layer's relations, where the foreign key is on this layer.
Definition: qgsvectorlayer.cpp:5177
qgsrelation.h
qgsrelationmanager.h
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
qgsrelationreferencewidgetwrapper.h
QgsRelationReferenceFactory::createSearchWidget
QgsSearchWidgetWrapper * createSearchWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
By default a simple QgsFilterLineEdit is returned as search widget.
Definition: qgsrelationreferencefactory.cpp:40
qgslogger.h
qgsrelationreferencewidget.h
qgsrelationreferenceconfigdlg.h
QgsRelationReferenceFactory::fieldScore
unsigned int fieldScore(const QgsVectorLayer *vl, int fieldIdx) const override
This method allows disabling this editor widget type for a certain field.
Definition: qgsrelationreferencefactory.cpp:57
qgsproject.h
qgsrelationreferencesearchwidgetwrapper.h
QgsRelationReferenceWidgetWrapper
Wraps a relation reference widget.
Definition: qgsrelationreferencewidgetwrapper.h:44