QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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  int normalRelationsCount = 0;
60  const QList<QgsRelation> relations = vl->referencingRelations( fieldIdx );
61  for ( const QgsRelation &rel : relations )
62  {
63  if ( rel.type() == QgsRelation::Normal )
64  normalRelationsCount++;
65  }
66  // generated relations should not be used for relation reference widget
67  return normalRelationsCount > 0 ? 21 /*A bit stronger than the range widget*/ : 5;
68 }
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.
Definition: qgsmapcanvas.h:86
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
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.
@ Normal
A normal relation.
Definition: qgsrelation.h:61
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.