blob: 94da87bedac2ce81ed478104c1ee74d846d4fd18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "typerolemodel.h"
TypeRoleModel::TypeRoleModel(QObject *parent)
: QAbstractListModel(parent)
{
_mapRoleNames[TypeRole] = "type";
_mapRoleNames[TextRole] = "text";
}
int TypeRoleModel::rowCount(const QModelIndex &) const
{
return 3;
}
QVariant TypeRoleModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return {};
constexpr Type types[] = {
Type::PlainText,
Type::Markdown,
Type::Rect
};
switch (role) {
case TypeRole: {
const Type type = types[index.row() % std::size(types)];
return QVariant::fromValue(type);
}
case TextRole: {
if (index.row() % std::size(types) == int(Type::Markdown))
return "*row* " + QString::number(index.row());
return "row " + QString::number(index.row());
}
}
return {};
}
|