From d77c9eeb73d1f26e358704ce14a5069d363b3add Mon Sep 17 00:00:00 2001 From: Damien Date: Wed, 21 Nov 2012 17:49:15 +0100 Subject: [PATCH] Add a column Start Time in the ride navigator fixes #33 --- src/RideNavigator.cpp | 31 +++++++++++++++++++++------ src/RideNavigatorProxy.h | 45 ++++++++++++++++++++++++++++++---------- 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/RideNavigator.cpp b/src/RideNavigator.cpp index 9277e0cf2..5e450e9a4 100644 --- a/src/RideNavigator.cpp +++ b/src/RideNavigator.cpp @@ -182,6 +182,7 @@ RideNavigator::resetView() nameMap.insert("filename", "File"); nameMap.insert("timestamp", "Last updated"); nameMap.insert("ride_date", "Date"); + nameMap.insert("ride_time", "Time"); // virtual columns show time from ride_date nameMap.insert("fingerprint", "Config Checksum"); // add metrics to the map @@ -541,7 +542,7 @@ RideNavigator::borderMenu(const QPoint &pos) connect(insCol, SIGNAL(triggered()), this, SLOT(showColumnChooser())); QAction *toggleGroupBy = new QAction(_groupBy >= 0 ? tr("Do Not Show in Groups") : tr("Show In Groups"), tableView); - toggleGroupBy->setEnabled(true); + toggleGroupBy->setEnabled(column!=1?true:false); // No group for Ride Time menu.addAction(toggleGroupBy); connect(toggleGroupBy, SIGNAL(triggered()), this, SLOT(setGroupByColumn())); @@ -713,7 +714,7 @@ GroupByModel::groupFromValue(QString headingName, QString value, double rank, do } else { - if (headingName == "Date") { + if (headingName == tr("Date")) { // get the date from value string QDateTime dateTime = QDateTime::fromString(value, Qt::ISODate); @@ -731,7 +732,22 @@ GroupByModel::groupFromValue(QString headingName, QString value, double rank, do else { return dateTime.toString("yyyy-MM (MMMM)"); } - } + } /*else if (headingName == tr("Time")) { + + // get the date from value string + QDateTime dateTime = QDateTime::fromString(value, Qt::ISODate); + + if (dateTime.time().hour()>=6 && dateTime.time().hour()<13) + return "Morning"; + else if (dateTime.time().hour()>=13 && dateTime.time().hour()<16) + return "Afternoon"; + else if (dateTime.time().hour()>=16 && dateTime.time().hour()<21) + return "Evening"; + else { + return "Night"; + } + }*/ + // not a metric, i.e. metadata return value; } @@ -764,7 +780,7 @@ RideNavigator::showColumnChooser() void RideNavigator::selectRide(const QModelIndex &index) { - QModelIndex fileIndex = tableView->model()->index(index.row(), 1, index.parent()); + QModelIndex fileIndex = tableView->model()->index(index.row(), 2, index.parent()); // column 2 for filename ? QString filename = tableView->model()->data(fileIndex, Qt::DisplayRole).toString(); main->selectRideFile(filename); @@ -813,7 +829,7 @@ RideNavigator::rideTreeSelectionChanged() QModelIndex group = tableView->model()->index(i,0,QModelIndex()); for (int j=0; jmodel()->rowCount(group); j++) { - QString fileName = tableView->model()->data(tableView->model()->index(j,1, group), Qt::DisplayRole).toString(); + QString fileName = tableView->model()->data(tableView->model()->index(j,2, group), Qt::DisplayRole).toString(); if (fileName == rideItem->fileName) { // we set current index to column 2 (date/time) since we can be guaranteed it is always show (all others are removable) QItemSelection row(tableView->model()->index(j,0,group), @@ -821,7 +837,7 @@ RideNavigator::rideTreeSelectionChanged() tableView->selectionModel()->select(row, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); //tableView->selectionModel()->setCurrentIndex(tableView->model()->index(j,0,group), QItemSelectionModel::NoUpdate); tableView->selectionModel()->setCurrentIndex(tableView->model()->index(j,0,group), QItemSelectionModel::NoUpdate); - tableView->scrollTo(tableView->model()->index(j,2,group), QAbstractItemView::PositionAtCenter); + tableView->scrollTo(tableView->model()->index(j,3,group), QAbstractItemView::PositionAtCenter); active = false; return; } @@ -918,6 +934,9 @@ void NavigatorCellDelegate::paint(QPainter *painter, const QStyleOptionViewItem if (columnName == tr("Date")) { QDateTime dateTime = QDateTime::fromString(value, Qt::ISODate); value = dateTime.toString("MMM d, yyyy"); // same format as ride list + } else if (columnName == tr("Time")) { + QDateTime dateTime = QDateTime::fromString(value, Qt::ISODate); + value = dateTime.toString("hh:mm:ss"); // same format as ride list } else if (columnName == tr("Last updated")) { QDateTime dateTime; dateTime.setTime_t(index.model()->data(index, Qt::DisplayRole).toInt()); diff --git a/src/RideNavigatorProxy.h b/src/RideNavigatorProxy.h index f39f356c9..9212b6a62 100644 --- a/src/RideNavigatorProxy.h +++ b/src/RideNavigatorProxy.h @@ -65,6 +65,9 @@ private: int calendarText; int colorColumn; int fileIndex; + int dateColumn; + + QString starttimeHeader; QList groups; QList groupIndexes; @@ -113,6 +116,10 @@ public: if (model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString() == "ZCalendar_Text") { calendarText = i; } + if (model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString() == "ride_date") { + dateColumn = i; + } + starttimeHeader = "ride_time"; //initialisation with techname } connect(model, SIGNAL(modelReset()), this, SLOT(sourceModelChanged())); @@ -156,7 +163,7 @@ public: } return sourceModel()->index(groupToSourceRow.value(groups[groupNo])->at(proxyIndex.row()), - proxyIndex.column()-1, // accomodate virtual column + proxyIndex.column()-2, // accomodate virtual columns QModelIndex()); } return QModelIndex(); @@ -173,7 +180,7 @@ public: } else { QModelIndex *p = new QModelIndex(createIndex(groupNo, 0, (void*)NULL)); if (sourceIndex.row() > 0 && sourceIndex.row() < sourceRowToGroupRow.size()) - return createIndex(sourceRowToGroupRow[sourceIndex.row()], sourceIndex.column()+1, &p); // accomodate virtual column + return createIndex(sourceRowToGroupRow[sourceIndex.row()], sourceIndex.column()+2, &p); // accomodate virtual columns else return QModelIndex(); } @@ -264,8 +271,20 @@ public: } } else { + // column 1 = ride_time we have to use ride_date + if (proxyIndex.column() == 1) { + QString date; - returning = sourceModel()->data(mapToSource(proxyIndex), role); + // hideous code, sorry + int groupNo = ((QModelIndex*)proxyIndex.internalPointer())->row(); + if (groupNo < 0 || groupNo >= groups.count() || proxyIndex.column() == 0) + date=""; + else date = sourceModel()->data(sourceModel()->index(groupToSourceRow.value(groups[groupNo])->at(proxyIndex.row()), dateColumn)).toString(); + + returning = date;//sourceModel()->data(sourceModel()->index(proxyIndex.row(),dateColumn)).toString(); + } + else + returning = sourceModel()->data(mapToSource(proxyIndex), role); } } else if (proxyIndex.internalPointer() == NULL) { @@ -297,21 +316,25 @@ public: } QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const { - if (section) - return sourceModel()->headerData(section-1, orientation, role); + if (section>1) + return sourceModel()->headerData(section-2, orientation, role); // accomodate virtual columns + else if (section == 1) // return header for virtual column ride_time + return QVariant(starttimeHeader); else return QVariant("*"); } bool setHeaderData (int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole) { - if (section) - return sourceModel()->setHeaderData(section-1, orientation, value, role); + if (section>1) + return sourceModel()->setHeaderData(section-2, orientation, value, role); // accomodate virtual columns + else if (section == 1) // set header for virtual column ride_time + starttimeHeader = value.toString(); else return true; } int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { - return sourceModel()->columnCount(QModelIndex())+1; // accomodate virtual group column + return sourceModel()->columnCount(QModelIndex())+2; // accomodate virtual group column and starttime } int rowCount(const QModelIndex &parent = QModelIndex()) const { @@ -362,9 +385,9 @@ public: void setGroupBy(int column) { // shift down - if (column >= 0) column -= 1; + if (column >= 0) column -= 2; // accomodate virtual column - groupBy = column; // accomodate virtual column + groupBy = column; setGroups(); } @@ -372,7 +395,7 @@ public: if (row == -1) return(""); if (groupBy == -1) return tr("All Activities"); - else return groupFromValue(headerData(groupBy+1, + else return groupFromValue(headerData(groupBy+2, // accomodate virtual column Qt::Horizontal).toString(), sourceModel()->data(sourceModel()->index(row,groupBy)).toString(), rankedRows[row].value, rankedRows.count());