summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <[email protected]>2017-11-14 09:57:38 +0100
committerAlbert Astals Cid <[email protected]>2017-11-14 09:57:38 +0100
commit8e80a4f57048ef095229a87b669ce84b56f9f995 (patch)
tree5347b677beeb2000e6ff11c94c3bb8b1f832f309
parent302c38672f3e50130adf583288c13ad5401e3472 (diff)
Account for Okular::PagePrivate::findEquivalentForm failing
It should never fail but it's better if we have the backup for not crashing at least if it does
-rw-r--r--core/document.cpp13
-rw-r--r--core/documentcommands.cpp42
-rw-r--r--core/documentcommands_p.h22
3 files changed, 54 insertions, 23 deletions
diff --git a/core/document.cpp b/core/document.cpp
index 3517f01..c3ccf7f 100644
--- a/core/document.cpp
+++ b/core/document.cpp
@@ -4385,10 +4385,19 @@ bool Document::swapBackingFile( const QString &newFileName, const QUrl &url )
{
// Trust me on the const_cast ^_^
QUndoCommand *uc = const_cast<QUndoCommand *>( d->m_undoStack->command( i ) );
- if (OkularUndoCommand *ouc = dynamic_cast<OkularUndoCommand*>( uc )) ouc->refreshInternalPageReferences( newPagesVector );
+ if (OkularUndoCommand *ouc = dynamic_cast<OkularUndoCommand*>( uc ))
+ {
+ const bool success = ouc->refreshInternalPageReferences( newPagesVector );
+ if ( !success )
+ {
+ qWarning() << "Document::swapBackingFile: refreshInternalPageReferences failed" << ouc;
+ return false;
+ }
+ }
else
{
- qWarning() << "Unhandled undo command" << uc;
+ qWarning() << "Document::swapBackingFile: Unhandled undo command" << uc;
+ return false;
}
}
diff --git a/core/documentcommands.cpp b/core/documentcommands.cpp
index 4f9c5e8..58804a7 100644
--- a/core/documentcommands.cpp
+++ b/core/documentcommands.cpp
@@ -88,7 +88,7 @@ void AddAnnotationCommand::redo()
m_done = true;
}
-void AddAnnotationCommand::refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector )
+bool AddAnnotationCommand::refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector )
{
if ( m_done )
{
@@ -99,6 +99,8 @@ void AddAnnotationCommand::refreshInternalPageReferences( const QVector< Okular:
auto a = newPagesVector[m_pageNumber]->annotation( m_annotation->uniqueName() );
if (a) m_annotation = a;
}
+
+ return true;
}
@@ -133,7 +135,7 @@ void RemoveAnnotationCommand::redo()
m_done = true;
}
-void RemoveAnnotationCommand::refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector )
+bool RemoveAnnotationCommand::refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector )
{
if ( !m_done )
{
@@ -144,6 +146,8 @@ void RemoveAnnotationCommand::refreshInternalPageReferences( const QVector< Okul
auto a = newPagesVector[m_pageNumber]->annotation( m_annotation->uniqueName() );
if (a) m_annotation = a;
}
+
+ return true;
}
ModifyAnnotationPropertiesCommand::ModifyAnnotationPropertiesCommand( DocumentPrivate* docPriv,
@@ -174,11 +178,13 @@ void ModifyAnnotationPropertiesCommand::redo()
m_docPriv->performModifyPageAnnotation( m_pageNumber, m_annotation, true );
}
-void ModifyAnnotationPropertiesCommand::refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector )
+bool ModifyAnnotationPropertiesCommand::refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector )
{
// Same reason for not unconditionally updating m_annotation, the annotation pointer can be stored in an add/Remove command
auto a = newPagesVector[m_pageNumber]->annotation( m_annotation->uniqueName() );
if (a) m_annotation = a;
+
+ return true;
}
@@ -247,11 +253,13 @@ Okular::NormalizedRect TranslateAnnotationCommand::translateBoundingRectangle( c
return boundingRect;
}
-void TranslateAnnotationCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
+bool TranslateAnnotationCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
{
// Same reason for not unconditionally updating m_annotation, the annotation pointer can be stored in an add/Remove command
auto a = newPagesVector[m_pageNumber]->annotation( m_annotation->uniqueName() );
if (a) m_annotation = a;
+
+ return true;
}
@@ -320,11 +328,13 @@ Okular::NormalizedRect AdjustAnnotationCommand::adjustBoundingRectangle(
return Okular::NormalizedRect( left, top, right, bottom );
}
-void AdjustAnnotationCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
+bool AdjustAnnotationCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
{
// Same reason for not unconditionally updating m_annotation, the annotation pointer can be stored in an add/Remove command
auto a = newPagesVector[m_pageNumber]->annotation( m_annotation->uniqueName() );
if (a) m_annotation = a;
+
+ return true;
}
@@ -464,10 +474,12 @@ bool EditAnnotationContentsCommand::mergeWith(const QUndoCommand* uc)
}
}
-void EditAnnotationContentsCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
+bool EditAnnotationContentsCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
{
auto a = newPagesVector[m_pageNumber]->annotation( m_annotation->uniqueName() );
if (a) m_annotation = a;
+
+ return true;
}
@@ -522,9 +534,11 @@ bool EditFormTextCommand::mergeWith(const QUndoCommand* uc)
}
}
-void EditFormTextCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
+bool EditFormTextCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
{
m_form = dynamic_cast<FormFieldText *>(Okular::PagePrivate::findEquivalentForm( newPagesVector[m_pageNumber], m_form ));
+
+ return m_form;
}
@@ -558,9 +572,11 @@ void EditFormListCommand::redo()
m_docPriv->notifyFormChanges( m_pageNumber );
}
-void EditFormListCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
+bool EditFormListCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
{
m_form = dynamic_cast<FormFieldChoice *>(Okular::PagePrivate::findEquivalentForm( newPagesVector[m_pageNumber], m_form ));
+
+ return m_form;
}
@@ -650,9 +666,11 @@ bool EditFormComboCommand::mergeWith( const QUndoCommand *uc )
}
}
-void EditFormComboCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
+bool EditFormComboCommand::refreshInternalPageReferences( const QVector< Page * > &newPagesVector )
{
m_form = dynamic_cast<FormFieldChoice *>(Okular::PagePrivate::findEquivalentForm( newPagesVector[m_pageNumber], m_form ));
+
+ return m_form;
}
@@ -705,15 +723,19 @@ void EditFormButtonsCommand::redo()
m_docPriv->notifyFormChanges( m_pageNumber );
}
-void EditFormButtonsCommand::refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector )
+bool EditFormButtonsCommand::refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector )
{
const QList< FormFieldButton* > oldFormButtons = m_formButtons;
m_formButtons.clear();
foreach( FormFieldButton* oldFormButton, oldFormButtons )
{
FormFieldButton *button = dynamic_cast<FormFieldButton *>(Okular::PagePrivate::findEquivalentForm( newPagesVector[m_pageNumber], oldFormButton ));
+ if ( !button )
+ return false;
m_formButtons << button;
}
+
+ return true;
}
void EditFormButtonsCommand::clearFormButtonStates()
diff --git a/core/documentcommands_p.h b/core/documentcommands_p.h
index 44b7c19..055d35c 100644
--- a/core/documentcommands_p.h
+++ b/core/documentcommands_p.h
@@ -28,7 +28,7 @@ class Page;
class OkularUndoCommand : public QUndoCommand
{
public:
- virtual void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) = 0;
+ virtual bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) = 0;
};
class AddAnnotationCommand : public OkularUndoCommand
@@ -42,7 +42,7 @@ class AddAnnotationCommand : public OkularUndoCommand
void redo() override;
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate * m_docPriv;
@@ -59,7 +59,7 @@ class RemoveAnnotationCommand : public OkularUndoCommand
void undo() override;
void redo() override;
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate * m_docPriv;
@@ -79,7 +79,7 @@ class ModifyAnnotationPropertiesCommand : public OkularUndoCommand
void undo() override;
void redo() override;
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate * m_docPriv;
@@ -105,7 +105,7 @@ class TranslateAnnotationCommand : public OkularUndoCommand
Okular::NormalizedPoint minusDelta();
Okular::NormalizedRect translateBoundingRectangle( const Okular::NormalizedPoint & delta );
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate * m_docPriv;
@@ -132,7 +132,7 @@ class AdjustAnnotationCommand : public OkularUndoCommand
Okular::NormalizedRect adjustBoundingRectangle(
const Okular::NormalizedPoint & delta1, const Okular::NormalizedPoint & delta2 );
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate * m_docPriv;
@@ -199,7 +199,7 @@ class EditAnnotationContentsCommand : public EditTextCommand
int id() const override;
bool mergeWith(const QUndoCommand *uc) override;
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate * m_docPriv;
@@ -223,7 +223,7 @@ class EditFormTextCommand : public EditTextCommand
int id() const override;
bool mergeWith( const QUndoCommand *uc ) override;
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate* m_docPriv;
@@ -244,7 +244,7 @@ class EditFormListCommand : public OkularUndoCommand
void undo() override;
void redo() override;
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate* m_docPriv;
@@ -272,7 +272,7 @@ class EditFormComboCommand : public EditTextCommand
int id() const override;
bool mergeWith( const QUndoCommand *uc ) override;
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
Okular::DocumentPrivate* m_docPriv;
@@ -294,7 +294,7 @@ class EditFormButtonsCommand : public OkularUndoCommand
void undo() override;
void redo() override;
- void refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
+ bool refreshInternalPageReferences( const QVector< Okular::Page * > &newPagesVector ) override;
private:
void clearFormButtonStates();