Commit f69e2114 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Use poppler choicesWithExportValues if available

parent aa683348
......@@ -261,6 +261,8 @@ class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
}
return list.join( QStringLiteral( ";" ) );
}
QMap<QString, QString> exportValues;
};
......@@ -306,6 +308,18 @@ bool FormFieldChoice::canBeSpellChecked() const
return false;
}
void FormFieldChoice::setExportValues( const QMap<QString,QString> &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:
......
......@@ -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<QString,QString> &values );
private:
Q_DECLARE_PRIVATE( FormFieldChoice )
Q_DISABLE_COPY( FormFieldChoice )
......
......@@ -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:
......
......@@ -94,6 +94,16 @@ int main()
}
" HAVE_POPPLER_0_80)
check_cxx_source_compiles("
#include <poppler-form.h>
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
......
......@@ -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
......@@ -320,6 +320,15 @@ PopplerFormFieldChoice::PopplerFormFieldChoice( std::unique_ptr<Poppler::FormFie
m_rect = Okular::NormalizedRect::fromQRectF( m_field->rect() );
m_id = m_field->id();
SET_ACTIONS
#ifdef HAVE_POPPLER_0_87
QMap<QString, QString> values;
for ( const QPair<QString, QString> &value : m_field->choicesWithExportValues() )
{
values.insert(value.first, value.second);
}
setExportValues( values );
#endif
}
Okular::NormalizedRect PopplerFormFieldChoice::rect() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment