]> git.mxchange.org Git - flightgear.git/commitdiff
Basics on catalog list model in the GUI.
authorJames Turner <zakalawe@mac.com>
Thu, 12 Mar 2015 13:29:06 +0000 (13:29 +0000)
committerJames Turner <zakalawe@mac.com>
Fri, 10 Apr 2015 13:44:44 +0000 (14:44 +0100)
src/GUI/CMakeLists.txt
src/GUI/CatalogListModel.cxx [new file with mode: 0644]
src/GUI/CatalogListModel.hxx [new file with mode: 0644]
src/GUI/Launcher.ui
src/GUI/QtLauncher.cxx
src/GUI/QtLauncher.hxx

index 8bf480b351a5f10e9ce12cd1b4182f17138e1642..542e41107f4cfe28f9a85eba54fa93362424e23a 100644 (file)
@@ -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 (file)
index 0000000..9b7d264
--- /dev/null
@@ -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 (file)
index 0000000..dfbe724
--- /dev/null
@@ -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
index a7fdaa0560844ff587473104fd4a7e7f1152e0be..781919efcbd6c77704d1e4845119feb053b2cd41 100644 (file)
           <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">
            </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>
            </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>
             </property>
            </widget>
           </item>
+          <item row="0" column="0" colspan="3">
+           <widget class="QListView" name="catalogsList"/>
+          </item>
          </layout>
         </widget>
        </item>
index dcfd82b2d57c05c33ad29d86ac768a38910f498d..82e55d0e93c8777d510210d92173448c5971cf71 100644 (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"
 
index 43e4602b7fbeab7a6d74652495f47cb5c1d28c50..33de985f05454080e16d17a161b36bff1ab07790 100644 (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;