// CatalogListModel.cxx - part of GUI launcher using Qt5 // // Written by James Turner, started March 2015. // // Copyright (C) 2015 James Turner // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "CatalogListModel.hxx" #include #include // Simgear #include #include #include #include // FlightGear #include
CatalogListModel::CatalogListModel(QObject* pr, simgear::pkg::RootRef& rootRef) : QAbstractListModel(pr), m_packageRoot(rootRef) { } CatalogListModel::~CatalogListModel() { } void CatalogListModel::refresh() { beginResetModel(); endResetModel(); } int CatalogListModel::rowCount(const QModelIndex& parent) const { return m_packageRoot->catalogs().size(); } QVariant CatalogListModel::data(const QModelIndex& index, int role) const { simgear::pkg::CatalogRef cat = m_packageRoot->catalogs().at(index.row()); if (role == Qt::DisplayRole) { return QString::fromStdString(cat->description()).trimmed(); } else if (role == Qt::ToolTipRole) { return QString::fromStdString(cat->url()); } else if (role == CatalogUrlRole) { return QUrl(QString::fromStdString(cat->url())); } else if (role == CatalogIdRole) { return QString::fromStdString(cat->id()); } else if (role == CatalogPackageCountRole) { return static_cast(cat->packages().size()); } else if (role == CatalogInstallCountRole) { return static_cast(cat->installedPackages().size()); } return QVariant(); } bool CatalogListModel::setData(const QModelIndex &index, const QVariant &value, int role) { return false; }