Kstars

sessionsortfilterproxymodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Akarsh Simha <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "sessionsortfilterproxymodel.h"
8 
9 #include <QTime>
10 #include <QModelIndex>
11 #include <QSortFilterProxyModel>
12 
13 SessionSortFilterProxyModel::SessionSortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
14 {
15 }
16 
17 bool SessionSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
18 {
19  QVariant leftData = sourceModel()->data(left);
20  QVariant rightData = sourceModel()->data(right);
21  if (leftData.type() == QVariant::Time)
22  {
23  // We are sorting the observing time.
24  return (leftData.toTime().addSecs(12 * 3600) <
25  rightData.toTime().addSecs(12 * 3600)); // Note that QTime wraps, so this should work.
26  }
27  else
28  {
29  // Do default sorting for now
30  // TODO: Need to add sorting by RA / Dec / magnitude etc, although these are not as important
31  return QSortFilterProxyModel::lessThan(left, right);
32  }
33 }
QTime addSecs(int s) const const
QVariant::Type type() const const
virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const const
QTime toTime() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.