]> git.mxchange.org Git - flightgear.git/blob - src/GUI/CatalogListModel.cxx
Remove some debug output.
[flightgear.git] / src / GUI / CatalogListModel.cxx
1 // CatalogListModel.cxx - part of GUI launcher using Qt5
2 //
3 // Written by James Turner, started March 2015.
4 //
5 // Copyright (C) 2015 James Turner <zakalawe@mac.com>
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 #include "CatalogListModel.hxx"
22
23 #include <QDebug>
24 #include <QUrl>
25
26 // Simgear
27 #include <simgear/props/props_io.hxx>
28 #include <simgear/structure/exception.hxx>
29 #include <simgear/misc/sg_path.hxx>
30
31 #include <simgear/package/Package.hxx>
32
33 // FlightGear
34 #include <Main/globals.hxx>
35
36 CatalogListModel::CatalogListModel(QObject* pr, simgear::pkg::RootRef& rootRef) :
37     QAbstractListModel(pr),
38     m_packageRoot(rootRef)
39 {
40 }
41
42 CatalogListModel::~CatalogListModel()
43 {
44 }
45
46 void CatalogListModel::refresh()
47 {
48     beginResetModel();
49     endResetModel();
50 }
51
52 int CatalogListModel::rowCount(const QModelIndex& parent) const
53 {
54     return m_packageRoot->catalogs().size();
55 }
56
57 QVariant CatalogListModel::data(const QModelIndex& index, int role) const
58 {
59     simgear::pkg::CatalogRef cat = m_packageRoot->catalogs().at(index.row());
60
61     if (role == Qt::DisplayRole) {
62         return QString::fromStdString(cat->description());
63     } else if (role == Qt::ToolTipRole) {
64         return QString::fromStdString(cat->url());
65     } else if (role == CatalogUrlRole) {
66         return QUrl(QString::fromStdString(cat->url()));
67     } else if (role == CatalogIdRole) {
68         return QString::fromStdString(cat->id());
69     } else if (role == CatalogPackageCountRole) {
70         return static_cast<quint32>(cat->packages().size());
71     } else if (role == CatalogInstallCountRole) {
72         return static_cast<quint32>(cat->installedPackages().size());
73     }
74
75     return QVariant();
76 }
77
78 bool CatalogListModel::setData(const QModelIndex &index, const QVariant &value, int role)
79 {
80     return false;
81 }