Commit 3b7bfb2e authored by Oliver Sander's avatar Oliver Sander
Browse files

Use std::unique_ptr for several FormField objects

parent 30e5a492
Pipeline #11406 passed with stage
in 11 minutes and 1 second
/***************************************************************************
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
* Copyright (C) 2018 by Intevation GmbH <intevation@intevation.de> *
* Copyright (C) 2019 by Oliver Sander <oliver.sander@tu-dresden.de> *
* *
* 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 *
......@@ -21,42 +22,37 @@
extern Okular::Action* createLinkFromPopplerLink(const Poppler::Link *popplerLink, bool deletePopplerLink = true);
#ifdef HAVE_POPPLER_0_65
# define SET_ANNOT_ACTIONS \
setAdditionalAction( Okular::Annotation::CursorEntering, createLinkFromPopplerLink( field->additionalAction( Poppler::Annotation::CursorEnteringAction ) ) ); \
setAdditionalAction( Okular::Annotation::CursorLeaving, createLinkFromPopplerLink( field->additionalAction( Poppler::Annotation::CursorLeavingAction ) ) ); \
setAdditionalAction( Okular::Annotation::MousePressed, createLinkFromPopplerLink( field->additionalAction( Poppler::Annotation::MousePressedAction ) ) ); \
setAdditionalAction( Okular::Annotation::MouseReleased, createLinkFromPopplerLink( field->additionalAction( Poppler::Annotation::MouseReleasedAction ) ) ); \
setAdditionalAction( Okular::Annotation::FocusIn, createLinkFromPopplerLink( field->additionalAction( Poppler::Annotation::FocusInAction ) ) ); \
setAdditionalAction( Okular::Annotation::FocusOut, createLinkFromPopplerLink( field->additionalAction( Poppler::Annotation::FocusOutAction ) ) );
setAdditionalAction( Okular::Annotation::CursorEntering, createLinkFromPopplerLink( m_field->additionalAction( Poppler::Annotation::CursorEnteringAction ) ) ); \
setAdditionalAction( Okular::Annotation::CursorLeaving, createLinkFromPopplerLink( m_field->additionalAction( Poppler::Annotation::CursorLeavingAction ) ) ); \
setAdditionalAction( Okular::Annotation::MousePressed, createLinkFromPopplerLink( m_field->additionalAction( Poppler::Annotation::MousePressedAction ) ) ); \
setAdditionalAction( Okular::Annotation::MouseReleased, createLinkFromPopplerLink( m_field->additionalAction( Poppler::Annotation::MouseReleasedAction ) ) ); \
setAdditionalAction( Okular::Annotation::FocusIn, createLinkFromPopplerLink( m_field->additionalAction( Poppler::Annotation::FocusInAction ) ) ); \
setAdditionalAction( Okular::Annotation::FocusOut, createLinkFromPopplerLink( m_field->additionalAction( Poppler::Annotation::FocusOutAction ) ) );
#else
# define SET_ANNOT_ACTIONS
#endif
#ifdef HAVE_POPPLER_0_53
#define SET_ACTIONS \
setActivationAction( createLinkFromPopplerLink( field->activationAction() ) ); \
setAdditionalAction( Okular::FormField::FieldModified, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::FieldModified ) ) ); \
setAdditionalAction( Okular::FormField::FormatField, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::FormatField ) ) ); \
setAdditionalAction( Okular::FormField::ValidateField, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::ValidateField ) ) ); \
setAdditionalAction( Okular::FormField::CalculateField, createLinkFromPopplerLink( field->additionalAction( Poppler::FormField::CalculateField ) ) ); \
setActivationAction( createLinkFromPopplerLink( m_field->activationAction() ) ); \
setAdditionalAction( Okular::FormField::FieldModified, createLinkFromPopplerLink( m_field->additionalAction( Poppler::FormField::FieldModified ) ) ); \
setAdditionalAction( Okular::FormField::FormatField, createLinkFromPopplerLink( m_field->additionalAction( Poppler::FormField::FormatField ) ) ); \
setAdditionalAction( Okular::FormField::ValidateField, createLinkFromPopplerLink( m_field->additionalAction( Poppler::FormField::ValidateField ) ) ); \
setAdditionalAction( Okular::FormField::CalculateField, createLinkFromPopplerLink( m_field->additionalAction( Poppler::FormField::CalculateField ) ) ); \
SET_ANNOT_ACTIONS
#else
#define SET_ACTIONS \
setActivationAction( createLinkFromPopplerLink( field->activationAction() ) );
setActivationAction( createLinkFromPopplerLink( m_field->activationAction() ) );
#endif
PopplerFormFieldButton::PopplerFormFieldButton( Poppler::FormFieldButton * field )
: Okular::FormFieldButton(), m_field( field )
PopplerFormFieldButton::PopplerFormFieldButton( std::unique_ptr<Poppler::FormFieldButton> field )
: Okular::FormFieldButton(), m_field( std::move( field ) )
{
m_rect = Okular::NormalizedRect::fromQRectF( m_field->rect() );
m_id = m_field->id();
SET_ACTIONS
}
PopplerFormFieldButton::~PopplerFormFieldButton()
{
delete m_field;
}
Okular::NormalizedRect PopplerFormFieldButton::rect() const
{
return m_rect;
......@@ -183,19 +179,14 @@ void PopplerFormFieldButton::setIcon( Okular::FormField *field )
}
PopplerFormFieldText::PopplerFormFieldText( Poppler::FormFieldText * field )
: Okular::FormFieldText(), m_field( field )
PopplerFormFieldText::PopplerFormFieldText( std::unique_ptr<Poppler::FormFieldText> field )
: Okular::FormFieldText(), m_field( std::move( field ) )
{
m_rect = Okular::NormalizedRect::fromQRectF( m_field->rect() );
m_id = m_field->id();
SET_ACTIONS
}
PopplerFormFieldText::~PopplerFormFieldText()
{
delete m_field;
}
Okular::NormalizedRect PopplerFormFieldText::rect() const
{
return m_rect;
......@@ -328,19 +319,14 @@ bool PopplerFormFieldText::canBeSpellChecked() const
}
PopplerFormFieldChoice::PopplerFormFieldChoice( Poppler::FormFieldChoice * field )
: Okular::FormFieldChoice(), m_field( field )
PopplerFormFieldChoice::PopplerFormFieldChoice( std::unique_ptr<Poppler::FormFieldChoice> field )
: Okular::FormFieldChoice(), m_field( std::move( field ) )
{
m_rect = Okular::NormalizedRect::fromQRectF( m_field->rect() );
m_id = m_field->id();
SET_ACTIONS
}
PopplerFormFieldChoice::~PopplerFormFieldChoice()
{
delete m_field;
}
Okular::NormalizedRect PopplerFormFieldChoice::rect() const
{
return m_rect;
......@@ -478,8 +464,8 @@ class DummySignatureInfo : public Okular::SignatureInfo
#endif
PopplerFormFieldSignature::PopplerFormFieldSignature( Poppler::FormFieldSignature * field )
: Okular::FormFieldSignature(), m_field( field )
PopplerFormFieldSignature::PopplerFormFieldSignature( std::unique_ptr<Poppler::FormFieldSignature> field )
: Okular::FormFieldSignature(), m_field( std::move( field ) )
{
m_rect = Okular::NormalizedRect::fromQRectF( m_field->rect() );
m_id = m_field->id();
......@@ -493,7 +479,6 @@ PopplerFormFieldSignature::PopplerFormFieldSignature( Poppler::FormFieldSignatur
PopplerFormFieldSignature::~PopplerFormFieldSignature()
{
delete m_field;
delete m_info;
}
......
/***************************************************************************
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
* Copyright (C) 2019 by Oliver Sander <oliver.sander@tu-dresden.de> *
* *
* 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 *
......@@ -17,8 +18,7 @@
class PopplerFormFieldButton : public Okular::FormFieldButton
{
public:
explicit PopplerFormFieldButton( Poppler::FormFieldButton * field );
virtual ~PopplerFormFieldButton();
explicit PopplerFormFieldButton( std::unique_ptr<Poppler::FormFieldButton> field );
// inherited from Okular::FormField
Okular::NormalizedRect rect() const override;
......@@ -50,7 +50,7 @@ class PopplerFormFieldButton : public Okular::FormFieldButton
#endif
private:
Poppler::FormFieldButton * m_field;
std::unique_ptr<Poppler::FormFieldButton> m_field;
Okular::NormalizedRect m_rect;
int m_id;
......@@ -59,8 +59,7 @@ class PopplerFormFieldButton : public Okular::FormFieldButton
class PopplerFormFieldText : public Okular::FormFieldText
{
public:
explicit PopplerFormFieldText( Poppler::FormFieldText * field );
virtual ~PopplerFormFieldText();
explicit PopplerFormFieldText( std::unique_ptr<Poppler::FormFieldText> field );
// inherited from Okular::FormField
Okular::NormalizedRect rect() const override;
......@@ -87,7 +86,7 @@ class PopplerFormFieldText : public Okular::FormFieldText
bool canBeSpellChecked() const override;
private:
Poppler::FormFieldText * m_field;
std::unique_ptr<Poppler::FormFieldText> m_field;
Okular::NormalizedRect m_rect;
int m_id;
......@@ -96,8 +95,7 @@ class PopplerFormFieldText : public Okular::FormFieldText
class PopplerFormFieldChoice : public Okular::FormFieldChoice
{
public:
explicit PopplerFormFieldChoice( Poppler::FormFieldChoice * field );
virtual ~PopplerFormFieldChoice();
explicit PopplerFormFieldChoice( std::unique_ptr<Poppler::FormFieldChoice> field );
// inherited from Okular::FormField
Okular::NormalizedRect rect() const override;
......@@ -125,7 +123,7 @@ class PopplerFormFieldChoice : public Okular::FormFieldChoice
bool canBeSpellChecked() const override;
private:
Poppler::FormFieldChoice * m_field;
std::unique_ptr<Poppler::FormFieldChoice> m_field;
Okular::NormalizedRect m_rect;
int m_id;
......@@ -134,7 +132,7 @@ class PopplerFormFieldChoice : public Okular::FormFieldChoice
class PopplerFormFieldSignature : public Okular::FormFieldSignature
{
public:
PopplerFormFieldSignature( Poppler::FormFieldSignature * field );
PopplerFormFieldSignature( std::unique_ptr<Poppler::FormFieldSignature> field );
virtual ~PopplerFormFieldSignature();
// inherited from Okular::FormField
......@@ -151,7 +149,7 @@ class PopplerFormFieldSignature : public Okular::FormFieldSignature
const Okular::SignatureInfo &signatureInfo() const override;
private:
Poppler::FormFieldSignature * m_field;
std::unique_ptr<Poppler::FormFieldSignature> m_field;
Okular::SignatureInfo *m_info;
Okular::NormalizedRect m_rect;
int m_id;
......
......@@ -5,6 +5,7 @@
* Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group *
* company, info@kdab.com. Work sponsored by the *
* LiMux project of the city of Munich *
* Copyright (C) 2019 by Oliver Sander <oliver.sander@tu-dresden.de> *
* *
* 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 *
......@@ -1971,16 +1972,16 @@ void PDFGenerator::addFormFields( Poppler::Page * popplerPage, Okular::Page * pa
switch ( f->type() )
{
case Poppler::FormField::FormButton:
of = new PopplerFormFieldButton( static_cast<Poppler::FormFieldButton*>( f ) );
of = new PopplerFormFieldButton( std::unique_ptr<Poppler::FormFieldButton>( static_cast<Poppler::FormFieldButton*>( f ) ) );
break;
case Poppler::FormField::FormText:
of = new PopplerFormFieldText( static_cast<Poppler::FormFieldText*>( f ) );
of = new PopplerFormFieldText( std::unique_ptr<Poppler::FormFieldText>( static_cast<Poppler::FormFieldText*>( f ) ) );
break;
case Poppler::FormField::FormChoice:
of = new PopplerFormFieldChoice( static_cast<Poppler::FormFieldChoice*>( f ) );
of = new PopplerFormFieldChoice( std::unique_ptr<Poppler::FormFieldChoice>( static_cast<Poppler::FormFieldChoice*>( f ) ) );
break;
case Poppler::FormField::FormSignature: {
of = new PopplerFormFieldSignature( static_cast<Poppler::FormFieldSignature*>( f ) );
of = new PopplerFormFieldSignature( std::unique_ptr<Poppler::FormFieldSignature>( static_cast<Poppler::FormFieldSignature*>( f ) ) );
break;
}
default: ;
......
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