-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchedulerModel.cpp
75 lines (57 loc) · 2.29 KB
/
SchedulerModel.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// SchedulerModel.cpp
// Scheduler
//
// Created by David Flores on 1/23/16.
// Copyright © 2016 David Flores. All rights reserved.
//
#include "stdafx.h"
#include "SchedulerModel.h"
#include "SchedulerModelIndex.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static const int g_kiMinuteQuantum = 30;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SchedulerModel::SchedulerModel()
{
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SchedulerModel::~SchedulerModel()
{
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
size_t
SchedulerModel::GetColumnCount()
{
return 1;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InfiniteModelIndex*
SchedulerModel::CreateInitialModelIndex()
{
QDateTime dateTimeCurrent(QDateTime::currentDateTime());
QDate dateCurrent(dateTimeCurrent.date());
QTime timeCurrent(dateTimeCurrent.time());
int iCurrentMinute = timeCurrent.minute();
QTime timeCurrentFloored(timeCurrent.hour(), iCurrentMinute - (iCurrentMinute % g_kiMinuteQuantum));
return new SchedulerModelIndex(QDateTime(dateCurrent, timeCurrentFloored));
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InfiniteModelIndex*
SchedulerModel::CreateIndexBeforeIndex(const InfiniteModelIndex* pNextModelIndex)
{
if ( pNextModelIndex == nullptr )
return nullptr;
assert(dynamic_cast<const SchedulerModelIndex*>(pNextModelIndex) != nullptr);
const SchedulerModelIndex* pNextSchedulerModelIndex = static_cast<const SchedulerModelIndex*>(pNextModelIndex);
return new SchedulerModelIndex(pNextSchedulerModelIndex->GetDateTime().addSecs(-60*g_kiMinuteQuantum));
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InfiniteModelIndex*
SchedulerModel::CreateIndexAfterIndex(const InfiniteModelIndex* pPreviousModelIndex)
{
if ( pPreviousModelIndex == nullptr )
return nullptr;
assert(dynamic_cast<const SchedulerModelIndex*>(pPreviousModelIndex) != nullptr);
const SchedulerModelIndex* pPreviousSchedulerModelIndex = static_cast<const SchedulerModelIndex*>(pPreviousModelIndex);
return new SchedulerModelIndex(pPreviousSchedulerModelIndex->GetDateTime().addSecs(60*g_kiMinuteQuantum));
}