QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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;
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 
84  void displayWarning( const QString &message );
85 
86  // TODO QGIS 4.0 - make private
87 
92  void hideButtonBox();
93 
94  // TODO QGIS 4.0 - make private
95 
100  void showButtonBox();
101 
102  // TODO QGIS 4.0 - make private
103 
108  void disconnectButtonBox();
109 
114  void addInterface( QgsAttributeFormInterface *iface SIP_TRANSFER );
115 
121  QgsVectorLayer *layer() { return mLayer; }
122 
128  bool editable();
129 
135  QgsAttributeEditorContext::Mode mode() const { return mMode; }
136 
143  void setMode( QgsAttributeEditorContext::Mode mode );
144 
150  void setEditCommandMessage( const QString &message ) { mEditCommandMessage = message; }
151 
160  bool eventFilter( QObject *object, QEvent *event ) override;
161 
167  void setMultiEditFeatureIds( const QgsFeatureIds &fids );
168 
175  void setMessageBar( QgsMessageBar *messageBar );
176 
184  QString aggregateFilter() const;
185 
186  signals:
187 
196  Q_DECL_DEPRECATED void attributeChanged( const QString &attribute, const QVariant &value ) SIP_DEPRECATED;
197 
206  void widgetValueChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
207 
216  void beforeSave( bool &ok ) SIP_SKIP;
217 
221  void featureSaved( const QgsFeature &feature );
222 
229  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
230 
235  void modeChanged( QgsAttributeEditorContext::Mode mode );
236 
241  void closed();
242 
247  void zoomToFeatures( const QString &filter );
248 
253  void flashFeatures( const QString &filter );
254 
255  public slots:
256 
264  void changeAttribute( const QString &field, const QVariant &value, const QString &hintText = QString() );
265 
271  void setFeature( const QgsFeature &feature );
272 
278  bool save();
279 
283  void resetValues();
284 
289  void resetSearch();
290 
294  void refreshFeature();
295 
296  private slots:
297  void onAttributeChanged( const QVariant &value, const QVariantList &additionalFieldValues );
298  void onAttributeAdded( int idx );
299  void onAttributeDeleted( int idx );
300  void onUpdatedFields();
301  void onConstraintStatusChanged( const QString &constraint,
302  const QString &description, const QString &err, QgsEditorWidgetWrapper::ConstraintResult result );
303  void preventFeatureRefresh();
304  void synchronizeEnabledState();
305  void layerSelectionChanged();
306 
308  bool saveMultiEdits();
309  void resetMultiEdit( bool promptToSave = false );
310  void multiEditMessageClicked( const QString &link );
311 
312  void filterAndTriggered();
313  void filterOrTriggered();
314  void filterTriggered();
315 
316  void searchZoomTo();
317  void searchFlash();
318  void searchSetSelection();
319  void searchAddToSelection();
320  void searchRemoveFromSelection();
321  void searchIntersectSelection();
322 
323  private:
324  void init();
325 
326  void cleanPython();
327 
328  void initPython();
329 
330  void updateJoinedFields( const QgsEditorWidgetWrapper &eww );
331 
332  bool fieldIsEditable( int fieldIndex ) const;
333 
334  bool fieldIsEditable( const QgsVectorLayer &layer, int fieldIndex, QgsFeatureId fid ) const;
335 
336  void updateDefaultValueDependencies();
337 
338  struct WidgetInfo
339  {
340  QWidget *widget = nullptr;
341  QString labelText;
342  QString toolTip;
343  QString hint;
344  bool labelOnTop = false;
345  bool labelAlignRight = false;
346  bool showLabel = true;
347  };
348 
349  WidgetInfo createWidgetFromDef( const QgsAttributeEditorElement *widgetDef, QWidget *parent, QgsVectorLayer *vl, QgsAttributeEditorContext &context );
350 
351  void addWidgetWrapper( QgsEditorWidgetWrapper *eww );
352 
357  void createWrappers();
358  void afterWidgetInit();
359 
360  void scanForEqualAttributes( QgsFeatureIterator &fit, QSet< int > &mixedValueFields, QHash< int, QVariant > &fieldSharedValues ) const;
361 
363  bool saveEdits();
364 
366  void createDefaultValueDependencies();
367 
369  bool updateDefaultValues( const int originIdx );
370 
371  int messageTimeout();
372  void clearMultiEditMessages();
373  void pushSelectedFeaturesMessage();
374  void runSearchSelect( QgsVectorLayer::SelectBehavior behavior );
375 
376  QString createFilterExpression() const;
377 
379  void updateAllConstraints();
380  void updateConstraints( QgsEditorWidgetWrapper *w );
381  void updateContainersVisibility();
382  void updateConstraint( const QgsFeature &ft, QgsEditorWidgetWrapper *eww );
383  bool currentFormFeature( QgsFeature &feature );
384  bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
385  QList<QgsEditorWidgetWrapper *> constraintDependencies( QgsEditorWidgetWrapper *w );
386 
387  QgsRelationWidgetWrapper *setupRelationWidgetWrapper( const QgsRelation &rel, const QgsAttributeEditorContext &context );
388 
389  QgsVectorLayer *mLayer = nullptr;
390  QgsFeature mFeature;
391  QgsMessageBar *mMessageBar = nullptr;
392  bool mOwnsMessageBar;
393  QgsMessageBarItem *mMultiEditUnsavedMessageBarItem = nullptr;
394  QgsMessageBarItem *mMultiEditMessageBarItem = nullptr;
395  QList<QgsWidgetWrapper *> mWidgets;
396  QgsAttributeEditorContext mContext;
397  QDialogButtonBox *mButtonBox = nullptr;
398  QWidget *mSearchButtonBox = nullptr;
399  QList<QgsAttributeFormInterface *> mInterfaces;
400  QMap< int, QgsAttributeFormEditorWidget * > mFormEditorWidgets;
401  QList< QgsAttributeFormWidget *> mFormWidgets;
402  QgsExpressionContext mExpressionContext;
403  QMap<const QgsVectorLayerJoinInfo *, QgsFeature> mJoinedFeatures;
404  bool mValuesInitialized = false;
405  bool mDirty = false;
406  bool mIsSettingFeature = false;
407 
408  struct ContainerInformation
409  {
410  ContainerInformation( QgsTabWidget *tabWidget, QWidget *widget, const QgsExpression &expression )
411  : tabWidget( tabWidget )
412  , widget( widget )
413  , expression( expression )
414  , isVisible( true )
415  {}
416 
417  ContainerInformation( QWidget *widget, const QgsExpression &expression )
418  : widget( widget )
419  , expression( expression )
420  , isVisible( true )
421  {}
422 
423  QgsTabWidget *tabWidget = nullptr;
424  QWidget *widget = nullptr;
425  QgsExpression expression;
426  bool isVisible;
427 
428  void apply( QgsExpressionContext *expressionContext );
429  };
430 
431  void registerContainerInformation( ContainerInformation *info );
432 
433  void updateIcon( QgsEditorWidgetWrapper *eww );
434 
435  void reloadIcon( const QString &file, const QString &tooltip, QSvgWidget *sw );
436 
437  // Contains information about tabs and groupboxes, their visibility state visibility conditions
438  QVector<ContainerInformation *> mContainerVisibilityInformation;
439  QMap<QString, QVector<ContainerInformation *> > mContainerInformationDependency;
440 
441  // Variables below are used for Python
442  static int sFormCounter;
443  int mFormNr;
444  QString mPyFormVarName;
445 
447  bool mIsSaving;
448 
450  bool mPreventFeatureRefresh;
451 
452  bool mIsSettingMultiEditFeatures;
453 
454  QgsFeatureIds mMultiEditFeatureIds;
455  bool mUnsavedMultiEditChanges;
456 
457  QString mEditCommandMessage;
458 
460 
461  QMap<QWidget *, QSvgWidget *> mIconMap;
462 
467  QMap<int, QgsWidgetWrapper *> mDefaultValueDependencies;
468 
470  QList<int> mAlreadyUpdatedFields;
471 
472  friend class TestQgsDualView;
473  friend class TestQgsAttributeForm;
474 };
475 
476 #endif // QGSATTRIBUTEFORM_H
477 
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:53
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:126
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:106
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.