-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchedulerController.cpp
82 lines (64 loc) · 2.32 KB
/
SchedulerController.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
76
77
78
79
80
81
82
//
// SchedulerController.cpp
// Scheduler
//
// Created by David Flores on 1/23/16.
// Copyright © 2016 David Flores. All rights reserved.
//
#include "stdafx.h"
#include "SchedulerController.h"
#include "CalendarWidget.h"
#include "InfiniteModelIndex.h"
#include "InfiniteTreeView.h"
#include "SchedulerModel.h"
#include "SchedulerModelIndex.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SchedulerController::SchedulerController(CalendarWidget* pCalendarWidget, InfiniteTreeView* pInfiniteTreeView) :
m_pCalendarWidget(pCalendarWidget),
m_pInfiniteTreeView(pInfiniteTreeView),
m_pSchedulerModel(new SchedulerModel),
m_bCurrentlyDisplayingDate(false),
m_bCurrentlyDisplayingIndexRange(false)
{
m_pCalendarWidget->SetDelegate(this);
m_pInfiniteTreeView->SetController(this);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SchedulerController::~SchedulerController()
{
delete m_pSchedulerModel;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void
SchedulerController::DisplayingDate(const QDate& date)
{
if ( m_bCurrentlyDisplayingIndexRange )
return;
m_bCurrentlyDisplayingDate = true;
QDateTime dateTime(date, QTime(0, 0));
m_pInfiniteTreeView->ScrollToIndex(new SchedulerModelIndex(dateTime));
m_bCurrentlyDisplayingDate = false;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InfiniteModel*
SchedulerController::GetModel() const
{
return m_pSchedulerModel;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void
SchedulerController::DisplayingIndexRange(InfiniteModelIndex* pFirstVisibleIndex, InfiniteModelIndex*)
{
if ( m_bCurrentlyDisplayingDate )
return;
if ( pFirstVisibleIndex == nullptr )
return;
m_bCurrentlyDisplayingIndexRange = true;
assert(dynamic_cast<const SchedulerModelIndex*>(pFirstVisibleIndex) != nullptr);
const SchedulerModelIndex* pFirstVisibleSchedulerModelIndex = static_cast<const SchedulerModelIndex*>(pFirstVisibleIndex);
QDateTime dateTimeFirstVisible = pFirstVisibleSchedulerModelIndex->GetDateTime();
QDate dateFirstVisible = dateTimeFirstVisible.date();
if ( m_pCalendarWidget->selectedDate() != dateFirstVisible )
m_pCalendarWidget->setSelectedDate(dateFirstVisible);
m_bCurrentlyDisplayingIndexRange = false;
}