Use persistent model index.

This commit is contained in:
John Maguire 2010-08-02 14:07:34 +00:00
parent 992e0fb95e
commit 8166a50b2a
2 changed files with 9 additions and 7 deletions

View File

@ -2,7 +2,7 @@
#define MODELFUTUREWATCHER_H
#include <QFutureWatcher>
#include <QModelIndex>
#include <QPersistentModelIndex>
template <typename T>
class ModelFutureWatcher : public QFutureWatcher<T> {
@ -15,10 +15,10 @@ class ModelFutureWatcher : public QFutureWatcher<T> {
~ModelFutureWatcher() {
}
const QModelIndex& index() const { return index_; }
const QPersistentModelIndex& index() const { return index_; }
private:
QModelIndex index_;
QPersistentModelIndex index_;
};

View File

@ -251,10 +251,12 @@ bool Playlist::setData(const QModelIndex &index, const QVariant &value, int) {
void Playlist::SongSaveComplete() {
ModelFutureWatcher<bool>* watcher = static_cast<ModelFutureWatcher<bool>*>(sender());
watcher->deleteLater();
const QModelIndex& index = watcher->index();
item_at(index.row())->Reload();
emit dataChanged(index, index);
emit EditingFinished(index);
const QPersistentModelIndex& index = watcher->index();
if (index.isValid()) {
item_at(index.row())->Reload();
emit dataChanged(index, index);
emit EditingFinished(index);
}
}
int Playlist::current_index() const {