From f40b42f8db068d304ef630e17f0b505980699778 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 18 Jan 2013 18:02:07 +0100 Subject: [PATCH] Fix my fixes for 313147 and 313146 It actually fixed them but make the toc reload keeping not work anymore :D --- part.cpp | 15 +++++++++++---- ui/toc.cpp | 21 +++++++++++++++++++++ ui/toc.h | 2 ++ ui/tocmodel.cpp | 14 +++++++++----- ui/tocmodel.h | 1 + 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/part.cpp b/part.cpp index 9c4baa8ea..f1cdc11b1 100644 --- a/part.cpp +++ b/part.cpp @@ -1545,7 +1545,7 @@ void Part::slotFileDirty( const QString& path ) void Part::slotDoFileDirty() { - bool prepareTocForReload = false; + bool tocReloadPrepared = false; // do the following the first time the file is reloaded if ( m_viewportDirty.pageNumber == -1 ) @@ -1565,7 +1565,8 @@ void Part::slotDoFileDirty() m_wasPresentationOpen = ((PresentationWidget*)m_presentationWidget != 0); // preserves the toc state after reload - prepareTocForReload = true; + m_toc->prepareForReload(); + tocReloadPrepared = true; // store the page rotation m_dirtyPageRotation = m_document->rotation(); @@ -1577,10 +1578,16 @@ void Part::slotDoFileDirty() // close and (try to) reopen the document if ( !closeUrl() ) + { + if ( tocReloadPrepared ) + { + m_toc->rollbackReload(); + } return; + } - if ( prepareTocForReload ) - m_toc->prepareForReload(); + if ( tocReloadPrepared ) + m_toc->finishReload(); // inform the user about the operation in progress m_pageView->displayMessage( i18n("Reloading the document...") ); diff --git a/ui/toc.cpp b/ui/toc.cpp index bfb0c5a48..bde7c9716 100644 --- a/ui/toc.cpp +++ b/ui/toc.cpp @@ -72,6 +72,16 @@ void TOC::notifySetup( const QVector< Okular::Page * > & /*pages*/, int setupFla // request synopsis description (is a dom tree) const Okular::DocumentSynopsis * syn = m_document->documentSynopsis(); + if ( !syn ) + { + if ( m_document->isOpened() ) + { + // Make sure we clear the reload old model data + m_model->setOldModelData( 0, QVector() ); + } + emit hasTOC( false ); + return; + } m_model->fill( syn ); emit hasTOC( !m_model->isEmpty() ); @@ -91,6 +101,17 @@ void TOC::prepareForReload() TOCModel *m = m_model; m_model = new TOCModel( m_document, m_treeView ); m_model->setOldModelData( m, list ); +} + +void TOC::rollbackReload() +{ + TOCModel *m = m_model; + m_model = m->clearOldModelData(); + delete m; +} + +void TOC::finishReload() +{ m_treeView->setModel( m_model ); } diff --git a/ui/toc.h b/ui/toc.h index 595c8c80f..d89889632 100644 --- a/ui/toc.h +++ b/ui/toc.h @@ -39,6 +39,8 @@ Q_OBJECT void reparseConfig(); void prepareForReload(); + void rollbackReload(); + void finishReload(); signals: void hasTOC(bool has); diff --git a/ui/tocmodel.cpp b/ui/tocmodel.cpp index 2fc9a205b..4ad6695bb 100644 --- a/ui/tocmodel.cpp +++ b/ui/tocmodel.cpp @@ -266,12 +266,8 @@ static QModelIndex indexForIndex( const QModelIndex &oldModelIndex, QAbstractIte void TOCModel::fill( const Okular::DocumentSynopsis *toc ) { - if ( !toc ) { - delete d->m_oldModel; - d->m_oldModel = 0; - d->m_oldTocExpandedIndexes.clear(); + if ( !toc ) return; - } clear(); emit layoutAboutToBeChanged(); @@ -374,6 +370,14 @@ void TOCModel::setOldModelData( TOCModel *model, const QVector &lis d->m_oldTocExpandedIndexes = list; } +TOCModel *TOCModel::clearOldModelData() const +{ + TOCModel *oldModel = d->m_oldModel; + d->m_oldModel = 0; + d->m_oldTocExpandedIndexes.clear(); + return oldModel; +} + QString TOCModel::externalFileNameForIndex( const QModelIndex &index ) const { if ( !index.isValid() ) diff --git a/ui/tocmodel.h b/ui/tocmodel.h index 42d653321..a19086d9d 100644 --- a/ui/tocmodel.h +++ b/ui/tocmodel.h @@ -45,6 +45,7 @@ class TOCModel : public QAbstractItemModel bool isEmpty() const; bool equals( const TOCModel *model ) const; void setOldModelData( TOCModel *model, const QVector &list ); + TOCModel *clearOldModelData() const; QString externalFileNameForIndex( const QModelIndex &index ) const; Okular::DocumentViewport viewportForIndex( const QModelIndex &index ) const;