diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-18 19:44:29 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-18 19:44:29 +0100 |
| commit | a19bfaa489507827dea1449991f1f5398a28beb1 (patch) | |
| tree | ee30c2ae12143d00bdefd319162dfa1522ee9c1c /src/modlistbypriorityproxy.h | |
| parent | 59f055ba93381b965cdc04557ac1dce2df36bd07 (diff) | |
Better handling of layoutChanged in by-priority proxy to avoid resetting.
Diffstat (limited to 'src/modlistbypriorityproxy.h')
| -rw-r--r-- | src/modlistbypriorityproxy.h | 24 |
1 files changed, 16 insertions, 8 deletions
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<int>& roles = QVector<int>()); + void onModelRowsRemoved(const QModelIndex& parent, int first, int last); + void onModelLayoutChanged(const QList<QPersistentModelIndex>& parents, LayoutChangeHint hint); + void onModelReset(); + void onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles = QVector<int>()); 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<std::unique_ptr<TreeItem>> children; + std::vector<TreeItem*> 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<unsigned int, TreeItem*> m_IndexToItem; + std::map<unsigned int, std::unique_ptr<TreeItem>> m_IndexToItem; private: OrganizerCore& m_core; |
