1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Multiple data styles fixes

This commit is contained in:
Martin Tůma 2022-09-23 21:36:02 +02:00
parent a8299050c5
commit 1921087346
5 changed files with 120 additions and 97 deletions

View File

@ -29,10 +29,12 @@ AreaItem::AreaItem(const Area &area, Map *map, GraphicsItem *parent)
_digitalZoom = 0; _digitalZoom = 0;
if (_area.style().isValid()) { if (_area.style().isValid()) {
_width = (_area.style().pen().style() == Qt::NoPen) _width = (_area.style().width() >= 0)
? 0 : _area.style().pen().width(); ? _area.style().width() : 2;
_pen = _area.style().pen(); _pen = _area.style().stroke().isValid()
_brush = _area.style().brush(); ? QPen(area.style().stroke(), _width) : QPen(Qt::NoPen);
_brush = _area.style().fill().isValid()
? QBrush(_area.style().fill()) : QBrush(Qt::NoBrush);
} else { } else {
_width = 2; _width = 2;
_opacity = 0.5; _opacity = 0.5;
@ -128,7 +130,7 @@ void AreaItem::setOpacity(qreal opacity)
void AreaItem::setWidth(qreal width) void AreaItem::setWidth(qreal width)
{ {
if (_area.style().isValid()) if (_area.style().width() >= 0)
return; return;
if (_width == width) if (_width == width)
return; return;

View File

@ -20,60 +20,59 @@ static int markerSize(const QString &str)
static void setAreaProperties(Area &area, const QJsonValue &properties) static void setAreaProperties(Area &area, const QJsonValue &properties)
{ {
if (!properties.isObject())
return;
QJsonObject o(properties.toObject());
if (o["name"].isString())
area.setName(o["name"].toString());
if (o["title"].isString())
area.setName(o["title"].toString());
if (o["description"].isString())
area.setDescription(o["description"].toString());
QColor strokeColor(0x55, 0x55, 0x55); QColor strokeColor(0x55, 0x55, 0x55);
QColor fillColor(0x55, 0x55, 0x55); QColor fillColor(0x55, 0x55, 0x55, 0x99);
double strokeWidth = 2; double strokeWidth = 2;
if (o["stroke"].isString()) if (properties.isObject()) {
strokeColor = QColor(o["stroke"].toString()); QJsonObject o(properties.toObject());
if (o["stroke-opacity"].isDouble())
strokeColor.setAlphaF(o["stroke-opacity"].toDouble());
if (o["stroke-width"].isDouble())
strokeWidth = o["stroke-width"].toDouble();
if (o["fill"].isString())
fillColor = QColor(o["fill"].toString());
if (o["fill-opacity"].isDouble())
fillColor.setAlphaF(o["fill-opacity"].toDouble());
else
fillColor.setAlphaF(0.6);
area.setStyle(PolygonStyle(QPen(strokeColor, strokeWidth), if (o["name"].isString())
QBrush(fillColor))); area.setName(o["name"].toString());
if (o["title"].isString())
area.setName(o["title"].toString());
if (o["description"].isString())
area.setDescription(o["description"].toString());
if (o["stroke"].isString())
strokeColor = QColor(o["stroke"].toString());
if (o["stroke-opacity"].isDouble())
strokeColor.setAlphaF(o["stroke-opacity"].toDouble());
if (o["stroke-width"].isDouble())
strokeWidth = o["stroke-width"].toDouble();
if (o["fill"].isString())
fillColor = QColor(o["fill"].toString());
if (o["fill-opacity"].isDouble())
fillColor.setAlphaF(o["fill-opacity"].toDouble());
else
fillColor.setAlphaF(0.6);
}
area.setStyle(PolygonStyle(fillColor, strokeColor, strokeWidth));
} }
static void setTrackProperties(TrackData &track, const QJsonValue &properties) static void setTrackProperties(TrackData &track, const QJsonValue &properties)
{ {
if (!properties.isObject())
return;
QJsonObject o(properties.toObject());
if (o["name"].isString())
track.setName(o["name"].toString());
if (o["title"].isString())
track.setName(o["title"].toString());
if (o["description"].isString())
track.setDescription(o["description"].toString());
QColor color(0x55, 0x55, 0x55); QColor color(0x55, 0x55, 0x55);
double width = 2; double width = 2;
if (o["stroke"].isString()) if (properties.isObject()) {
color = QColor(o["stroke"].toString()); QJsonObject o(properties.toObject());
if (o["stroke-opacity"].isDouble())
color.setAlphaF(o["stroke-opacity"].toDouble()); if (o["name"].isString())
if (o["stroke-width"].isDouble()) track.setName(o["name"].toString());
width = o["stroke-width"].toDouble(); if (o["title"].isString())
track.setName(o["title"].toString());
if (o["description"].isString())
track.setDescription(o["description"].toString());
if (o["stroke"].isString())
color = QColor(o["stroke"].toString());
if (o["stroke-opacity"].isDouble())
color.setAlphaF(o["stroke-opacity"].toDouble());
if (o["stroke-width"].isDouble())
width = o["stroke-width"].toDouble();
}
track.setStyle(LineStyle(color, width)); track.setStyle(LineStyle(color, width));
} }
@ -81,28 +80,28 @@ static void setTrackProperties(TrackData &track, const QJsonValue &properties)
static void setWaypointProperties(Waypoint &waypoint, static void setWaypointProperties(Waypoint &waypoint,
const QJsonValue &properties) const QJsonValue &properties)
{ {
if (!properties.isObject())
return;
QJsonObject o(properties.toObject());
if (o["name"].isString())
waypoint.setName(o["name"].toString());
if (o["title"].isString())
waypoint.setName(o["title"].toString());
if (o["description"].isString())
waypoint.setDescription(o["description"].toString());
QColor color(0x7e, 0x7e, 0x7e); QColor color(0x7e, 0x7e, 0x7e);
int size = MARKER_SIZE_MEDIUM; int size = MARKER_SIZE_MEDIUM;
if (o["marker-color"].isString()) if (!properties.isObject()) {
color = QColor(o["marker-color"].toString()); QJsonObject o(properties.toObject());
if (o["marker-symbol"].isString())
waypoint.setSymbol(o["marker-symbol"].toString());
if (o["marker-size"].isString())
size = markerSize(o["marker-size"].toString());
waypoint.setStyle(PointStyle(QPixmap(), color, size)); if (o["name"].isString())
waypoint.setName(o["name"].toString());
if (o["title"].isString())
waypoint.setName(o["title"].toString());
if (o["description"].isString())
waypoint.setDescription(o["description"].toString());
if (o["marker-color"].isString())
color = QColor(o["marker-color"].toString());
if (o["marker-symbol"].isString())
waypoint.setSymbol(o["marker-symbol"].toString());
if (o["marker-size"].isString())
size = markerSize(o["marker-size"].toString());
}
waypoint.setStyle(PointStyle(color, size));
} }

View File

@ -643,15 +643,22 @@ void KMLParser::placemark(const Ctx &ctx, QList<TrackData> &tracks,
wp->setTimestamp(timestamp); wp->setTimestamp(timestamp);
wp->setAddress(address); wp->setAddress(address);
wp->setPhone(phone); wp->setPhone(phone);
wp->setStyle(pointStyles.value(id)); PointStyleMap::iterator it = pointStyles.find(id);
wp->setStyle(it == pointStyles.end()
? PointStyle(QColor(0x55, 0x55, 0x55)) : *it);
} else if (tp) { } else if (tp) {
tp->setName(name); tp->setName(name);
tp->setDescription(desc); tp->setDescription(desc);
tp->setStyle(lineStyles.value(id)); LineStyleMap::iterator it = lineStyles.find(id);
tp->setStyle(it == lineStyles.end()
? LineStyle(QColor(0x55, 0x55, 0x55), 2) : *it);
} else if (ap) { } else if (ap) {
ap->setName(name); ap->setName(name);
ap->setDescription(desc); ap->setDescription(desc);
ap->setStyle(polyStyles.value(id)); PolygonStyleMap::iterator it = polyStyles.find(id);
ap->setStyle(it == polyStyles.end()
? PolygonStyle(QColor(0x55, 0x55, 0x55, 0x99),
QColor(0x55, 0x55, 0x55, 0x99), 2) : *it);
} }
} }
@ -669,6 +676,21 @@ QString KMLParser::icon()
return path; return path;
} }
QColor KMLParser::color()
{
QString str(_reader.readElementText());
if (str.size() != 8)
return QColor();
bool aok, bok, gok, rok;
int a = str.midRef(0, 2).toInt(&aok, 16);
int b = str.midRef(2, 2).toInt(&bok, 16);
int g = str.midRef(4, 2).toInt(&gok, 16);
int r = str.midRef(6, 2).toInt(&rok, 16);
return (aok && bok && gok && rok) ? QColor(r, g, b, a) : QColor();
}
QString KMLParser::styleUrl() QString KMLParser::styleUrl()
{ {
QString id(_reader.readElementText()); QString id(_reader.readElementText());
@ -679,28 +701,28 @@ void KMLParser::iconStyle(const QDir &dir, const QString &id,
PointStyleMap &styles) PointStyleMap &styles)
{ {
QPixmap img; QPixmap img;
QColor color(Qt::white); QColor c(0x55, 0x55, 0x55);
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("Icon")) if (_reader.name() == QLatin1String("Icon"))
img = QPixmap(dir.absoluteFilePath(icon())); img = QPixmap(dir.absoluteFilePath(icon()));
else if (_reader.name() == QLatin1String("color")) else if (_reader.name() == QLatin1String("color"))
color = QColor("#" + _reader.readElementText()); c = color();
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
styles.insert(id, PointStyle(img, color)); styles.insert(id, PointStyle(img, c));
} }
void KMLParser::polyStyle(const QString &id, PolygonStyleMap &styles) void KMLParser::polyStyle(const QString &id, PolygonStyleMap &styles)
{ {
QColor color(Qt::white); QColor c(0x55, 0x55, 0x55, 0x99);
uint fill = 1, outline = 1; uint fill = 1, outline = 1;
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("color")) if (_reader.name() == QLatin1String("color"))
color = QColor("#" + _reader.readElementText()); c = color();
else if (_reader.name() == QLatin1String("fill")) else if (_reader.name() == QLatin1String("fill"))
fill = _reader.readElementText().toUInt(); fill = _reader.readElementText().toUInt();
else if (_reader.name() == QLatin1String("outline")) else if (_reader.name() == QLatin1String("outline"))
@ -709,29 +731,25 @@ void KMLParser::polyStyle(const QString &id, PolygonStyleMap &styles)
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
QPen pen = (color.isValid() && outline) styles.insert(id, PolygonStyle(fill ? c : QColor(),
? QPen(color) : QPen(Qt::NoPen); outline ? c : QColor(), 2));
QBrush brush = (color.isValid() && fill)
? QBrush(color) : QBrush(Qt::NoBrush);
styles.insert(id, PolygonStyle(pen, brush));
} }
void KMLParser::lineStyle(const QString &id, LineStyleMap &styles) void KMLParser::lineStyle(const QString &id, LineStyleMap &styles)
{ {
QColor color(Qt::white); QColor c(0x55, 0x55, 0x55);
uint width = 1; double width = 2;
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("color")) if (_reader.name() == QLatin1String("color"))
color = QColor("#" + _reader.readElementText()); c = color();
else if (_reader.name() == QLatin1String("width")) else if (_reader.name() == QLatin1String("width"))
width = _reader.readElementText().toUInt(); width = _reader.readElementText().toDouble();
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
styles.insert(id, LineStyle(color, width)); styles.insert(id, LineStyle(c, width));
} }
void KMLParser::styleMapPair(const QString &id, PointStyleMap &pointStyles, void KMLParser::styleMapPair(const QString &id, PointStyleMap &pointStyles,

View File

@ -63,6 +63,7 @@ private:
QDateTime timeStamp(); QDateTime timeStamp();
qreal number(); qreal number();
QDateTime time(); QDateTime time();
QColor color();
QString icon(); QString icon();
QString styleUrl(); QString styleUrl();
void style(const QDir &dir, PointStyleMap &pointStyles, void style(const QDir &dir, PointStyleMap &pointStyles,

View File

@ -10,6 +10,8 @@ public:
PointStyle() : _size(-1) {} PointStyle() : _size(-1) {}
PointStyle(const QPixmap &icon, const QColor &color = QColor(), int size = -1) PointStyle(const QPixmap &icon, const QColor &color = QColor(), int size = -1)
: _icon(icon), _color(color), _size(size) {} : _icon(icon), _color(color), _size(size) {}
PointStyle(const QColor &color, int size = -1)
: _color(color), _size(size) {}
const QColor &color() const {return _color;} const QColor &color() const {return _color;}
const QPixmap &icon() const {return _icon;} const QPixmap &icon() const {return _icon;}
@ -23,34 +25,35 @@ private:
class PolygonStyle { class PolygonStyle {
public: public:
PolygonStyle() PolygonStyle() : _width(-1) {}
: _pen(QPen(Qt::NoPen)), _brush(QBrush(Qt::NoBrush)) {} PolygonStyle(const QColor &fill, const QColor &stroke = QColor(),
PolygonStyle(const QPen &pen, const QBrush &brush) qreal width = -1) : _fill(fill), _stroke(stroke), _width(width) {}
: _pen(pen), _brush(brush) {}
const QPen &pen() const {return _pen;} const QColor &fill() const {return _fill;}
const QBrush &brush() const {return _brush;} const QColor &stroke() const {return _stroke;}
qreal width() const {return _width;}
bool isValid() const bool isValid() const
{return _pen.style() != Qt::NoPen || _brush.style() != Qt::NoBrush;} {return _fill.isValid() || _stroke.isValid();}
private: private:
QPen _pen; QColor _fill;
QBrush _brush; QColor _stroke;
qreal _width;
}; };
class LineStyle { class LineStyle {
public: public:
LineStyle() : _width(-1) {} LineStyle() : _width(-1) {}
LineStyle(const QColor &color, int width = -1) LineStyle(const QColor &color, qreal width = -1)
: _color(color), _width(width) {} : _color(color), _width(width) {}
const QColor &color() const {return _color;} const QColor &color() const {return _color;}
int width() const {return _width;} qreal width() const {return _width;}
private: private:
QColor _color; QColor _color;
int _width; qreal _width;
}; };
#endif // STYLE_H #endif // STYLE_H