Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 57c9cae2 authored by Fabio D'Urso's avatar Fabio D'Urso

Don't save form contents to docdata/

But existing saved form from previous Okular versions are preserved
parent 3b227582
......@@ -1198,12 +1198,13 @@ void DocumentPrivate::saveDocumentInfo() const
// 2.1. Save page attributes (bookmark state, annotations, ... ) to DOM
QDomElement pageList = doc.createElement( "pageList" );
root.appendChild( pageList );
// OriginalAnnotationPageItems tells to store the same unmodified
// annotation list that we read when we opened the file and ignore any
// change made by the user. Since we don't store annotations in
// docdata/ any more, this is necessary to preserve annotations that
// previous Okular version had stored there.
const PageItems saveWhat = AllPageItems | OriginalAnnotationPageItems;
// OriginalAnnotationPageItems and OriginalFormFieldPageItems tell to
// store the same unmodified annotation list and form contents that we
// read when we opened the file and ignore any change made by the user.
// Since we don't store annotations and forms docdata/ any more, this is
// necessary to preserve annotations/forms that previous Okular version
// had stored there.
const PageItems saveWhat = AllPageItems | OriginalAnnotationPageItems | OriginalFormFieldPageItems;
// <page list><page number='x'>.... </page> save pages that hold data
QVector< Page * >::const_iterator pIt = m_pagesVector.constBegin(), pEnd = m_pagesVector.constEnd();
for ( ; pIt != pEnd; ++pIt )
......@@ -2921,6 +2922,16 @@ void DocumentPrivate::notifyAnnotationChanges( int page )
foreachObserverD( notifyPageChanged( page, flags ) );
}
void DocumentPrivate::notifyFormChanges( int page )
{
// Unless we're still loading initial form contents from metadata, the user
// now needs to save or form changes will be lost
if ( !m_metadataLoadingCompleted )
return;
foreachObserverD( notifyPageChanged( page, DocumentObserver::NeedSaveAs ) );
}
void Document::addPageAnnotation( int page, Annotation * annotation )
{
// Transform annotation's base boundary rectangle into unrotated coordinates
......
......@@ -133,6 +133,7 @@ class DocumentPrivate
bool savePageDocumentInfo( KTemporaryFile *infoFile, int what ) const;
DocumentViewport nextDocumentViewport() const;
void notifyAnnotationChanges( int page );
void notifyFormChanges( int page );
bool canAddAnnotationsNatively() const;
bool canModifyExternalAnnotations() const;
bool canRemoveExternalAnnotations() const;
......
......@@ -368,6 +368,7 @@ void EditFormTextCommand::undo()
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
m_form->setText( m_prevContents );
emit m_docPriv->m_parent->formTextChangedByUndoRedo( m_pageNumber, m_form, m_prevContents, m_prevCursorPos, m_prevAnchorPos );
m_docPriv->notifyFormChanges( m_pageNumber );
}
void EditFormTextCommand::redo()
......@@ -375,6 +376,7 @@ void EditFormTextCommand::redo()
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
m_form->setText( m_newContents );
emit m_docPriv->m_parent->formTextChangedByUndoRedo( m_pageNumber, m_form, m_newContents, m_newCursorPos, m_newCursorPos );
m_docPriv->notifyFormChanges( m_pageNumber );
}
int EditFormTextCommand::id() const
......@@ -415,6 +417,7 @@ void EditFormListCommand::undo()
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
m_form->setCurrentChoices( m_prevChoices );
emit m_docPriv->m_parent->formListChangedByUndoRedo( m_pageNumber, m_form, m_prevChoices );
m_docPriv->notifyFormChanges( m_pageNumber );
}
void EditFormListCommand::redo()
......@@ -422,6 +425,7 @@ void EditFormListCommand::redo()
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
m_form->setCurrentChoices( m_newChoices );
emit m_docPriv->m_parent->formListChangedByUndoRedo( m_pageNumber, m_form, m_newChoices );
m_docPriv->notifyFormChanges( m_pageNumber );
}
EditFormComboCommand::EditFormComboCommand( Okular::DocumentPrivate* docPriv,
......@@ -468,6 +472,7 @@ void EditFormComboCommand::undo()
}
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
emit m_docPriv->m_parent->formComboChangedByUndoRedo( m_pageNumber, m_form, m_prevContents, m_prevCursorPos, m_prevAnchorPos );
m_docPriv->notifyFormChanges( m_pageNumber );
}
void EditFormComboCommand::redo()
......@@ -482,6 +487,7 @@ void EditFormComboCommand::redo()
}
moveViewportIfBoundingRectNotFullyVisible( m_form->rect(), m_docPriv, m_pageNumber );
emit m_docPriv->m_parent->formComboChangedByUndoRedo( m_pageNumber, m_form, m_newContents, m_newCursorPos, m_newCursorPos );
m_docPriv->notifyFormChanges( m_pageNumber );
}
int EditFormComboCommand::id() const
......@@ -538,6 +544,7 @@ void EditFormButtonsCommand::undo()
Okular::NormalizedRect boundingRect = buildBoundingRectangleForButtons( m_formButtons );
moveViewportIfBoundingRectNotFullyVisible( boundingRect, m_docPriv, m_pageNumber );
emit m_docPriv->m_parent->formButtonsChangedByUndoRedo( m_pageNumber, m_formButtons );
m_docPriv->notifyFormChanges( m_pageNumber );
}
void EditFormButtonsCommand::redo()
......@@ -553,6 +560,7 @@ void EditFormButtonsCommand::redo()
Okular::NormalizedRect boundingRect = buildBoundingRectangleForButtons( m_formButtons );
moveViewportIfBoundingRectNotFullyVisible( boundingRect, m_docPriv, m_pageNumber );
emit m_docPriv->m_parent->formButtonsChangedByUndoRedo( m_pageNumber, m_formButtons );
m_docPriv->notifyFormChanges( m_pageNumber );
}
void EditFormButtonsCommand::clearFormButtonStates()
......
......@@ -45,7 +45,7 @@ class OKULAR_EXPORT DocumentObserver
TextSelection = 8, ///< Text selection has been changed
Annotations = 16, ///< Annotations have been changed
BoundingBox = 32, ///< Bounding boxes have been changed
NeedSaveAs = 64 ///< Set along with Annotations when Save As is needed or annotation changes will be lost @since 0.15 (KDE 4.9)
NeedSaveAs = 64 ///< Set when "Save" is needed or annotation/form changes will be lost @since 0.15 (KDE 4.9)
};
/**
......
......@@ -832,6 +832,10 @@ void PagePrivate::restoreLocalContents( const QDomNode & pageNode )
// parse formList child element
else if ( childElement.tagName() == "forms" )
{
// Clone forms as root node in restoredFormFieldList
const QDomNode clonedNode = restoredFormFieldList.importNode( childElement, true );
restoredFormFieldList.appendChild( clonedNode );
if ( formfields.isEmpty() )
continue;
......@@ -927,7 +931,17 @@ void PagePrivate::saveLocalContents( QDomNode & parentNode, QDomDocument & docum
}
// add forms info if has got any
if ( ( what & FormFieldPageItems ) && !formfields.isEmpty() )
if ( ( what & FormFieldPageItems ) && ( what & OriginalFormFieldPageItems ) )
{
const QDomElement savedDocRoot = restoredFormFieldList.documentElement();
if ( !savedDocRoot.isNull() )
{
// Import and append node in target document
const QDomNode importedNode = document.importNode( savedDocRoot, true );
pageElement.appendChild( importedNode );
}
}
else if ( ( what & FormFieldPageItems ) && !formfields.isEmpty() )
{
// create the formList
QDomElement formListElement = document.createElement( "forms" );
......
......@@ -48,7 +48,11 @@ enum PageItem
/* If set along with AnnotationPageItems, tells saveLocalContents to save
* the original annotations (if any) instead of the modified ones */
OriginalAnnotationPageItems = 0x100
OriginalAnnotationPageItems = 0x100,
/* If set along with FormFieldPageItems, tells saveLocalContents to save
* the original form contents (if any) instead of the modified one */
OriginalFormFieldPageItems = 0x200
};
Q_DECLARE_FLAGS(PageItems, PageItem)
......@@ -142,6 +146,7 @@ class PagePrivate
bool m_isBoundingBoxKnown : 1;
QDomDocument restoredLocalAnnotationList; // <annotationList>...</annotationList>
QDomDocument restoredFormFieldList; // <forms>...</forms>
};
}
......
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