Skip to content

Commit

Permalink
GcChartWindow Refactor
Browse files Browse the repository at this point in the history
.. use GcChartWindow as the base class for all charts -- so
   we can truly upload *any* chart to the cloudDB

.. miscellaneous charts that were still defined as GcWindow
   have been converted to GcChartWindow

.. GcChartWindow layout issues (using QGridLayout insted of
   a QStackedLayout) are fixed which will also resolve a few
   rendering issues related to NOWEBKIT.

.. Aerolab needed lots of cosmetic fixups once it became
   a GcChartWindow

.. Added 'Upload Chart...' to mirror the 'Download Chart..'
   option on the hamburger menu as users will instinctively
   look for the option there instead of under the chart menu.
  • Loading branch information
liversedge committed May 30, 2016
1 parent 696101b commit c09a974
Show file tree
Hide file tree
Showing 38 changed files with 203 additions and 116 deletions.
15 changes: 11 additions & 4 deletions src/Charts/Aerolab.cpp
Expand Up @@ -26,6 +26,7 @@
#include "Settings.h"
#include "Units.h"
#include "Colors.h"
#include "TimeUtils.h"

#include <cmath>
#include <qwt_series_data.h>
Expand Down Expand Up @@ -267,6 +268,11 @@ Aerolab::configChanged(qint32)
intervalHighlighterCurve->setBrush(ihlbrush); // fill below the line

//XXX broken this->legend()->remove( intervalHighlighterCurve ); // don't show in legend
QPalette palette;
palette.setColor(QPalette::WindowText, GColor(CPLOTMARKER));
palette.setColor(QPalette::Text, GColor(CPLOTMARKER));
axisWidget(QwtPlot::xBottom)->setPalette(palette);
axisWidget(QwtPlot::yLeft)->setPalette(palette);
}

void
Expand Down Expand Up @@ -723,13 +729,14 @@ void Aerolab::refreshIntervalMarkers()
}
d_mrk.clear();

QRegExp wkoAuto("^(Peak *[0-9]*(s|min)|Entire workout|Find #[0-9]*) *\\([^)]*\\)$");
//QRegExp wkoAuto("^(Peak *[0-9]*(s|min)|Entire workout|Find #[0-9]*) *\\([^)]*\\)$");
if ( rideItem->ride() )
{
foreach(IntervalItem *interval, rideItem->intervals()) {
// skip WKO autogenerated peak intervals
if (wkoAuto.exactMatch(interval->name))
continue;

// only plot user intervals
if (interval->type != RideFileInterval::USER) continue;

QwtPlotMarker *mrk = new QwtPlotMarker;
d_mrk.append(mrk);
mrk->attach(this);
Expand Down
66 changes: 49 additions & 17 deletions src/Charts/AerolabWindow.cpp
Expand Up @@ -21,6 +21,7 @@
#include "Context.h"
#include "AerolabWindow.h"
#include "Aerolab.h"
#include "TabView.h"
#include "IntervalItem.h"
#include "RideItem.h"
#include "Colors.h"
Expand All @@ -29,7 +30,7 @@
#include <qwt_plot_zoomer.h>

AerolabWindow::AerolabWindow(Context *context) :
GcWindow(context), context(context) {
GcChartWindow(context), context(context) {
setControls(NULL);

// Aerolab tab layout:
Expand All @@ -49,7 +50,7 @@ AerolabWindow::AerolabWindow(Context *context) :

// Crr:
QHBoxLayout *crrLayout = new QHBoxLayout;
QLabel *crrLabel = new QLabel(tr("Crr"), this);
crrLabel = new QLabel(tr("Crr"), this);
crrLabel->setFixedWidth(labelWidth1);
crrLineEdit = new QLineEdit();
crrLineEdit->setFixedWidth(75);
Expand All @@ -72,7 +73,7 @@ AerolabWindow::AerolabWindow(Context *context) :

// CdA:
QHBoxLayout *cdaLayout = new QHBoxLayout;
QLabel *cdaLabel = new QLabel(tr("CdA"), this);
cdaLabel = new QLabel(tr("CdA"), this);
cdaLabel->setFixedWidth(labelWidth1);
cdaLineEdit = new QLineEdit();
cdaLineEdit->setFixedWidth(75);
Expand All @@ -95,7 +96,7 @@ AerolabWindow::AerolabWindow(Context *context) :

// Eta:
QHBoxLayout *etaLayout = new QHBoxLayout;
QLabel *etaLabel = new QLabel(tr("Eta"), this);
etaLabel = new QLabel(tr("Eta"), this);
etaLabel->setFixedWidth(labelWidth1);
etaLineEdit = new QLineEdit();
etaLineEdit->setFixedWidth(75);
Expand Down Expand Up @@ -128,7 +129,7 @@ AerolabWindow::AerolabWindow(Context *context) :

// Total mass:
QHBoxLayout *mLayout = new QHBoxLayout;
QLabel *mLabel = new QLabel(tr("Total Mass (kg)"), this);
mLabel = new QLabel(tr("Total Mass (kg)"), this);
mLabel->setFixedWidth(labelWidth2);
mLineEdit = new QLineEdit();
mLineEdit->setFixedWidth(70);
Expand All @@ -151,7 +152,7 @@ AerolabWindow::AerolabWindow(Context *context) :

// Rho:
QHBoxLayout *rhoLayout = new QHBoxLayout;
QLabel *rhoLabel = new QLabel(tr("Rho (kg/m^3)"), this);
rhoLabel = new QLabel(tr("Rho (kg/m^3)"), this);
rhoLabel->setFixedWidth(labelWidth2);
rhoLineEdit = new QLineEdit();
rhoLineEdit->setFixedWidth(70);
Expand All @@ -174,7 +175,7 @@ AerolabWindow::AerolabWindow(Context *context) :

// Elevation offset:
QHBoxLayout *eoffsetLayout = new QHBoxLayout;
QLabel *eoffsetLabel = new QLabel(tr("Eoffset (m)"), this);
eoffsetLabel = new QLabel(tr("Eoffset (m)"), this);
eoffsetLabel->setFixedWidth(labelWidth2);
eoffsetLineEdit = new QLineEdit();
eoffsetLineEdit->setFixedWidth(70);
Expand All @@ -196,11 +197,11 @@ AerolabWindow::AerolabWindow(Context *context) :
eoffsetLayout->addWidget( eoffsetSlider );

QVBoxLayout *checkboxLayout = new QVBoxLayout;
QCheckBox *eoffsetAuto = new QCheckBox(tr("eoffset auto"), this);
eoffsetAuto = new QCheckBox(tr("eoffset auto"), this);
eoffsetAuto->setCheckState(Qt::Checked);
checkboxLayout->addWidget(eoffsetAuto);

QCheckBox *constantAlt = new QCheckBox(tr("Constant altitude (velodrome,...)"), this);
constantAlt = new QCheckBox(tr("Constant altitude (velodrome,...)"), this);
checkboxLayout->addWidget(constantAlt);

eoffsetLayout->addLayout(checkboxLayout);
Expand Down Expand Up @@ -264,7 +265,7 @@ AerolabWindow::AerolabWindow(Context *context) :
// Build the tab layout:
vLayout->addWidget(aerolab);
vLayout->addLayout(cLayout);
setLayout(vLayout);
setChartLayout(vLayout);


// tooltip on hover over point
Expand Down Expand Up @@ -307,16 +308,47 @@ AerolabWindow::configChanged(qint32)
setProperty("color", GColor(CPLOTBACKGROUND));

QPalette palette;
palette.setBrush(QPalette::Window, QBrush(GColor(CPLOTBACKGROUND)));
palette.setBrush(QPalette::Background, QBrush(GColor(CPLOTBACKGROUND)));
palette.setBrush(QPalette::Base, QBrush(GColor(CPLOTBACKGROUND)));

palette.setColor(QPalette::Window, GColor(CPLOTBACKGROUND));
palette.setColor(QPalette::Background, GColor(CPLOTBACKGROUND));

// only change base if moved away from white plots
// which is a Mac thing
#ifndef Q_OS_MAC
if (GColor(CPLOTBACKGROUND) != Qt::white)
#endif
{
palette.setColor(QPalette::Base, GCColor::alternateColor(GColor(CPLOTBACKGROUND)));
palette.setColor(QPalette::Window, GColor(CPLOTBACKGROUND));
}

palette.setColor(QPalette::WindowText, GCColor::invertColor(GColor(CPLOTBACKGROUND)));
palette.setColor(QPalette::Text, GCColor::invertColor(GColor(CPLOTBACKGROUND)));
palette.setColor(QPalette::Normal, QPalette::Window, GCColor::invertColor(GColor(CPLOTBACKGROUND)));
setPalette(palette);
setStyleSheet(QString("background-color: %1; color: %2; border: %1")
.arg(GColor(CPLOTBACKGROUND).name())
.arg(GCColor::invertColor(GColor(CPLOTBACKGROUND)).name()));
aerolab->setPalette(palette);
crrLabel->setPalette(palette);
cdaLabel->setPalette(palette);
etaLabel->setPalette(palette);
mLabel->setPalette(palette);
rhoLabel->setPalette(palette);
eoffsetLabel->setPalette(palette);
crrSlider->setPalette(palette);
crrLineEdit->setPalette(palette);
cdaSlider->setPalette(palette);
cdaLineEdit->setPalette(palette);
mSlider->setPalette(palette);
mLineEdit->setPalette(palette);
rhoSlider->setPalette(palette);
rhoLineEdit->setPalette(palette);
etaSlider->setPalette(palette);
etaLineEdit->setPalette(palette);
eoffsetLineEdit->setPalette(palette);
eoffsetAuto->setPalette(palette);
constantAlt->setPalette(palette);

#ifndef Q_OS_MAC
aerolab->setStyleSheet(TabView::ourStyleSheet());
#endif
}

void
Expand Down
12 changes: 11 additions & 1 deletion src/Charts/AerolabWindow.h
Expand Up @@ -33,7 +33,7 @@ class QLCDNumber;
class RideItem;
class IntervalItem;

class AerolabWindow : public GcWindow {
class AerolabWindow : public GcChartWindow {
Q_OBJECT
G_OBJECT

Expand Down Expand Up @@ -77,6 +77,16 @@ class AerolabWindow : public GcWindow {
Aerolab *aerolab;
QwtPlotZoomer *allZoomer;

// labels
QLabel *crrLabel;
QLabel *cdaLabel;
QLabel *etaLabel;
QLabel *mLabel;
QLabel *rhoLabel;
QLabel *eoffsetLabel;

QCheckBox *eoffsetAuto, *constantAlt;

// Bike parameter controls:
QSlider *crrSlider;
QLineEdit *crrLineEdit;
Expand Down
4 changes: 2 additions & 2 deletions src/Charts/ChartBar.cpp
Expand Up @@ -124,8 +124,8 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con
chartMenu = barMenu->addMenu(tr("Add Chart"));

#ifdef GC_HAS_CLOUD_DB
QAction *cloudAction = barMenu->addAction(tr("Download Chart..."));
connect(cloudAction, SIGNAL(triggered(bool)), context->mainWindow, SLOT(addChartFromCloudDB()));
barMenu->addAction(tr("Upload Chart..."), context->mainWindow, SLOT(exportChartToCloudDB()));
barMenu->addAction(tr("Download Chart..."), context->mainWindow, SLOT(addChartFromCloudDB()));
#endif
// menu
connect(menuButton, SIGNAL(clicked()), this, SLOT(menuPopup()));
Expand Down
5 changes: 3 additions & 2 deletions src/Charts/DiaryWindow.cpp
Expand Up @@ -27,14 +27,15 @@
#include "HelpWhatsThis.h"

DiaryWindow::DiaryWindow(Context *context) :
GcWindow(context), context(context), active(false)
GcChartWindow(context), context(context), active(false)
{
setControls(NULL);

// get config
fieldDefinitions = context->athlete->rideMetadata()->getFields();

QVBoxLayout *vlayout = new QVBoxLayout(this);
QVBoxLayout *vlayout = new QVBoxLayout;
setChartLayout(vlayout);

// controls
QHBoxLayout *controls = new QHBoxLayout;
Expand Down
2 changes: 1 addition & 1 deletion src/Charts/DiaryWindow.h
Expand Up @@ -39,7 +39,7 @@
#include "RideSummaryWindow.h"


class DiaryWindow : public GcWindow
class DiaryWindow : public GcChartWindow
{
Q_OBJECT
G_OBJECT
Expand Down
19 changes: 12 additions & 7 deletions src/Charts/GoldenCheetah.cpp
Expand Up @@ -695,6 +695,9 @@ GcChartWindow::GcChartWindow(Context *context) : GcWindow(context), context(cont

_mainWidget = new QWidget(this);
_mainWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_chart = new QWidget(this);
_chart->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_chart->hide();
_blank = new QWidget(this);
_blank->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

Expand All @@ -703,11 +706,13 @@ GcChartWindow::GcChartWindow(Context *context) : GcWindow(context), context(cont
_layout->setCurrentWidget(_mainWidget);

// Main layout
_mainLayout = new QGridLayout();
_mainLayout = new QStackedLayout(_mainWidget);
_mainLayout->setStackingMode(QStackedLayout::StackAll);
_mainLayout->setContentsMargins(2,2,2,2);

// reveal widget
_revealControls = new QWidget();
_revealControls = new QWidget(this);
_revealControls->hide();
_revealControls->setFixedHeight(50);
_revealControls->setStyleSheet("background-color: rgba(100%, 100%, 100%, 80%)");
_revealControls->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
Expand All @@ -729,10 +734,8 @@ GcChartWindow::GcChartWindow(Context *context) : GcWindow(context), context(cont
_unrevealTimer = new QTimer();
connect(_unrevealTimer, SIGNAL(timeout()), this, SLOT(hideRevealControls()));

_revealControls->hide();

_mainLayout->addWidget(_revealControls,0,0, Qt::AlignTop);
_mainWidget->setLayout(_mainLayout);
_mainLayout->addWidget(_chart);
_mainLayout->addWidget(_revealControls);

connect(this, SIGNAL(colorChanged(QColor)), this, SLOT(colorChanged(QColor)));

Expand Down Expand Up @@ -790,14 +793,16 @@ void
GcChartWindow:: setChartLayout(QLayout *layout)
{
_chartLayout = layout;
_mainLayout->addLayout(_chartLayout,0,0, Qt::AlignTop);
_chart->setLayout(_chartLayout);
_chart->show();
}

void
GcChartWindow:: setRevealLayout(QLayout *layout)
{
_revealLayout = layout;
_revealControls->setLayout(_revealLayout);
_revealControls->hide();
}

void
Expand Down
5 changes: 3 additions & 2 deletions src/Charts/GoldenCheetah.h
Expand Up @@ -223,7 +223,7 @@ class GcChartWindow : public GcWindow
Q_OBJECT

QStackedLayout *_layout;
QGridLayout *_mainLayout;
QStackedLayout *_mainLayout;
QVBoxLayout *_defaultBlankLayout;

QLayout *_chartLayout,
Expand All @@ -241,6 +241,8 @@ class GcChartWindow : public GcWindow
QTimer *_unrevealTimer;
Context *context;

public:

// reveal
bool virtual hasReveal() { return false; }
void reveal();
Expand All @@ -254,7 +256,6 @@ class GcChartWindow : public GcWindow
void serializeChartToQTextStream(QTextStream& out);


public:
GcChartWindow(Context *context);

// parse a .gchart file / or string and return a list of charts expressed
Expand Down

0 comments on commit c09a974

Please sign in to comment.