/
LTMWindow.h
318 lines (261 loc) · 11 KB
/
LTMWindow.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
* Copyright (c) 2010 Mark Liversedge (liversedge@gmail.com)
*
* 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_LTMWindow_h
#define _GC_LTMWindow_h 1
#include "GoldenCheetah.h"
#include "MainWindow.h" // for isfiltered and filters
#include <QtGui>
#include <QStackedWidget>
#ifdef NOWEBKIT
#include <QWebEngineView>
#else
#include <QWebView>
#include <QWebFrame>
#endif
#include <QTimer>
#include "Context.h"
#include "Season.h"
#include "LTMPlot.h"
#include "LTMPopup.h"
#include "LTMTool.h"
#include "LTMSettings.h"
#include "LTMCanvasPicker.h"
#include "GcPane.h"
#include "Settings.h"
#include "Colors.h"
#include <cmath>
class QwtPlotPanner;
class QxtSpanSlider;
class QwtPlotPicker;
class AllPlot;
#include <qwt_plot_picker.h>
#include <qwt_text_engine.h>
#include <qwt_picker_machine.h>
#include <qwt_compat.h>
#include "qxtstringspinbox.h" // for reveal control groupby selection
// track the cursor and display the value for the chosen axis
class LTMToolTip : public QwtPlotPicker
{
public:
LTMToolTip(int xaxis, int yaxis,
RubberBand rb, DisplayMode dm, QWidget *pc, QString fmt) :
QwtPlotPicker(xaxis, yaxis, rb, dm, pc),
format(fmt) { setStateMachine(new QwtPickerDragPointMachine());}
virtual QRect trackerRect(const QFont &font) const
{
return QwtPlotPicker::trackerRect(font).adjusted(-3,-3,3,3);
}
virtual QwtText trackerText(const QPoint &/*pos*/) const
{
QwtText text(tip);
QFont stGiles;
stGiles.fromString(appsettings->value(this, GC_FONT_CHARTLABELS, QFont().toString()).toString());
stGiles.setPointSize(appsettings->value(NULL, GC_FONT_CHARTLABELS_SIZE, 8).toInt());
stGiles.setWeight(QFont::Bold);
text.setFont(stGiles);
text.setBackgroundBrush(QBrush( GColor(CPLOTMARKER)));
text.setColor(GColor(CRIDEPLOTBACKGROUND));
text.setBorderRadius(6);
text.setRenderFlags(Qt::AlignCenter | Qt::AlignVCenter);
return text;
}
void setFormat(QString fmt) { format = fmt; }
void setText(QString txt) { tip = txt; }
protected:
friend class ::AllPlot;
private:
QString format;
QString tip;
};
class LTMWindow : public GcChartWindow
{
Q_OBJECT
G_OBJECT
Q_PROPERTY(bool preset READ preset WRITE setPreset USER true)
Q_PROPERTY(int bin READ bin WRITE setBin USER true)
Q_PROPERTY(bool shade READ shade WRITE setShade USER true)
Q_PROPERTY(bool data READ data WRITE setData USER true)
Q_PROPERTY(bool stack READ stack WRITE setStack USER true)
Q_PROPERTY(int stackWidth READ stackW WRITE setStackW USER true)
Q_PROPERTY(bool legend READ legend WRITE setLegend USER true)
Q_PROPERTY(bool events READ events WRITE setEvents USER true)
Q_PROPERTY(bool banister READ banister WRITE setBanister USER true)
Q_PROPERTY(QString filter READ filter WRITE setFilter USER true)
Q_PROPERTY(QDate fromDate READ fromDate WRITE setFromDate USER true)
Q_PROPERTY(QDate toDate READ toDate WRITE setToDate USER true)
Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate USER true)
Q_PROPERTY(int lastN READ lastN WRITE setLastN USER true)
Q_PROPERTY(int lastNX READ lastNX WRITE setLastNX USER true)
Q_PROPERTY(int prevN READ prevN WRITE setPrevN USER true)
Q_PROPERTY(LTMSettings settings READ getSettings WRITE applySettings USER true)
Q_PROPERTY(int useSelected READ useSelected WRITE setUseSelected USER true) // !! must be last property !!
public:
LTMWindow(Context *);
~LTMWindow();
// reveal / filters
bool hasReveal() { return true; }
bool isFiltered() const { return (ltmTool->isFiltered() || context->ishomefiltered || context->isfiltered); }
// comparing things
bool isCompare() const { return context->isCompareDateRanges; }
// used by children
Context *context;
// get/set properties
int bin() const { return ltmTool->groupBy->currentIndex(); }
void setBin(int x) { rGroupBy->setValue(x); ltmTool->groupBy->setCurrentIndex(x); }
bool shade() const { return ltmTool->shadeZones->isChecked(); }
void setShade(bool x) { ltmTool->shadeZones->setChecked(x); }
bool data() const { return ltmTool->showData->isChecked(); }
void setData(bool x) { ltmTool->showData->setChecked(x); }
bool legend() const { return ltmTool->showLegend->isChecked(); }
void setLegend(bool x) { ltmTool->showLegend->setChecked(x); }
bool events() const { return ltmTool->showEvents->isChecked(); }
void setEvents(bool x) { ltmTool->showEvents->setChecked(x); }
bool banister() const { return ltmTool->showBanister->isChecked(); }
void setBanister(bool x) { ltmTool->showBanister->setChecked(x); }
bool stack() const { return ltmTool->showStack->isChecked(); }
void setStack(bool x) { ltmTool->showStack->setChecked(x); }
int stackW() const { return ltmTool->stackSlider->value(); }
void setStackW(int x) { ltmTool->stackSlider->setValue(x); }
bool preset() const { return ltmTool->usePreset->isChecked(); }
void setPreset(bool x) { ltmTool->usePreset->setChecked(x); }
int useSelected() { return ltmTool->dateSetting->mode(); }
void setUseSelected(int x) { ltmTool->dateSetting->setMode(x); }
QDate fromDate() { return ltmTool->dateSetting->fromDate(); }
void setFromDate(QDate date) { return ltmTool->dateSetting->setFromDate(date); }
QDate toDate() { return ltmTool->dateSetting->toDate(); }
void setToDate(QDate date) { return ltmTool->dateSetting->setToDate(date); }
QDate startDate() { return ltmTool->dateSetting->startDate(); }
void setStartDate(QDate date) { return ltmTool->dateSetting->setStartDate(date); }
int lastN() { return ltmTool->dateSetting->lastN(); }
void setLastN(int x) { ltmTool->dateSetting->setLastN(x); }
int lastNX() { return ltmTool->dateSetting->lastNX(); }
void setLastNX(int x) { ltmTool->dateSetting->setLastNX(x); }
int prevN() { return ltmTool->dateSetting->prevN(); }
void setPrevN(int x) { ltmTool->dateSetting->setPrevN(x); }
QString filter() const { return ltmTool->searchBox->filter(); }
void setFilter(QString x) { ltmTool->searchBox->setFilter(x); }
LTMSettings getSettings() const { return settings; }
void applySettings(LTMSettings x) {
bool events =settings.events; // remember - they don't get saved in settings..
settings = x;
settings.events = events;
settings.ltmTool = ltmTool;
ltmTool->applySettings();
}
// when part of library don't show the basic
// tab, its not relevant, but do make sure the
// use sidebar settings is not true !
void hideBasic();
public slots:
void rideSelected(); // notification to refresh
void presetSelected(int index); // when a preset is selected in the sidebar
// show the banister helper
void showBanister(bool relevant); // show banister helper if relevant to plot
void tuneBanister(); // when t1/t2 change
void refreshBanister(); // refresh banister helper
void refreshPlot(); // normal mode
void refreshCompare(); // compare mode
void refreshStackPlots(); // stacked plots
void refreshDataTable(); // data table
void styleChanged(int);
void compareChanged();
void dateRangeChanged(DateRange);
void filterChanged();
void groupBySelected(int);
void showEventsClicked(int);
void rGroupBySelected(int);
void shadeZonesClicked(int);
void showDataClicked(int);
void showStackClicked(int);
void zoomSliderChanged();
void showLegendClicked(int);
void applyClicked();
void refreshUpdate(QDate);
void refresh();
void pointClicked(QwtPlotCurve*, int);
int groupForDate(QDate);
void useCustomRange(DateRange);
void useStandardRange();
void useThruToday();
// user changed the date range
void spanSliderChanged();
void moveLeft();
void moveRight();
void exportData();
void exportConfig();
QString dataTable(bool html=true); // true as html, false as csv
void configChanged(qint32);
protected:
// receive events
bool event(QEvent *event);
private:
// passed from Context *
DateRange plotted;
bool useCustom;
bool useToToday; // truncate to today
DateRange custom; // custom date range supplied
// stack for plot or summary
QStackedWidget *stackWidget;
// summary view
#ifdef NOWEBKIT
QWebEngineView *dataSummary;
#else
QWebView *dataSummary;
#endif
// popup - the GcPane to display within
// and the LTMPopup contents widdget
GcPane *popup;
LTMPopup *ltmPopup;
// local state
bool dirty;
bool stackDirty;
bool compareDirty;
LTMSettings settings; // all the plot settings
QList<RideBest> bestsresults;
// when one curve per plot we split the settings
QScrollArea *plotArea;
QWidget *plotWidget, *plotsWidget;
QVBoxLayout *plotsLayout;
QList<LTMSettings> plotSettings;
QList<LTMPlot *> plots;
// when comparing things we have a plot for each data series
// with a curve for each date range on the plot
QScrollArea *compareplotArea;
QWidget *compareplotsWidget;
QVBoxLayout *compareplotsLayout;
QList<LTMSettings> compareplotSettings;
QList<LTMPlot *> compareplots;
// Widgets
LTMPlot *ltmPlot;
QxtSpanSlider *spanSlider;
QPushButton *scrollLeft, *scrollRight;
LTMTool *ltmTool;
// reveal controls
QxtStringSpinBox *rGroupBy;
QCheckBox *rData,
*rStack;
// banister helper
QComboBox *banCombo;
QComboBox *banPerf;
QDoubleSpinBox *banT1;
QDoubleSpinBox *banT2;
QLabel *ilabel, *plabel, *peaklabel, *t1label1, *t1label2, *t2label1, *t2label2, *RMSElabel, *perflabel;
QTime lastRefresh;
bool firstshow;
};
#endif // _GC_LTMWindow_h