diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-12-27 14:55:20 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-02 15:38:14 +0100 |
| commit | d0512da75805be194d949a6d6bac8184314da0e6 (patch) | |
| tree | 27758203a442e3e90510d8c5d8f89848d6f5ffd8 /src/modlistbypriorityproxy.h | |
| parent | be0d6aef00891286f33242073627611413ad79c4 (diff) | |
Use an intermediate structure to store the separator tree.
Diffstat (limited to 'src/modlistbypriorityproxy.h')
| -rw-r--r-- | src/modlistbypriorityproxy.h | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/src/modlistbypriorityproxy.h b/src/modlistbypriorityproxy.h index 6ec04b9b..d5f59f4c 100644 --- a/src/modlistbypriorityproxy.h +++ b/src/modlistbypriorityproxy.h @@ -2,6 +2,7 @@ #define MODLISBYPRIORITYPROXY_H #include <optional> +#include <set> #include <vector> #include <QAbstractProxyModel> @@ -14,43 +15,71 @@ #include "modinfo.h" class ModList; +class Profile; class ModListByPriorityProxy : public QAbstractProxyModel { Q_OBJECT public: - explicit ModListByPriorityProxy(ModList* modList, QObject* parent = nullptr); + explicit ModListByPriorityProxy(Profile* profile, QObject* parent = nullptr); ~ModListByPriorityProxy(); + void setProfile(Profile* profile) { m_Profile = profile; } + void setSourceModel(QAbstractItemModel* sourceModel) override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex& child) const override; + Qt::ItemFlags flags(const QModelIndex& idx) const override; QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; int columnCount(const QModelIndex& index) const override; bool hasChildren(const QModelIndex& parent) const override; + bool setData(const QModelIndex& index, const QVariant& value, int role) override; + QModelIndex mapFromSource(const QModelIndex& sourceIndex) const override; QModelIndex mapToSource(const QModelIndex& proxyIndex) const override; +signals: + void expandItem(const QModelIndex& index); + +public slots: + + void expanded(const QModelIndex& index); + void collapsed(const QModelIndex& index); + private: void buildTree(); + void expandItems(const QModelIndex& index); - struct ModInfoWithPriority { - const ModInfo::Ptr mod; - const int priority; - }; + struct TreeItem { + ModInfo::Ptr mod; + unsigned int index; + std::vector<std::unique_ptr<TreeItem>> children; + TreeItem* parent; - std::vector<ModInfoWithPriority> topLevelItems() const; - std::vector<ModInfoWithPriority> childItems(int priority) const; - std::optional<ModInfoWithPriority> separator(int priority) const; + std::size_t childIndex(TreeItem* child) const { + for (std::size_t i = 0; i < children.size(); ++i) { + if (children[i].get() == child) { + return i; + } + } + return -1; + } -private: + TreeItem() : TreeItem(nullptr, -1) { } + TreeItem(ModInfo::Ptr mod, unsigned int index, TreeItem* parent = nullptr) : + mod(mod), index(index), parent(parent) { } + }; - ModList* m_ModList; + TreeItem m_Root; + std::map<unsigned int, TreeItem*> m_IndexToItem; + std::set<QString> m_CollapsedItems; +private: + Profile* m_Profile; }; #endif //GROUPINGPROXY_H |
