X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fcurrentalertstablemodel.cpp;h=62e83274c677e1fb10590aab4a252d9113898c6e;hb=383c3ee723d6ff55d01bcc83a8f98fab1b32cc03;hp=c4dadccfd2e6fa1fb4f117352389b6f0b3f8f145;hpb=55e83dd6677893a7d2ed9de67c675fd9b45a68bc;p=kitchenalert diff --git a/src/currentalertstablemodel.cpp b/src/currentalertstablemodel.cpp index c4dadcc..62e8327 100644 --- a/src/currentalertstablemodel.cpp +++ b/src/currentalertstablemodel.cpp @@ -1,7 +1,7 @@ /************************************************************************** KitchenAlert - Copyright (C) 2010 Heli Hyvättinen + Copyright (C) 2010-2011 Heli Hyvättinen This file is part of KitchenAlert. @@ -45,9 +45,9 @@ int CurrentAlertsTableModel::rowCount(const QModelIndex &parent) const //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(); } @@ -84,16 +84,16 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const 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); } @@ -138,7 +138,7 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const - qDebug () << timeAsText; +// qDebug () << timeAsText; return timeAsText; @@ -165,24 +165,24 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const - 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(); @@ -195,26 +195,43 @@ QVariant CurrentAlertsTableModel::data(const QModelIndex &index, int role) const -void CurrentAlertsTableModel::addTimers(QList timers) +void CurrentAlertsTableModel::addTimers(QList 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 + } @@ -228,7 +245,7 @@ void CurrentAlertsTableModel::startTimer(QModelIndex index) if (ptimer != NULL) { ptimer->start(); - refreshTimeColumn(); + refreshTimeAndStatusColumns(); } } @@ -238,7 +255,7 @@ void CurrentAlertsTableModel::stopTimer(QModelIndex index) if (ptimer != NULL) { ptimer->stop(); - refreshTimeColumn(); + refreshTimeAndStatusColumns(); } } @@ -248,7 +265,7 @@ void CurrentAlertsTableModel::snoozeTimer(QModelIndex index) if (ptimer != NULL) { ptimer->snooze(); - refreshTimeColumn(); + refreshTimeAndStatusColumns(); } } @@ -276,8 +293,11 @@ void CurrentAlertsTableModel::setUpdateViewOnChanges(bool update) { 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) { @@ -291,3 +311,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); +} +