Use poppler choicesWithExportValues if available

remotes/origin/work/aacid/use_mimes_open_dialog
Albert Astals Cid 6 years ago
parent aa6833483e
commit f69e2114e7
  1. 14
      core/form.cpp
  2. 16
      core/form.h
  3. 6
      core/script/kjs_field.cpp
  4. 10
      generators/poppler/CMakeLists.txt
  5. 3
      generators/poppler/config-okular-poppler.h.cmake
  6. 9
      generators/poppler/formfields.cpp

@ -261,6 +261,8 @@ class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
} }
return list.join( QStringLiteral( ";" ) ); return list.join( QStringLiteral( ";" ) );
} }
QMap<QString, QString> exportValues;
}; };
@ -306,6 +308,18 @@ bool FormFieldChoice::canBeSpellChecked() const
return false; 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 class Okular::FormFieldSignaturePrivate : public Okular::FormFieldPrivate
{ {
public: public:

@ -419,9 +419,25 @@ class OKULARCORE_EXPORT FormFieldChoice : public FormField
*/ */
virtual bool canBeSpellChecked() const; virtual bool canBeSpellChecked() const;
/**
* Returns the export value for a given choice
*
* @since 1.11
*/
QString exportValueForChoice( const QString &choice ) const;
protected: protected:
FormFieldChoice(); 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: private:
Q_DECLARE_PRIVATE( FormFieldChoice ) Q_DECLARE_PRIVATE( FormFieldChoice )
Q_DISABLE_COPY( FormFieldChoice ) Q_DISABLE_COPY( FormFieldChoice )

@ -155,7 +155,11 @@ static KJSObject fieldGetValue( KJSContext */*context*/, void *object )
case FormField::FormChoice: case FormField::FormChoice:
{ {
const FormFieldChoice *choice = static_cast< const FormFieldChoice * >( field ); 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; break;
} }
case FormField::FormSignature: case FormField::FormSignature:

@ -94,6 +94,16 @@ int main()
} }
" HAVE_POPPLER_0_80) " 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( configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config-okular-poppler.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config-okular-poppler.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config-okular-poppler.h ${CMAKE_CURRENT_BINARY_DIR}/config-okular-poppler.h

@ -21,3 +21,6 @@
/* Defined if we have the 0.80 version of the Poppler library */ /* Defined if we have the 0.80 version of the Poppler library */
#cmakedefine HAVE_POPPLER_0_80 1 #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_rect = Okular::NormalizedRect::fromQRectF( m_field->rect() );
m_id = m_field->id(); m_id = m_field->id();
SET_ACTIONS 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 Okular::NormalizedRect PopplerFormFieldChoice::rect() const

Loading…
Cancel
Save