File indexing completed on 2024-04-14 14:29:56

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2021 Julius Künzel <jk.kdedev@smartlab.uber.space>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-or-later
0006 */
0007 
0008 #include "kaboutapplicationcomponentmodel_p.h"
0009 #include "debug.h"
0010 
0011 namespace KDEPrivate
0012 {
0013 KAboutApplicationComponentModel::KAboutApplicationComponentModel(const QList<KAboutComponent> &componentList, QObject *parent)
0014     : QAbstractListModel(parent)
0015     , m_componentList(componentList)
0016 {
0017     m_profileList.reserve(componentList.size());
0018     for (const auto &component : std::as_const(m_componentList)) {
0019         KAboutApplicationComponentProfile profile =
0020             KAboutApplicationComponentProfile(component.name(), component.description(), component.version(), component.webAddress(), component.license());
0021         m_profileList.append(profile);
0022     }
0023 }
0024 
0025 int KAboutApplicationComponentModel::rowCount(const QModelIndex &parent) const
0026 {
0027     Q_UNUSED(parent)
0028     return m_componentList.count();
0029 }
0030 
0031 QVariant KAboutApplicationComponentModel::data(const QModelIndex &index, int role) const
0032 {
0033     if (!index.isValid()) {
0034         qCWarning(DEBUG_KXMLGUI) << "ERROR: invalid index";
0035         return QVariant();
0036     }
0037     if (index.row() >= rowCount()) {
0038         qCWarning(DEBUG_KXMLGUI) << "ERROR: index out of bounds";
0039         return QVariant();
0040     }
0041     if (role == Qt::DisplayRole) {
0042         //        qCDebug(DEBUG_KXMLGUI) << "Spitting data for name " << m_profileList.at( index.row() ).name();
0043         QVariant var;
0044         var.setValue(m_profileList.at(index.row()));
0045         return var;
0046     } else {
0047         return QVariant();
0048     }
0049 }
0050 
0051 Qt::ItemFlags KAboutApplicationComponentModel::flags(const QModelIndex &index) const
0052 {
0053     if (index.isValid()) {
0054         return Qt::ItemIsEnabled;
0055     }
0056     return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
0057 }
0058 
0059 } // namespace KDEPrivate
0060 
0061 #include "moc_kaboutapplicationcomponentmodel_p.cpp"