]> git.mxchange.org Git - flightgear.git/blob - src/GUI/CatalogListModel.cxx
Basics on catalog list model in the GUI.
[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 // FlightGear
32 #include <Main/globals.hxx>
33
34 CatalogListModel::CatalogListModel(QObject* pr, simgear::pkg::RootRef& rootRef) :
35     QAbstractListModel(pr),
36     m_packageRoot(rootRef)
37 {
38 }
39
40 CatalogListModel::~CatalogListModel()
41 {
42 }
43
44 int CatalogListModel::rowCount(const QModelIndex& parent) const
45 {
46     return m_packageRoot->catalogs().size();
47 }
48
49 QVariant CatalogListModel::data(const QModelIndex& index, int role) const
50 {
51     simgear::pkg::CatalogRef cat = m_packageRoot->catalogs().at(index.row());
52
53     if (role == Qt::DisplayRole) {
54         return QString::fromStdString(cat->description());
55     } else if (role == Qt::ToolTipRole) {
56         return QString::fromStdString(cat->url());
57     } else if (role == CatalogUrlRole) {
58         return QUrl(QString::fromStdString(cat->url()));
59     } else if (role == CatalogIdRole) {
60         return QString::fromStdString(cat->id());
61     }
62
63     return QVariant();
64 }
65
66 bool CatalogListModel::setData(const QModelIndex &index, const QVariant &value, int role)
67 {
68     return false;
69 }