QGIS/src/gui/qgsattributeformeditorwidget.h
Nyall Dawson 66b51d4a81 [FEATURE] Edit attributes of multiple features simultaneously
This change allows the attributes of multiple features to be edited
simultaneously. It is enabled when the attribute table dialog is in
"form mode", via a new "multi edit" button on the toolbar.

In this mode, attribute value changes will apply to all selected
features. New widgets appear next to each editor widget allowing for
display of the current multi-edit state and for rolling back changes
on a field-by-field basis.

Changes are made as a single edit command, so pressing undo will
rollback the attribute changes for all selected features at once.

Multiedit mode is only available for auto generated and drag and
drop forms - it is not supported by custom ui forms.

Sponsored by Kanton Basel Stadt
2016-04-18 15:15:11 +10:00

131 lines
4.2 KiB
C++

/***************************************************************************
qgsattributeformeditorwidget.h
-----------------------------
Date : March 2016
Copyright : (C) 2016 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSATTRIBUTEFORMEDITORWIDGET_H
#define QGSATTRIBUTEFORMEDITORWIDGET_H
#include <QWidget>
#include <QVariant>
class QgsAttributeForm;
class QgsEditorWidgetWrapper;
class QgsMultiEditToolButton;
class QgsVectorLayer;
/** \ingroup gui
* \class QgsAttributeFormEditorWidget
* A widget consisting of both an editor widget and additional widgets for controlling the behaviour
* of the editor widget depending on a number of possible modes. For instance, if the parent attribute
* form is in the multi edit mode, this widget will show both the editor widget and a tool button for
* controlling the multi edit results.
* \note Added in version 2.16
*/
class GUI_EXPORT QgsAttributeFormEditorWidget : public QWidget
{
Q_OBJECT
public:
//! Widget modes
enum Mode
{
DefaultMode, /*!< Default mode, only the editor widget is shown */
MultiEditMode, /*!< Multi edit mode, both the editor widget and a QgsMultiEditToolButton is shown */
// TODO: SearchMode, /*!< Layer search/filter mode */
};
/** Constructor for QgsAttributeFormEditorWidget.
* @param editorWidget associated editor widget wrapper
* @param form parent attribute form
*/
explicit QgsAttributeFormEditorWidget( QgsEditorWidgetWrapper* editorWidget, QgsAttributeForm* form );
~QgsAttributeFormEditorWidget();
/** Sets the current mode for the widget. The widget will adapt its state and visible widgets to
* reflect the updated mode. Eg, showing multi edit tool buttons if the mode is set to MultiEditMode.
* @param mode widget mode
* @see mode()
*/
void setMode( Mode mode );
/** Returns the current mode for the widget.
* @see setMode()
*/
Mode mode() const { return mMode; }
/** Resets the widget to an initial value.
* @param initialValue initial value to show in widget
* @param mixedValue set to true to initially show the mixed values state
*/
void initialize( const QVariant& initialValue, bool mixedValues = false );
/** Returns true if the widget's value has been changed since it was initialized.
* @see initialize()
*/
bool hasChanged() const { return mIsChanged; }
/** Returns the current value of the attached editor widget.
*/
QVariant currentValue() const;
public slots:
/** Sets whether the widget should be displayed in a "mixed values" mode.
* @param mixed set to true to show in a mixed values state
*/
void setIsMixed( bool mixed );
/** Called when field values have been committed;
*/
void changesCommitted();
signals:
//! Emitted when the widget's value changes
//! @param value new widget value
void valueChanged( const QVariant& value );
private slots:
//! Triggered when editor widget's value changes
void editorWidgetChanged( const QVariant& value );
//! Triggered when multi edit tool button requests value reset
void resetValue();
//! Triggered when the multi edit tool button "set field value" action is selected
void setFieldTriggered();
private:
QgsEditorWidgetWrapper* mWidget;
QgsAttributeForm* mForm;
Mode mMode;
QgsMultiEditToolButton* mMultiEditButton;
QVariant mPreviousValue;
bool mBlockValueUpdate;
bool mIsMixed;
bool mIsChanged;
QgsVectorLayer* layer();
void updateWidgets();
};
#endif // QGSATTRIBUTEFORMEDITORWIDGET_H