User Chart and property "perspective" SEGV

.. lots of problems related to this, notably:

   * UserChart is no longer a GcWindow so doesn't have any
     properties registered.

   * Even if it was the property was not being registered
     by GcWindow or GcChartWindow anyway

   * The value was not being initialised so checking for
     NULL was kinda pointless (groan)

   * OverviewItems looked up the property and never found
     it, so crashes were avoided by accident.

.. One interesting point that was revealed during testing
   and debugging-- the UserChart program does not honor
   any filtering EXCEPT for the activity{ } function, which
   although it is not by design, is quite useful.

Fixes #4021
This commit is contained in:
Mark Liversedge
2021-08-26 13:46:44 +01:00
parent 1e480b6965
commit ec46e545f5
7 changed files with 25 additions and 2 deletions

View File

@@ -25,6 +25,7 @@
#include "Utils.h"
#include "mvjson.h"
#include "LTMSettings.h"
#include "Perspective.h"
#ifdef GC_HAS_CLOUD_DB
#include "CloudDBChart.h"
@@ -195,11 +196,13 @@ GcWindow::GcWindow(Context *context) : QFrame(context->mainWindow), dragState(No
qRegisterMetaType<GcWinID>("type");
qRegisterMetaType<QColor>("color");
qRegisterMetaType<DateRange>("dateRange");
qRegisterMetaType<Perspective*>("perspective");
nomenu = false;
revealed = false;
setParent(context->mainWindow);
setControls(NULL);
setRideItem(NULL);
setPerspective(NULL);
setTitle("");
showtitle=true;
setContentsMargins(0,0,0,0);

View File

@@ -57,6 +57,7 @@ private:
// what kind of window is this?
Q_PROPERTY(GcWinID type READ type WRITE setType) // not a user modifiable property
Q_PROPERTY(Perspective *perspective READ getPerspective WRITE setPerspective USER false)
// each window has an instance name - default set
// by the widget constructor but overide from layou manager
@@ -104,6 +105,7 @@ private:
bool _gripped;
int _style;
bool _noevents; // don't work with events
Perspective *_perspective;
enum drag { None, Close, Flip, Move, Left, Right, Top, Bottom, TLCorner, TRCorner, BLCorner, BRCorner };
typedef enum drag DragState;
@@ -147,6 +149,9 @@ public:
void addAction(QAction *act) { actions << act; }
void setNoEvents(bool x) { _noevents = x; }
void setPerspective(Perspective *x) { _perspective=x; }
Perspective *getPerspective() const { return _perspective; }
void virtual setControls(QWidget *x);
QWidget *controls() const;

View File

@@ -84,7 +84,7 @@ static void setFilter(ChartSpaceItem *item, Specification &spec)
// property gets set after chartspace is initialised, so when we start up its not
// available, but comes later...
if (item->parent->window->property("perspective").isValid())
if (item->parent->window->myPerspective != NULL)
fs.addFilter(item->parent->window->myPerspective->isFiltered(), item->parent->window->myPerspective->filterlist(item->parent->myDateRange));
// local filter

View File

@@ -51,6 +51,9 @@ UserChart::UserChart(QWidget *parent, Context *context, bool rangemode)
main->setSpacing(0);
main->setContentsMargins(0,0,0,0);
// we don't know our perspective yet...
setPerspective(NULL);
// the chart
chart = new GenericChart(this, context);
main->addWidget(chart);
@@ -184,6 +187,7 @@ UserChart::setRide(const RideItem *item)
// cast so we can work with it
UserChartData *ucd = static_cast<UserChartData*>(series.user1);
// NOTE: specification is blank so doesn't honor perspective or filters, use activity {} in program for that (!!)
ucd->compute(const_cast<RideItem*>(ride), Specification(), dr);
series.xseries = ucd->x.asNumeric();
series.yseries = ucd->y.asNumeric();

View File

@@ -41,6 +41,8 @@ class UserChart : public QWidget {
Q_OBJECT
Q_PROPERTY (Perspective* perspective READ getPerspective WRITE setPerspective USER false)
friend class ::Leaf; // data filter eval accessing our curve data
public:
@@ -54,6 +56,9 @@ class UserChart : public QWidget {
QString settings() const;
void applySettings(QString);
Perspective *getPerspective() const { return perspective_; }
void setPerspective(Perspective *x) { perspective_ = x; }
// set background for all charts, legends etc
void setBackgroundColor(QColor bgcolor);
void setGraphicsItem(QGraphicsItem *);
@@ -95,6 +100,7 @@ class UserChart : public QWidget {
private:
Perspective *perspective_;
Context *context;
bool rangemode;
bool stale;

View File

@@ -22,7 +22,6 @@
UserChartOverviewItem::UserChartOverviewItem(ChartSpace *parent, QString name, QString settings) : ChartSpaceItem(parent, name), space_(parent)
{
// a META widget, "RPE" using the FOSTER modified 0-10 scale
this->type = OverviewItemType::USERCHART;
// default is a bit bigger

View File

@@ -74,6 +74,7 @@ UserChartWindow::configChanged()
QColor bgcolor = rangemode ? GColor(CTRENDPLOTBACKGROUND) : GColor(CPLOTBACKGROUND);
setProperty("color", bgcolor);
chart->setProperty("perspective", QVariant::fromValue<Perspective*>(myPerspective));
chart->setBackgroundColor(bgcolor);
update();
@@ -85,18 +86,23 @@ UserChartWindow::configChanged()
void
UserChartWindow::setRide(RideItem *item)
{
chart->setProperty("perspective", QVariant::fromValue<Perspective*>(myPerspective));
chart->setRide(item);
}
void
UserChartWindow::setDateRange(DateRange d)
{
chart->setProperty("perspective", QVariant::fromValue<Perspective*>(myPerspective));
chart->setDateRange(d);
}
void
UserChartWindow::refresh()
{
// we get called when filters and perspectives change so lets set the property
chart->setProperty("perspective", QVariant::fromValue<Perspective*>(myPerspective));
if (!amVisible()) { stale=true; return; }
chart->refresh();