[Kstars-devel] [kstars] kstars: The sorting by meridian transit time / observation time for an
Akarsh Simha
akarshsimha at gmail.com
Sat Apr 14 14:29:56 UTC 2012
Git commit 75ecf3988ce3d815e9f92cd4991d5d8eb22cf4dc by Akarsh Simha.
Committed on 14/04/2012 at 16:25.
Pushed by asimha into branch 'master'.
The sorting by meridian transit time / observation time for an
observation session is not the same as a simple QTime compare.
Any observation session starts at sunset and stops at sunrise --
midnight is not the starting point. So the objects that should be
observed first are those which transit meridian just after 12 PM. So
the correct sorting procedure would place 12 PM first, followed by 1
PM and so on till 11 PM, followed by 12 AM and so on till 11:59 AM.
This sorting is achieved easily by sorting the time + 12 hours instead
of the time itself. Since QTime wraps around after 24 hours, this
works well.
This commit introduces this by:
1. Creating a SessionSortFilterProxyModel, subclassed from
QSortFilterProxyModel, reimplementing lessThan()
2. Using this sort model rather than the default one for the session
planner.
CCMAIL: kstars-devel at kde.org
M +1 -0 kstars/CMakeLists.txt
M +2 -1 kstars/tools/observinglist.cpp
A +40 -0 kstars/tools/sessionsortfilterproxymodel.cpp [License: GPL (v2+)]
A +48 -0 kstars/tools/sessionsortfilterproxymodel.h [License: GPL (v2+)]
http://commits.kde.org/kstars/75ecf3988ce3d815e9f92cd4991d5d8eb22cf4dc
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index dd733ee..c5f46b9 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -115,6 +115,7 @@ set(libkstarstools_SRCS
tools/modcalcsidtime.cpp
tools/modcalcvlsr.cpp
tools/observinglist.cpp
+ tools/sessionsortfilterproxymodel.cpp
tools/obslistwizard.cpp
tools/planetviewer.cpp
tools/pvplotwidget.cpp
diff --git a/kstars/tools/observinglist.cpp b/kstars/tools/observinglist.cpp
index 4165cc4..b5ed624 100644
--- a/kstars/tools/observinglist.cpp
+++ b/kstars/tools/observinglist.cpp
@@ -16,6 +16,7 @@
***************************************************************************/
#include "observinglist.h"
+#include "sessionsortfilterproxymodel.h"
#include <stdio.h>
@@ -118,7 +119,7 @@ ObservingList::ObservingList( KStars *_ks )
ui->TableView->setModel( m_SortModel );
ui->TableView->horizontalHeader()->setStretchLastSection( true );
ui->TableView->horizontalHeader()->setResizeMode( QHeaderView::ResizeToContents );
- m_SortModelSession = new QSortFilterProxyModel;
+ m_SortModelSession = new SessionSortFilterProxyModel;
m_SortModelSession->setSourceModel( m_Session );
m_SortModelSession->setDynamicSortFilter( true );
ui->SessionView->setModel( m_SortModelSession );
diff --git a/kstars/tools/sessionsortfilterproxymodel.cpp b/kstars/tools/sessionsortfilterproxymodel.cpp
new file mode 100644
index 0000000..2bf0d87
--- /dev/null
+++ b/kstars/tools/sessionsortfilterproxymodel.cpp
@@ -0,0 +1,40 @@
+/**************************************************************************
+ sessionsortfilterproxymodel.cpp - K Desktop Planetarium
+ -------------------
+ begin : Sat Apr 14 2012
+ copyright : (C) 2012 by Akarsh Simha
+ email : akarsh.simha at kdemail.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include "sessionsortfilterproxymodel.h"
+
+#include <QTime>
+#include <QModelIndex>
+#include <QSortFilterProxyModel>
+
+SessionSortFilterProxyModel::SessionSortFilterProxyModel( QObject *parent )
+ : QSortFilterProxyModel( parent ) {
+}
+
+bool SessionSortFilterProxyModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const {
+ QVariant leftData = sourceModel()->data( left );
+ QVariant rightData = sourceModel()->data( right );
+ if( leftData.type() == QVariant::Time ) {
+ // We are sorting the observing time.
+ return( leftData.toTime().addSecs( 12 * 3600 ) < rightData.toTime().addSecs( 12 * 3600 ) ); // Note that QTime wraps, so this should work.
+ }
+ else {
+ // Do default sorting for now
+ // TODO: Need to add sorting by RA / Dec / magnitude etc, although these are not as important
+ return QSortFilterProxyModel::lessThan( left, right );
+ }
+}
diff --git a/kstars/tools/sessionsortfilterproxymodel.h b/kstars/tools/sessionsortfilterproxymodel.h
new file mode 100644
index 0000000..31d3ba2
--- /dev/null
+++ b/kstars/tools/sessionsortfilterproxymodel.h
@@ -0,0 +1,48 @@
+/**************************************************************************
+ sessionsortfilterproxymodel.h - K Desktop Planetarium
+ -------------------
+ begin : Sat Apr 14 2012
+ copyright : (C) 2012 by Akarsh Simha
+ email : akarsh.simha at kdemail.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include<QSortFilterProxyModel>
+
+class QModelIndex;
+
+/**
+ *@class SessionSortFilterProxyModel
+ *@short Sort best observation times by reimplementing lessThan() to work on the transit times of objects
+ *
+ * Any observing session starts at about sunset (~ 6 PM local time)
+ * and goes on till sunrise (~ 6 AM local time). Thus, the correct
+ * order to view objects in is to view those with meridian transit
+ * times just after 12 noon local time first, working towards those
+ * that transit in the evening, and finishing the ones that have
+ * meridian transits just before 12 noon at the end of the
+ * session. So, the observing session list should be sorted in a
+ * special manner when sorting by time. This class reimplements
+ * lessThan() in QSortFilterProxyModel to obtain the required sorting.
+ */
+
+class SessionSortFilterProxyModel : public QSortFilterProxyModel
+{
+
+ Q_OBJECT;
+
+ public:
+ SessionSortFilterProxyModel( QObject *parent = 0 );
+
+ protected:
+ bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
+
+};
More information about the Kstars-devel
mailing list