1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2021 Julius Künzel <jk.kdedev@smartlab.uber.space>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "kaboutapplicationcomponentmodel_p.h"
9#include "debug.h"
10
11namespace KDEPrivate
12{
13KAboutApplicationComponentModel::KAboutApplicationComponentModel(const QList<KAboutComponent> &componentList, QObject *parent)
14 : QAbstractListModel(parent)
15 , m_componentList(componentList)
16{
17 m_profileList.reserve(asize: componentList.size());
18 for (const auto &component : std::as_const(t: m_componentList)) {
19 KAboutApplicationComponentProfile profile =
20 KAboutApplicationComponentProfile(component.name(), component.description(), component.version(), component.webAddress(), component.license());
21 m_profileList.append(t: profile);
22 }
23}
24
25int KAboutApplicationComponentModel::rowCount(const QModelIndex &parent) const
26{
27 Q_UNUSED(parent)
28 return m_componentList.count();
29}
30
31QVariant KAboutApplicationComponentModel::data(const QModelIndex &index, int role) const
32{
33 if (!index.isValid()) {
34 qCWarning(DEBUG_KXMLGUI) << "ERROR: invalid index";
35 return QVariant();
36 }
37 if (index.row() >= rowCount()) {
38 qCWarning(DEBUG_KXMLGUI) << "ERROR: index out of bounds";
39 return QVariant();
40 }
41 if (role == Qt::DisplayRole) {
42 // qCDebug(DEBUG_KXMLGUI) << "Spitting data for name " << m_profileList.at( index.row() ).name();
43 QVariant var;
44 var.setValue(m_profileList.at(i: index.row()));
45 return var;
46 } else {
47 return QVariant();
48 }
49}
50
51Qt::ItemFlags KAboutApplicationComponentModel::flags(const QModelIndex &index) const
52{
53 if (index.isValid()) {
54 return Qt::ItemIsEnabled;
55 }
56 return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
57}
58
59} // namespace KDEPrivate
60
61#include "moc_kaboutapplicationcomponentmodel_p.cpp"
62

source code of kxmlgui/src/kaboutapplicationcomponentmodel_p.cpp