mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 11:39:16 +02:00
Added support for "data defined" styles
This commit is contained in:
@ -28,10 +28,17 @@ AreaItem::AreaItem(const Area &area, Map *map, GraphicsItem *parent)
|
||||
_map = map;
|
||||
_digitalZoom = 0;
|
||||
|
||||
_width = 2;
|
||||
_opacity = 0.5;
|
||||
QBrush brush(Qt::SolidPattern);
|
||||
_pen = QPen(brush, _width);
|
||||
if (_area.style().isValid()) {
|
||||
_width = (_area.style().pen().style() == Qt::NoPen)
|
||||
? 0 : _area.style().pen().width();
|
||||
_pen = _area.style().pen();
|
||||
_brush = _area.style().brush();
|
||||
} else {
|
||||
_width = 2;
|
||||
_opacity = 0.5;
|
||||
QBrush brush(Qt::SolidPattern);
|
||||
_pen = QPen(brush, _width);
|
||||
}
|
||||
|
||||
updatePainterPath();
|
||||
|
||||
@ -91,6 +98,8 @@ void AreaItem::setMap(Map *map)
|
||||
|
||||
void AreaItem::setColor(const QColor &color)
|
||||
{
|
||||
if (_area.style().isValid())
|
||||
return;
|
||||
if (_pen.color() == color)
|
||||
return;
|
||||
|
||||
@ -104,6 +113,8 @@ void AreaItem::setColor(const QColor &color)
|
||||
|
||||
void AreaItem::setOpacity(qreal opacity)
|
||||
{
|
||||
if (_area.style().isValid())
|
||||
return;
|
||||
if (_opacity == opacity)
|
||||
return;
|
||||
|
||||
@ -117,6 +128,8 @@ void AreaItem::setOpacity(qreal opacity)
|
||||
|
||||
void AreaItem::setWidth(qreal width)
|
||||
{
|
||||
if (_area.style().isValid())
|
||||
return;
|
||||
if (_width == width)
|
||||
return;
|
||||
|
||||
@ -128,6 +141,8 @@ void AreaItem::setWidth(qreal width)
|
||||
|
||||
void AreaItem::setStyle(Qt::PenStyle style)
|
||||
{
|
||||
if (_area.style().isValid())
|
||||
return;
|
||||
if (_pen.style() == style)
|
||||
return;
|
||||
|
||||
|
@ -11,7 +11,8 @@ GraphItem::GraphItem(const Graph &graph, GraphType type, int width,
|
||||
Q_ASSERT(_graph.isValid());
|
||||
|
||||
_units = Metric;
|
||||
_pen = QPen(color, width, style, Qt::FlatCap);
|
||||
_pen = QPen(graph.color().isValid() ? graph.color() : color, width, style,
|
||||
Qt::FlatCap);
|
||||
_sx = 0; _sy = 0;
|
||||
_time = _graph.hasTime();
|
||||
setZValue(2.0);
|
||||
@ -54,6 +55,8 @@ void GraphItem::setGraphType(GraphType type)
|
||||
|
||||
void GraphItem::setColor(const QColor &color)
|
||||
{
|
||||
if (_graph.color().isValid())
|
||||
return;
|
||||
if (_pen.color() == color)
|
||||
return;
|
||||
|
||||
|
@ -32,15 +32,16 @@ static inline unsigned segments(qreal distance)
|
||||
Units PathItem::_units = Metric;
|
||||
QTimeZone PathItem::_timeZone = QTimeZone::utc();
|
||||
|
||||
PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
|
||||
: GraphicsItem(parent), _path(path), _map(map), _graph(0)
|
||||
PathItem::PathItem(const Path &path, const LineStyle &style, Map *map,
|
||||
QGraphicsItem *parent) : GraphicsItem(parent), _path(path), _style(style),
|
||||
_map(map), _graph(0)
|
||||
{
|
||||
Q_ASSERT(_path.isValid());
|
||||
|
||||
_digitalZoom = 0;
|
||||
_width = 3;
|
||||
QBrush brush(Qt::SolidPattern);
|
||||
_pen = QPen(brush, _width);
|
||||
_width = (_style.width() >= 0) ? _style.width() : 3;
|
||||
_pen = _style.color().isValid()
|
||||
? QPen(_style.color(), _width) : QPen(QBrush(Qt::SolidPattern), _width);
|
||||
_showMarker = true;
|
||||
_showTicks = false;
|
||||
_markerInfoType = MarkerInfoItem::None;
|
||||
@ -153,6 +154,8 @@ void PathItem::setMap(Map *map)
|
||||
|
||||
void PathItem::setColor(const QColor &color)
|
||||
{
|
||||
if (_style.color().isValid())
|
||||
return;
|
||||
if (_pen.color() == color)
|
||||
return;
|
||||
|
||||
@ -166,6 +169,8 @@ void PathItem::setColor(const QColor &color)
|
||||
|
||||
void PathItem::setWidth(qreal width)
|
||||
{
|
||||
if (_style.color().isValid())
|
||||
return;
|
||||
if (_width == width)
|
||||
return;
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <QPen>
|
||||
#include <QTimeZone>
|
||||
#include "data/path.h"
|
||||
#include "data/link.h"
|
||||
#include "data/style.h"
|
||||
#include "graphicsscene.h"
|
||||
#include "markerinfoitem.h"
|
||||
#include "units.h"
|
||||
@ -19,7 +21,8 @@ class PathItem : public QObject, public GraphicsItem
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PathItem(const Path &path, Map *map, QGraphicsItem *parent = 0);
|
||||
PathItem(const Path &path, const LineStyle &style, Map *map,
|
||||
QGraphicsItem *parent = 0);
|
||||
virtual ~PathItem() {}
|
||||
|
||||
QPainterPath shape() const {return _shape;}
|
||||
@ -66,6 +69,11 @@ protected:
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
QString _name;
|
||||
QString _desc;
|
||||
QString _comment;
|
||||
QVector<Link> _links;
|
||||
|
||||
static Units _units;
|
||||
static QTimeZone _timeZone;
|
||||
|
||||
@ -81,6 +89,7 @@ private:
|
||||
unsigned tickSize() const;
|
||||
|
||||
Path _path;
|
||||
LineStyle _style;
|
||||
Map *_map;
|
||||
QList<GraphItem *> _graphs;
|
||||
GraphItem *_graph;
|
||||
|
@ -36,7 +36,7 @@ ToolTip RouteItem::info() const
|
||||
}
|
||||
|
||||
RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent)
|
||||
: PathItem(route.path(), map, parent)
|
||||
: PathItem(route.path(), route.style(), map, parent)
|
||||
{
|
||||
const RouteData &waypoints = route.data();
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef ROUTEITEM_H
|
||||
#define ROUTEITEM_H
|
||||
|
||||
#include "data/link.h"
|
||||
#include "pathitem.h"
|
||||
|
||||
class Map;
|
||||
@ -26,11 +25,6 @@ public:
|
||||
QDateTime date() const {return QDateTime();}
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
QString _desc;
|
||||
QString _comment;
|
||||
QVector<Link> _links;
|
||||
|
||||
QVector<WaypointItem*> _waypoints;
|
||||
};
|
||||
|
||||
|
@ -41,7 +41,7 @@ ToolTip TrackItem::info() const
|
||||
}
|
||||
|
||||
TrackItem::TrackItem(const Track &track, Map *map, QGraphicsItem *parent)
|
||||
: PathItem(track.path(), map, parent)
|
||||
: PathItem(track.path(), track.style(), map, parent)
|
||||
{
|
||||
_name = track.name();
|
||||
_desc = track.description();
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define TRACKITEM_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include "data/link.h"
|
||||
#include "pathitem.h"
|
||||
|
||||
class Map;
|
||||
@ -19,10 +18,6 @@ public:
|
||||
QDateTime date() const {return _date;}
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
QString _desc;
|
||||
QString _comment;
|
||||
QVector<Link> _links;
|
||||
QDateTime _date;
|
||||
qreal _time;
|
||||
qreal _movingTime;
|
||||
|
@ -77,12 +77,14 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
|
||||
_waypoint = waypoint;
|
||||
_showLabel = true;
|
||||
_showIcon = false;
|
||||
_size = 8;
|
||||
_color = Qt::black;
|
||||
_size = (_waypoint.style().size() >= 0)
|
||||
? _waypoint.style().size() : 8;
|
||||
_color = (_waypoint.style().color().isValid())
|
||||
? _waypoint.style().color() : Qt::black;
|
||||
|
||||
_icon = (_waypoint.icon().isNull())
|
||||
_icon = (_waypoint.style().icon().isNull())
|
||||
? Waypoint::symbolIcon(_waypoint.symbol())
|
||||
: &_waypoint.icon();
|
||||
: &_waypoint.style().icon();
|
||||
|
||||
_font.setPixelSize(FS(_size));
|
||||
_font.setFamily(FONT_FAMILY);
|
||||
@ -98,6 +100,7 @@ void WaypointItem::updateCache()
|
||||
{
|
||||
QPainterPath p;
|
||||
qreal pointSize = _font.bold() ? HS(_size) : _size;
|
||||
const QPixmap &icon = _waypoint.style().icon();
|
||||
|
||||
if (_showLabel && !_waypoint.name().isEmpty()) {
|
||||
QFontMetrics fm(_font);
|
||||
@ -105,15 +108,15 @@ void WaypointItem::updateCache()
|
||||
|
||||
if (_showIcon && _icon) {
|
||||
if (_font.bold())
|
||||
p.addRect(-_icon->width() * 0.625, _waypoint.icon().isNull()
|
||||
p.addRect(-_icon->width() * 0.625, icon.isNull()
|
||||
? -_icon->height() * 1.25 : -_icon->height() * 0.625,
|
||||
_icon->width() * 1.25, _icon->height() * 1.25);
|
||||
else
|
||||
p.addRect(-_icon->width()/2.0, _waypoint.icon().isNull()
|
||||
p.addRect(-_icon->width()/2.0, icon.isNull()
|
||||
? -_icon->height() : -_icon->height()/2, _icon->width(),
|
||||
_icon->height());
|
||||
|
||||
if (_waypoint.icon().isNull())
|
||||
if (icon.isNull())
|
||||
p.addRect(0, 0, _labelBB.width(), _labelBB.height()
|
||||
+ fm.descent());
|
||||
else
|
||||
@ -127,11 +130,11 @@ void WaypointItem::updateCache()
|
||||
} else {
|
||||
if (_showIcon && _icon) {
|
||||
if (_font.bold())
|
||||
p.addRect(-_icon->width() * 0.625, _waypoint.icon().isNull()
|
||||
p.addRect(-_icon->width() * 0.625, icon.isNull()
|
||||
? -_icon->height() * 1.25 : -_icon->height() * 0.625,
|
||||
_icon->width() * 1.25, _icon->height() * 1.25);
|
||||
else
|
||||
p.addRect(-_icon->width()/2, _waypoint.icon().isNull()
|
||||
p.addRect(-_icon->width()/2, icon.isNull()
|
||||
? -_icon->height() : -_icon->height()/2, _icon->width(),
|
||||
_icon->height());
|
||||
} else
|
||||
@ -147,13 +150,14 @@ void WaypointItem::paint(QPainter *painter,
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
qreal pointSize = _font.bold() ? HS(_size) : _size;
|
||||
const QPixmap &icon = _waypoint.style().icon();
|
||||
|
||||
painter->setPen(_color);
|
||||
|
||||
if (_showLabel && !_waypoint.name().isEmpty()) {
|
||||
painter->setFont(_font);
|
||||
if (_showIcon && _icon) {
|
||||
if (_waypoint.icon().isNull())
|
||||
if (icon.isNull())
|
||||
painter->drawText(-qMax(_labelBB.x(), 0), _labelBB.height(),
|
||||
_waypoint.name());
|
||||
else
|
||||
@ -167,12 +171,12 @@ void WaypointItem::paint(QPainter *painter,
|
||||
painter->setBrush(QBrush(_color, Qt::SolidPattern));
|
||||
if (_showIcon && _icon) {
|
||||
if (_font.bold())
|
||||
painter->drawPixmap(-_icon->width() * 0.625, _waypoint.icon().isNull()
|
||||
painter->drawPixmap(-_icon->width() * 0.625, icon.isNull()
|
||||
? -_icon->height() * 1.25 : -_icon->height() * 0.625,
|
||||
_icon->scaled(_icon->width() * 1.25, _icon->height() * 1.25,
|
||||
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
else
|
||||
painter->drawPixmap(-_icon->width()/2.0, _waypoint.icon().isNull()
|
||||
painter->drawPixmap(-_icon->width()/2.0, icon.isNull()
|
||||
? -_icon->height() : -_icon->height()/2, *_icon);
|
||||
} else
|
||||
painter->drawEllipse(-pointSize/2, -pointSize/2, pointSize, pointSize);
|
||||
@ -184,6 +188,8 @@ void WaypointItem::paint(QPainter *painter,
|
||||
|
||||
void WaypointItem::setSize(int size)
|
||||
{
|
||||
if (_waypoint.style().size() >= 0)
|
||||
return;
|
||||
if (_size == size)
|
||||
return;
|
||||
|
||||
@ -195,6 +201,8 @@ void WaypointItem::setSize(int size)
|
||||
|
||||
void WaypointItem::setColor(const QColor &color)
|
||||
{
|
||||
if (_waypoint.style().color().isValid())
|
||||
return;
|
||||
if (_color == color)
|
||||
return;
|
||||
|
||||
|
Reference in New Issue
Block a user