Files
BlackAngelTV 5a6aaae244 refactor(tree): give the logic layer and the shell a folder each
src/ and include/ are what is left: the controller the screens delegate
to, its workers and its data model (core/), and the window and entry
point that hold them together (app/). With those moved, src/ and
include/ are empty and go away — a header is now always next to its
source, in a folder named after what it does.
2026-09-29 21:26:04 +02:00

59 lines
1.7 KiB
C++

#include "package-model.h"
PackageModel::PackageModel(QObject* parent) : QAbstractListModel(parent) {}
int PackageModel::rowCount(const QModelIndex& parent) const {
Q_UNUSED(parent);
return static_cast<int>(m_packages.size());
}
QVariant PackageModel::data(const QModelIndex& index, int role) const {
if (!index.isValid() || index.row() >= static_cast<int>(m_packages.size())) {
return QVariant();
}
const PackageInfo& pkg = m_packages[index.row()];
switch (role) {
case NameRole: return QString::fromStdString(pkg.name);
case VersionRole: return QString::fromStdString(pkg.version);
case DescriptionRole: return QString::fromStdString(pkg.description);
case RepositoryRole: return QString::fromStdString(pkg.repository);
case InstalledRole: return pkg.installed;
case SizeRole: return QString::fromStdString(pkg.size);
case UpdateAvailableRole: return pkg.updateAvailable;
default: return QVariant();
}
}
QHash<int, QByteArray> PackageModel::roleNames() const {
return {
{NameRole, "name"},
{VersionRole, "version"},
{DescriptionRole, "description"},
{RepositoryRole, "repository"},
{InstalledRole, "installed"},
{SizeRole, "size"},
{UpdateAvailableRole, "updateAvailable"}
};
}
void PackageModel::setPackages(const std::vector<PackageInfo>& packages) {
beginResetModel();
m_packages = packages;
endResetModel();
}
void PackageModel::clear() {
beginResetModel();
m_packages.clear();
endResetModel();
}
PackageInfo PackageModel::getPackage(int row) const {
if (row >= 0 && row < static_cast<int>(m_packages.size())) {
return m_packages[row];
}
return PackageInfo{};
}