From 9c57cca93c5a0307665fca4c4b6a207b7d19e15c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 22 Mar 2011 20:12:06 +0000 Subject: [PATCH] Fix possible crash when changing the priority of a file --- src/torrentfilesmodel.h | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/torrentfilesmodel.h b/src/torrentfilesmodel.h index 3be7a1fb0..ff184da7d 100644 --- a/src/torrentfilesmodel.h +++ b/src/torrentfilesmodel.h @@ -357,7 +357,7 @@ public: Q_ASSERT(fp[i] >= 0); files_index[i]->setProgress(fp[i]); } - emit layoutChanged(); + emit dataChanged(index(0,0), index(rowCount(), columnCount())); } void updateFilesPriorities(std::vector fprio) { @@ -366,7 +366,7 @@ public: //qDebug("Called updateFilesPriorities with %d", fprio[i]); files_index[i]->setPriority(fprio[i]); } - emit layoutChanged(); + emit dataChanged(index(0,0), index(rowCount(), columnCount())); } std::vector getFilesPriorities(unsigned int nbFiles) const { @@ -405,8 +405,8 @@ public: item->setPriority(prio::IGNORED); else item->setPriority(prio::NORMAL); + emit dataChanged(this->index(0,0), this->index(rowCount(), columnCount())); emit filteredFilesChanged(); - emit dataChanged(this->index(0,0), this->index(rowCount(), 0)); } return true; } @@ -536,14 +536,13 @@ public: void clear() { qDebug("clear called"); - emit layoutAboutToBeChanged(); + beginResetModel(); if(files_index) { delete [] files_index; files_index = 0; } rootItem->deleteAllChildren(); - reset(); - emit layoutChanged(); + endResetModel(); } void setupModelData(const libtorrent::torrent_info &t) { @@ -590,21 +589,19 @@ public: public slots: void selectAll() { - emit layoutAboutToBeChanged(); for(int i=0; ichildCount(); ++i) { TorrentFileItem *child = rootItem->child(i); if(child->getPriority() == prio::IGNORED) child->setPriority(prio::NORMAL); } - emit layoutChanged(); + emit dataChanged(index(0,0), index(rowCount(), columnCount())); } void selectNone() { - emit layoutAboutToBeChanged(); for(int i=0; ichildCount(); ++i) { rootItem->child(i)->setPriority(prio::IGNORED); } - emit layoutChanged(); + emit dataChanged(index(0,0), index(rowCount(), columnCount())); } signals: @@ -645,11 +642,10 @@ public: } QModelIndex parent(const QModelIndex & child) const { - if(!child.isValid()) return QModelIndex(); - Q_ASSERT(sourceModel()); - QModelIndex sourceParent = sourceModel()->parent(mapToSource(child)); - if(!sourceParent.isValid()) return QModelIndex(); - return mapFromSource(sourceParent); + if(!child.isValid()) return QModelIndex(); + QModelIndex sourceParent = m_model->parent(mapToSource(child)); + if(!sourceParent.isValid()) return QModelIndex(); + return mapFromSource(sourceParent); } signals: @@ -669,14 +665,14 @@ public slots: for(int i=0; i