Fix my fixes for 313147 and 313146

It actually fixed them but make the toc reload keeping not work anymore :D
This commit is contained in:
Albert Astals Cid 2013-01-18 18:02:07 +01:00
parent a4a7d5039d
commit f40b42f8db
5 changed files with 44 additions and 9 deletions

View file

@ -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...") );

View file

@ -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<QModelIndex>() );
}
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 );
}

View file

@ -39,6 +39,8 @@ Q_OBJECT
void reparseConfig();
void prepareForReload();
void rollbackReload();
void finishReload();
signals:
void hasTOC(bool has);

View file

@ -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<QModelIndex> &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() )

View file

@ -45,6 +45,7 @@ class TOCModel : public QAbstractItemModel
bool isEmpty() const;
bool equals( const TOCModel *model ) const;
void setOldModelData( TOCModel *model, const QVector<QModelIndex> &list );
TOCModel *clearOldModelData() const;
QString externalFileNameForIndex( const QModelIndex &index ) const;
Okular::DocumentViewport viewportForIndex( const QModelIndex &index ) const;