1
0
Fork 0

Basics on catalog list model in the GUI.

This commit is contained in:
James Turner 2015-03-12 13:29:06 +00:00
parent 9745a6fce3
commit d9a53e1140
6 changed files with 152 additions and 6 deletions

View file

@ -87,6 +87,8 @@ if (HAVE_QT)
AircraftItemDelegate.cxx
AircraftModel.hxx
AircraftModel.cxx
CatalogListModel.cxx
CatalogListModel.hxx
${uic_sources}
${qrc_sources})

View file

@ -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;
}

View file

@ -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

View file

@ -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>

View file

@ -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"

View file

@ -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;