This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
forked from ggalt/Thermostat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermoeventwindow.cpp
125 lines (105 loc) · 3.92 KB
/
thermoeventwindow.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "thermoeventwindow.h"
#include <QQmlEngine>
#include <QQmlContext>
#include <QQuickItem>
#include <QDebug>
#include <QObject>
#include <QQmlProperty>
#include <QString>
thermoEventWindow::thermoEventWindow(QWindow *parent) : QQuickView(parent)
{
setObjectName("thermoEventWindow");
qDebug() << "start of thermoeventwindow";
}
thermoEventWindow::~thermoEventWindow()
{
close();
}
void thermoEventWindow::Init( void )
{
theEvent = new thermostatEvent(this);
engine()->rootContext()->setContextProperty("thermostatEvent", theEvent);
setSource(QUrl(QLatin1String("qrc:/qml/ThermostatEventPage.qml")));
QQuickItem *item = this->rootObject();
QObject::connect(item, SIGNAL(accepted()),
this, SLOT(acceptResult()));
QObject::connect(item, SIGNAL(cancelled()),
this, SLOT(cancelResult()));
this->show();
}
void thermoEventWindow::acceptResult(void)
{
// property alias dayOfWeek: tmblDayOfWeek.dayResult
// property alias hour: tmblHour.hourResult
// property alias minute: tmblMinute.minuteResult
// property alias targetTemp: sliderTemp.value
// property int fanState
// property int heatState
// qDebug() << "Attempt to read property" << QQmlProperty::read(this->rootObject(),"dayOfWeek").toString();
int fanState = QQmlProperty::read(rootObject(),"fanState").toInt();
int heatState = QQmlProperty::read(rootObject(), "heatState").toInt();
QString dayOfWeek = QQmlProperty::read(rootObject(), "dayOfWeek").toString();
QString hour = QQmlProperty::read(rootObject(), "hour").toString();
QString minutes = QQmlProperty::read(rootObject(), "minute").toString();
QString targetTemp = QQmlProperty::read(rootObject(), "targetTemp").toString();
/// FAN
if(fanState==1) // fan is set to "ON"
theEvent->setFanState(thermostatEvent::FanOn);
else // fans is set o "AUTO"
theEvent->setFanState(thermostatEvent::FanAuto);
/// AC / HEAT
if(heatState==1) // AC is ON
theEvent->setCoolingState(thermostatEvent::Cool);
else // HEAT is ON
theEvent->setCoolingState(thermostatEvent::Heat);
// DAY OF WEEK
if( dayOfWeek == "SUN" ) {
theEvent->setDayOfTheWeek(thermostatEvent::Sunday);
}
else if( dayOfWeek == "MON" ) {
theEvent->setDayOfTheWeek(thermostatEvent::Monday);
}
else if( dayOfWeek == "TUE" ) {
theEvent->setDayOfTheWeek(thermostatEvent::Tuesday);
}
else if( dayOfWeek == "WED" ) {
theEvent->setDayOfTheWeek(thermostatEvent::Wednesday);
}
else if( dayOfWeek == "THUR" ) {
theEvent->setDayOfTheWeek(thermostatEvent::Thursday);
}
else if( dayOfWeek == "FRI" ) {
theEvent->setDayOfTheWeek(thermostatEvent::Friday);
}
else if ( dayOfWeek == "SAT" ) {
theEvent->setDayOfTheWeek(thermostatEvent::Saturday);
}
else if( dayOfWeek == "ALL" ) {
theEvent->setDayOfTheWeek(thermostatEvent::AllWeek);
}
else if( dayOfWeek == "WKND" ) {
theEvent->setDayOfTheWeek(thermostatEvent::Weekend);
}
else if( dayOfWeek == "WDYS" ) {
theEvent->setDayOfTheWeek(thermostatEvent::WeekDays);
} else {
qDebug() << "Day of Week out of range";
}
QTime t;
int hh = hour.left(2).toInt();
if(hour.contains("PM"))
hh += 12;
int mm = minutes.toInt();
t.setHMS(hh,mm,0,0);
theEvent->setStartTime(t);
theEvent->setTargetTemp(targetTemp.toInt());
qDebug() << "Complete Event -- Start Time:" << theEvent->startTime() << "Day of Week" <<
theEvent->dayOfTheWeek() << "Target temp:" << theEvent->targetTemp() <<
"Fan State:" << theEvent->fanState() << "Heat State:" << theEvent->coolingState();
emit addEvent(theEvent);
this->deleteLater();
}
void thermoEventWindow:: cancelResult(void)
{
this->deleteLater();
}