From 8669ce641a6dd5c5053d68c7edcf442df58d4e13 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sat, 21 Jun 2014 22:58:20 +0100 Subject: [PATCH] 3d plot code update .. to reflect current code requirements NOTE: there is a 'phantom' widget with the 3d window that covers the left side of the chart bar and makes it impossible to click on the summary button. --- src/GcWindowRegistry.cpp | 2 +- src/ModelPlot.cpp | 104 ++++++++------------------------------- src/ModelPlot.h | 42 +++------------- src/ModelWindow.cpp | 24 +++------ src/ModelWindow.h | 13 ++--- 5 files changed, 38 insertions(+), 147 deletions(-) diff --git a/src/GcWindowRegistry.cpp b/src/GcWindowRegistry.cpp index 676f660be..ba7a6d59c 100644 --- a/src/GcWindowRegistry.cpp +++ b/src/GcWindowRegistry.cpp @@ -146,7 +146,7 @@ GcWindowRegistry::newGcWindow(GcWinID id, Context *context) case GcWindowTypes::PerformanceManager: // retired now returns an LTM case GcWindowTypes::LTM: returning = new LTMWindow(context); break; #ifdef GC_HAVE_QWTPLOT3D - case GcWindowTypes::Model: returning = new ModelWindow(context, context->athlete->home); break; + case GcWindowTypes::Model: returning = new ModelWindow(context); break; #else case GcWindowTypes::Model: returning = new GcWindow(); break; #endif diff --git a/src/ModelPlot.cpp b/src/ModelPlot.cpp index 509951348..5ade3c81a 100644 --- a/src/ModelPlot.cpp +++ b/src/ModelPlot.cpp @@ -145,7 +145,7 @@ class ModelDataProvider : public Function public: - ModelDataProvider (BasicModelPlot &plot, ModelSettings *settings); + ModelDataProvider (ModelPlot &plot, ModelSettings *settings); void setData(RideFile *ride, int x, int y, int z, int col); // set the maps and return mesh dimension // return z value for x,y - std qwt3plot method @@ -179,7 +179,7 @@ class ModelDataProvider : public Function double maxz, minz; double cranklength; // used for CPV/AEPF calculation bool useMetricUnits; - BasicModelPlot &plot; + ModelPlot &plot; }; double @@ -314,7 +314,7 @@ ModelDataProvider::describeType(int type, bool longer) * Edit it with caution, there be dragons here. * *----------------------------------------------------------------------*/ -ModelDataProvider::ModelDataProvider (BasicModelPlot &plot, ModelSettings *settings) : Function(plot), plot(plot) +ModelDataProvider::ModelDataProvider (ModelPlot &plot, ModelSettings *settings) : Function(plot), plot(plot) { // get application settings cranklength = appsettings->value(NULL, GC_CRANKLENGTH, 0.0).toDouble() / 1000.0; @@ -813,7 +813,13 @@ ModelDataProvider::ModelDataProvider (BasicModelPlot &plot, ModelSettings *setti * *----------------------------------------------------------------------*/ -BasicModelPlot::BasicModelPlot(Context *context, ModelSettings *settings) : context(context) +ModelPlot::ModelPlot(Context *context, QWidget *parent, ModelSettings *settings) : +#if QWT3D_MINOR_VERSION > 2 + GridPlot(parent), +#else + SurfacePlot(parent), +#endif + context(context) { diag_=0; currentStyle = STYLE_BAR; @@ -873,7 +879,7 @@ BasicModelPlot::BasicModelPlot(Context *context, ModelSettings *settings) : cont } void -BasicModelPlot::configChanged() +ModelPlot::configChanged() { // setColors bg QColor rgba = GColor(CPLOTBACKGROUND); @@ -894,7 +900,7 @@ BasicModelPlot::configChanged() } void -BasicModelPlot::setStyle(int index) +ModelPlot::setStyle(int index) { if (currentStyle == STYLE_BAR) degrade(bar); else degrade(water); @@ -934,7 +940,7 @@ BasicModelPlot::setStyle(int index) } void -BasicModelPlot::setData(ModelSettings *settings) +ModelPlot::setData(ModelSettings *settings) { delete modelDataProvider; settings->colorProvider = modelDataColor; @@ -954,7 +960,7 @@ BasicModelPlot::setData(ModelSettings *settings) } void -BasicModelPlot::setFrame(bool frame) +ModelPlot::setFrame(bool frame) { if (intervals_ && frame == true) { intervals_ |= SHOW_FRAME; @@ -966,7 +972,7 @@ BasicModelPlot::setFrame(bool frame) } void -BasicModelPlot::setLegend(bool legend, int coltype) +ModelPlot::setLegend(bool legend, int coltype) { if (legend == true && coltype != MODEL_NONE) { showColorLegend(true); @@ -976,7 +982,7 @@ BasicModelPlot::setLegend(bool legend, int coltype) } void -BasicModelPlot::setGrid(bool grid) +ModelPlot::setGrid(bool grid) { if (grid == true) coordinates()->setGridLines(true, true, Qwt3D::BACK | Qwt3D::LEFT | Qwt3D::FLOOR); @@ -987,7 +993,7 @@ BasicModelPlot::setGrid(bool grid) } void -BasicModelPlot::setZPane(int z) +ModelPlot::setZPane(int z) { //zpane = (modelDataProvider->maxz-modelDataProvider->minz) / 100 * z; zpane = (modelDataProvider->getMaxz()-modelDataProvider->getMinz()) / 100 * z; @@ -996,7 +1002,7 @@ BasicModelPlot::setZPane(int z) } void -BasicModelPlot::resetViewPoint() +ModelPlot::resetViewPoint() { setRotation(45, 0, 30); // seems most pleasing setShift(0,0,0); // centre so movement feels natural @@ -1005,76 +1011,6 @@ BasicModelPlot::resetViewPoint() } -/*---------------------------------------------------------------------- - * MODEL PLOT - * Nothing special - just a framed BasicModelPlot - *----------------------------------------------------------------------*/ -ModelPlot::ModelPlot(Context *context, ModelSettings *settings) : QFrame(context->mainWindow), context(context) -{ - // the distinction between a model plot and a basic model plot - // is only to provide a frame for the qwt3d plot (it looks odd - // when compared to the other plots without one) - layout = new QVBoxLayout; - setLineWidth(1); - setFrameStyle(QFrame::NoFrame); - setContentsMargins(0,0,0,0); - basicModelPlot = new BasicModelPlot(context, settings); - layout->addWidget(basicModelPlot); - layout->setContentsMargins(2,2,2,2); - setLayout(layout); - - connect(context, SIGNAL(configChanged()), basicModelPlot, SLOT(configChanged())); -} - -void -ModelPlot::setStyle(int index) -{ - basicModelPlot->setStyle(index); -} - -void -ModelPlot::setResolution(int val) -{ - basicModelPlot->setResolution(val); -} - -void -ModelPlot::setData(ModelSettings *settings) -{ - basicModelPlot->setData(settings); -} - -void -ModelPlot::resetViewPoint() -{ - basicModelPlot->resetViewPoint(); -} - -void -ModelPlot::setGrid(bool grid) -{ - basicModelPlot->setGrid(grid); -} - -void -ModelPlot::setLegend(bool legend, int coltype) -{ - basicModelPlot->setLegend(legend, coltype); -} - -void -ModelPlot::setFrame(bool frame) -{ - basicModelPlot->setFrame(frame); -} - -void -ModelPlot::setZPane(int z) -{ - basicModelPlot->setZPane(z); -} - - /*---------------------------------------------------------------------- * WATER VERTEX ENRICHMENT * @@ -1090,7 +1026,7 @@ Water::Water() { } -Water::Water(BasicModelPlot *model) : model(model) {} +Water::Water(ModelPlot *model) : model(model) {} void Water::drawBegin() { @@ -1207,7 +1143,7 @@ Bar::Bar() { } -Bar::Bar(BasicModelPlot *model) : model(model) {} +Bar::Bar(ModelPlot *model) : model(model) {} void Bar::drawBegin() { diff --git a/src/ModelPlot.h b/src/ModelPlot.h index 695427c0a..d127b69c0 100644 --- a/src/ModelPlot.h +++ b/src/ModelPlot.h @@ -80,9 +80,9 @@ class Water; // the core surface plot // qwtplot3d api changes between 0.2.x and 0.3.x #if QWT3D_MINOR_VERSION > 2 -class BasicModelPlot : public GridPlot +class ModelPlot : public GridPlot #else -class BasicModelPlot : public SurfacePlot +class ModelPlot : public SurfacePlot #endif { Q_OBJECT @@ -90,7 +90,7 @@ class BasicModelPlot : public SurfacePlot public: - BasicModelPlot(Context *, ModelSettings *); + ModelPlot(Context *, QWidget *parent, ModelSettings *p = NULL); Context *context; @@ -133,7 +133,7 @@ class Bar : public Qwt3D::VertexEnrichment { public: Bar(); - Bar(BasicModelPlot *); + Bar(ModelPlot *); Qwt3D::Enrichment* clone() const {return new Bar(*this);} @@ -143,7 +143,7 @@ public: private: double level_; - BasicModelPlot *model; + ModelPlot *model; //double diag_; }; @@ -152,41 +152,13 @@ class Water : public Qwt3D::VertexEnrichment { public: Water(); - Water(BasicModelPlot *); + Water(ModelPlot *); Qwt3D::Enrichment* clone() const {return new Water(*this);} void drawBegin(); void drawEnd(); void draw(Qwt3D::Triple const&); - BasicModelPlot *model; + ModelPlot *model; }; -// just a frame containing the raw 3d plot (for now) -class ModelPlot : public QFrame -{ - Q_OBJECT - G_OBJECT - - public: - - ModelPlot(Context *, ModelSettings *); - void setData(ModelSettings *settings); - void resetViewPoint(); - void setStyle(int); - void setGrid(bool); - void setLegend(bool, int); - void setFrame(bool); - void setZPane(int); - - BasicModelPlot *basicModelPlot; - - public slots: - void setResolution(int); - - private: - Context *context; - QVBoxLayout *layout; -}; - - #endif // _GC_ModelPlot_h diff --git a/src/ModelWindow.cpp b/src/ModelWindow.cpp index 7aa754cd5..df6339dfa 100644 --- a/src/ModelWindow.cpp +++ b/src/ModelWindow.cpp @@ -46,20 +46,16 @@ ModelWindow::addStandardChannels(QComboBox *box) box->addItem(tr("Longitude"), MODEL_LONG); } -ModelWindow::ModelWindow(Context *context, const QDir &home) : - GcChartWindow(context), home(home), context(context), ride(NULL), current(NULL) +ModelWindow::ModelWindow(Context *context) : + GcChartWindow(context), context(context), ride(NULL), current(NULL) { - QWidget *c = new QWidget; + QWidget *c = new QWidget(this); QFormLayout *cl = new QFormLayout(c); setControls(c); - // hidden text when plot invalid - nodata = new QLabel(tr("No data or bin size too large."), this); - nodata->hide(); - // the plot widget QHBoxLayout *mainLayout = new QHBoxLayout; - modelPlot= new ModelPlot(context, NULL); + modelPlot= new ModelPlot(context, this); zpane = new QSlider(Qt::Vertical); zpane->setTickInterval(1); zpane->setMinimum(0); @@ -67,7 +63,6 @@ ModelWindow::ModelWindow(Context *context, const QDir &home) : zpane->setValue(0); mainLayout->addWidget(zpane); mainLayout->addWidget(modelPlot); - mainLayout->addWidget(nodata); setChartLayout(mainLayout); // preset Values @@ -144,11 +139,7 @@ ModelWindow::ModelWindow(Context *context, const QDir &home) : legend->setChecked(true); cl->addRow(legend); - //resetView = new QPushButton(tr("Reset View")); - //cl->addRow(resetView); - // now connect up the widgets - //connect(main, SIGNAL(rideSelected()), this, SLOT(rideSelected())); connect(this, SIGNAL(rideItemChanged(RideItem*)), this, SLOT(rideSelected())); connect(context, SIGNAL(intervalSelected()), this, SLOT(intervalSelected())); connect(presetValues, SIGNAL(currentIndexChanged(int)), this, SLOT(applyPreset(int))); @@ -163,7 +154,6 @@ ModelWindow::ModelWindow(Context *context, const QDir &home) : connect(ignore, SIGNAL(stateChanged(int)), this, SLOT(setDirty())); connect(binWidthSlider, SIGNAL(valueChanged(int)), this, SLOT(setBinWidthFromSlider())); connect(binWidthLineEdit, SIGNAL(editingFinished()), this, SLOT(setBinWidthFromLineEdit())); - //connect(resetView, SIGNAL(clicked()), this, SLOT(resetViewPoint())); connect(zpane, SIGNAL(valueChanged(int)), this, SLOT(setZPane(int))); connect(context, SIGNAL(configChanged()), this, SLOT(configChanged())); @@ -261,12 +251,12 @@ ModelWindow::setData(bool adjustPlot) // if setdata resulted in the plot being hidden // then the settings were not valid. - if (modelPlot->basicModelPlot->isHidden()) { + if (modelPlot->isHidden()) { zpane->hide(); - nodata->show(); + setIsBlank(true); } else { zpane->show(); - nodata->hide(); + setIsBlank(false); } setClean(); diff --git a/src/ModelWindow.h b/src/ModelWindow.h index 7282b1b58..ac6907c21 100644 --- a/src/ModelWindow.h +++ b/src/ModelWindow.h @@ -72,7 +72,7 @@ class ModelWindow : public GcChartWindow public: - ModelWindow(Context *, const QDir &); + ModelWindow(Context *); // reveal bool hasReveal() { return false; } @@ -122,11 +122,9 @@ class ModelWindow : public GcChartWindow protected: // passed from Context * - QDir home; Context *context; - bool useMetricUnits; - bool active; + bool active; bool dirty; // settings changed but not reploted ModelSettings settings; // last used settings @@ -136,16 +134,12 @@ class ModelWindow : public GcChartWindow // layout ModelPlot *modelPlot; - // labels - QLabel *nodata; - QLabel *presetLabel, *xLabel, *yLabel, *zLabel, *colorLabel, - *binLabel, - *rpresetLabel; + *binLabel; // top of screen selectors QComboBox *presetValues; @@ -160,7 +154,6 @@ class ModelWindow : public GcChartWindow *grid, *frame, *legend; - QPushButton *resetView; QLineEdit *binWidthLineEdit; QSlider *binWidthSlider;