//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();
}
- qDebug () << timeAsText;
+// qDebug () << timeAsText;
- return timeAsText;
+ return timeAsText;
case statusColumnNumber_:
//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";
+// qDebug() << "black background";
return QBrush (QColor(Qt::black));
}
else
{
- qDebug() << "red background";
+// qDebug() << "red background";
return QBrush (QColor(Qt::red));
}
default:
foreach (Timer* timer, timers)
{
connect (timer,SIGNAL(remainingTimeChanged()),this,SLOT(refreshTimeColumn()));
- qDebug() << "timer connected";
+// qDebug() << "timer connected";
timer->setParent(this); //The model becomes the timers parent giving the timer access to model
}
+
+ int nextRow = rowCount(QModelIndex()); //As row numbering starts from zero, number of the rows is the row number of the row after current ones
+ int lastRow = nextRow + timers.length()-1;
+ beginInsertRows(QModelIndex(),nextRow,lastRow);
currentTimers_.append(timers);
- qDebug() << "Timers should be appended";
- reset();
+ endInsertRows();
+// qDebug() << "Timers should be appended";
+// reset();
}
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";
+// qDebug() << "Refresh time column";
}
}
return false;
}
+
+void CurrentAlertsTableModel::removeTimer(QModelIndex index)
+{
+ if (index.isValid())
+ {
+ int row = index.row();
+ beginRemoveRows(QModelIndex(),row,row);
+ Timer* p_timer = currentTimers_.takeAt(row);
+ endRemoveRows();
+ delete p_timer;
+ }
+}
ui->setupUi(this);
-
-
- connect(ui->CreateNewScheduleButton, SIGNAL (pressed()), this, SLOT (newTimerSequence()));
-
-
//alerts' tableview setup
ui->ComingAlertsTableView->setModel(&model_);
ui->ComingAlertsTableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->ComingAlertsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
- ui->ComingAlertsTableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
+ ui->ComingAlertsTableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
+ ui->ComingAlertsTableView->horizontalHeader()->resizeSection(0,460);
+ ui->ComingAlertsTableView->horizontalHeader()->resizeSection(1,140);
+ ui->ComingAlertsTableView->horizontalHeader()->resizeSection(2,100);
+
+ ui->ComingAlertsTableView->verticalHeader()->setResizeMode(QHeaderView::Fixed);
+ ui->ComingAlertsTableView->verticalHeader()->setDefaultSectionSize(40);
+
+
+
+
ui->ComingAlertsTableView->horizontalHeader()->hide();
+ ui->ComingAlertsTableView->setWordWrap(true);
- //Buttons used to reacting an alarm are hidden by default
+ //Buttons used when a timer is selected are disabled by default and enabled upon selection
disableSelectionDependentButtons();
-
connect(ui->ComingAlertsTableView->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this,SLOT(timerSelected(QItemSelection,QItemSelection)));
+ //connect buttons to respective functions
+ connect(ui->CreateNewScheduleButton, SIGNAL (pressed()), this, SLOT (newTimerSequence()));
connect(ui->DoneButton,SIGNAL(clicked()),this,SLOT(stop()));
connect(ui->RestartButton,SIGNAL(clicked()),this,SLOT(restart()));
connect(ui->SnoozeButton,SIGNAL(clicked()),this, SLOT(snooze()));
+ connect(ui->RemoveButton,SIGNAL(clicked()),this,SLOT(remove()));
// menu setup
if (createdialog.exec() == QDialog::Accepted) //if user pressed OK
{
+ //get user input from the dialog
- QList<Timer *> alltimers = createdialog.getTimers(); //get user input from the dialog
- Timer* timer1 = alltimers.at(0); // take first timer (currently the only one!)
+ QList<Timer *> alltimers = createdialog.getTimers();
+
+ // take first timer (currently the only one!)
+
+
+ Timer* timer1 = alltimers.at(0);
+
+
+ //connect alert
- timer1->start();
connect(timer1,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex)));
+ //Disable buttons, as selection is cleared when view is refreshed to show the new timer
+
+ disableSelectionDependentButtons();
- model_.addTimers(alltimers); // give timers to the model
- // ui->ComingAlertsTableView->resizeColumnsToContents();
+ // give timers to the model
+ model_.addTimers(alltimers);
- //Disable buttons, as selection is cleared when view is refreshed to show the new timer
- disableSelectionDependentButtons();
+ //start the timer when it's safely in the model (consider moving this to the model's addTimers function)
+ timer1->start();
+
}
// if cancelled, do nothing
// The alerting timer is selected
ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
- qDebug() << "Should be selected now";
+// qDebug() << "Should be selected now";
//Snooze button is enabled
ui->SnoozeButton->setEnabled(true);
- //The alert sound is played
+ //The alert sound is played (consider moving this operation inside timer, as now stopping one alert will silence all alerting alerts)
alertSound_.play();
{
ui->DoneButton->setEnabled(true);
ui->RestartButton->setEnabled(true);
+ ui->RemoveButton->setEnabled(true);
//enabled only when alerting
}
ui->SnoozeButton->setDisabled(true);
alertSound_.stop();
+ qDebug() << "Stopped.";
}
QModelIndex KitchenAlertMainWindow::selectedRow()
void KitchenAlertMainWindow::openAbout()
{
- QMessageBox::about(this,tr("About KitchenAlert"),tr("<p>Version 0.1"
+ QMessageBox::about(this,tr("About KitchenAlert"),tr("<p>Version 0.1.1"
"<p>Copyright © Heli Hyvättinen 2010"
"<p>License: General Public License v3"
"<p>Bugtracker and project page: https://garage.maemo.org/projects/kitchenalert/"));
ui->DoneButton->setDisabled(true);
ui->SnoozeButton->setDisabled(true);
ui->RestartButton->setDisabled(true);
+ ui->RemoveButton->setDisabled(true);
+}
+void KitchenAlertMainWindow::remove()
+{
+ QModelIndex row = selectedRow();
+ if (row.isValid())
+ {
+ model_.removeTimer(row);
+ alertSound_.stop();
+ ui->ComingAlertsTableView->clearSelection();
+ disableSelectionDependentButtons();
+ }
}