19 changes: 17 additions & 2 deletions src/Gui/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ TabView::~TabView()
perspectives_.clear();
}

// this generally gets re-implemented in the view, so e.g. AnalysisView
// has its own version of this method that switches perspective to match
// the type of activity based upon the perspective's associated "switch expression".
void
TabView::setRide(RideItem*ride)
{
if (loaded) page()->setProperty("ride", QVariant::fromValue<RideItem*>(dynamic_cast<RideItem*>(ride)));
if (loaded) {
page()->setProperty("ride", QVariant::fromValue<RideItem*>(dynamic_cast<RideItem*>(ride)));
}
}

void
Expand Down Expand Up @@ -462,7 +467,7 @@ TabView::exportPerspective(Perspective *p, QString filename)
p->toFile(filename);
}

void
Perspective *
TabView::addPerspective(QString name)
{
Perspective *page = new Perspective(context, name, type);
Expand All @@ -473,6 +478,7 @@ TabView::addPerspective(QString name)

// append
appendPerspective(page);
return page;
}

void
Expand Down Expand Up @@ -724,6 +730,10 @@ TabView::setPerspectives(QComboBox *perspectiveSelector)
// one to get the ride item and date range selected
if (!loaded) {
loaded = true;

// generally we just go to the first perspective
// but on analysis view they get selected on the basis
// of the currently selected ride
perspectiveSelected(0);

// due to visibility optimisation we need to force the first tab to be selected in tab mode
Expand Down Expand Up @@ -915,20 +925,25 @@ bool ViewParser::startElement( const QString&, const QString&, const QString &na

QString name="General";
int typetouse=type;
QString expression;
for(int i=0; i<attrs.count(); i++) {
if (attrs.qName(i) == "style") {
style = Utils::unprotect(attrs.value(i)).toInt();
}
if (attrs.qName(i) == "name") {
name = Utils::unprotect(attrs.value(i));
}
if (attrs.qName(i) == "expression") {
expression = Utils::unprotect(attrs.value(i));
}
if (attrs.qName(i) == "type") {
typetouse = Utils::unprotect(attrs.value(i)).toInt();
}
}

// we need a new perspective for this view type
page = new Perspective(context, name, typetouse);
page->setExpression(expression);
perspectives.append(page);
}
else if (name == "chart") {
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/TabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class TabView : public QWidget
void perspectiveSelected(int index); // combobox selections changed because the user selected a perspective

// add a new perspective
void addPerspective(QString);
Perspective *addPerspective(QString);
void removePerspective(Perspective *);
void swapPerspective(int from, int to); // reorder by moving 1 pos at a time

Expand Down
27 changes: 27 additions & 0 deletions src/Gui/Views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,34 @@ AnalysisView::~AnalysisView()
void
AnalysisView::setRide(RideItem *ride)
{
// when ride selected, but not from the sidebar.
static_cast<AnalysisSidebar*>(sidebar())->setRide(ride); // save settings

// if we are the current view and the current perspective is no longer relevant
// then lets go find one to switch to..
if (context->mainWindow->athleteTab()->currentView() == 1 && page()->relevant(ride) != true) {

// lets find one to switch to
Perspective *found=page();
foreach(Perspective *p, perspectives_){
if (p->relevant(ride)) {
found =p;
break;
}
}

// none of them want to be selected, so we can stay on the current one
// so long as it doesn't have an expression that failed...
if (found == page() && page()->expression() != "")
found = perspectives_[0];

// if we need to switch, i.e. not already on it
if (found != page()) {
context->mainWindow->switchPerspective(perspectives_.indexOf(found));
}
}

// tell the perspective we have selected a ride
page()->setProperty("ride", QVariant::fromValue<RideItem*>(dynamic_cast<RideItem*>(ride)));
}

Expand Down
16 changes: 8 additions & 8 deletions src/Gui/Views.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class AnalysisView : public TabView

AnalysisView(Context *context, QStackedWidget *controls);
~AnalysisView();
void close();
void setRide(RideItem*ride);
void close() override;
void setRide(RideItem*ride) override;
void addIntervals();

RideNavigator *rideNavigator();

public slots:

bool isBlank();
bool isBlank() override;
void compareChanged(bool);

private:
Expand All @@ -61,11 +61,11 @@ class DiaryView : public TabView

DiaryView(Context *context, QStackedWidget *controls);
~DiaryView();
void setRide(RideItem*ride);
void setRide(RideItem*ride) override;

public slots:

bool isBlank();
bool isBlank() override;
void dateRangeChanged(DateRange);

private:
Expand All @@ -82,11 +82,11 @@ class TrainView : public TabView

TrainView(Context *context, QStackedWidget *controls);
~TrainView();
void close();
void close() override;

public slots:

bool isBlank();
bool isBlank() override;
void onSelectionChanged();

private:
Expand Down Expand Up @@ -117,7 +117,7 @@ class HomeView : public TabView

public slots:

bool isBlank();
bool isBlank() override;
void justSelected();
void dateRangeChanged(DateRange);
void compareChanged(bool);
Expand Down