Commit f31eb3cb authored by Joao Oliveira's avatar Joao Oliveira Committed by Joao Oliveira

Created private functions to avoid duplicated code in Document

parent 17814fc3
Pipeline #6953 passed with stage
in 12 minutes and 31 seconds
...@@ -2212,6 +2212,36 @@ void DocumentPrivate::clearAndWaitForRequests() ...@@ -2212,6 +2212,36 @@ void DocumentPrivate::clearAndWaitForRequests()
while ( startEventLoop ); while ( startEventLoop );
} }
int DocumentPrivate::findFieldPageNumber( Okular::FormField *field )
{
// Lookup the page of the FormField
int foundPage = -1;
for ( uint pageIdx = 0, nPages = m_parent->pages(); pageIdx < nPages; pageIdx++ )
{
const Page *p = m_parent->page( pageIdx );
if ( p && p->formFields().contains( field ) )
{
foundPage = static_cast< int >( pageIdx );
break;
}
}
return foundPage;
}
void DocumentPrivate::executeScriptEvent( std::shared_ptr< Event > event, const Okular::ScriptAction * linkscript )
{
if ( !m_scripter )
{
m_scripter = new Scripter( this );
}
m_scripter->setEvent( event.get() );
m_scripter->execute( linkscript->scriptType(), linkscript->script() );
// Clear out the event after execution
m_scripter->setEvent( nullptr );
}
Document::Document( QWidget *widget ) Document::Document( QWidget *widget )
: QObject( nullptr ), d( new DocumentPrivate( this ) ) : QObject( nullptr ), d( new DocumentPrivate( this ) )
{ {
...@@ -4309,16 +4339,7 @@ void Document::processFormatAction( const Action * action, Okular::FormFieldText ...@@ -4309,16 +4339,7 @@ void Document::processFormatAction( const Action * action, Okular::FormFieldText
} }
// Lookup the page of the FormFieldText // Lookup the page of the FormFieldText
int foundPage = -1; int foundPage = d->findFieldPageNumber( fft );
for ( uint pageIdx = 0, nPages = pages(); pageIdx < nPages; pageIdx++ )
{
const Page *p = page( pageIdx );
if ( p && p->formFields().contains( fft ) )
{
foundPage = static_cast< int >( pageIdx );
break;
}
}
if ( foundPage == -1 ) if ( foundPage == -1 )
{ {
...@@ -4331,15 +4352,8 @@ void Document::processFormatAction( const Action * action, Okular::FormFieldText ...@@ -4331,15 +4352,8 @@ void Document::processFormatAction( const Action * action, Okular::FormFieldText
std::shared_ptr< Event > event = Event::createFormatEvent( fft, d->m_pagesVector[foundPage] ); std::shared_ptr< Event > event = Event::createFormatEvent( fft, d->m_pagesVector[foundPage] );
const ScriptAction * linkscript = static_cast< const ScriptAction * >( action ); const ScriptAction * linkscript = static_cast< const ScriptAction * >( action );
if ( !d->m_scripter )
{
d->m_scripter = new Scripter( d );
}
d->m_scripter->setEvent( event.get() );
d->m_scripter->execute( linkscript->scriptType(), linkscript->script() );
// Clear out the event after execution d->executeScriptEvent( event, linkscript );
d->m_scripter->setEvent( nullptr );
const QString formattedText = event->value().toString(); const QString formattedText = event->value().toString();
if ( formattedText != unformattedText ) if ( formattedText != unformattedText )
...@@ -4373,16 +4387,7 @@ void Document::processKeystrokeAction( const Action * action, Okular::FormFieldT ...@@ -4373,16 +4387,7 @@ void Document::processKeystrokeAction( const Action * action, Okular::FormFieldT
return; return;
} }
// Lookup the page of the FormFieldText // Lookup the page of the FormFieldText
int foundPage = -1; int foundPage = d->findFieldPageNumber( fft );
for ( uint pageIdx = 0, nPages = pages(); pageIdx < nPages; pageIdx++ )
{
const Page *p = page( pageIdx );
if ( p && p->formFields().contains( fft ) )
{
foundPage = static_cast< int >( pageIdx );
break;
}
}
if ( foundPage == -1 ) if ( foundPage == -1 )
{ {
...@@ -4393,15 +4398,9 @@ void Document::processKeystrokeAction( const Action * action, Okular::FormFieldT ...@@ -4393,15 +4398,9 @@ void Document::processKeystrokeAction( const Action * action, Okular::FormFieldT
std::shared_ptr< Event > event = Event::createKeystrokeEvent( fft, d->m_pagesVector[foundPage] ); std::shared_ptr< Event > event = Event::createKeystrokeEvent( fft, d->m_pagesVector[foundPage] );
const ScriptAction * linkscript = static_cast< const ScriptAction * >( action ); const ScriptAction * linkscript = static_cast< const ScriptAction * >( action );
if ( !d->m_scripter )
{
d->m_scripter = new Scripter( d );
}
d->m_scripter->setEvent( event.get() );
d->m_scripter->execute( linkscript->scriptType(), linkscript->script() );
// Clear out the event after execution d->executeScriptEvent( event, linkscript );
d->m_scripter->setEvent( nullptr );
returnCode = event->returnCode(); returnCode = event->returnCode();
} }
...@@ -4410,17 +4409,8 @@ void Document::processFocusAction( const Action * action, Okular::FormField *fie ...@@ -4410,17 +4409,8 @@ void Document::processFocusAction( const Action * action, Okular::FormField *fie
if ( !action || action->actionType() != Action::Script ) if ( !action || action->actionType() != Action::Script )
return; return;
// Lookup the page of the FormField // Lookup the page of the FormFieldText
int foundPage = -1; int foundPage = d->findFieldPageNumber( field );
for ( uint pageIdx = 0, nPages = pages(); pageIdx < nPages; pageIdx++ )
{
const Page *p = page( pageIdx );
if ( p && p->formFields().contains( field ) )
{
foundPage = static_cast< int >( pageIdx );
break;
}
}
if ( foundPage == -1 ) if ( foundPage == -1 )
{ {
...@@ -4431,15 +4421,8 @@ void Document::processFocusAction( const Action * action, Okular::FormField *fie ...@@ -4431,15 +4421,8 @@ void Document::processFocusAction( const Action * action, Okular::FormField *fie
std::shared_ptr< Event > event = Event::createFormFocusEvent( field, d->m_pagesVector[foundPage] ); std::shared_ptr< Event > event = Event::createFormFocusEvent( field, d->m_pagesVector[foundPage] );
const ScriptAction * linkscript = static_cast< const ScriptAction * >( action ); const ScriptAction * linkscript = static_cast< const ScriptAction * >( action );
if ( !d->m_scripter )
{
d->m_scripter = new Scripter( d );
}
d->m_scripter->setEvent( event.get() );
d->m_scripter->execute( linkscript->scriptType(), linkscript->script() );
// Clear out the event after execution d->executeScriptEvent( event, linkscript );
d->m_scripter->setEvent( nullptr );
} }
void Document::processValidateAction( const Action * action, Okular::FormFieldText *fft, bool &returnCode ) void Document::processValidateAction( const Action * action, Okular::FormFieldText *fft, bool &returnCode )
...@@ -4448,16 +4431,7 @@ void Document::processValidateAction( const Action * action, Okular::FormFieldTe ...@@ -4448,16 +4431,7 @@ void Document::processValidateAction( const Action * action, Okular::FormFieldTe
return; return;
// Lookup the page of the FormFieldText // Lookup the page of the FormFieldText
int foundPage = -1; int foundPage = d->findFieldPageNumber( fft );
for ( uint pageIdx = 0, nPages = pages(); pageIdx < nPages; pageIdx++ )
{
const Page *p = page( pageIdx );
if ( p && p->formFields().contains( fft ) )
{
foundPage = static_cast< int >( pageIdx );
break;
}
}
if ( foundPage == -1 ) if ( foundPage == -1 )
{ {
...@@ -4468,15 +4442,8 @@ void Document::processValidateAction( const Action * action, Okular::FormFieldTe ...@@ -4468,15 +4442,8 @@ void Document::processValidateAction( const Action * action, Okular::FormFieldTe
std::shared_ptr< Event > event = Event::createFormValidateEvent( fft, d->m_pagesVector[foundPage] ); std::shared_ptr< Event > event = Event::createFormValidateEvent( fft, d->m_pagesVector[foundPage] );
const ScriptAction * linkscript = static_cast< const ScriptAction * >( action ); const ScriptAction * linkscript = static_cast< const ScriptAction * >( action );
if ( !d->m_scripter )
{
d->m_scripter = new Scripter( d );
}
d->m_scripter->setEvent( event.get() );
d->m_scripter->execute( linkscript->scriptType(), linkscript->script() );
// Clear out the event after execution d->executeScriptEvent( event, linkscript );
d->m_scripter->setEvent( nullptr );
returnCode = event->returnCode(); returnCode = event->returnCode();
} }
......
...@@ -12,8 +12,10 @@ ...@@ -12,8 +12,10 @@
#define _OKULAR_DOCUMENT_P_H_ #define _OKULAR_DOCUMENT_P_H_
#include "document.h" #include "document.h"
#include "script/event_p.h"
#include "synctex/synctex_parser.h" #include "synctex/synctex_parser.h"
#include <memory>
// qt/kde/system includes // qt/kde/system includes
#include <QHash> #include <QHash>
...@@ -41,6 +43,7 @@ struct ArchiveData; ...@@ -41,6 +43,7 @@ struct ArchiveData;
struct RunningSearch; struct RunningSearch;
namespace Okular { namespace Okular {
class ScriptAction;
class ConfigInterface; class ConfigInterface;
class PageController; class PageController;
class SaveInterface; class SaveInterface;
...@@ -227,6 +230,17 @@ class DocumentPrivate ...@@ -227,6 +230,17 @@ class DocumentPrivate
void clearAndWaitForRequests(); void clearAndWaitForRequests();
/*
* Executes a ScriptAction with the event passed as parameter.
*/
void executeScriptEvent( std::shared_ptr< Event > event, const Okular::ScriptAction * linkscript );
/*
* Find the corresponding page number for the form field passed as parameter.
*/
int findFieldPageNumber( Okular::FormField *field );
// member variables // member variables
Document *m_parent; Document *m_parent;
QPointer<QWidget> m_widget; QPointer<QWidget> m_widget;
......
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