File: timemodel.cpp

package info (click to toggle)
qt6-remoteobjects 6.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,812 kB
  • sloc: cpp: 20,883; sh: 29; makefile: 26
file content (45 lines) | stat: -rw-r--r-- 1,079 bytes parent folder | download | duplicates (2)
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
// Copyright (C) 2017 Ford Motor Company
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include "timemodel.h"

MinuteTimer::MinuteTimer(QObject *parent) : MinuteTimerSimpleSource(parent), zone(0)
{
    time = QTime::currentTime();
    setHour(time.hour());
    setMinute(time.minute());
    timer.start(60000-time.second()*1000, this);
}

MinuteTimer::~MinuteTimer()
{
    timer.stop();
}

//![0]
void MinuteTimer::timerEvent(QTimerEvent *)
{
    QTime now = QTime::currentTime();
    if (now.second() == 59 && now.minute() == time.minute() && now.hour() == time.hour()) {
        // just missed time tick over, force it, wait extra 0.5 seconds
        time = time.addSecs(60);
        timer.start(60500, this);
    } else {
        time = now;
        timer.start(60000-time.second()*1000, this);
    }
    qDebug()<<"Time"<<time;
    setHour(time.hour());
    setMinute(time.minute());
    emit timeChanged();
}
//![0]

void MinuteTimer::SetTimeZone(const int &zn)
{
    qDebug()<<"SetTimeZone"<<zn;
    if (zn != zone)
    {
        zone = zn;
    }
}