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.
This commit is contained in:
Damien
2012-01-21 21:16:35 +00:00
committed by Mark Liversedge
parent 8eb349ded0
commit 1d0a858df6
7 changed files with 97 additions and 2 deletions

View File

@@ -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

View File

@@ -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);
}

41
src/IntervalTreeView.cpp Normal file
View File

@@ -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);
}

43
src/IntervalTreeView.h Normal file
View File

@@ -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 <QtGui>
class MainWindow;
class IntervalTreeView : public QTreeWidget
{
Q_OBJECT;
public:
IntervalTreeView(MainWindow *main);
protected:
MainWindow *mainWindow;
void dropEvent(QDropEvent* event);
};
#endif // _GC_IntervalTreeView_h

View File

@@ -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
*--------------------------------------------------------------------*/

View File

@@ -28,6 +28,7 @@
#include <qwt_plot_curve.h>
#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;

View File

@@ -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 \