QGIS API Documentation  2.15.0-Master (972fc9f)
qgsattributeform.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributeform.h
3  --------------------------------------
4  Date : 3.5.2014
5  Copyright : (C) 2014 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 QGSATTRIBUTEFORM_H
17 #define QGSATTRIBUTEFORM_H
18 
19 #include "qgsfeature.h"
20 #include "qgsvectorlayer.h"
22 
23 #include <QWidget>
24 #include <QLabel>
25 #include <QDialogButtonBox>
26 
29 class QgsMessageBar;
30 class QgsMessageBarItem;
31 class QgsWidgetWrapper;
32 
33 class GUI_EXPORT QgsAttributeForm : public QWidget
34 {
35  Q_OBJECT
36 
37  public:
38 
40  enum Mode
41  {
43  AddFeatureMode,
47  };
48 
51  {
55  };
56 
57  explicit QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &feature = QgsFeature(),
58  const QgsAttributeEditorContext& context = QgsAttributeEditorContext(), QWidget *parent = nullptr );
60 
61  const QgsFeature& feature() { return mFeature; }
62 
67  // TODO QGIS 3.0 - make private
68  void hideButtonBox();
69 
74  // TODO QGIS 3.0 - make private
75  void showButtonBox();
76 
81  // TODO QGIS 3.0 - make private
82  void disconnectButtonBox();
83 
88  void addInterface( QgsAttributeFormInterface* iface );
89 
95  QgsVectorLayer* layer() { return mLayer; }
96 
102  bool editable();
103 
108  Mode mode() const { return mMode; }
109 
115  void setMode( Mode mode );
116 
125  Q_DECL_DEPRECATED void setIsAddDialog( bool isAddDialog );
126 
132  void setEditCommandMessage( const QString& message ) { mEditCommandMessage = message; }
133 
142  bool eventFilter( QObject* object, QEvent* event ) override;
143 
148  void setMultiEditFeatureIds( const QgsFeatureIds& fids );
149 
155  void setMessageBar( QgsMessageBar* messageBar );
156 
157  signals:
164  void attributeChanged( const QString& attribute, const QVariant& value );
165 
174  void beforeSave( bool& ok );
175 
179  void featureSaved( const QgsFeature& feature );
180 
186  void filterExpressionSet( const QString& expression, QgsAttributeForm::FilterType type );
187 
191  void modeChanged( QgsAttributeForm::Mode mode );
192 
196  void closed();
197 
198  public slots:
205  void changeAttribute( const QString& field, const QVariant& value );
206 
212  void setFeature( const QgsFeature& feature );
213 
219  bool save();
220 
226  Q_DECL_DEPRECATED void accept() { save(); }
227 
233  Q_DECL_DEPRECATED void reject() { resetValues(); }
234 
238  void resetValues();
239 
243  void resetSearch();
244 
248  void refreshFeature();
249 
250  private slots:
251  void onAttributeChanged( const QVariant& value );
252  void onAttributeAdded( int idx );
253  void onAttributeDeleted( int idx );
254  void onUpdatedFields();
255  void onConstraintStatusChanged( const QString& constraint,
256  const QString &description, const QString& err, bool ok );
257  void preventFeatureRefresh();
258  void synchronizeEnabledState();
259  void layerSelectionChanged();
260 
262  bool saveMultiEdits();
263  void resetMultiEdit( bool promptToSave = false );
264  void multiEditMessageClicked( const QString& link );
265 
266  void filterAndTriggered();
267  void filterOrTriggered();
268  void filterTriggered();
269 
270  void searchSetSelection();
271  void searchAddToSelection();
272  void searchRemoveFromSelection();
273  void searchIntersectSelection();
274 
275  private:
276  void init();
277 
278  void cleanPython();
279 
280  void initPython();
281 
282  struct WidgetInfo
283  {
284  WidgetInfo()
285  : widget( nullptr )
286  , labelOnTop( false )
287  , labelAlignRight( false )
288  {}
289 
290  QWidget* widget;
291  QString labelText;
292  bool labelOnTop;
293  bool labelAlignRight;
294  };
295 
296  WidgetInfo createWidgetFromDef( const QgsAttributeEditorElement* widgetDef, QWidget* parent, QgsVectorLayer* vl, QgsAttributeEditorContext& context );
297 
298  void addWidgetWrapper( QgsEditorWidgetWrapper* eww );
299 
304  void createWrappers();
305  void afterWidgetInit();
306 
307  void scanForEqualAttributes( QgsFeatureIterator& fit, QSet< int >& mixedValueFields, QHash< int, QVariant >& fieldSharedValues ) const;
308 
310  bool saveEdits();
311 
312  int messageTimeout();
313  void clearMultiEditMessages();
314  void pushSelectedFeaturesMessage();
315  void runSearchSelect( QgsVectorLayer::SelectBehaviour behaviour );
316 
317  QString createFilterExpression() const;
318 
320  void updateAllConstaints();
321  void updateConstraints( QgsEditorWidgetWrapper *w );
322  bool currentFormFeature( QgsFeature &feature );
323  bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
324  void constraintDependencies( QgsEditorWidgetWrapper *w, QList<QgsEditorWidgetWrapper*> &wDeps );
325  void clearInvalidConstraintsMessage();
326  void displayInvalidConstraintMessage( const QStringList &invalidFields,
327  const QStringList &description );
328 
329  QgsVectorLayer* mLayer;
330  QgsFeature mFeature;
331  QgsMessageBar* mMessageBar;
332  bool mOwnsMessageBar;
333  QgsMessageBarItem* mMultiEditUnsavedMessageBarItem;
334  QgsMessageBarItem* mMultiEditMessageBarItem;
335  QLabel* mInvalidConstraintMessage;
336  QList<QgsWidgetWrapper*> mWidgets;
337  QgsAttributeEditorContext mContext;
338  QDialogButtonBox* mButtonBox;
339  QWidget* mSearchButtonBox;
342 
343  // Variables below are used for python
344  static int sFormCounter;
345  int mFormNr;
346  QString mPyFormVarName;
347 
349  bool mIsSaving;
350 
352  bool mPreventFeatureRefresh;
353 
355  bool mIsSettingFeature;
356  bool mIsSettingMultiEditFeatures;
357 
358  QgsFeatureIds mMultiEditFeatureIds;
359  bool mUnsavedMultiEditChanges;
360 
361  QString mEditCommandMessage;
362 
363  Mode mMode;
364 
366  QMap<QWidget*, QLabel*> mBuddyMap;
367 
368  friend class TestQgsDualView;
369  friend class TestQgsAttributeForm;
370 };
371 
372 #endif // QGSATTRIBUTEFORM_H
373 
Wrapper for iterator of features from vector data provider or vector layer.
This is an abstract base class for any elements of a drag and drop form.
Q_DECL_DEPRECATED void accept()
Alias for save()
This class contains context information for attribute editor widgets.
Manages an editor widget Widget and wrapper share the same parent.
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
QgsVectorLayer * layer()
Returns the layer for which this form is shown.
Mode mode() const
Returns the current mode of the form.
A widget consisting of both an editor widget and additional widgets for controlling the behaviour of ...
FilterType
Filter types.
virtual bool eventFilter(QObject *watched, QEvent *event)
Q_DECL_DEPRECATED void reject()
Alias for resetValues()
void setEditCommandMessage(const QString &message)
Sets the edit command message (Undo) that will be used when the dialog is accepted.
SelectBehaviour
Selection behaviour.
const QgsFeature & feature()
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.