QGIS API Documentation  3.6.0-Noosa (5873452)
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_sip.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 
77  // TODO QGIS 4.0 - make private
78 
83  void hideButtonBox();
84 
85  // TODO QGIS 4.0 - make private
86 
91  void showButtonBox();
92 
93  // TODO QGIS 4.0 - make private
94 
99  void disconnectButtonBox();
100 
105  void addInterface( QgsAttributeFormInterface *iface SIP_TRANSFER );
106 
112  QgsVectorLayer *layer() { return mLayer; }
113 
119  bool editable();
120 
126  QgsAttributeEditorContext::Mode mode() const { return mMode; }
127 
134  void setMode( QgsAttributeEditorContext::Mode mode );
135 
141  void setEditCommandMessage( const QString &message ) { mEditCommandMessage = message; }
142 
151  bool eventFilter( QObject *object, QEvent *event ) override;
152 
158  void setMultiEditFeatureIds( const QgsFeatureIds &fids );
159 
166  void setMessageBar( QgsMessageBar *messageBar );
167 
175  QString aggregateFilter() const;
176 
177  signals:
178 
187  Q_DECL_DEPRECATED void attributeChanged( const QString &attribute, const QVariant &value ) SIP_DEPRECATED;
188 
197  void widgetValueChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
198 
207  void beforeSave( bool &ok ) SIP_SKIP;
208 
212  void featureSaved( const QgsFeature &feature );
213 
220  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
221 
226  void modeChanged( QgsAttributeEditorContext::Mode mode );
227 
232  void closed();
233 
238  void zoomToFeatures( const QString &filter );
239 
244  void flashFeatures( const QString &filter );
245 
246  public slots:
247 
255  void changeAttribute( const QString &field, const QVariant &value, const QString &hintText = QString() );
256 
262  void setFeature( const QgsFeature &feature );
263 
269  bool save();
270 
274  void resetValues();
275 
280  void resetSearch();
281 
285  void refreshFeature();
286 
287  private slots:
288  void onAttributeChanged( const QVariant &value );
289  void onAttributeAdded( int idx );
290  void onAttributeDeleted( int idx );
291  void onUpdatedFields();
292  void onConstraintStatusChanged( const QString &constraint,
293  const QString &description, const QString &err, QgsEditorWidgetWrapper::ConstraintResult result );
294  void preventFeatureRefresh();
295  void synchronizeEnabledState();
296  void layerSelectionChanged();
297 
299  bool saveMultiEdits();
300  void resetMultiEdit( bool promptToSave = false );
301  void multiEditMessageClicked( const QString &link );
302 
303  void filterAndTriggered();
304  void filterOrTriggered();
305  void filterTriggered();
306 
307  void searchZoomTo();
308  void searchFlash();
309  void searchSetSelection();
310  void searchAddToSelection();
311  void searchRemoveFromSelection();
312  void searchIntersectSelection();
313 
314  private:
315  void init();
316 
317  void cleanPython();
318 
319  void initPython();
320 
321  void updateJoinedFields( const QgsEditorWidgetWrapper &eww );
322 
323  bool fieldIsEditable( int fieldIndex ) const;
324 
325  bool fieldIsEditable( const QgsVectorLayer &layer, int fieldIndex, QgsFeatureId fid ) const;
326 
327  struct WidgetInfo
328  {
329  QWidget *widget = nullptr;
330  QString labelText;
331  QString toolTip;
332  QString hint;
333  bool labelOnTop = false;
334  bool labelAlignRight = false;
335  bool showLabel = true;
336  };
337 
338  WidgetInfo createWidgetFromDef( const QgsAttributeEditorElement *widgetDef, QWidget *parent, QgsVectorLayer *vl, QgsAttributeEditorContext &context );
339 
340  void addWidgetWrapper( QgsEditorWidgetWrapper *eww );
341 
346  void createWrappers();
347  void afterWidgetInit();
348 
349  void scanForEqualAttributes( QgsFeatureIterator &fit, QSet< int > &mixedValueFields, QHash< int, QVariant > &fieldSharedValues ) const;
350 
352  bool saveEdits();
353 
354  int messageTimeout();
355  void clearMultiEditMessages();
356  void pushSelectedFeaturesMessage();
357  void runSearchSelect( QgsVectorLayer::SelectBehavior behavior );
358 
359  QString createFilterExpression() const;
360 
362  void updateAllConstraints();
363  void updateConstraints( QgsEditorWidgetWrapper *w );
364  void updateContainersVisibility();
365  void updateConstraint( const QgsFeature &ft, QgsEditorWidgetWrapper *eww );
366  bool currentFormFeature( QgsFeature &feature );
367  bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
368  QList<QgsEditorWidgetWrapper *> constraintDependencies( QgsEditorWidgetWrapper *w );
369 
370  QgsVectorLayer *mLayer = nullptr;
371  QgsFeature mFeature;
372  QgsMessageBar *mMessageBar = nullptr;
373  bool mOwnsMessageBar;
374  QgsMessageBarItem *mMultiEditUnsavedMessageBarItem = nullptr;
375  QgsMessageBarItem *mMultiEditMessageBarItem = nullptr;
376  QList<QgsWidgetWrapper *> mWidgets;
377  QgsAttributeEditorContext mContext;
378  QDialogButtonBox *mButtonBox = nullptr;
379  QWidget *mSearchButtonBox = nullptr;
380  QList<QgsAttributeFormInterface *> mInterfaces;
381  QMap< int, QgsAttributeFormEditorWidget * > mFormEditorWidgets;
382  QList< QgsAttributeFormWidget *> mFormWidgets;
383  QgsExpressionContext mExpressionContext;
384  QMap<const QgsVectorLayerJoinInfo *, QgsFeature> mJoinedFeatures;
385  bool mValuesInitialized = false;
386  bool mDirty = false;
387  bool mIsSettingFeature = false;
388 
389  struct ContainerInformation
390  {
391  ContainerInformation( QgsTabWidget *tabWidget, QWidget *widget, const QgsExpression &expression )
392  : tabWidget( tabWidget )
393  , widget( widget )
394  , expression( expression )
395  , isVisible( true )
396  {}
397 
398  ContainerInformation( QWidget *widget, const QgsExpression &expression )
399  : widget( widget )
400  , expression( expression )
401  , isVisible( true )
402  {}
403 
404  QgsTabWidget *tabWidget = nullptr;
405  QWidget *widget = nullptr;
406  QgsExpression expression;
407  bool isVisible;
408 
409  void apply( QgsExpressionContext *expressionContext );
410  };
411 
412  void registerContainerInformation( ContainerInformation *info );
413 
414  void updateIcon( QgsEditorWidgetWrapper *eww );
415 
416  void reloadIcon( const QString &file, const QString &tooltip, QSvgWidget *sw );
417 
418  // Contains information about tabs and groupboxes, their visibility state visibility conditions
419  QVector<ContainerInformation *> mContainerVisibilityInformation;
420  QMap<QString, QVector<ContainerInformation *> > mContainerInformationDependency;
421 
422  // Variables below are used for Python
423  static int sFormCounter;
424  int mFormNr;
425  QString mPyFormVarName;
426 
428  bool mIsSaving;
429 
431  bool mPreventFeatureRefresh;
432 
433  bool mIsSettingMultiEditFeatures;
434 
435  QgsFeatureIds mMultiEditFeatureIds;
436  bool mUnsavedMultiEditChanges;
437 
438  QString mEditCommandMessage;
439 
441 
442  QMap<QWidget *, QSvgWidget *> mIconMap;
443 
444  friend class TestQgsDualView;
445  friend class TestQgsAttributeForm;
446 };
447 
448 #endif // QGSATTRIBUTEFORM_H
449 
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
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.
This class contains context information for attribute editor widgets.
Manages an editor widget Widget and wrapper share the same parent.
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
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:55
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.
QgsAttributeEditorContext::Mode mode() const
Returns the current mode of the form.
#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.
#define SIP_DEPRECATED
Definition: qgis_sip.h:99
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.
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.