From 80ebb46d36e95223fcf985b6d8b603da0aa353fd Mon Sep 17 00:00:00 2001 From: Fabio D'Urso Date: Sun, 2 Jun 2013 15:55:49 +0200 Subject: [PATCH] Don't attempt to restore old TOCModel if it hasn't been actually saved Because if it hasn't been saved (54b4a20e07a4566d34a256039b36505c5b1f64b1) this results in m_model == 0, which makes us crash. --- ui/toc.cpp | 3 +++ ui/tocmodel.cpp | 5 +++++ ui/tocmodel.h | 1 + 3 files changed, 9 insertions(+) diff --git a/ui/toc.cpp b/ui/toc.cpp index 874363594..fec6df2d3 100644 --- a/ui/toc.cpp +++ b/ui/toc.cpp @@ -100,6 +100,9 @@ void TOC::prepareForReload() void TOC::rollbackReload() { + if( !m_model->hasOldModelData() ) + return; + TOCModel *m = m_model; m_model = m->clearOldModelData(); delete m; diff --git a/ui/tocmodel.cpp b/ui/tocmodel.cpp index 4ad6695bb..ce9336621 100644 --- a/ui/tocmodel.cpp +++ b/ui/tocmodel.cpp @@ -370,6 +370,11 @@ void TOCModel::setOldModelData( TOCModel *model, const QVector &lis d->m_oldTocExpandedIndexes = list; } +bool TOCModel::hasOldModelData() const +{ + return (d->m_oldModel != 0); +} + TOCModel *TOCModel::clearOldModelData() const { TOCModel *oldModel = d->m_oldModel; diff --git a/ui/tocmodel.h b/ui/tocmodel.h index a19086d9d..0ef175ce9 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 ); + bool hasOldModelData() const; TOCModel *clearOldModelData() const; QString externalFileNameForIndex( const QModelIndex &index ) const;