QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgis.h"
22 #include "qgseditorwidgetwrapper.h"
23 
24 #include <QWidget>
25 #include <QSvgWidget>
26 #include <QLabel>
27 #include <QDialogButtonBox>
28 #include "qgis_gui.h"
29 
30 
33 class QgsMessageBar;
34 class QgsMessageBarItem;
35 class QgsWidgetWrapper;
36 class QgsTabWidget;
38 
43 class GUI_EXPORT QgsAttributeForm : public QWidget
44 {
45  Q_OBJECT
46 
47  public:
48 
50  enum Mode
51  {
53  AddFeatureMode,
58  IdentifyMode
59  };
60 
63  {
67  };
68 
69  explicit QgsAttributeForm( QgsVectorLayer *vl,
70  const QgsFeature &feature = QgsFeature(),
72  QWidget *parent SIP_TRANSFERTHIS = nullptr );
73  ~QgsAttributeForm() override;
74 
75  const QgsFeature &feature() { return mFeature; }
76 
81  // TODO QGIS 3.0 - make private
82  void hideButtonBox();
83 
88  // TODO QGIS 3.0 - make private
89  void showButtonBox();
90 
95  // TODO QGIS 3.0 - make private
96  void disconnectButtonBox();
97 
102  void addInterface( QgsAttributeFormInterface *iface SIP_TRANSFER );
103 
109  QgsVectorLayer *layer() { return mLayer; }
110 
116  bool editable();
117 
123  Mode mode() const { return mMode; }
124 
131  void setMode( Mode mode );
132 
138  void setEditCommandMessage( const QString &message ) { mEditCommandMessage = message; }
139 
148  bool eventFilter( QObject *object, QEvent *event ) override;
149 
155  void setMultiEditFeatureIds( const QgsFeatureIds &fids );
156 
163  void setMessageBar( QgsMessageBar *messageBar );
164 
172  QString aggregateFilter() const;
173 
174  signals:
175 
183  Q_DECL_DEPRECATED void attributeChanged( const QString &attribute, const QVariant &value );
184 
193  void widgetValueChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
194 
203  void beforeSave( bool &ok ) SIP_SKIP;
204 
208  void featureSaved( const QgsFeature &feature );
209 
216  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
217 
222  void modeChanged( QgsAttributeForm::Mode mode );
223 
228  void closed();
229 
234  void zoomToFeatures( const QString &filter );
235 
240  void flashFeatures( const QString &filter );
241 
242  public slots:
243 
251  void changeAttribute( const QString &field, const QVariant &value, const QString &hintText = QString() );
252 
258  void setFeature( const QgsFeature &feature );
259 
265  bool save();
266 
270  void resetValues();
271 
276  void resetSearch();
277 
281  void refreshFeature();
282 
283  private slots:
284  void onAttributeChanged( const QVariant &value );
285  void onAttributeAdded( int idx );
286  void onAttributeDeleted( int idx );
287  void onUpdatedFields();
288  void onConstraintStatusChanged( const QString &constraint,
289  const QString &description, const QString &err, QgsEditorWidgetWrapper::ConstraintResult result );
290  void preventFeatureRefresh();
291  void synchronizeEnabledState();
292  void layerSelectionChanged();
293 
295  bool saveMultiEdits();
296  void resetMultiEdit( bool promptToSave = false );
297  void multiEditMessageClicked( const QString &link );
298 
299  void filterAndTriggered();
300  void filterOrTriggered();
301  void filterTriggered();
302 
303  void searchZoomTo();
304  void searchFlash();
305  void searchSetSelection();
306  void searchAddToSelection();
307  void searchRemoveFromSelection();
308  void searchIntersectSelection();
309 
310  private:
311  void init();
312 
313  void cleanPython();
314 
315  void initPython();
316 
317  void updateJoinedFields( const QgsEditorWidgetWrapper &eww );
318 
319  bool fieldIsEditable( int fieldIndex ) const;
320 
321  bool fieldIsEditable( const QgsVectorLayer &layer, int fieldIndex, QgsFeatureId fid ) const;
322 
323  struct WidgetInfo
324  {
325  QWidget *widget = nullptr;
326  QString labelText;
327  QString hint;
328  bool labelOnTop = false;
329  bool labelAlignRight = false;
330  bool showLabel = true;
331  };
332 
333  WidgetInfo createWidgetFromDef( const QgsAttributeEditorElement *widgetDef, QWidget *parent, QgsVectorLayer *vl, QgsAttributeEditorContext &context );
334 
335  void addWidgetWrapper( QgsEditorWidgetWrapper *eww );
336 
341  void createWrappers();
342  void afterWidgetInit();
343 
344  void scanForEqualAttributes( QgsFeatureIterator &fit, QSet< int > &mixedValueFields, QHash< int, QVariant > &fieldSharedValues ) const;
345 
347  bool saveEdits();
348 
349  int messageTimeout();
350  void clearMultiEditMessages();
351  void pushSelectedFeaturesMessage();
352  void runSearchSelect( QgsVectorLayer::SelectBehavior behavior );
353 
354  QString createFilterExpression() const;
355 
357  void updateAllConstraints();
358  void updateConstraints( QgsEditorWidgetWrapper *w );
359  void updateConstraint( const QgsFeature &ft, QgsEditorWidgetWrapper *eww );
360  bool currentFormFeature( QgsFeature &feature );
361  bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
362  QList<QgsEditorWidgetWrapper *> constraintDependencies( QgsEditorWidgetWrapper *w );
363 
364  QgsVectorLayer *mLayer = nullptr;
365  QgsFeature mFeature;
366  QgsMessageBar *mMessageBar = nullptr;
367  bool mOwnsMessageBar;
368  QgsMessageBarItem *mMultiEditUnsavedMessageBarItem = nullptr;
369  QgsMessageBarItem *mMultiEditMessageBarItem = nullptr;
370  QList<QgsWidgetWrapper *> mWidgets;
371  QgsAttributeEditorContext mContext;
372  QDialogButtonBox *mButtonBox = nullptr;
373  QWidget *mSearchButtonBox = nullptr;
374  QList<QgsAttributeFormInterface *> mInterfaces;
375  QMap< int, QgsAttributeFormEditorWidget * > mFormEditorWidgets;
376  QList< QgsAttributeFormWidget *> mFormWidgets;
377  QgsExpressionContext mExpressionContext;
378  QMap<const QgsVectorLayerJoinInfo *, QgsFeature> mJoinedFeatures;
379  bool mValuesInitialized = false;
380  bool mDirty = false;
381  bool mIsSettingFeature = false;
382 
383  struct ContainerInformation
384  {
385  ContainerInformation( QgsTabWidget *tabWidget, QWidget *widget, const QgsExpression &expression )
386  : tabWidget( tabWidget )
387  , widget( widget )
388  , expression( expression )
389  , isVisible( true )
390  {}
391 
392  ContainerInformation( QWidget *widget, const QgsExpression &expression )
393  : widget( widget )
394  , expression( expression )
395  , isVisible( true )
396  {}
397 
398  QgsTabWidget *tabWidget = nullptr;
399  QWidget *widget = nullptr;
400  QgsExpression expression;
401  bool isVisible;
402 
403  void apply( QgsExpressionContext *expressionContext );
404  };
405 
406  void registerContainerInformation( ContainerInformation *info );
407 
408  void updateIcon( QgsEditorWidgetWrapper *eww );
409 
410  void reloadIcon( const QString &file, const QString &tooltip, QSvgWidget *sw );
411 
412  // Contains information about tabs and groupboxes, their visibility state visibility conditions
413  QVector<ContainerInformation *> mContainerVisibilityInformation;
414  QMap<QString, QVector<ContainerInformation *> > mContainerInformationDependency;
415 
416  // Variables below are used for Python
417  static int sFormCounter;
418  int mFormNr;
419  QString mPyFormVarName;
420 
422  bool mIsSaving;
423 
425  bool mPreventFeatureRefresh;
426 
427  bool mIsSettingMultiEditFeatures;
428 
429  QgsFeatureIds mMultiEditFeatureIds;
430  bool mUnsavedMultiEditChanges;
431 
432  QString mEditCommandMessage;
433 
434  Mode mMode;
435 
436  QMap<QWidget *, QSvgWidget *> mIconMap;
437 
438  friend class TestQgsDualView;
439  friend class TestQgsAttributeForm;
440 };
441 
442 #endif // QGSATTRIBUTEFORM_H
443 
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.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Base class for all widgets shown on a QgsAttributeForm.
Multi edit mode, for editing fields of multiple features at once.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:544
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:45
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
QgsVectorLayer * layer()
Returns the layer for which this form is shown.
A widget consisting of both an editor widget and additional widgets for controlling the behavior of t...
FilterType
Filter types.
#define SIP_SKIP
Definition: qgis_sip.h:119
Form values are used for searching/filtering the layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Filter should be combined using "AND".
void setEditCommandMessage(const QString &message)
Sets the edit command message (Undo) that will be used when the dialog is accepted.
SelectBehavior
Selection behavior.
ConstraintResult
Result of constraint checks.
Filter should be combined using "OR".
Form is in aggregate search mode, show each widget in this mode.
Mode mode() const
Returns the current mode of the form.
qint64 QgsFeatureId
Definition: qgsfeature.h:37
const QgsFeature & feature()
Single edit mode, for editing a single feature.
Filter should replace any existing filter.
Represents a vector layer which manages a vector based data sets.
The QgsTabWidget class is the same as the QTabWidget but with additional methods to temporarily hide/...
Definition: qgstabwidget.h:29
Manages an editor widget Widget and wrapper share the same parent.