Krita Source Code Documentation
Loading...
Searching...
No Matches
KoGenericRegistryModel.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2 *
3 * SPDX-FileCopyrightText: 2007 Cyrille Berger <cberger@cberger.net>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8#ifndef _KO_GENERIC_REGISTRY_MODEL_H_
9#define _KO_GENERIC_REGISTRY_MODEL_H_
10
11#include <QAbstractListModel>
12#include "KoGenericRegistry.h"
13
19template<typename T>
20class KoGenericRegistryModel : public QAbstractListModel
21{
22
23public:
24
26
28
29public:
30
34 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
35
40 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
41
45 T get(const QModelIndex &index) const;
46
47private:
48
50};
51
52// -- Implementation --
53template<typename T>
57
58template<typename T>
62
63template<typename T>
64int KoGenericRegistryModel<T>::rowCount(const QModelIndex &/*parent*/) const
65{
66 return m_registry->keys().size();
67}
68
69template<typename T>
70QVariant KoGenericRegistryModel<T>::data(const QModelIndex &index, int role) const
71{
72 if (!index.isValid()) {
73 return QVariant();
74 }
75 if (role == Qt::DisplayRole || role == Qt::EditRole) {
76 return QVariant(get(index)->name());
77 }
78 return QVariant();
79}
80
81template<typename T>
82T KoGenericRegistryModel<T>::get(const QModelIndex &index) const
83{
84 return m_registry->get(m_registry->keys()[index.row()]);
85}
86
87#endif
VertexDescriptor get(PredecessorMap const &m, VertexDescriptor v)
T get(const QModelIndex &index) const
KoGenericRegistry< T > * m_registry
int rowCount(const QModelIndex &parent=QModelIndex()) const override
KoGenericRegistryModel(KoGenericRegistry< T > *registry)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override