QGIS API Documentation  2.12.0-Lyon
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 
37 class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
38 {
39  Q_OBJECT
40  Q_PROPERTY( bool openFormButtonVisible READ openFormButtonVisible WRITE setOpenFormButtonVisible )
41 
42  public:
45 
47  {
49  Pan,
50  Scale
51  };
52 
53  explicit QgsRelationReferenceWidget( QWidget* parent );
54 
56 
57  void setRelation( const QgsRelation& relation, bool allowNullValue );
58 
59  void setRelationEditable( bool editable );
60 
62  void setForeignKey( const QVariant &value );
63 
65  QVariant foreignKey();
66 
67  void setEditorContext( const QgsAttributeEditorContext& context, QgsMapCanvas* canvas, QgsMessageBar* messageBar );
68 
70  bool embedForm() {return mEmbedForm;}
71  void setEmbedForm( bool display );
72 
74  bool readOnlySelector() {return mReadOnlySelector;}
75  void setReadOnlySelector( bool readOnly );
76 
78  bool allowMapIdentification() {return mAllowMapIdentification;}
79  void setAllowMapIdentification( bool allowMapIdentification );
80 
82  bool orderByValue() { return mOrderByValue; }
84  void setOrderByValue( bool orderByValue );
86  void setFilterFields( const QStringList& filterFields );
87 
89  bool openFormButtonVisible() {return mOpenFormButtonVisible;}
90  void setOpenFormButtonVisible( bool openFormButtonVisible );
91 
97  bool chainFilters() { return mChainFilters; }
98 
99 
106  void setChainFilters( bool chainFilters );
107 
110  QgsFeature referencedFeature();
111 
112  public slots:
114  void openForm();
115 
117  void mapIdentification();
118 
120  void deleteForeignKey();
121 
122  protected:
123  virtual void showEvent( QShowEvent* e ) override;
124 
125  void init();
126 
127  signals:
128  void foreignKeyChanged( QVariant );
129 
130  private slots:
131  void highlightActionTriggered( QAction* action );
132  void deleteHighlight();
133  void comboReferenceChanged( int index );
134  void featureIdentified( const QgsFeature& feature );
135  void unsetMapTool();
136  void mapToolDeactivated();
137  void filterChanged();
138 
139  private:
140  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
141  void updateAttributeEditorFrame( const QgsFeature& feature );
142 
143  // initialized
144  QgsAttributeEditorContext mEditorContext;
145  QgsMapCanvas* mCanvas;
146  QgsMessageBar* mMessageBar;
147  QVariant mForeignKey;
148  QgsFeature mFeature;
149  int mFkeyFieldIdx;
150  bool mAllowNull;
151  QgsHighlight* mHighlight;
152  QgsMapToolIdentifyFeature* mMapTool;
153  QgsMessageBarItem* mMessageBarItem;
154  QString mRelationName;
155  QgsAttributeForm* mReferencedAttributeForm;
156  QgsVectorLayer* mReferencedLayer;
157  QgsVectorLayer* mReferencingLayer;
158  QgsAttributeTableModel* mMasterModel;
159  QgsAttributeTableFilterModel* mFilterModel;
160  QgsFeatureListModel* mFeatureListModel;
161  QList<QComboBox*> mFilterComboBoxes;
162  QWidget* mWindowWidget;
163  bool mShown;
164  QgsRelation mRelation;
165  bool mIsEditable;
166  QStringList mFilterFields;
168 
169  // Q_PROPERTY
170  bool mEmbedForm;
171  bool mReadOnlySelector;
172  bool mAllowMapIdentification;
173  bool mOrderByValue;
174  bool mOpenFormButtonVisible;
175  bool mChainFilters;
176 
177  // UI
178  QVBoxLayout* mTopLayout;
179  QToolButton* mMapIdentificationButton;
180  QToolButton* mRemoveFKButton;
181  QToolButton* mOpenFormButton;
182  QToolButton* mHighlightFeatureButton;
183  QAction* mHighlightFeatureAction;
184  QAction* mScaleHighlightFeatureAction;
185  QAction* mPanHighlightFeatureAction;
186  QComboBox* mComboBox;
187  QWidget* mChooserContainer;
188  QWidget* mFilterContainer;
189  QHBoxLayout* mFilterLayout;
190  QgsCollapsibleGroupBox* mAttributeEditorFrame;
191  QVBoxLayout* mAttributeEditorLayout;
192  QLineEdit* mLineEdit;
193  QLabel* mInvalidLabel;
194 };
195 
196 #endif // QGSRELATIONREFERENCEWIDGET_H
Methods in this class are used to handle basic operations on vector layers.
static unsigned index
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:176
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:107
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:36
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
bool chainFilters()
Determines if the filters are chained.
QPair< QVariant, QgsFeatureId > ValueRelationItem
Represents a vector layer which manages a vector based data sets.
bool openFormButtonVisible()
determines the open form button is visible in the widget