mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-12-01 07:01:16 +01:00
Fixed "zero distance" graph crash
Improved "no graph data" reporting
This commit is contained in:
parent
fc18283172
commit
cf6d27b1f5
@ -3,6 +3,8 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPaintEngine>
|
#include <QPaintEngine>
|
||||||
#include <QPaintDevice>
|
#include <QPaintDevice>
|
||||||
|
#include <QGraphicsSimpleTextItem>
|
||||||
|
#include <QPalette>
|
||||||
#include "data/graph.h"
|
#include "data/graph.h"
|
||||||
#include "opengl.h"
|
#include "opengl.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -41,6 +43,9 @@ GraphView::GraphView(QWidget *parent)
|
|||||||
_sliderInfo->setZValue(3.0);
|
_sliderInfo->setZValue(3.0);
|
||||||
_info = new InfoItem();
|
_info = new InfoItem();
|
||||||
_grid = new GridItem();
|
_grid = new GridItem();
|
||||||
|
_message = new QGraphicsSimpleTextItem(tr("Data not available"));
|
||||||
|
_message->setBrush(QPalette().brush(QPalette::Disabled,
|
||||||
|
QPalette::WindowText));
|
||||||
|
|
||||||
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
||||||
SLOT(emitSliderPositionChanged(const QPointF&)));
|
SLOT(emitSliderPositionChanged(const QPointF&)));
|
||||||
@ -157,9 +162,16 @@ void GraphView::setGraphType(GraphType type)
|
|||||||
_bounds = QRectF();
|
_bounds = QRectF();
|
||||||
|
|
||||||
for (int i = 0; i < _graphs.count(); i++) {
|
for (int i = 0; i < _graphs.count(); i++) {
|
||||||
_graphs.at(i)->setGraphType(type);
|
GraphItem *gi = _graphs.at(i);
|
||||||
if (_graphs.at(i)->scene() == _scene)
|
gi->setGraphType(type);
|
||||||
_bounds |= _graphs.at(i)->bounds();
|
if (!_hide.contains(gi->id())) {
|
||||||
|
if (gi->bounds().width() > 0)
|
||||||
|
addItem(gi);
|
||||||
|
else
|
||||||
|
removeItem(gi);
|
||||||
|
}
|
||||||
|
if (gi->scene() == _scene)
|
||||||
|
_bounds |= gi->bounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == Distance)
|
if (type == Distance)
|
||||||
@ -198,8 +210,10 @@ void GraphView::addGraph(GraphItem *graph, int id)
|
|||||||
|
|
||||||
if (!_hide.contains(id)) {
|
if (!_hide.contains(id)) {
|
||||||
_visible.append(graph);
|
_visible.append(graph);
|
||||||
|
if (graph->bounds().width() > 0) {
|
||||||
_scene->addItem(graph);
|
_scene->addItem(graph);
|
||||||
_bounds |= graph->bounds();
|
_bounds |= graph->bounds();
|
||||||
|
}
|
||||||
setXUnits();
|
setXUnits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,15 +240,17 @@ void GraphView::showGraph(bool show, int id)
|
|||||||
_visible.clear();
|
_visible.clear();
|
||||||
_bounds = QRectF();
|
_bounds = QRectF();
|
||||||
for (int i = 0; i < _graphs.count(); i++) {
|
for (int i = 0; i < _graphs.count(); i++) {
|
||||||
GraphItem* gi = _graphs.at(i);
|
GraphItem *gi = _graphs.at(i);
|
||||||
if (_hide.contains(gi->id()))
|
if (_hide.contains(gi->id()))
|
||||||
removeItem(gi);
|
removeItem(gi);
|
||||||
else {
|
else {
|
||||||
addItem(gi);
|
|
||||||
_visible.append(gi);
|
_visible.append(gi);
|
||||||
|
if (gi->bounds().width() > 0) {
|
||||||
|
addItem(gi);
|
||||||
_bounds |= gi->bounds();
|
_bounds |= gi->bounds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF GraphView::bounds() const
|
QRectF GraphView::bounds() const
|
||||||
@ -246,6 +262,7 @@ QRectF GraphView::bounds() const
|
|||||||
|
|
||||||
void GraphView::redraw()
|
void GraphView::redraw()
|
||||||
{
|
{
|
||||||
|
if (!_graphs.isEmpty())
|
||||||
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,10 +280,12 @@ void GraphView::redraw(const QSizeF &size)
|
|||||||
removeItem(_slider);
|
removeItem(_slider);
|
||||||
removeItem(_info);
|
removeItem(_info);
|
||||||
removeItem(_grid);
|
removeItem(_grid);
|
||||||
_scene->setSceneRect(QRectF());
|
addItem(_message);
|
||||||
|
_scene->setSceneRect(_scene->itemsBoundingRect());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeItem(_message);
|
||||||
addItem(_xAxis);
|
addItem(_xAxis);
|
||||||
addItem(_yAxis);
|
addItem(_yAxis);
|
||||||
addItem(_slider);
|
addItem(_slider);
|
||||||
@ -324,9 +343,11 @@ void GraphView::redraw(const QSizeF &size)
|
|||||||
_scene->setSceneRect(_scene->itemsBoundingRect());
|
_scene->setSceneRect(_scene->itemsBoundingRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::resizeEvent(QResizeEvent *)
|
void GraphView::resizeEvent(QResizeEvent *e)
|
||||||
{
|
{
|
||||||
redraw();
|
redraw(e->size() - QSizeF(MARGIN, MARGIN));
|
||||||
|
|
||||||
|
QGraphicsView::resizeEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::mousePressEvent(QMouseEvent *e)
|
void GraphView::mousePressEvent(QMouseEvent *e)
|
||||||
|
@ -16,6 +16,7 @@ class InfoItem;
|
|||||||
class GraphItem;
|
class GraphItem;
|
||||||
class PathItem;
|
class PathItem;
|
||||||
class GridItem;
|
class GridItem;
|
||||||
|
class QGraphicsSimpleTextItem;
|
||||||
|
|
||||||
class GraphView : public QGraphicsView
|
class GraphView : public QGraphicsView
|
||||||
{
|
{
|
||||||
@ -64,7 +65,6 @@ protected:
|
|||||||
|
|
||||||
QRectF bounds() const;
|
QRectF bounds() const;
|
||||||
void redraw();
|
void redraw();
|
||||||
void redraw(const QSizeF &size);
|
|
||||||
void addInfo(const QString &key, const QString &value);
|
void addInfo(const QString &key, const QString &value);
|
||||||
void clearInfo();
|
void clearInfo();
|
||||||
void skipColor() {_palette.nextColor();}
|
void skipColor() {_palette.nextColor();}
|
||||||
@ -77,6 +77,7 @@ private slots:
|
|||||||
void newSliderPosition(const QPointF &pos);
|
void newSliderPosition(const QPointF &pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void redraw(const QSizeF &size);
|
||||||
void setXUnits();
|
void setXUnits();
|
||||||
void createXLabel();
|
void createXLabel();
|
||||||
void createYLabel();
|
void createYLabel();
|
||||||
@ -85,8 +86,8 @@ private:
|
|||||||
void removeItem(QGraphicsItem *item);
|
void removeItem(QGraphicsItem *item);
|
||||||
void addItem(QGraphicsItem *item);
|
void addItem(QGraphicsItem *item);
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent *);
|
void resizeEvent(QResizeEvent *e);
|
||||||
void mousePressEvent(QMouseEvent *);
|
void mousePressEvent(QMouseEvent *e);
|
||||||
|
|
||||||
Units _units;
|
Units _units;
|
||||||
qreal _xScale, _yScale;
|
qreal _xScale, _yScale;
|
||||||
@ -104,6 +105,7 @@ private:
|
|||||||
SliderInfoItem *_sliderInfo;
|
SliderInfoItem *_sliderInfo;
|
||||||
InfoItem *_info;
|
InfoItem *_info;
|
||||||
GridItem *_grid;
|
GridItem *_grid;
|
||||||
|
QGraphicsSimpleTextItem *_message;
|
||||||
|
|
||||||
QList<GraphItem*> _visible;
|
QList<GraphItem*> _visible;
|
||||||
QSet<int> _hide;
|
QSet<int> _hide;
|
||||||
|
Loading…
Reference in New Issue
Block a user