summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2015-06-10 21:22:54 +0200
committerTannin <devnull@localhost>2015-06-10 21:22:54 +0200
commitd25a81071c078585f14176283b89e1a6b0ad5795 (patch)
tree002ccfa83c9db52f15dc4c2e919b7d68836f8594 /src
parentef9a61886c090e184c042f884687f401e25b1faa (diff)
more generic solution to the problem fixed in changeset bb74f8eb639c, now also applied in another location
Diffstat (limited to 'src')
-rw-r--r--src/modlist.cpp19
-rw-r--r--src/modlist.h4
-rw-r--r--src/modlistsortproxy.cpp23
-rw-r--r--src/modlistsortproxy.h9
4 files changed, 42 insertions, 13 deletions
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<ModListSortProxy*>(model);
- std::vector<int> filter;
- if (filterModel != nullptr) {
- filter = filterModel->categoryFilter();
- filterModel->setCategoryFilter(std::vector<int>());
- }
+ 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<int>());
+}
+
+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<int> m_PreChangeFilters;
+
};
#endif // MODLISTSORTPROXY_H