QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
Classes | Public Types | Public Slots | Signals | Public Member Functions | Friends | List of all members
QgsAttributeForm Class Reference

#include <qgsattributeform.h>

Inheritance diagram for QgsAttributeForm:
Inheritance graph
[legend]

Public Types

enum  FilterType { ReplaceFilter , FilterAnd , FilterOr }
 Filter types. More...
 
enum  Mode {
  SingleEditMode , AddFeatureMode , MultiEditMode , SearchMode ,
  AggregateSearchMode , IdentifyMode
}
 Form modes. More...
 

Public Slots

void changeAttribute (const QString &field, const QVariant &value, const QString &hintText=QString())
 Call this to change the content of a given attribute.
 
void changeGeometry (const QgsGeometry &geometry)
 Changes the geometry of the feature attached to the form.
 
void parentFormValueChanged (const QString &attribute, const QVariant &newValue)
 Is called in embedded forms when an attribute value in the parent form has changed to newValue.
 
void refreshFeature ()
 reload current feature
 
void resetSearch ()
 Resets the search/filter form values.
 
void resetValues ()
 Sets all values to the values of the current feature.
 
bool save ()
 Save all the values from the editors to the layer.
 
bool saveWithDetails (QString *error=nullptr)
 Save all the values from the editors to the layer.
 
void setFeature (const QgsFeature &feature)
 Update all editors to correspond to a different feature.
 

Signals

Q_DECL_DEPRECATED void attributeChanged (const QString &attribute, const QVariant &value)
 Notifies about changes of attributes, this signal is not emitted when the value is set back to the original one.
 
void beforeSave (bool &ok)
 Will be emitted before the feature is saved.
 
void closed ()
 Emitted when the user selects the close option from the form's button bar.
 
void featureSaved (const QgsFeature &feature)
 Emitted when a feature is changed or added.
 
void filterExpressionSet (const QString &expression, QgsAttributeForm::FilterType type)
 Emitted when a filter expression is set using the form.
 
void flashFeatures (const QString &filter)
 Emitted when the user chooses to flash a filtered set of features.
 
void modeChanged (QgsAttributeEditorContext::Mode mode)
 Emitted when the form changes mode.
 
void openFilteredFeaturesAttributeTable (const QString &filter)
 Emitted when the user chooses to open the attribute table dialog with a filtered set of features.
 
void widgetValueChanged (const QString &attribute, const QVariant &value, bool attributeChanged)
 Notifies about changes of attributes.
 
void zoomToFeatures (const QString &filter)
 Emitted when the user chooses to zoom to a filtered set of features.
 

Public Member Functions

 QgsAttributeForm (QgsVectorLayer *vl, const QgsFeature &feature=QgsFeature(), const QgsAttributeEditorContext &context=QgsAttributeEditorContext(), QWidget *parent=nullptr)
 
 ~QgsAttributeForm () override
 
void addInterface (QgsAttributeFormInterface *iface)
 Takes ownership.
 
QString aggregateFilter () const
 The aggregate filter is only useful if the form is in AggregateFilter mode.
 
QgsFeature currentFormFeature () const
 Returns the feature that is currently displayed in the form with all the changes received on editing the values in the widgets.
 
void disconnectButtonBox ()
 Disconnects the button box (OK/Cancel) from the accept/resetValues slots If this method is called, you have to create these connections from outside.
 
void displayWarning (const QString &message)
 Displays a warning message in the form message bar.
 
bool editable ()
 Returns if the form is currently in editable mode.
 
bool eventFilter (QObject *object, QEvent *event) override
 Intercepts keypress on custom form (escape should not close it)
 
const QgsFeaturefeature ()
 
void hideButtonBox ()
 Hides the button box (OK/Cancel) and enables auto-commit.
 
QgsVectorLayerlayer ()
 Returns the layer for which this form is shown.
 
QgsAttributeEditorContext::Mode mode () const
 Returns the current mode of the form.
 
bool needsGeometry () const
 Returns true if any of the form widgets need feature geometry.
 
void setEditCommandMessage (const QString &message)
 Sets the edit command message (Undo) that will be used when the dialog is accepted.
 
void setExtraContextScope (QgsExpressionContextScope *extraScope)
 Sets an additional expression context scope to be used for calculations in this form.
 
void setMessageBar (QgsMessageBar *messageBar)
 Sets the message bar to display feedback from the form in.
 
void setMode (QgsAttributeEditorContext::Mode mode)
 Sets the current mode of the form.
 
void setMultiEditFeatureIds (const QgsFeatureIds &fids)
 Sets all feature IDs which are to be edited if the form is in multiedit mode.
 
void showButtonBox ()
 Shows the button box (OK/Cancel) and disables auto-commit.
 

Friends

class TestQgsAttributeForm
 
class TestQgsDualView
 

Detailed Description

Definition at line 47 of file qgsattributeform.h.

Member Enumeration Documentation

◆ FilterType

Filter types.

Enumerator
ReplaceFilter 

Filter should replace any existing filter.

FilterAnd 

Filter should be combined using "AND".

FilterOr 

Filter should be combined using "OR".

Definition at line 66 of file qgsattributeform.h.

◆ Mode

Form modes.

Deprecated:
Use QgsAttributeEditorContext::Mode instead.
Enumerator
SingleEditMode 

Single edit mode, for editing a single feature.

AddFeatureMode 

Add feature mode, for setting attributes for a new feature. In this mode the dialog will be editable even with an invalid feature and will add a new feature when the form is accepted.

MultiEditMode 

Multi edit mode, for editing fields of multiple features at once.

SearchMode 

Form values are used for searching/filtering the layer.

AggregateSearchMode 

Form is in aggregate search mode, show each widget in this mode.

IdentifyMode 

Identify the feature.

Definition at line 54 of file qgsattributeform.h.

Constructor & Destructor Documentation

◆ QgsAttributeForm()

QgsAttributeForm::QgsAttributeForm ( QgsVectorLayer vl,
const QgsFeature feature = QgsFeature(),
const QgsAttributeEditorContext context = QgsAttributeEditorContext(),
QWidget *  parent = nullptr 
)
explicit

Definition at line 77 of file qgsattributeform.cpp.

◆ ~QgsAttributeForm()

QgsAttributeForm::~QgsAttributeForm ( )
override

Definition at line 106 of file qgsattributeform.cpp.

Member Function Documentation

◆ addInterface()

void QgsAttributeForm::addInterface ( QgsAttributeFormInterface iface)

Takes ownership.

Parameters
iface

Definition at line 134 of file qgsattributeform.cpp.

◆ aggregateFilter()

QString QgsAttributeForm::aggregateFilter ( ) const

The aggregate filter is only useful if the form is in AggregateFilter mode.

In this case it will return a combined expression according to the chosen filters on all attribute widgets.

Definition at line 3021 of file qgsattributeform.cpp.

◆ attributeChanged

Q_DECL_DEPRECATED void QgsAttributeForm::attributeChanged ( const QString &  attribute,
const QVariant &  value 
)
signal

Notifies about changes of attributes, this signal is not emitted when the value is set back to the original one.

Parameters
attributeThe name of the attribute that changed.
valueThe new value of the attribute.
Deprecated:
since 3.0

◆ beforeSave

void QgsAttributeForm::beforeSave ( bool &  ok)
signal

Will be emitted before the feature is saved.

Use this signal to perform sanity checks. You can set the parameter ok to false to notify the form that you don't want it to be saved. If you want the form to be saved, leave the parameter untouched.

Parameters
okSet this parameter to false if you don't want the form to be saved
Note
not available in Python bindings

◆ changeAttribute

void QgsAttributeForm::changeAttribute ( const QString &  field,
const QVariant &  value,
const QString &  hintText = QString() 
)
slot

Call this to change the content of a given attribute.

Will update the editor(s) related to this field.

Parameters
fieldThe field to change
valueThe new value
hintTextA hint text for non existent joined features

Definition at line 270 of file qgsattributeform.cpp.

◆ changeGeometry

void QgsAttributeForm::changeGeometry ( const QgsGeometry geometry)
slot

Changes the geometry of the feature attached to the form.

Since
QGIS 3.30

Definition at line 297 of file qgsattributeform.cpp.

◆ closed

void QgsAttributeForm::closed ( )
signal

Emitted when the user selects the close option from the form's button bar.

◆ currentFormFeature()

QgsFeature QgsAttributeForm::currentFormFeature ( ) const
inline

Returns the feature that is currently displayed in the form with all the changes received on editing the values in the widgets.

Since
QGIS 3.16

Definition at line 87 of file qgsattributeform.h.

◆ disconnectButtonBox()

void QgsAttributeForm::disconnectButtonBox ( )

Disconnects the button box (OK/Cancel) from the accept/resetValues slots If this method is called, you have to create these connections from outside.

Definition at line 128 of file qgsattributeform.cpp.

◆ displayWarning()

void QgsAttributeForm::displayWarning ( const QString &  message)

Displays a warning message in the form message bar.

Parameters
messagemessage string
See also
mode()
Since
QGIS 3.12

Definition at line 728 of file qgsattributeform.cpp.

◆ editable()

bool QgsAttributeForm::editable ( )

Returns if the form is currently in editable mode.

Returns
Editable mode of this form

Definition at line 139 of file qgsattributeform.cpp.

◆ eventFilter()

bool QgsAttributeForm::eventFilter ( QObject *  object,
QEvent *  event 
)
override

Intercepts keypress on custom form (escape should not close it)

Parameters
objectThe object for which the event has been sent
eventThe event which is being filtered
Returns
true if the event has been handled (key was ESC)

Definition at line 2841 of file qgsattributeform.cpp.

◆ feature()

const QgsFeature & QgsAttributeForm::feature ( )
inline

Definition at line 79 of file qgsattributeform.h.

◆ featureSaved

void QgsAttributeForm::featureSaved ( const QgsFeature feature)
signal

Emitted when a feature is changed or added.

◆ filterExpressionSet

void QgsAttributeForm::filterExpressionSet ( const QString &  expression,
QgsAttributeForm::FilterType  type 
)
signal

Emitted when a filter expression is set using the form.

Parameters
expressionfilter expression
typefilter type

◆ flashFeatures

void QgsAttributeForm::flashFeatures ( const QString &  filter)
signal

Emitted when the user chooses to flash a filtered set of features.

◆ hideButtonBox()

void QgsAttributeForm::hideButtonBox ( )

Hides the button box (OK/Cancel) and enables auto-commit.

Note
set Embed in QgsAttributeEditorContext in constructor instead

Definition at line 112 of file qgsattributeform.cpp.

◆ layer()

QgsVectorLayer * QgsAttributeForm::layer ( )
inline

Returns the layer for which this form is shown.

Returns
Layer

Definition at line 132 of file qgsattributeform.h.

◆ mode()

QgsAttributeEditorContext::Mode QgsAttributeForm::mode ( ) const
inline

Returns the current mode of the form.

See also
setMode()

Definition at line 145 of file qgsattributeform.h.

◆ modeChanged

void QgsAttributeForm::modeChanged ( QgsAttributeEditorContext::Mode  mode)
signal

Emitted when the form changes mode.

Parameters
modenew mode

◆ needsGeometry()

bool QgsAttributeForm::needsGeometry ( ) const

Returns true if any of the form widgets need feature geometry.

Since
QGIS 3.20

Definition at line 1540 of file qgsattributeform.cpp.

◆ openFilteredFeaturesAttributeTable

void QgsAttributeForm::openFilteredFeaturesAttributeTable ( const QString &  filter)
signal

Emitted when the user chooses to open the attribute table dialog with a filtered set of features.

Since
QGIS 3.24

◆ parentFormValueChanged

void QgsAttributeForm::parentFormValueChanged ( const QString &  attribute,
const QVariant &  newValue 
)
slot

Is called in embedded forms when an attribute value in the parent form has changed to newValue.

Notify the form widgets that something has changed in case they have filter expressions that depend on the parent form scope.

Since
QGIS 3.14

Definition at line 1528 of file qgsattributeform.cpp.

◆ refreshFeature

void QgsAttributeForm::refreshFeature ( )
slot

reload current feature

Definition at line 1514 of file qgsattributeform.cpp.

◆ resetSearch

void QgsAttributeForm::resetSearch ( )
slot

Resets the search/filter form values.

Definition at line 945 of file qgsattributeform.cpp.

◆ resetValues

void QgsAttributeForm::resetValues ( )
slot

Sets all values to the values of the current feature.

Definition at line 919 of file qgsattributeform.cpp.

◆ save

bool QgsAttributeForm::save ( )
slot

Save all the values from the editors to the layer.

Returns
true if successful

Definition at line 841 of file qgsattributeform.cpp.

◆ saveWithDetails

bool QgsAttributeForm::saveWithDetails ( QString *  error = nullptr)
slot

Save all the values from the editors to the layer.

Parameters
errorif specified, will be set to an explanatory error message if an error occurs while saving the form.
Returns
true if save was successful
Since
QGIS 3.18

Definition at line 846 of file qgsattributeform.cpp.

◆ setEditCommandMessage()

void QgsAttributeForm::setEditCommandMessage ( const QString &  message)
inline

Sets the edit command message (Undo) that will be used when the dialog is accepted.

Parameters
messageThe message

Definition at line 159 of file qgsattributeform.h.

◆ setExtraContextScope()

void QgsAttributeForm::setExtraContextScope ( QgsExpressionContextScope extraScope)

Sets an additional expression context scope to be used for calculations in this form.

Since
QGIS 3.16

Definition at line 3039 of file qgsattributeform.cpp.

◆ setFeature

void QgsAttributeForm::setFeature ( const QgsFeature feature)
slot

Update all editors to correspond to a different feature.

Parameters
featureThe feature which will be represented by the form

Definition at line 302 of file qgsattributeform.cpp.

◆ setMessageBar()

void QgsAttributeForm::setMessageBar ( QgsMessageBar messageBar)

Sets the message bar to display feedback from the form in.

This is used in the search/filter mode to display the count of selected features.

Parameters
messageBartarget message bar

Definition at line 3013 of file qgsattributeform.cpp.

◆ setMode()

void QgsAttributeForm::setMode ( QgsAttributeEditorContext::Mode  mode)

Sets the current mode of the form.

Parameters
modeform mode
See also
mode()

Definition at line 144 of file qgsattributeform.cpp.

◆ setMultiEditFeatureIds()

void QgsAttributeForm::setMultiEditFeatureIds ( const QgsFeatureIds fids)

Sets all feature IDs which are to be edited if the form is in multiedit mode.

Parameters
fidsfeature ID list

Definition at line 2917 of file qgsattributeform.cpp.

◆ showButtonBox()

void QgsAttributeForm::showButtonBox ( )

Shows the button box (OK/Cancel) and disables auto-commit.

Note
set Embed in QgsAttributeEditorContext in constructor instead

Definition at line 121 of file qgsattributeform.cpp.

◆ widgetValueChanged

void QgsAttributeForm::widgetValueChanged ( const QString &  attribute,
const QVariant &  value,
bool  attributeChanged 
)
signal

Notifies about changes of attributes.

Parameters
attributeThe name of the attribute that changed.
valueThe new value of the attribute.
attributeChangedIf true, it corresponds to an actual change of the feature attribute

◆ zoomToFeatures

void QgsAttributeForm::zoomToFeatures ( const QString &  filter)
signal

Emitted when the user chooses to zoom to a filtered set of features.

Friends And Related Symbol Documentation

◆ TestQgsAttributeForm

friend class TestQgsAttributeForm
friend

Definition at line 564 of file qgsattributeform.h.

◆ TestQgsDualView

friend class TestQgsDualView
friend

Definition at line 563 of file qgsattributeform.h.


The documentation for this class was generated from the following files: