1 /**************************************************************************
4 Copyright (C) 2010 Heli Hyvättinen
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **************************************************************************/
26 #include "currentalertstablemodel.h"
29 Timer::Timer(QObject *parent) :
34 _actualTimer.setInterval(1000); // 1 s
35 connect(&_actualTimer, SIGNAL(timeout()), this, SLOT(secondPassed()));
41 int Timer::getOriginalTimeInSeconds()
46 void Timer::setOriginalTimeInSeconds(int seconds)
48 _originalTime = seconds;
51 int Timer::getRemainingTimeInSeconds()
53 return _remainingTime;
56 QString Timer::getAlertText()
61 void Timer::setAlertText(QString text)
66 void Timer::secondPassed()
69 emit remainingTimeChanged();
71 if (_remainingTime == 0)
74 emit alert(whereAmI());
75 qDebug() << "alerting";
82 _remainingTime = _originalTime;
91 _remainingTime = 0; //Stopped timer shows 00:00:00 (which unfortunately makes it red...)
103 bool Timer::isAlerting()
108 QModelIndex Timer::whereAmI()
112 QObject * p_parent = parent();
115 CurrentAlertsTableModel* p_parentModel = qobject_cast<CurrentAlertsTableModel *> (p_parent);
117 if (p_parentModel == NULL) //If no parent or parent is not of right class, return an invalid index
118 return QModelIndex();
121 return p_parentModel->giveIndexForTimer(this);