From a19bfaa489507827dea1449991f1f5398a28beb1 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Mon, 18 Jan 2021 19:44:29 +0100 Subject: Better handling of layoutChanged in by-priority proxy to avoid resetting. --- src/modlistbypriorityproxy.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/modlistbypriorityproxy.h') diff --git a/src/modlistbypriorityproxy.h b/src/modlistbypriorityproxy.h index 380e257b..77e0fe3d 100644 --- a/src/modlistbypriorityproxy.h +++ b/src/modlistbypriorityproxy.h @@ -33,10 +33,6 @@ public: // void setSortOrder(Qt::SortOrder order); - // refresh the proxy by rebuilding the inner structure - // - void refresh(); - void setSourceModel(QAbstractItemModel* sourceModel) override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; @@ -57,21 +53,33 @@ public slots: protected slots: - void modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector& roles = QVector()); + void onModelRowsRemoved(const QModelIndex& parent, int first, int last); + void onModelLayoutChanged(const QList& parents, LayoutChangeHint hint); + void onModelReset(); + void onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector& roles = QVector()); private: + // fill the mapping from index to item (required by buildTree), should + // only be used for full model reset because it destroys existing references + // to tree items + // + void buildMapping(); + + // create the actual tree by creating parent/child associations, requires + // the mapping to be created (by a previous buildMapping call) + // void buildTree(); struct TreeItem { ModInfo::Ptr mod; unsigned int index; - std::vector> children; + std::vector children; TreeItem* parent; std::size_t childIndex(TreeItem* child) const { for (std::size_t i = 0; i < children.size(); ++i) { - if (children[i].get() == child) { + if (children[i] == child) { return i; } } @@ -84,7 +92,7 @@ private: }; TreeItem m_Root; - std::map m_IndexToItem; + std::map> m_IndexToItem; private: OrganizerCore& m_core; -- cgit v1.3.1