QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsrelationreferencewidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelationreferencewidget.h
3  --------------------------------------
4  Date : 20.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 QGSRELATIONREFERENCEWIDGET_H
17 #define QGSRELATIONREFERENCEWIDGET_H
18 
20 #include "qgscollapsiblegroupbox.h"
21 #include "qgsfeature.h"
22 #include "qgshighlight.h"
24 #include "qgsattributetablemodel.h"
26 #include "qgsfeaturelistmodel.h"
27 
28 #include <QComboBox>
29 #include <QToolButton>
30 #include <QLineEdit>
31 #include <QHBoxLayout>
32 #include <QStandardItemModel>
33 
34 class QgsAttributeForm;
36 
40 class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
41 {
42  Q_OBJECT
43  Q_PROPERTY( bool openFormButtonVisible READ openFormButtonVisible WRITE setOpenFormButtonVisible )
44 
45  public:
48 
50  {
52  Pan,
53  Scale
54  };
55 
56  explicit QgsRelationReferenceWidget( QWidget* parent );
57 
59 
60  void setRelation( const QgsRelation& relation, bool allowNullValue );
61 
62  void setRelationEditable( bool editable );
63 
65  void setForeignKey( const QVariant &value );
66 
68  QVariant foreignKey() const;
69 
70  void setEditorContext( const QgsAttributeEditorContext& context, QgsMapCanvas* canvas, QgsMessageBar* messageBar );
71 
73  bool embedForm() { return mEmbedForm; }
74  void setEmbedForm( bool display );
75 
77  bool readOnlySelector() { return mReadOnlySelector; }
78  void setReadOnlySelector( bool readOnly );
79 
81  bool allowMapIdentification() { return mAllowMapIdentification; }
82  void setAllowMapIdentification( bool allowMapIdentification );
83 
85  bool orderByValue() { return mOrderByValue; }
87  void setOrderByValue( bool orderByValue );
89  void setFilterFields( const QStringList& filterFields );
90 
92  bool openFormButtonVisible() { return mOpenFormButtonVisible; }
93  void setOpenFormButtonVisible( bool openFormButtonVisible );
94 
100  bool chainFilters() const { return mChainFilters; }
101 
108  void setChainFilters( bool chainFilters );
109 
112  QgsFeature referencedFeature() const;
113 
117  void showIndeterminateState();
118 
124  bool allowAddFeatures() const;
125 
131  void setAllowAddFeatures( bool allowAddFeatures );
132 
133  public slots:
135  void openForm();
136 
138  void mapIdentification();
139 
141  void deleteForeignKey();
142 
143  protected:
144  virtual void showEvent( QShowEvent* e ) override;
145 
146  void init();
147 
148  signals:
149  void foreignKeyChanged( const QVariant& );
150 
151  private slots:
152  void highlightActionTriggered( QAction* action );
153  void deleteHighlight();
154  void comboReferenceChanged( int index );
155  void featureIdentified( const QgsFeature& feature );
156  void unsetMapTool();
157  void mapToolDeactivated();
158  void filterChanged();
159  void addEntry();
160  void editTextUpdated( const QString &text );
161 
162  private:
163  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
164  void updateAttributeEditorFrame( const QgsFeature& feature );
165  void disableChainedComboBoxes( const QComboBox *scb );
166  void updateAddEntryButton();
167 
168  // initialized
169  QgsAttributeEditorContext mEditorContext;
170  QgsMapCanvas* mCanvas;
171  QgsMessageBar* mMessageBar;
172  QVariant mForeignKey;
173  QgsFeature mFeature;
174  // Index of the referenced layer key
175  int mReferencedFieldIdx;
176  int mReferencingFieldIdx;
177  bool mAllowNull;
178  QgsHighlight* mHighlight;
179  QgsMapToolIdentifyFeature* mMapTool;
180  QgsMessageBarItem* mMessageBarItem;
181  QString mRelationName;
182  QgsAttributeForm* mReferencedAttributeForm;
183  QPointer<QgsVectorLayer> mReferencedLayer;
184  QPointer<QgsVectorLayer> mReferencingLayer;
185  QgsAttributeTableModel* mMasterModel;
186  QgsAttributeTableFilterModel* mFilterModel;
187  QgsFeatureListModel* mFeatureListModel;
188  QList<QComboBox*> mFilterComboBoxes;
189  QWidget* mWindowWidget;
190  bool mShown;
191  QgsRelation mRelation;
192  bool mIsEditable;
193  QStringList mFilterFields;
195 
196  // Q_PROPERTY
197  bool mEmbedForm;
198  bool mReadOnlySelector;
199  bool mAllowMapIdentification;
200  bool mOrderByValue;
201  bool mOpenFormButtonVisible;
202  bool mChainFilters;
203  bool mAllowAddFeatures;
204 
205  // UI
206  QVBoxLayout* mTopLayout;
207  QToolButton* mMapIdentificationButton;
208  QToolButton* mRemoveFKButton;
209  QToolButton* mOpenFormButton;
210  QToolButton* mHighlightFeatureButton;
211  QToolButton* mAddEntryButton;
212  QAction* mHighlightFeatureAction;
213  QAction* mScaleHighlightFeatureAction;
214  QAction* mPanHighlightFeatureAction;
215  QComboBox* mComboBox;
216  QWidget* mChooserContainer;
217  QWidget* mFilterContainer;
218  QHBoxLayout* mFilterLayout;
219  QgsCollapsibleGroupBox* mAttributeEditorFrame;
220  QVBoxLayout* mAttributeEditorLayout;
221  QLineEdit* mLineEdit;
222  QLabel* mInvalidLabel;
223 
224  friend class TestQgsRelationReferenceWidget;
225 };
226 
227 #endif // QGSRELATIONREFERENCEWIDGET_H
Methods in this class are used to handle basic operations on vector layers.
static unsigned index
bool chainFilters() const
Determines if the filters are chained.
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
This class contains context information for attribute editor widgets.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:42
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
bool orderByValue()
If the widget will order the combobox entries by value.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
bool allowMapIdentification()
determines if the widge offers the possibility to select the related feature on the map (using a dedi...
bool embedForm()
determines if the form of the related feature will be shown
virtual void showEvent(QShowEvent *event)
A class for highlight features on the map.
Definition: qgshighlight.h:37
QVector< ValueRelationItem > ValueRelationCache
The QgsMapToolIdentifyFeature class is a map tool to identify a feature on a chosen layer...
bool readOnlySelector()
determines if the foreign key is shown in a combox box or a read-only line edit
QPair< QVariant, QgsFeatureId > ValueRelationItem
bool openFormButtonVisible()
determines the open form button is visible in the widget