From cfc158977f5d8fa3c801d0b7b6185cf44639cfbd Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 3 Mar 2017 00:41:06 +0100 Subject: [PATCH] Add the additional action to form --- core/form.cpp | 13 +++++++++++++ core/form.h | 21 +++++++++++++++++++++ core/form_p.h | 1 + 3 files changed, 35 insertions(+) diff --git a/core/form.cpp b/core/form.cpp index 245b72af4..9061aa3be 100644 --- a/core/form.cpp +++ b/core/form.cpp @@ -73,6 +73,19 @@ void FormField::setActivationAction( Action *action ) d->m_activateAction = action; } +Action* FormField::additionalAction( AdditionalActionType type ) const +{ + Q_D( const FormField ); + return d->m_additionalActions.value(type); +} + +void FormField::setAdditionalAction( AdditionalActionType type, Action *action ) +{ + Q_D( FormField ); + delete d->m_additionalActions.value(type); + d->m_additionalActions[type] = action; +} + class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate { diff --git a/core/form.h b/core/form.h index 3832810a4..359019e7d 100644 --- a/core/form.h +++ b/core/form.h @@ -93,6 +93,26 @@ class OKULARCORE_EXPORT FormField Action* activationAction() const; + /** + * Describes the type of form additional action. + * + * @since 1.1 + */ + enum AdditionalActionType + { + FieldModified, ///< An action to be performed when the user modifies the field + FormatField, ///< An action to be performed before the field is formatted to display its value + ValidateField, ///< An action to be performed when the field value changes + CalculateField, ///< An action to be performed when the field needs to be recalculated + }; + + /** + * Returns the additional action of the given @p type or @c nullptr if no action has been defined. + * + * @since 1.1 + */ + Action* additionalAction( AdditionalActionType type ) const; + protected: /// @cond PRIVATE FormField( FormFieldPrivate &dd ); @@ -101,6 +121,7 @@ class OKULARCORE_EXPORT FormField /// @endcond void setActivationAction( Action *action ); + void setAdditionalAction( AdditionalActionType type, Action *action ); private: Q_DISABLE_COPY( FormField ) diff --git a/core/form_p.h b/core/form_p.h index 33d778a16..c4347b980 100644 --- a/core/form_p.h +++ b/core/form_p.h @@ -33,6 +33,7 @@ class FormFieldPrivate FormField::FieldType m_type; QString m_default; Action *m_activateAction; + QHash m_additionalActions; Q_DECLARE_PUBLIC( FormField ) FormField *q_ptr;