1 // CatalogListModel.cxx - part of GUI launcher using Qt5
3 // Written by James Turner, started March 2015.
5 // Copyright (C) 2015 James Turner <zakalawe@mac.com>
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.
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.
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.
21 #include "CatalogListModel.hxx"
27 #include <simgear/props/props_io.hxx>
28 #include <simgear/structure/exception.hxx>
29 #include <simgear/misc/sg_path.hxx>
32 #include <Main/globals.hxx>
34 CatalogListModel::CatalogListModel(QObject* pr, simgear::pkg::RootRef& rootRef) :
35 QAbstractListModel(pr),
36 m_packageRoot(rootRef)
40 CatalogListModel::~CatalogListModel()
44 int CatalogListModel::rowCount(const QModelIndex& parent) const
46 return m_packageRoot->catalogs().size();
49 QVariant CatalogListModel::data(const QModelIndex& index, int role) const
51 simgear::pkg::CatalogRef cat = m_packageRoot->catalogs().at(index.row());
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());
66 bool CatalogListModel::setData(const QModelIndex &index, const QVariant &value, int role)