QGIS API Documentation 3.41.0-Master (25ec5511245)
Loading...
Searching...
No Matches
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 "qgsrelation.h"
24
27 , mCanvas( canvas )
28 , mMessageBar( messageBar )
29{
30}
31
32QgsEditorWidgetWrapper *QgsRelationReferenceFactory::create( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const
33{
34 return new QgsRelationReferenceWidgetWrapper( vl, fieldIdx, editor, mCanvas, mMessageBar, parent );
35}
36
38{
39 return new QgsRelationReferenceSearchWidgetWrapper( vl, fieldIdx, mCanvas, parent );
40}
41
43{
44 return new QgsRelationReferenceConfigDlg( vl, fieldIdx, parent );
45}
46
48{
49 QHash<const char *, int> map = QHash<const char *, int>();
50 map.insert( QgsRelationReferenceWidget::staticMetaObject.className(), 10 );
51 return map;
52}
53
54unsigned int QgsRelationReferenceFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
55{
56 int normalRelationsCount = 0;
57 const QList<QgsRelation> relations = vl->referencingRelations( fieldIdx );
58 for ( const QgsRelation &rel : relations )
59 {
60 switch ( rel.type() )
61 {
63 normalRelationsCount++;
64 break;
65
67 break;
68 }
69 }
70 // generated relations should not be used for relation reference widget
71 return normalRelationsCount > 0 ? 21 /*A bit stronger than the range widget*/ : 5;
72}
@ Generated
A generated relation is a child of a polymorphic relation.
@ Normal
A normal relation.
This class should be subclassed for every configurable editor widget type.
Every attribute editor widget needs a factory, which inherits this class.
Manages an editor widget Widget and wrapper share the same parent.
Map canvas is a class for displaying all GIS data types on a canvas.
A bar for displaying non-blocking messages to the user.
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
QgsRelationReferenceFactory(const QString &name, QgsMapCanvas *canvas, QgsMessageBar *messageBar)
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
QgsSearchWidgetWrapper * createSearchWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
By default a simple QgsFilterLineEdit is returned as search widget.
unsigned int fieldScore(const QgsVectorLayer *vl, int fieldIdx) const override
This method allows disabling this editor widget type for a certain field.
QHash< const char *, int > supportedWidgetTypes() override
Returns a list of widget types which this editor widget supports.
Represents a relationship between two vector layers.
Definition qgsrelation.h:44
Shows a search widget on a filter form.
Represents a vector layer which manages a vector based data sets.
QList< QgsRelation > referencingRelations(int idx) const
Returns the layer's relations, where the foreign key is on this layer.