summaryrefslogtreecommitdiffstats
path: root/pokemod/Time.cpp
blob: 90488e1fa1c51d7ea8c74a66510b93043f8c48f3 (plain)
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
126
/*
 * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// Header include
#include "Time.h"

// Pokemod includes
#include "Pokemod.h"

Time::Time(const Time& time) :
        Object("Time", time.parent(), time.id())
{
    *this = time;
}

Time::Time(const Pokemod* parent, const int id) :
        Object("Time", parent, id),
        m_name(""),
        m_hour(0),
        m_minute(0)
{
}

Time::Time(const Time& time, const Pokemod* parent, const int id) :
        Object("Time", parent, id)
{
    *this = time;
}

Time::Time(const QDomElement& xml, const Pokemod* parent, const int id) :
        Object("Time", parent, id)
{
    load(xml, id);
}

void Time::validate()
{
    if (m_name.isEmpty())
        emit(error("Name is empty"));
    TEST(setHour, hour);
    TEST(setMinute, minute);
}

void Time::load(const QDomElement& xml, int id)
{
    LOAD_ID();
    LOAD(QString, name);
    LOAD(int, hour);
    LOAD(int, minute);
}

QDomElement Time::save() const
{
    SAVE_CREATE();
    SAVE(QString, name);
    SAVE(int, hour);
    SAVE(int, minute);
    return xml;
}

void Time::setName(const QString& name)
{
    m_name = name;
    emit(changed());
}

void Time::setHour(const int hour)
{
    if (24 <= hour)
    {
        emit(error(bounds("hour")));
        return;
    }
    m_hour = hour;
    emit(changed());
}

void Time::setMinute(const int minute)
{
    if (60 <= minute)
    {
        emit(error(bounds("minute")));
        return;
    }
    m_minute = minute;
    emit(changed());
}

QString Time::name() const
{
    return m_name;
}

int Time::hour() const
{
    return m_hour;
}

int Time::minute() const
{
    return m_minute;
}

Time& Time::operator=(const Time& rhs)
{
    if (this == &rhs)
        return *this;
    COPY(name);
    COPY(hour);
    COPY(minute);
    return *this;
}