From 1d0a858df6985b6a2accd2a68317bae019e47be4 Mon Sep 17 00:00:00 2001 From: Damien Date: Sat, 21 Jan 2012 21:16:35 +0000 Subject: [PATCH] Reorganise intervals by drag and drop The interval view now allows the user to drag and drop intervals up and down in the list. We could extend the drag and drop of intervals to support analysis of segments/intervals from multiple rides in the future too. Fixes #405. --- src/AllPlotWindow.cpp | 1 + src/BestIntervalDialog.cpp | 1 + src/IntervalTreeView.cpp | 41 ++++++++++++++++++++++++++++++++++++ src/IntervalTreeView.h | 43 ++++++++++++++++++++++++++++++++++++++ src/MainWindow.cpp | 8 ++++++- src/MainWindow.h | 3 ++- src/src.pro | 2 ++ 7 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/IntervalTreeView.cpp create mode 100644 src/IntervalTreeView.h diff --git a/src/AllPlotWindow.cpp b/src/AllPlotWindow.cpp index 75f69688e..67b0dd1a5 100644 --- a/src/AllPlotWindow.cpp +++ b/src/AllPlotWindow.cpp @@ -1011,6 +1011,7 @@ AllPlotWindow::setEndSelection(AllPlot* plot, double xValue, bool newInterval, Q QTreeWidgetItem *last = new IntervalItem(ride->ride(), name, duration1, duration2, distance1, distance2, allIntervals->childCount()+1); + last->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); allIntervals->addChild(last); // select this new interval diff --git a/src/BestIntervalDialog.cpp b/src/BestIntervalDialog.cpp index 202b53325..69f8f236a 100644 --- a/src/BestIntervalDialog.cpp +++ b/src/BestIntervalDialog.cpp @@ -326,6 +326,7 @@ BestIntervalDialog::addClicked() ride->timeToDistance(start), ride->timeToDistance(stop), allIntervals->childCount()+1); + last->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); // add allIntervals->addChild(last); } diff --git a/src/IntervalTreeView.cpp b/src/IntervalTreeView.cpp new file mode 100644 index 000000000..664ccc423 --- /dev/null +++ b/src/IntervalTreeView.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012 Damien Grauser (Damien.Grauser@pev-geneve.ch) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "IntervalTreeView.h" +#include "IntervalItem.h" +#include "MainWindow.h" + + +IntervalTreeView::IntervalTreeView(MainWindow *mainWindow) : mainWindow(mainWindow) +{ + setDragDropMode(QAbstractItemView::InternalMove); + setDragDropOverwriteMode(true); + setDropIndicatorShown(true); + invisibleRootItem()->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); +} + +void +IntervalTreeView::dropEvent(QDropEvent* event) +{ + IntervalItem* item1 = (IntervalItem *)itemAt(event->pos()); + QTreeWidget::dropEvent(event); + IntervalItem* item2 = (IntervalItem *)itemAt(event->pos()); + + if (item1==topLevelItem(0) || item1 != item2) + QTreeWidget::itemChanged(item2, 0); +} diff --git a/src/IntervalTreeView.h b/src/IntervalTreeView.h new file mode 100644 index 000000000..4a411374a --- /dev/null +++ b/src/IntervalTreeView.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012 Damien Grauser (Damien.Grauser@pev-geneve.ch) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _GC_IntervalTreeView_h +#define _GC_IntervalTreeView_h 1 +#include "GoldenCheetah.h" + +#include + +class MainWindow; + +class IntervalTreeView : public QTreeWidget +{ + Q_OBJECT; + + public: + IntervalTreeView(MainWindow *main); + + protected: + MainWindow *mainWindow; + + void dropEvent(QDropEvent* event); + + + + +}; +#endif // _GC_IntervalTreeView_h diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 001c5a8e7..ce7726cd4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -33,6 +33,7 @@ #include "ManualRideDialog.h" #include "RideItem.h" #include "IntervalItem.h" +#include "IntervalTreeView.h" #include "IntervalSummaryWindow.h" #ifdef GC_HAVE_ICAL #include "DiaryWindow.h" @@ -381,7 +382,7 @@ MainWindow::MainWindow(const QDir &home) : // INTERVALS intervalSummaryWindow = new IntervalSummaryWindow(this); - intervalWidget = new QTreeWidget(); + intervalWidget = new IntervalTreeView(this); intervalWidget->setColumnCount(1); intervalWidget->setIndentation(5); intervalWidget->setSortingEnabled(false); @@ -394,6 +395,8 @@ MainWindow::MainWindow(const QDir &home) : intervalWidget->setFrameStyle(QFrame::NoFrame); allIntervals = new QTreeWidgetItem(intervalWidget, FOLDER_TYPE); + allIntervals->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); + allIntervals->setText(0, tr("Intervals")); intervalWidget->expandItem(allIntervals); @@ -892,6 +895,7 @@ MainWindow::rideTreeWidgetSelectionChanged() selected->timeToDistance(intervals.at(i).start), selected->timeToDistance(intervals.at(i).stop), allIntervals->childCount()+1); + add->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); allIntervals->addChild(add); } } @@ -1653,6 +1657,7 @@ MainWindow::addIntervalForPowerPeaksForSecs(RideFile *ride, int windowSizeSecs, ride->timeToDistance(i.start), ride->timeToDistance(i.stop), allIntervals->childCount()+1); + peak->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); allIntervals->addChild(peak); } @@ -1779,6 +1784,7 @@ MainWindow::intervalTreeWidgetSelectionChanged() intervalSelected(); } + /*---------------------------------------------------------------------- * Utility *--------------------------------------------------------------------*/ diff --git a/src/MainWindow.h b/src/MainWindow.h index 9ad674171..ba8518213 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -28,6 +28,7 @@ #include #include "RideItem.h" #include "IntervalItem.h" +#include "IntervalTreeView.h" #include "GcWindowRegistry.h" #include "QuarqdClient.h" #include "RealtimeData.h" @@ -358,7 +359,7 @@ class MainWindow : public QMainWindow QSplitter *metaSplitter; QTreeWidget *treeWidget; QSplitter *intervalSplitter; - QTreeWidget *intervalWidget; + IntervalTreeView *intervalWidget; // Miscellany QuarqdClient *client; diff --git a/src/src.pro b/src/src.pro index fe906c324..d114c5a31 100644 --- a/src/src.pro +++ b/src/src.pro @@ -241,6 +241,7 @@ HEADERS += \ HrPwWindow.h \ IntervalItem.h \ IntervalSummaryWindow.h \ + IntervalTreeView.h \ JsonRideFile.h \ LogTimeScaleDraw.h \ LogTimeScaleEngine.h \ @@ -421,6 +422,7 @@ SOURCES += \ HrPwWindow.cpp \ IntervalItem.cpp \ IntervalSummaryWindow.cpp \ + IntervalTreeView.cpp \ LogTimeScaleDraw.cpp \ LogTimeScaleEngine.cpp \ LTMCanvasPicker.cpp \