QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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;
39 
44 class GUI_EXPORT QgsAttributeForm : public QWidget
45 {
46  Q_OBJECT
47 
48  public:
49 
51  enum Mode
52  {
54  AddFeatureMode,
59  IdentifyMode
60  };
61 
64  {
68  };
69 
70  explicit QgsAttributeForm( QgsVectorLayer *vl,
71  const QgsFeature &feature = QgsFeature(),
73  QWidget *parent SIP_TRANSFERTHIS = nullptr );
74  ~QgsAttributeForm() override;
75 
76  const QgsFeature &feature() { return mFeature; }
77 
82  // TODO QGIS 3.0 - make private
83  void hideButtonBox();
84 
89  // TODO QGIS 3.0 - make private
90  void showButtonBox();
91 
96  // TODO QGIS 3.0 - make private
97  void disconnectButtonBox();
98 
103  void addInterface( QgsAttributeFormInterface *iface SIP_TRANSFER );
104 
110  QgsVectorLayer *layer() { return mLayer; }
111 
117  bool editable();
118 
124  QgsAttributeEditorContext::Mode mode() const { return mMode; }
125 
132  void setMode( QgsAttributeEditorContext::Mode mode );
133 
139  void setEditCommandMessage( const QString &message ) { mEditCommandMessage = message; }
140 
149  bool eventFilter( QObject *object, QEvent *event ) override;
150 
156  void setMultiEditFeatureIds( const QgsFeatureIds &fids );
157 
164  void setMessageBar( QgsMessageBar *messageBar );
165 
173  QString aggregateFilter() const;
174 
175  signals:
176 
185  Q_DECL_DEPRECATED void attributeChanged( const QString &attribute, const QVariant &value ) SIP_DEPRECATED;
186 
195  void widgetValueChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
196 
205  void beforeSave( bool &ok ) SIP_SKIP;
206 
210  void featureSaved( const QgsFeature &feature );
211 
218  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
219 
224  void modeChanged( QgsAttributeEditorContext::Mode mode );
225 
230  void closed();
231 
236  void zoomToFeatures( const QString &filter );
237 
242  void flashFeatures( const QString &filter );
243 
244  public slots:
245 
253  void changeAttribute( const QString &field, const QVariant &value, const QString &hintText = QString() );
254 
260  void setFeature( const QgsFeature &feature );
261 
267  bool save();
268 
272  void resetValues();
273 
278  void resetSearch();
279 
283  void refreshFeature();
284 
285  private slots:
286  void onAttributeChanged( const QVariant &value );
287  void onAttributeAdded( int idx );
288  void onAttributeDeleted( int idx );
289  void onUpdatedFields();
290  void onConstraintStatusChanged( const QString &constraint,
291  const QString &description, const QString &err, QgsEditorWidgetWrapper::ConstraintResult result );
292  void preventFeatureRefresh();
293  void synchronizeEnabledState();
294  void layerSelectionChanged();
295 
297  bool saveMultiEdits();
298  void resetMultiEdit( bool promptToSave = false );
299  void multiEditMessageClicked( const QString &link );
300 
301  void filterAndTriggered();
302  void filterOrTriggered();
303  void filterTriggered();
304 
305  void searchZoomTo();
306  void searchFlash();
307  void searchSetSelection();
308  void searchAddToSelection();
309  void searchRemoveFromSelection();
310  void searchIntersectSelection();
311 
312  private:
313  void init();
314 
315  void cleanPython();
316 
317  void initPython();
318 
319  void updateJoinedFields( const QgsEditorWidgetWrapper &eww );
320 
321  bool fieldIsEditable( int fieldIndex ) const;
322 
323  bool fieldIsEditable( const QgsVectorLayer &layer, int fieldIndex, QgsFeatureId fid ) const;
324 
325  struct WidgetInfo
326  {
327  QWidget *widget = nullptr;
328  QString labelText;
329  QString toolTip;
330  QString hint;
331  bool labelOnTop = false;
332  bool labelAlignRight = false;
333  bool showLabel = true;
334  };
335 
336  WidgetInfo createWidgetFromDef( const QgsAttributeEditorElement *widgetDef, QWidget *parent, QgsVectorLayer *vl, QgsAttributeEditorContext &context );
337 
338  void addWidgetWrapper( QgsEditorWidgetWrapper *eww );
339 
344  void createWrappers();
345  void afterWidgetInit();
346 
347  void scanForEqualAttributes( QgsFeatureIterator &fit, QSet< int > &mixedValueFields, QHash< int, QVariant > &fieldSharedValues ) const;
348 
350  bool saveEdits();
351 
352  int messageTimeout();
353  void clearMultiEditMessages();
354  void pushSelectedFeaturesMessage();
355  void runSearchSelect( QgsVectorLayer::SelectBehavior behavior );
356 
357  QString createFilterExpression() const;
358 
360  void updateAllConstraints();
361  void updateConstraints( QgsEditorWidgetWrapper *w );
362  void updateContainersVisibility();
363  void updateConstraint( const QgsFeature &ft, QgsEditorWidgetWrapper *eww );
364  bool currentFormFeature( QgsFeature &feature );
365  bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
366  QList<QgsEditorWidgetWrapper *> constraintDependencies( QgsEditorWidgetWrapper *w );
367 
368  QgsRelationWidgetWrapper *setupRelationWidgetWrapper( const QgsRelation &rel, const QgsAttributeEditorContext &context );
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.
#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.
QgsAttributeEditorContext::Mode mode() const
Returns the current mode of the form.
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.