File: timechartmodel.cpp

package info (click to toggle)
kdiagram 3.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,732 kB
  • sloc: cpp: 52,386; makefile: 7; sh: 2
file content (62 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
 *
 * This file is part of the KD Chart library.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "timechartmodel.h"

TimeChartModel::TimeChartModel( QObject* parent )
    : QSortFilterProxyModel( parent )
{
}

QPair< QDateTime, QDateTime > TimeChartModel::visibleRange() const
{
    return range;
}

void TimeChartModel::setVisibleRange( const QDateTime& start, const QDateTime& end )
{
    const QPair< QDateTime, QDateTime > r = qMakePair( start, end );
    if ( r == range )
        return;

    range = r;
    invalidateFilter();
}

void TimeChartModel::setVisibleStart( const QDateTime& start )
{
    setVisibleRange( start, range.second );
}

void TimeChartModel::setVisibleEnd( const QDateTime& end )
{
    setVisibleRange( range.first, end );
}

/*!
 \reimp
 */
QVariant TimeChartModel::data( const QModelIndex& index, int role ) const
{
    const QVariant v = QSortFilterProxyModel::data( index, role );
    if ( index.column() % 2 != 0 || role != Qt::DisplayRole )
        return v;
    else
        return QDateTime::fromSecsSinceEpoch( 0 ).secsTo( v.toDateTime() ) / 3600.0;
}

/*!
 \reimp
 */
bool TimeChartModel::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const
{
    const QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
    const QDateTime date = index.data().toDateTime();
    return ( date >= range.first || range.first.isNull() ) &&
           ( date <= range.second || range.second.isNull() );
}