forked from GoldenCheetah/GoldenCheetah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntervalNavigator.h
275 lines (216 loc) · 8.1 KB
/
IntervalNavigator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
* Copyright (c) 2014 Damien Grauser ([email protected])
*
* 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_IntervalNavigator_h
#define _GC_IntervalNavigator_h 1
#include "GoldenCheetah.h"
#include "Context.h"
#include "RideMetadata.h"
#include "Context.h"
#include "Settings.h"
#include "Colors.h"
#include <QSqlTableModel>
#include <QItemDelegate>
#include <QTreeView>
#include <QHeaderView>
#include <QScrollBar>
#include <QDragMoveEvent>
#include <QDragEnterEvent>
class IntervalNavigatorCellDelegate;
class IntervalGroupByModel;
class IntervalSearchFilter;
class SearchFilterBox;
class DiaryWindow;
class DiarySidebar;
class BUGFIXQSortFilterProxyModel;
class DataFilter;
class GcMiniCalendar;
class SearchBox;
class IntervalGlobalTreeView;
//
// The IntervalNavigator
//
// A list of rides displayed using a QTreeView on top of
// a QSQLTableModel which reads from the "metrics" table
// via the DBAccess database connection
//
class IntervalNavigator : public GcWindow
{
Q_OBJECT
G_OBJECT
Q_PROPERTY(int sortByIndex READ sortByIndex WRITE setSortByIndex USER true)
Q_PROPERTY(int sortByOrder READ sortByOrder WRITE setSortByOrder USER true)
Q_PROPERTY(int groupBy READ groupBy WRITE setGroupBy USER true)
Q_PROPERTY(QString columns READ columns WRITE setColumns USER true)
Q_PROPERTY(QString widths READ widths WRITE setWidths USER true)
friend class ::IntervalNavigatorCellDelegate;
friend class ::IntervalGroupByModel;
friend class ::DiaryWindow;
friend class ::DiarySidebar;
friend class ::GcMiniCalendar;
friend class ::DataFilter;
friend class ::SearchBox;
public:
IntervalNavigator(Context *, QString type, bool mainwindow = false);
~IntervalNavigator();
void borderMenu(const QPoint &pos);
// so the cell delegate can access
IntervalGlobalTreeView *tableView; // the view
Context *context;
public slots:
void configChanged(qint32);
void refresh();
void backgroundRefresh();
void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent*);
void showTreeContextMenuPopup(const QPoint &);
// working with columns
void columnsChanged();
void columnsResized(int, int, int);
void removeColumn();
void showColumnChooser();
// user double clicked or pressed enter on ride
void selectRide(const QModelIndex &index);
// user selection here or on mainwindow's ride list
void cursorRide();
void selectRow();
bool eventFilter(QObject *object, QEvent *e);
// drop column headings from column chooser
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
// how wide am I?
void setWidth(int x);
void setSortBy(int index, Qt::SortOrder);
void setGroupByColumn();
int sortByIndex() const { return _sortByIndex; }
void setSortByIndex(int x) { _sortByIndex = x; }
int sortByOrder() const { return _sortByOrder; }
void setSortByOrder(int x) { _sortByOrder = x; }
int groupBy() const { return _groupBy; }
void setGroupBy(int x) { _groupBy = x; }
QString columns() const { return _columns; }
void setColumns(QString x) { _columns = x; }
// These are used in the main sidebar to let the users
// add remove columns etc without using right click
QStringList columnNames() const;
void setGroupByColumnName(QString); // set blank turns it off
void noGroups() { currentColumn=-1; setGroupByColumn(); }
QString widths() const { return _widths; }
void setWidths (QString x) { _widths = x; resetView(); } // only reset once widths are set
void resetView(); // when columns/width changes
void searchStrings(QStringList);
void clearSearch();
protected:
IntervalGroupByModel *groupByModel; // for group by
BUGFIXQSortFilterProxyModel *sortModel; // for sort/filter
// keep track of the headers
QList<QString> logicalHeadings;
QList<QString> visualHeadings;
// this maps friendly names to metric names
QMap <QString, QString> nameMap;
QMap<QString, const RideMetric *> columnMetrics;
QString type;
private:
bool active;
bool mainwindow;
bool init;
int currentColumn;
int pwidth;
IntervalNavigatorCellDelegate *delegate;
QVBoxLayout *mainLayout;
QSqlTableModel *sqlModel;
// properties
int _sortByIndex;
int _sortByOrder;
int _groupBy;
QString _columns;
QString _widths;
// font metrics for display etc
int fontHeight;
QColor reverseColor; // used by delegate when 'use for color' set
// search filter
IntervalSearchFilter *searchFilter;
// search filter box
SearchFilterBox *searchFilterBox;
// support functions
void calcColumnsChanged(bool, int logicalIndex=0, int oldWidth=0, int newWidth=0);
void setColumnWidth(int, bool, int logicalIndex=0, int oldWidth=0, int newWidth=0);
};
//
// Used to paint the cells in the interval navigator
//
class IntervalNavigatorCellDelegate : public QItemDelegate
{
Q_OBJECT
G_OBJECT
public:
IntervalNavigatorCellDelegate(IntervalNavigator *, QObject *parent = 0);
// These are all null since we don't allow editing
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
// We increase the row height if there is a calendar text to display
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const ;
// override stanard painter to use color config to paint background
// and perform correct level of rounding for each column before displaying
// it will also override the values returned from metricDB with in-core values
// when the ride has been modified but not saved (i.e. data is dirty)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setWidth(int x) { pwidth=x; }
private slots:
void commitAndCloseEditor();
private:
IntervalNavigator *intervalNavigator;
int pwidth;
};
//
// Column Chooser for Intervals
//
// Used by the ride navigator, provides an array
// of pushbuttons representing each available field
// and lets the user drag them onto the IntervalNavigator
// to include into the column list. Similarly, the
// available columns can be dragged off the ride
// navigator and dropped back in the array
//
class IntervalColumnChooser : public QWidget
{
Q_OBJECT
G_OBJECT
public:
IntervalColumnChooser(QList<QString>&columnHeadings);
public slots:
void buttonClicked(QString name);
private:
QGridLayout *buttons;
QSignalMapper *clicked;
};
class IntervalGlobalTreeView : public QTreeView
{
Q_OBJECT;
public:
IntervalGlobalTreeView();
protected:
void dragEnterEvent(QDragEnterEvent *e) {
e->accept();
}
void dragMoveEvent(QDragMoveEvent *e) {
e->accept();
}
};
#endif