QGIS API Documentation  2.15.0-Master (13f053b)
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"
21 #include "qgseditorwidgetwrapper.h"
23 
24 #include <QWidget>
25 #include <QDialogButtonBox>
26 
29 class QgsMessageBar;
30 class QgsMessageBarItem;
31 
32 class GUI_EXPORT QgsAttributeForm : public QWidget
33 {
34  Q_OBJECT
35 
36  public:
37 
39  enum Mode
40  {
42  AddFeatureMode,
45  // TODO: SearchMode, /*!< Form values are used for searching/filtering the layer */
46  };
47 
48  explicit QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &feature = QgsFeature(), const QgsAttributeEditorContext& context = QgsAttributeEditorContext(), QWidget *parent = nullptr );
50 
51  const QgsFeature& feature() { return mFeature; }
52 
56  void hideButtonBox();
57 
61  void showButtonBox();
62 
67  void disconnectButtonBox();
68 
73  void addInterface( QgsAttributeFormInterface* iface );
74 
80  QgsVectorLayer* layer() { return mLayer; }
81 
87  bool editable();
88 
93  Mode mode() const { return mMode; }
94 
100  void setMode( Mode mode );
101 
110  Q_DECL_DEPRECATED void setIsAddDialog( bool isAddDialog );
111 
117  void setEditCommandMessage( const QString& message ) { mEditCommandMessage = message; }
118 
127  bool eventFilter( QObject* object, QEvent* event ) override;
128 
133  void setMultiEditFeatureIds( const QgsFeatureIds& fids );
134 
135  signals:
142  void attributeChanged( const QString& attribute, const QVariant& value );
143 
152  void beforeSave( bool& ok );
153 
157  void featureSaved( const QgsFeature& feature );
158 
159  public slots:
166  void changeAttribute( const QString& field, const QVariant& value );
167 
173  void setFeature( const QgsFeature& feature );
174 
180  bool save();
181 
187  Q_DECL_DEPRECATED void accept() { save(); }
188 
194  Q_DECL_DEPRECATED void reject() { resetValues(); }
195 
199  void resetValues();
200 
204  void refreshFeature();
205 
206  private slots:
207  void onAttributeChanged( const QVariant& value );
208  void onAttributeAdded( int idx );
209  void onAttributeDeleted( int idx );
210  void onUpdatedFields();
211 
212  void preventFeatureRefresh();
213  void synchronizeEnabledState();
214  void layerSelectionChanged();
215 
217  bool saveMultiEdits();
218  void resetMultiEdit( bool promptToSave = false );
219  void multiEditMessageClicked( const QString& link );
220 
221 
222  private:
223  void init();
224 
225  void cleanPython();
226 
227  void initPython();
228 
229  struct WidgetInfo
230  {
231  WidgetInfo()
232  : widget( nullptr )
233  , labelOnTop( false )
234  , labelAlignRight( false )
235  {}
236 
237  QWidget* widget;
238  QString labelText;
239  bool labelOnTop;
240  bool labelAlignRight;
241  };
242 
243  WidgetInfo createWidgetFromDef( const QgsAttributeEditorElement* widgetDef, QWidget* parent, QgsVectorLayer* vl, QgsAttributeEditorContext& context );
244 
245  void addWidgetWrapper( QgsEditorWidgetWrapper* eww );
246 
251  void createWrappers();
252  void connectWrappers();
253 
254  void scanForEqualAttributes( QgsFeatureIterator& fit, QSet< int >& mixedValueFields, QHash< int, QVariant >& fieldSharedValues ) const;
255 
257  bool saveEdits();
258 
259  int messageTimeout();
260  void clearMultiEditMessages();
261 
262  QgsVectorLayer* mLayer;
263  QgsFeature mFeature;
264  QgsMessageBar* mMessageBar;
265  QgsMessageBarItem* mMultiEditUnsavedMessageBarItem;
266  QgsMessageBarItem* mMultiEditMessageBarItem;
267  QList<QgsWidgetWrapper*> mWidgets;
268  QgsAttributeEditorContext mContext;
269  QDialogButtonBox* mButtonBox;
272 
273  // Variables below are used for python
274  static int sFormCounter;
275  int mFormNr;
276  QString mPyFormVarName;
277 
279  bool mIsSaving;
280 
282  bool mPreventFeatureRefresh;
283 
285  bool mIsSettingFeature;
286  bool mIsSettingMultiEditFeatures;
287 
288  QgsFeatureIds mMultiEditFeatureIds;
289  bool mUnsavedMultiEditChanges;
290 
291  QString mEditCommandMessage;
292 
293  Mode mMode;
294 
295  friend class TestQgsDualView;
296 };
297 
298 #endif // QGSATTRIBUTEFORM_H
299 
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 ...
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.
const QgsFeature & feature()
Represents a vector layer which manages a vector based data sets.