//No need to mind about the parameter, it has no meaning for table models.
- qDebug () << "rowCount asked";
+// qDebug () << "rowCount asked";
- qDebug () << currentTimers_.length();
+// qDebug () << currentTimers_.length();
return currentTimers_.length();
}
case alertTextColumnNumber_:
- return int (Qt::AlignLeft || Qt::AlignVCenter);
+ return int (Qt::AlignLeft | Qt::AlignVCenter);
case timeRemainingColumnNumber_:
- return int (Qt::AlignRight || Qt::AlignVCenter);
+ return int (Qt::AlignRight | Qt::AlignVCenter);
case statusColumnNumber_:
- return int (Qt::AlignLeft || Qt::AlignVCenter);
+ return int (Qt::AlignLeft | Qt::AlignVCenter);
}
- qDebug () << timeAsText;
+// qDebug () << timeAsText;
return timeAsText;
- case Qt::BackgroundRole :
+// case Qt::BackgroundRole :
- //For some reason, these have no effect at all!!! They are asked by the view though.
+// //For some reason, these have no effect at all!!! They are asked by the view though.
- //No need to care for the column number, all have the same color
+// //No need to care for the column number, all have the same color
- qDebug() << "BackgroundRole asked";
+// qDebug() << "BackgroundRole asked";
- if (currentTimers_.at(index.row())->isAlerting())
- {
- qDebug() << "black background";
- return QBrush (QColor(Qt::black));
- }
- else
- {
- qDebug() << "red background";
- return QBrush (QColor(Qt::red));
- }
+// if (currentTimers_.at(index.row())->isAlerting())
+// {
+// qDebug() << "black background";
+// return QBrush (QColor(Qt::black));
+// }
+// else
+// {
+// qDebug() << "red background";
+// return QBrush (QColor(Qt::red));
+// }
default:
return QVariant();
-void CurrentAlertsTableModel::addTimers(QList <Timer *> timers)
+void CurrentAlertsTableModel::addTimers(QList <Timer *> timers, bool startImmediately)
{
+
+//preparatory work
foreach (Timer* timer, timers)
{
- connect (timer,SIGNAL(remainingTimeChanged()),this,SLOT(refreshTimeColumn()));
- qDebug() << "timer connected";
+ connect (timer,SIGNAL(remainingTimeChanged()),this,SLOT(refreshTimeAndStatusColumns()));
+// qDebug() << "timer connected";
timer->setParent(this); //The model becomes the timers parent giving the timer access to model
}
+
+
+//Add the timers
+
+ beginResetModel();
currentTimers_.append(timers);
- qDebug() << "Timers should be appended";
- reset();
+ endResetModel();
+
+ //start the timers if requested
+
+ if (startImmediately)
+ {
+ foreach (Timer* timer, timers)
+ {
+ timer->start();
+ }
+ }
+
}
-void CurrentAlertsTableModel::refreshTimeColumn()
+void CurrentAlertsTableModel::refreshTimeAndStatusColumns()
{
if (updateViewOnChanges_ == true) //Only update GUI if active to save battery
{
- emit dataChanged(createIndex(0,1),createIndex(rowCount(QModelIndex())-1,1)); //Entire time column refreshed
- qDebug() << "Refresh time column";
+ emit dataChanged(createIndex(0,1),createIndex((rowCount(QModelIndex())-1),2)); //Entire time and status columns refreshed
+
}
if (ptimer != NULL)
{
ptimer->start();
- refreshTimeColumn();
+ refreshTimeAndStatusColumns();
}
}
if (ptimer != NULL)
{
ptimer->stop();
- refreshTimeColumn();
+ refreshTimeAndStatusColumns();
}
}
if (ptimer != NULL)
{
ptimer->snooze();
- refreshTimeColumn();
+ refreshTimeAndStatusColumns();
}
}
{
updateViewOnChanges_ = update;
if (update == true)
- reset(); //Refresh view to catch up with past changes
-}
+ {
+ 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)
{
}
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();
+
+}
+