Kstars

sessionsortfilterproxymodel.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Akarsh Simha <akarsh.simha@kdemail.net>
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
13SessionSortFilterProxyModel::SessionSortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
14{
15}
16
17bool 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}
virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const const
QTime addSecs(int s) const const
Type type() const const
void * data()
QTime toTime() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.