mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-02-17 16:20:48 +01:00
Fixed scale flicker issue on OS X
Performance improvements
This commit is contained in:
parent
9941faa218
commit
6acbf0d89f
@ -3,7 +3,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "infoitem.h"
|
#include "infoitem.h"
|
||||||
|
|
||||||
|
|
||||||
#define PADDING 10
|
#define PADDING 10
|
||||||
|
|
||||||
InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||||
@ -11,24 +10,21 @@ InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF InfoItem::boundingRect() const
|
void InfoItem::updateBoundingRect()
|
||||||
{
|
{
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setPixelSize(FONT_SIZE);
|
font.setPixelSize(FONT_SIZE);
|
||||||
font.setFamily(FONT_FAMILY);
|
font.setFamily(FONT_FAMILY);
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
QList<KV>::const_iterator i;
|
QList<KV>::const_iterator i;
|
||||||
int width = 0;
|
qreal width = 0;
|
||||||
|
|
||||||
if (_list.isEmpty())
|
|
||||||
return QRectF();
|
|
||||||
|
|
||||||
for (i = _list.constBegin(); i != _list.constEnd(); i++) {
|
for (i = _list.constBegin(); i != _list.constEnd(); i++) {
|
||||||
width += fm.width(i->key + ": ");
|
width += fm.width(i->key + ": ");
|
||||||
width += fm.width(i->value) + ((i == _list.end() - 1) ? 0 : PADDING);
|
width += fm.width(i->value) + ((i == _list.end() - 1) ? 0 : PADDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QRectF(0, 0, width, fm.height());
|
_boundingRect = QRectF(0, 0, width, _list.isEmpty() ? 0 : fm.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
@ -74,5 +70,13 @@ void InfoItem::insert(const QString &key, const QString &value)
|
|||||||
else
|
else
|
||||||
_list[i] = kv;
|
_list[i] = kv;
|
||||||
|
|
||||||
|
updateBoundingRect();
|
||||||
|
prepareGeometryChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InfoItem::clear()
|
||||||
|
{
|
||||||
|
_list.clear();
|
||||||
|
updateBoundingRect();
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,16 @@ class InfoItem : public QGraphicsItem
|
|||||||
public:
|
public:
|
||||||
InfoItem(QGraphicsItem *parent = 0);
|
InfoItem(QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const {return _boundingRect;}
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
void insert(const QString &key, const QString &value);
|
void insert(const QString &key, const QString &value);
|
||||||
void clear() {_list.clear();}
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateBoundingRect();
|
||||||
|
|
||||||
class KV {
|
class KV {
|
||||||
public:
|
public:
|
||||||
QString key;
|
QString key;
|
||||||
@ -29,6 +31,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
QList<KV> _list;
|
QList<KV> _list;
|
||||||
|
QRectF _boundingRect;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INFOITEM_H
|
#endif // INFOITEM_H
|
||||||
|
@ -17,11 +17,9 @@ ScaleItem::ScaleItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
|||||||
_units = Metric;
|
_units = Metric;
|
||||||
_zoom = ZOOM_MIN;
|
_zoom = ZOOM_MIN;
|
||||||
_lat = 0;
|
_lat = 0;
|
||||||
|
|
||||||
computeScale();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF ScaleItem::boundingRect() const
|
void ScaleItem::updateBoundingRect()
|
||||||
{
|
{
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setPixelSize(FONT_SIZE);
|
font.setPixelSize(FONT_SIZE);
|
||||||
@ -33,7 +31,7 @@ QRectF ScaleItem::boundingRect() const
|
|||||||
es = fm.tightBoundingRect(QString::number(_length * SEGMENTS));
|
es = fm.tightBoundingRect(QString::number(_length * SEGMENTS));
|
||||||
us = fm.tightBoundingRect(units());
|
us = fm.tightBoundingRect(units());
|
||||||
|
|
||||||
return QRectF(-ss.width()/2, 0,
|
_boundingRect = QRectF(-ss.width()/2, 0,
|
||||||
_width * SEGMENTS + ss.width()/2 + qMax(us.width() + PADDING, es.width()/2),
|
_width * SEGMENTS + ss.width()/2 + qMax(us.width() + PADDING, es.width()/2),
|
||||||
SCALE_HEIGHT + PADDING + ss.height() + 2*fm.descent());
|
SCALE_HEIGHT + PADDING + ss.height() + 2*fm.descent());
|
||||||
}
|
}
|
||||||
@ -110,6 +108,7 @@ void ScaleItem::setLatitude(qreal lat)
|
|||||||
{
|
{
|
||||||
_lat = lat;
|
_lat = lat;
|
||||||
computeScale();
|
computeScale();
|
||||||
|
updateBoundingRect();
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +116,7 @@ void ScaleItem::setZoom(int z)
|
|||||||
{
|
{
|
||||||
_zoom = z;
|
_zoom = z;
|
||||||
computeScale();
|
computeScale();
|
||||||
|
updateBoundingRect();
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,5 +124,6 @@ void ScaleItem::setUnits(enum Units units)
|
|||||||
{
|
{
|
||||||
_units = units;
|
_units = units;
|
||||||
computeScale();
|
computeScale();
|
||||||
|
updateBoundingRect();
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ class ScaleItem : public QGraphicsItem
|
|||||||
public:
|
public:
|
||||||
ScaleItem(QGraphicsItem *parent = 0);
|
ScaleItem(QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const {return _boundingRect;}
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ public:
|
|||||||
void setUnits(enum Units units);
|
void setUnits(enum Units units);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateBoundingRect();
|
||||||
void computeScale();
|
void computeScale();
|
||||||
QString units() const;
|
QString units() const;
|
||||||
|
|
||||||
@ -27,6 +28,8 @@ private:
|
|||||||
qreal _length;
|
qreal _length;
|
||||||
Units _units;
|
Units _units;
|
||||||
bool _scale;
|
bool _scale;
|
||||||
|
|
||||||
|
QRectF _boundingRect;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SCALEITEM_H
|
#endif // SCALEITEM_H
|
||||||
|
@ -21,6 +21,9 @@ Track::Track(QWidget *parent)
|
|||||||
setScene(_scene);
|
setScene(_scene);
|
||||||
setCacheMode(QGraphicsView::CacheBackground);
|
setCacheMode(QGraphicsView::CacheBackground);
|
||||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||||
|
#endif // Q_OS_MAC
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
@ -388,7 +391,8 @@ void Track::paintEvent(QPaintEvent *e)
|
|||||||
{
|
{
|
||||||
QPointF scenePos = mapToScene(rect().bottomLeft() + QPoint(SCALE_OFFSET,
|
QPointF scenePos = mapToScene(rect().bottomLeft() + QPoint(SCALE_OFFSET,
|
||||||
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
|
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
|
||||||
_mapScale->setPos(scenePos);
|
if (_mapScale->pos() != scenePos)
|
||||||
|
_mapScale->setPos(scenePos);
|
||||||
|
|
||||||
QGraphicsView::paintEvent(e);
|
QGraphicsView::paintEvent(e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user