diff --git a/core/form.cpp b/core/form.cpp index b1ebb29a6..2fed1ee06 100644 --- a/core/form.cpp +++ b/core/form.cpp @@ -261,6 +261,8 @@ class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate } return list.join( QStringLiteral( ";" ) ); } + + QMap exportValues; }; @@ -306,6 +308,18 @@ bool FormFieldChoice::canBeSpellChecked() const return false; } +void FormFieldChoice::setExportValues( const QMap &values ) +{ + Q_D( FormFieldChoice ); + d->exportValues = values; +} + +QString FormFieldChoice::exportValueForChoice( const QString &choice ) const +{ + Q_D( const FormFieldChoice ); + return d->exportValues.value(choice, choice); +} + class Okular::FormFieldSignaturePrivate : public Okular::FormFieldPrivate { public: diff --git a/core/form.h b/core/form.h index 9d1780643..9d42ce216 100644 --- a/core/form.h +++ b/core/form.h @@ -419,9 +419,25 @@ class OKULARCORE_EXPORT FormFieldChoice : public FormField */ virtual bool canBeSpellChecked() const; + /** + * Returns the export value for a given choice + * + * @since 1.11 + */ + QString exportValueForChoice( const QString &choice ) const; + protected: FormFieldChoice(); + /** + * The possible choices of the choice field. + * The key is the the display name of the choice, + * The value is the export value (i.e. for use in javascript, etc) of the choice + * + * @since 1.11 + */ + void setExportValues( const QMap &values ); + private: Q_DECLARE_PRIVATE( FormFieldChoice ) Q_DISABLE_COPY( FormFieldChoice ) diff --git a/core/script/kjs_field.cpp b/core/script/kjs_field.cpp index 6f174d54f..d03a533e2 100644 --- a/core/script/kjs_field.cpp +++ b/core/script/kjs_field.cpp @@ -155,7 +155,11 @@ static KJSObject fieldGetValue( KJSContext */*context*/, void *object ) case FormField::FormChoice: { const FormFieldChoice *choice = static_cast< const FormFieldChoice * >( field ); - Q_UNUSED( choice ); // ### + const QList< int > currentChoices = choice->currentChoices(); + if ( currentChoices.count() == 1 ) + { + return KJSString( choice->exportValueForChoice( choice->choices().at( currentChoices[0] ) ) ); + } break; } case FormField::FormSignature: diff --git a/generators/poppler/CMakeLists.txt b/generators/poppler/CMakeLists.txt index d8b106742..259a7a6f6 100644 --- a/generators/poppler/CMakeLists.txt +++ b/generators/poppler/CMakeLists.txt @@ -94,6 +94,16 @@ int main() } " HAVE_POPPLER_0_80) +check_cxx_source_compiles(" +#include +int main() +{ + Poppler::FormFieldChoice *ffc = nullptr; + ffc->choicesWithExportValues(); + return 0; +} +" HAVE_POPPLER_0_87) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config-okular-poppler.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-okular-poppler.h diff --git a/generators/poppler/config-okular-poppler.h.cmake b/generators/poppler/config-okular-poppler.h.cmake index 2fa86e7e1..022623d37 100644 --- a/generators/poppler/config-okular-poppler.h.cmake +++ b/generators/poppler/config-okular-poppler.h.cmake @@ -21,3 +21,6 @@ /* Defined if we have the 0.80 version of the Poppler library */ #cmakedefine HAVE_POPPLER_0_80 1 + +/* Defined if we have the 0.87 version of the Poppler library */ +#cmakedefine HAVE_POPPLER_0_87 1 diff --git a/generators/poppler/formfields.cpp b/generators/poppler/formfields.cpp index 79bf1ff93..4cada050f 100644 --- a/generators/poppler/formfields.cpp +++ b/generators/poppler/formfields.cpp @@ -320,6 +320,15 @@ PopplerFormFieldChoice::PopplerFormFieldChoice( std::unique_ptrrect() ); m_id = m_field->id(); SET_ACTIONS + +#ifdef HAVE_POPPLER_0_87 + QMap values; + for ( const QPair &value : m_field->choicesWithExportValues() ) + { + values.insert(value.first, value.second); + } + setExportValues( values ); +#endif } Okular::NormalizedRect PopplerFormFieldChoice::rect() const