Stopped timers now show full time and "stopped"
[kitchenalert] / src / currentalertstablemodel.cpp
index cc47fd0..d0e70c3 100644 (file)
@@ -1,7 +1,7 @@
 /**************************************************************************
         KitchenAlert
 
-        Copyright (C) 2010  Heli Hyvättinen
+        Copyright (C) 2010-2011  Heli Hyvättinen
 
         This file is part of KitchenAlert.
 
@@ -113,15 +113,26 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const
                 case timeRemainingColumnNumber_:
 
 
+                    if (currentTimers_.at(index.row())->isRunning()) //timer running
+                    {
+
 
                     allseconds = currentTimers_.at(index.row())->getRemainingTimeInSeconds();
 
 
-                    if (allseconds < 0)
-                    {
-                        timeAsText = tr("-", "negative sign");
-                        allseconds = -allseconds;
+                        if (allseconds < 0)
+                        {
+                            timeAsText = tr("-", "negative sign");
+                            allseconds = -allseconds;
 
+                        }
+                    }
+
+                    else //timer stopped or never started
+
+                    {
+                        //use original time
+                        allseconds = currentTimers_.at(index.row())->getOriginalTimeInSeconds();
                     }
 
                     hoursOnly.setNum( allseconds/(60*60));
@@ -146,7 +157,10 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const
                 case statusColumnNumber_:
 
                     if (currentTimers_.at(index.row())->isAlerting() == true)
-                        return QString("ALERT!");
+                        return tr("ALERT!");
+
+                    if (!currentTimers_.at(index.row())->isRunning())
+                        return tr("stopped");
 
                     else return QString();
 
@@ -293,8 +307,11 @@ void CurrentAlertsTableModel::setUpdateViewOnChanges(bool update)
 {
     updateViewOnChanges_ = update;
     if (update == true)
+    {
         refreshTimeAndStatusColumns(); //Refresh to catch up with past changes
-}
+//        qDebug() << "Just refreshed time and status colums after returning to the app";
+    }
+    }
 
 bool CurrentAlertsTableModel::isThisTimerAlerting(QModelIndex index)
 {
@@ -308,3 +325,22 @@ bool CurrentAlertsTableModel::isThisTimerAlerting(QModelIndex index)
     }
     return false;
 }
+
+void CurrentAlertsTableModel::removeTimer(QModelIndex index)
+{
+    if (index.isValid() == false)
+        return;
+
+    int i = index.row();
+    beginRemoveRows(QModelIndex(),i,i);
+    Timer * p_timer = currentTimers_.takeAt(i);
+    delete p_timer;
+    endRemoveRows();
+
+}
+
+bool CurrentAlertsTableModel::saveTimer(QModelIndex index, QString filename)
+{
+    return currentTimers_.at(index.row())->save(filename);
+}
+