2014-01-05 14:50:07 +01:00
/***************************************************************************
qgsattributeform.h
--------------------------------------
Date : 3.5.2014
Copyright : (C) 2014 Matthias Kuhn
2015-08-30 12:59:30 +02:00
Email : matthias at opengis dot ch
2014-01-05 14:50:07 +01:00
***************************************************************************
* *
* 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. *
* *
***************************************************************************/
class QgsAttributeForm : QWidget
{
%TypeHeaderCode
#include <qgsattributeform.h>
%End
public:
2016-03-08 14:11:33 +11:00
//! Form modes
enum Mode
{
SingleEditMode, /*!< Single edit mode, for editing a single feature */
2016-05-17 14:16:17 +10:00
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. */
2016-03-08 14:11:33 +11:00
MultiEditMode, /*!< Multi edit mode, for editing fields of multiple features at once */
2016-05-17 14:16:17 +10:00
SearchMode, /*!< Form values are used for searching/filtering the layer */
};
//! Filter types
enum FilterType
{
ReplaceFilter, /*!< Filter should replace any existing filter */
FilterAnd, /*!< Filter should be combined using "AND" */
FilterOr, /*!< Filter should be combined using "OR" */
2016-03-08 14:11:33 +11:00
};
2015-02-18 17:00:36 +11:00
explicit QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature& feature = QgsFeature(), const QgsAttributeEditorContext& context = QgsAttributeEditorContext(), QWidget *parent /TransferThis/ = 0 );
2014-01-05 14:50:07 +01:00
~QgsAttributeForm();
const QgsFeature& feature();
2014-11-20 14:17:51 +01:00
/**
* Hides the button box (Ok/Cancel) and enables auto-commit
*/
2014-01-05 14:50:07 +01:00
void hideButtonBox();
2014-11-20 14:17:51 +01:00
/**
* Shows the button box (Ok/Cancel) and disables auto-commit
*/
2014-01-05 14:50:07 +01:00
void showButtonBox();
2014-11-20 14:17:51 +01:00
/**
* 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 disconnectButtonBox();
2014-05-27 23:22:50 +02:00
/**
* Takes ownership
* @param iface
*/
void addInterface( QgsAttributeFormInterface* iface /Transfer/ );
2014-11-20 14:17:51 +01:00
/**
* Returns the layer for which this form is shown
*
* @return Layer
*/
2014-05-27 23:22:50 +02:00
QgsVectorLayer* layer();
2014-11-20 14:17:51 +01:00
/**
* Returns if the form is currently in editable mode.
*
* @return Editable mode of this form
*/
2014-05-27 23:22:50 +02:00
bool editable();
2016-03-08 14:11:33 +11:00
/** Returns the current mode of the form.
* @note added in QGIS 2.16
* @see setMode()
*/
Mode mode() const;
/** Sets the current mode of the form.
* @param mode form mode
* @note added in QGIS 2.16
* @see mode()
*/
void setMode( Mode mode );
2014-05-27 23:22:50 +02:00
/**
* Sets the edit command message (Undo) that will be used when the dialog is accepted
*
* @param message The message
*/
void setEditCommandMessage( const QString& message );
2014-11-20 14:17:51 +01:00
/**
* Intercepts keypress on custom form (escape should not close it)
*
* @param object The object for which the event has been sent
* @param event The event which is being filtered
*
* @return true if the event has been handled (key was ESC)
*/
bool eventFilter( QObject* object, QEvent* event );
2016-03-08 14:11:33 +11:00
/** Sets all feature IDs which are to be edited if the form is in multiedit mode
* @param fids feature ID list
* @note added in QGIS 2.16
*/
void setMultiEditFeatureIds( const QgsFeatureIds& fids );
2016-06-09 14:04:45 +10:00
/** 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.
* @param messageBar target message bar
* @note added in QGIS 2.16
*/
void setMessageBar( QgsMessageBar* messageBar );
2014-01-05 14:50:07 +01:00
signals:
/**
* Notifies about changes of attributes
*
* @param attribute The name of the attribute that changed.
* @param value The new value of the attribute.
*/
2015-10-26 22:46:25 +11:00
void attributeChanged( const QString& attribute, const QVariant& value );
2014-01-05 14:50:07 +01:00
2014-05-27 23:22:50 +02:00
/**
* 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.
*
* @param ok Set this parameter to false if you don't want the form to be saved
* @note not available in python bindings
*/
// void beforeSave( bool& ok );
/**
* Is emitted, when a feature is changed or added
*/
void featureSaved( const QgsFeature& feature );
2016-05-17 14:16:17 +10:00
/** Is emitted when a filter expression is set using the form.
* @param expression filter expression
* @param type filter type
* @note added in QGIS 2.16
*/
void filterExpressionSet( const QString& expression, QgsAttributeForm::FilterType type );
/** Emitted when the form changes mode.
* @param mode new mode
*/
void modeChanged( QgsAttributeForm::Mode mode );
2016-06-09 14:04:45 +10:00
/** Emitted when the user selects the close option from the form's button bar.
* @note added in QGIS 2.16
*/
void closed();
2016-12-15 20:47:58 +10:00
/**
* Emitted when the user chooses to zoom to a filtered set of features.
* @note added in QGIS 3.0
*/
void zoomToFeatures( const QString& filter );
2014-01-05 14:50:07 +01:00
public slots:
2014-11-20 14:17:51 +01:00
/**
* Call this to change the content of a given attribute. Will update the editor(s) related to this field.
*
* @param field The field to change
* @param value The new value
*/
2014-01-05 14:50:07 +01:00
void changeAttribute( const QString& field, const QVariant& value );
2014-11-20 14:17:51 +01:00
/**
* Update all editors to correspond to a different feature.
*
* @param feature The feature which will be represented by the form
*/
2014-01-05 14:50:07 +01:00
void setFeature( const QgsFeature& feature );
2014-11-20 14:17:51 +01:00
/**
* Save all the values from the editors to the layer.
*
* @return True if successful
*/
2014-01-05 14:50:07 +01:00
bool save();
2014-11-20 14:17:51 +01:00
/**
* Sets all values to the values of the current feature
*/
2014-01-05 14:50:07 +01:00
void resetValues();
2015-11-10 17:08:27 +11:00
2016-05-17 14:16:17 +10:00
/** Resets the search/filter form values.
* @note added in QGIS 2.16
*/
void resetSearch();
2015-11-10 17:08:27 +11:00
/**
* reload current feature
*/
void refreshFeature();
2014-01-05 14:50:07 +01:00
};