mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Allow drag and drop ride for compare
.. drag and drop a ride into the compare pane to get the entire ride rather than an interval.
This commit is contained in:
@@ -138,8 +138,7 @@ RideFileTableModel::flags(const QModelIndex &index) const
|
||||
if (!index.isValid())
|
||||
return Qt::ItemIsEditable;
|
||||
else
|
||||
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable |
|
||||
Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
QVariant
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <QtGui>
|
||||
#include <QString>
|
||||
#include <QTreeView>
|
||||
|
||||
RideNavigator::RideNavigator(Context *context, bool mainwindow) : context(context), active(false), _groupBy(-1)
|
||||
{
|
||||
@@ -66,7 +67,7 @@ RideNavigator::RideNavigator(Context *context, bool mainwindow) : context(contex
|
||||
#endif
|
||||
|
||||
// get setup
|
||||
tableView = new QTreeView;
|
||||
tableView = new RideTreeView;
|
||||
delegate = new NavigatorCellDelegate(this);
|
||||
tableView->setAnimated(true);
|
||||
tableView->setItemDelegate(delegate);
|
||||
@@ -89,6 +90,7 @@ RideNavigator::RideNavigator(Context *context, bool mainwindow) : context(contex
|
||||
tableView->viewport()->installEventFilter(this);
|
||||
tableView->setMouseTracking(true);
|
||||
tableView->setFrameStyle(QFrame::NoFrame);
|
||||
tableView->setAcceptDrops(true);
|
||||
|
||||
// good to go
|
||||
tableView->show();
|
||||
@@ -1063,3 +1065,14 @@ RideNavigator::showTreeContextMenuPopup(const QPoint &pos)
|
||||
// so the activity log for example doesn't have a context menu now
|
||||
emit customContextMenuRequested(tableView->mapToGlobal(pos+QPoint(0,tableView->header()->geometry().height())));
|
||||
}
|
||||
|
||||
RideTreeView::RideTreeView()
|
||||
{
|
||||
setDragDropMode(QAbstractItemView::InternalMove);
|
||||
setDragEnabled(true);
|
||||
setDragDropOverwriteMode(false);
|
||||
setDropIndicatorShown(true);
|
||||
#ifdef Q_OS_MAC
|
||||
setAttribute(Qt::WA_MacShowFocusRect, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include <QTableView>
|
||||
#include <QHeaderView>
|
||||
#include <QScrollBar>
|
||||
#include <QDragMoveEvent>
|
||||
#include <QDragEnterEvent>
|
||||
|
||||
class NavigatorCellDelegate;
|
||||
class GroupByModel;
|
||||
@@ -43,6 +45,7 @@ class BUGFIXQSortFilterProxyModel;
|
||||
class DataFilter;
|
||||
class GcMiniCalendar;
|
||||
class SearchBox;
|
||||
class RideTreeView;
|
||||
|
||||
//
|
||||
// The RideNavigator
|
||||
@@ -77,7 +80,7 @@ class RideNavigator : public GcWindow
|
||||
void borderMenu(const QPoint &pos);
|
||||
|
||||
// so the cell delegate can access
|
||||
QTreeView *tableView; // the view
|
||||
RideTreeView *tableView; // the view
|
||||
|
||||
Context *context;
|
||||
|
||||
@@ -244,4 +247,21 @@ private:
|
||||
QGridLayout *buttons;
|
||||
QSignalMapper *clicked;
|
||||
};
|
||||
|
||||
class RideTreeView : public QTreeView
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
RideTreeView();
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *e) {
|
||||
e->accept();
|
||||
}
|
||||
|
||||
void dragMoveEvent(QDragMoveEvent *e) {
|
||||
e->accept();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
|
||||
#include <QtGui>
|
||||
#include "RideNavigator.h"
|
||||
#include "RideItem.h"
|
||||
#include "RideFile.h"
|
||||
|
||||
// Proxy model for doing groupBy
|
||||
class GroupByModel : public QAbstractProxyModel
|
||||
@@ -191,13 +193,58 @@ public:
|
||||
// selectable. If we don't do that then the arrow keys don't work
|
||||
// since there are no valid rows to cursor up or down to.
|
||||
Qt::ItemFlags flags (const QModelIndex &/*index*/) const {
|
||||
|
||||
//if (index.internalPointer() == NULL) {
|
||||
// return Qt::ItemIsEnabled;
|
||||
//} else {
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
|
||||
//}
|
||||
}
|
||||
|
||||
QStringList mimeTypes() const {
|
||||
|
||||
QStringList returning;
|
||||
returning << "application/x-gc-intervals";
|
||||
|
||||
return returning;
|
||||
}
|
||||
|
||||
QMimeData *mimeData (const QModelIndexList &indexes) const {
|
||||
|
||||
QMimeData *returning = new QMimeData;
|
||||
|
||||
// we need to pack into a byte array
|
||||
QByteArray rawData;
|
||||
QDataStream stream(&rawData, QIODevice::WriteOnly);
|
||||
stream.setVersion(QDataStream::Qt_4_6);
|
||||
|
||||
// pack data
|
||||
stream << (quint64)(rideNavigator->context); // where did this come from?
|
||||
|
||||
RideItem *ride = rideNavigator->context->ride; // the currently selected ride
|
||||
|
||||
// if this ride has any kind of content
|
||||
if (ride && ride->ride() && ride->ride()->dataPoints().count() > 1) {
|
||||
|
||||
// serialize
|
||||
stream << (int)1;
|
||||
stream << QString(tr("Entire Ride"));
|
||||
stream << (quint64)(ride->ride()); // ridefile
|
||||
stream << (quint64)ride->ride()->dataPoints().first()->secs
|
||||
<< (quint64)ride->ride()->dataPoints().last()->secs;
|
||||
stream << (quint64)ride->ride()->dataPoints().first()->km
|
||||
<< (quint64)ride->ride()->dataPoints().last()->km;
|
||||
stream << (quint64)1;
|
||||
|
||||
} else {
|
||||
stream << (int)0; // nothing
|
||||
}
|
||||
|
||||
// and return as mime data
|
||||
returning->setData("application/x-gc-intervals", rawData);
|
||||
return returning;
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const {
|
||||
|
||||
// this is never called ! (QT-BUG)
|
||||
@@ -209,7 +256,7 @@ public:
|
||||
QVariant returning;
|
||||
|
||||
// if we are not at column 0 or we have a parent
|
||||
//if (proxyIndex.internalPointer() != NULL || proxyIndex.column() > 0) {
|
||||
//if (proxyIndex.internalPointer() != NULL || proxyIndex.column() > 0)
|
||||
if (proxyIndex.column() > 0) {
|
||||
|
||||
if (role == Qt::UserRole) {
|
||||
|
||||
Reference in New Issue
Block a user