diff --git a/src/GUI/CMakeLists.txt b/src/GUI/CMakeLists.txt index 8bf480b35..542e41107 100644 --- a/src/GUI/CMakeLists.txt +++ b/src/GUI/CMakeLists.txt @@ -87,6 +87,8 @@ if (HAVE_QT) AircraftItemDelegate.cxx AircraftModel.hxx AircraftModel.cxx + CatalogListModel.cxx + CatalogListModel.hxx ${uic_sources} ${qrc_sources}) diff --git a/src/GUI/CatalogListModel.cxx b/src/GUI/CatalogListModel.cxx new file mode 100644 index 000000000..9b7d264e2 --- /dev/null +++ b/src/GUI/CatalogListModel.cxx @@ -0,0 +1,69 @@ +// CatalogListModel.cxx - part of GUI launcher using Qt5 +// +// Written by James Turner, started March 2015. +// +// Copyright (C) 2015 James Turner <zakalawe@mac.com> +// +// 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 <QDebug> +#include <QUrl> + +// Simgear +#include <simgear/props/props_io.hxx> +#include <simgear/structure/exception.hxx> +#include <simgear/misc/sg_path.hxx> + +// FlightGear +#include <Main/globals.hxx> + +CatalogListModel::CatalogListModel(QObject* pr, simgear::pkg::RootRef& rootRef) : + QAbstractListModel(pr), + m_packageRoot(rootRef) +{ +} + +CatalogListModel::~CatalogListModel() +{ +} + +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()); + } 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()); + } + + return QVariant(); +} + +bool CatalogListModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + return false; +} diff --git a/src/GUI/CatalogListModel.hxx b/src/GUI/CatalogListModel.hxx new file mode 100644 index 000000000..dfbe724ad --- /dev/null +++ b/src/GUI/CatalogListModel.hxx @@ -0,0 +1,57 @@ +// CatalogListModel.hxx - part of GUI launcher using Qt5 +// +// Written by James Turner, started March 2015. +// +// Copyright (C) 2015 James Turner <zakalawe@mac.com> +// +// 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. + +#ifndef FG_GUI_CATALOG_LIST_MODEL +#define FG_GUI_CATALOG_LIST_MODEL + +#include <QAbstractListModel> +#include <QDateTime> +#include <QDir> +#include <QPixmap> +#include <QStringList> + +#include <simgear/package/Root.hxx> +#include <simgear/package/Catalog.hxx> + +const int CatalogUrlRole = Qt::UserRole + 1; +const int CatalogIdRole = Qt::UserRole + 2; + +class CatalogListModel : public QAbstractListModel +{ + Q_OBJECT +public: + CatalogListModel(QObject* pr, simgear::pkg::RootRef& root); + + ~CatalogListModel(); + + virtual int rowCount(const QModelIndex& parent) const; + + virtual QVariant data(const QModelIndex& index, int role) const; + + virtual bool setData(const QModelIndex &index, const QVariant &value, int role); + +private slots: + + +private: + simgear::pkg::RootRef m_packageRoot; +}; + +#endif // of FG_GUI_CATALOG_LIST_MODEL diff --git a/src/GUI/Launcher.ui b/src/GUI/Launcher.ui index a7fdaa056..781919efc 100644 --- a/src/GUI/Launcher.ui +++ b/src/GUI/Launcher.ui @@ -718,9 +718,6 @@ <property name="spacing"> <number>0</number> </property> - <item row="0" column="0" colspan="3"> - <widget class="QListWidget" name="aircraftPathsList_2"/> - </item> <item row="1" column="0"> <spacer name="horizontalSpacer_5"> <property name="orientation"> @@ -735,7 +732,7 @@ </spacer> </item> <item row="1" column="2"> - <widget class="QToolButton" name="removeAircraftPath_2"> + <widget class="QToolButton" name="removeCatalog"> <property name="sizePolicy"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -754,7 +751,7 @@ </widget> </item> <item row="1" column="1"> - <widget class="QToolButton" name="addAircraftPath_2"> + <widget class="QToolButton" name="addCatalog"> <property name="sizePolicy"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -772,6 +769,9 @@ </property> </widget> </item> + <item row="0" column="0" colspan="3"> + <widget class="QListView" name="catalogsList"/> + </item> </layout> </widget> </item> diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index dcfd82b2d..82e55d0e9 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -53,6 +53,7 @@ #include "EditRatingsFilterDialog.hxx" #include "AircraftItemDelegate.hxx" #include "AircraftModel.hxx" +#include "CatalogListModel.hxx" #include <Main/globals.hxx> #include <Navaids/NavDataCache.hxx> @@ -539,6 +540,9 @@ QtLauncher::QtLauncher() : connect(m_ui->removeAircraftPath, &QToolButton::clicked, this, &QtLauncher::onRemoveAircraftPath); + m_catalogsModel = new CatalogListModel(this, r); + m_ui->catalogsList->setModel(m_catalogsModel); + QSettings settings; m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList()); m_aircraftModel->scanDirs(); @@ -1137,5 +1141,15 @@ void QtLauncher::onSubsytemIdleTimeout() globals->get_subsystem_mgr()->update(0.0); } +void QtLauncher::onAddCatalog() +{ + +} + +void QtLauncher::onRemoveCatalog() +{ + +} + #include "QtLauncher.moc" diff --git a/src/GUI/QtLauncher.hxx b/src/GUI/QtLauncher.hxx index 43e4602b7..33de985f0 100644 --- a/src/GUI/QtLauncher.hxx +++ b/src/GUI/QtLauncher.hxx @@ -39,6 +39,7 @@ class QModelIndex; class AircraftProxyModel; class AircraftItemModel; class QCheckBox; +class CatalogListModel; class QtLauncher : public QDialog { @@ -80,6 +81,8 @@ private slots: void onAddAircraftPath(); void onRemoveAircraftPath(); + void onAddCatalog(); + void onRemoveCatalog(); void onRembrandtToggled(bool b); @@ -100,7 +103,8 @@ private: AirportSearchModel* m_airportsModel; AircraftProxyModel* m_aircraftProxy; AircraftItemModel* m_aircraftModel; - + CatalogListModel* m_catalogsModel; + FGAirportRef m_selectedAirport; QString m_selectedAircraft;