-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprotocolsmodel.cpp
More file actions
47 lines (37 loc) · 1.04 KB
/
Copy pathprotocolsmodel.cpp
File metadata and controls
47 lines (37 loc) · 1.04 KB
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
42
43
44
45
46
47
#include "protocolsmodel.h"
#include "protocol.h"
ProtocolsModel::ProtocolsModel(QObject* aParent)
: QAbstractListModel(aParent)
, mBuiltinConfigs(p8020_test_config_get_builtin())
{
}
auto
ProtocolsModel::rowCount(const QModelIndex&) const -> int
{
return mBuiltinConfigs.count;
}
auto
ProtocolsModel::data(const QModelIndex& aIndex, const int aRole) const
-> QVariant
{
if (aRole != Qt::DisplayRole) {
return {};
}
const TestConfig* const config = mBuiltinConfigs.configs[aIndex.row()];
char* const id = p8020_test_config_id(config);
char* const name = p8020_test_config_name(config);
QString result = QString("%2 [%1]").arg(id, name);
p8020_string_free(id);
p8020_string_free(name);
return result;
}
auto
ProtocolsModel::protocol(const int& aIndex) -> QSharedPointer<Protocol> const
{
// This will (obviously) change significantly once custom protocols are
// supported.
return QSharedPointer<Protocol>(new Protocol{
.tag = Protocol::BUILTIN_CONFIG,
.builtinConfig = mBuiltinConfigs.configs[aIndex],
});
}