From d25a81071c078585f14176283b89e1a6b0ad5795 Mon Sep 17 00:00:00 2001 From: Tannin Date: Wed, 10 Jun 2015 21:22:54 +0200 Subject: more generic solution to the problem fixed in changeset bb74f8eb639c, now also applied in another location --- src/modlist.cpp | 19 ++++++------------- src/modlist.h | 4 ++++ src/modlistsortproxy.cpp | 23 +++++++++++++++++++++++ src/modlistsortproxy.h | 9 +++++++++ 4 files changed, 42 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/modlist.cpp b/src/modlist.cpp index a7990132..df006e30 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -453,6 +453,8 @@ bool ModList::setData(const QModelIndex &index, const QVariant &value, int role) bool result = false; + emit aboutToChangeData(); + if (role == Qt::CheckStateRole) { bool enabled = value.toInt() == Qt::Checked; if (m_Profile->modEnabled(modID) != enabled) { @@ -512,6 +514,8 @@ bool ModList::setData(const QModelIndex &index, const QVariant &value, int role) } } + emit postDataChanged(); + IModList::ModStates newState = state(modID); if (oldState != newState) { try { @@ -1091,16 +1095,7 @@ bool ModList::deleteSelection(QAbstractItemView *itemView) bool ModList::toggleSelection(QAbstractItemView *itemView) { - QAbstractItemModel *model = itemView->model(); - - // having a filter active when dataChanged is called caused a crash - // (at least with some Qt versions) - ModListSortProxy *filterModel = qobject_cast(model); - std::vector filter; - if (filterModel != nullptr) { - filter = filterModel->categoryFilter(); - filterModel->setCategoryFilter(std::vector()); - } + emit aboutToChangeData(); QItemSelectionModel *selectionModel = itemView->selectionModel(); @@ -1115,9 +1110,7 @@ bool ModList::toggleSelection(QAbstractItemView *itemView) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); - if (filterModel != nullptr) { - filterModel->setCategoryFilter(filter); - } + emit postDataChanged(); return true; } diff --git a/src/modlist.h b/src/modlist.h index fed91f71..ed52a3ea 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -237,6 +237,10 @@ signals: */ void fileMoved(const QString &relativePath, const QString &oldOriginName, const QString &newOriginName); + void aboutToChangeData(); + + void postDataChanged(); + protected: // event filter, handles event from the header and the tree view itself diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index b40b4144..f646a079 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -376,3 +376,26 @@ bool ModListSortProxy::dropMimeData(const QMimeData *data, Qt::DropAction action return this->sourceModel()->dropMimeData(data, action, sourceIndex.row(), sourceIndex.column(), sourceIndex.parent()); } + +void ModListSortProxy::setSourceModel(QAbstractItemModel *sourceModel) +{ + QSortFilterProxyModel::setSourceModel(sourceModel); + + connect(sourceModel, SIGNAL(aboutToChangeData()), this, SLOT(aboutToChangeData())); + connect(sourceModel, SIGNAL(postDataChanged()), this, SLOT(postDataChanged())); +} + +void ModListSortProxy::aboutToChangeData() +{ + // having a filter active when dataChanged is called caused a crash + // (at least with some Qt versions) + m_PreChangeFilters = categoryFilter(); + setCategoryFilter(std::vector()); +} + +void ModListSortProxy::postDataChanged() +{ + setCategoryFilter(m_PreChangeFilters); + m_PreChangeFilters.clear(); +} + diff --git a/src/modlistsortproxy.h b/src/modlistsortproxy.h index 93092ba7..ce7e5eb5 100644 --- a/src/modlistsortproxy.h +++ b/src/modlistsortproxy.h @@ -58,6 +58,8 @@ public: virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + virtual void setSourceModel(QAbstractItemModel *sourceModel) override; + /** * @brief enable all mods visible under the current filter **/ @@ -112,6 +114,11 @@ private: bool filterMatchesModAnd(ModInfo::Ptr info, bool enabled) const; bool filterMatchesModOr(ModInfo::Ptr info, bool enabled) const; +private slots: + + void aboutToChangeData(); + void postDataChanged(); + private: Profile *m_Profile; @@ -124,6 +131,8 @@ private: bool m_FilterActive; FilterMode m_FilterMode; + std::vector m_PreChangeFilters; + }; #endif // MODLISTSORTPROXY_H -- cgit v1.3.1