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