QGIS API Documentation  3.6.0-Noosa (5873452)
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 * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
Shows a search widget on a filter form.
QHash< const char *, int > supportedWidgetTypes() override
Returns a list of widget types which this editor widget supports.
This class should be subclassed for every configurable editor widget type.
unsigned int fieldScore(const QgsVectorLayer *vl, int fieldIdx) const override
This method allows disabling this editor widget type for a certain field.
Manages an editor widget Widget and wrapper share the same parent.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
QgsSearchWidgetWrapper * createSearchWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
By default a simple QgsFilterLineEdit is returned as search widget.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
QList< QgsRelation > referencingRelations(int idx) const
Returns the layer&#39;s relations, where the foreign key is on this layer.
Every attribute editor widget needs a factory, which inherits this class.
QgsRelationReferenceFactory(const QString &name, QgsMapCanvas *canvas, QgsMessageBar *messageBar)
Represents a vector layer which manages a vector based data sets.
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.