summaryrefslogtreecommitdiffstats
path: root/api/dead/src/resources/ResourceProxyModel.h
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-04-10 17:01:24 +0200
committerPetr Mrázek <peterix@gmail.com>2016-05-01 00:00:24 +0200
commit1be7d573326570d63e55e36235537ed2b1831ae1 (patch)
treeba7037671cde8688e87e69acb753df80ec4cd4f9 /api/dead/src/resources/ResourceProxyModel.h
parentaa4842a91d35481264ae5a7c0ac17ea43610b600 (diff)
downloadMultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar.gz
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar.lz
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar.xz
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.zip
NOISSUE re/move some dead code and unused build system parts
Diffstat (limited to 'api/dead/src/resources/ResourceProxyModel.h')
-rw-r--r--api/dead/src/resources/ResourceProxyModel.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/api/dead/src/resources/ResourceProxyModel.h b/api/dead/src/resources/ResourceProxyModel.h
new file mode 100644
index 00000000..98a3dbd1
--- /dev/null
+++ b/api/dead/src/resources/ResourceProxyModel.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <QIdentityProxyModel>
+#include <memory>
+
+#include "multimc_logic_export.h"
+
+/// Convenience proxy model that transforms resource identifiers (strings) for Qt::DecorationRole into other types.
+class MULTIMC_LOGIC_EXPORT ResourceProxyModel : public QIdentityProxyModel
+{
+ Q_OBJECT
+public:
+ // resultTypeId is found using qMetaTypeId<T>()
+ explicit ResourceProxyModel(const int resultTypeId, QObject *parent = nullptr);
+
+ enum
+ {
+ // provide this role from your model if you want to show a placeholder
+ PlaceholderRole = Qt::UserRole + 0xabc // some random offset to not collide with other stuff
+ };
+
+ QVariant data(const QModelIndex &proxyIndex, int role) const override;
+ void setSourceModel(QAbstractItemModel *model) override;
+
+ /// Helper function, usage: m_view->setModel(ResourceProxyModel::mixin<QIcon>(m_model));
+ template <typename T>
+ static QAbstractItemModel *mixin(QAbstractItemModel *model)
+ {
+ ResourceProxyModel *proxy = new ResourceProxyModel(qMetaTypeId<T>(), model);
+ proxy->setSourceModel(model);
+ return proxy;
+ }
+
+private:
+ // mutable because it needs to be available from the const data()
+ mutable QMap<QPersistentModelIndex, std::shared_ptr<class Resource>> m_resources;
+
+ const int m_resultTypeId;
+};