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:
parent
a8299050c5
commit
1921087346
@ -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;
|
||||||
|
@ -20,8 +20,11 @@ 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())
|
QColor strokeColor(0x55, 0x55, 0x55);
|
||||||
return;
|
QColor fillColor(0x55, 0x55, 0x55, 0x99);
|
||||||
|
double strokeWidth = 2;
|
||||||
|
|
||||||
|
if (properties.isObject()) {
|
||||||
QJsonObject o(properties.toObject());
|
QJsonObject o(properties.toObject());
|
||||||
|
|
||||||
if (o["name"].isString())
|
if (o["name"].isString())
|
||||||
@ -31,10 +34,6 @@ static void setAreaProperties(Area &area, const QJsonValue &properties)
|
|||||||
if (o["description"].isString())
|
if (o["description"].isString())
|
||||||
area.setDescription(o["description"].toString());
|
area.setDescription(o["description"].toString());
|
||||||
|
|
||||||
QColor strokeColor(0x55, 0x55, 0x55);
|
|
||||||
QColor fillColor(0x55, 0x55, 0x55);
|
|
||||||
double strokeWidth = 2;
|
|
||||||
|
|
||||||
if (o["stroke"].isString())
|
if (o["stroke"].isString())
|
||||||
strokeColor = QColor(o["stroke"].toString());
|
strokeColor = QColor(o["stroke"].toString());
|
||||||
if (o["stroke-opacity"].isDouble())
|
if (o["stroke-opacity"].isDouble())
|
||||||
@ -47,15 +46,17 @@ static void setAreaProperties(Area &area, const QJsonValue &properties)
|
|||||||
fillColor.setAlphaF(o["fill-opacity"].toDouble());
|
fillColor.setAlphaF(o["fill-opacity"].toDouble());
|
||||||
else
|
else
|
||||||
fillColor.setAlphaF(0.6);
|
fillColor.setAlphaF(0.6);
|
||||||
|
}
|
||||||
|
|
||||||
area.setStyle(PolygonStyle(QPen(strokeColor, strokeWidth),
|
area.setStyle(PolygonStyle(fillColor, strokeColor, strokeWidth));
|
||||||
QBrush(fillColor)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setTrackProperties(TrackData &track, const QJsonValue &properties)
|
static void setTrackProperties(TrackData &track, const QJsonValue &properties)
|
||||||
{
|
{
|
||||||
if (!properties.isObject())
|
QColor color(0x55, 0x55, 0x55);
|
||||||
return;
|
double width = 2;
|
||||||
|
|
||||||
|
if (properties.isObject()) {
|
||||||
QJsonObject o(properties.toObject());
|
QJsonObject o(properties.toObject());
|
||||||
|
|
||||||
if (o["name"].isString())
|
if (o["name"].isString())
|
||||||
@ -65,15 +66,13 @@ static void setTrackProperties(TrackData &track, const QJsonValue &properties)
|
|||||||
if (o["description"].isString())
|
if (o["description"].isString())
|
||||||
track.setDescription(o["description"].toString());
|
track.setDescription(o["description"].toString());
|
||||||
|
|
||||||
QColor color(0x55, 0x55, 0x55);
|
|
||||||
double width = 2;
|
|
||||||
|
|
||||||
if (o["stroke"].isString())
|
if (o["stroke"].isString())
|
||||||
color = QColor(o["stroke"].toString());
|
color = QColor(o["stroke"].toString());
|
||||||
if (o["stroke-opacity"].isDouble())
|
if (o["stroke-opacity"].isDouble())
|
||||||
color.setAlphaF(o["stroke-opacity"].toDouble());
|
color.setAlphaF(o["stroke-opacity"].toDouble());
|
||||||
if (o["stroke-width"].isDouble())
|
if (o["stroke-width"].isDouble())
|
||||||
width = o["stroke-width"].toDouble();
|
width = o["stroke-width"].toDouble();
|
||||||
|
}
|
||||||
|
|
||||||
track.setStyle(LineStyle(color, width));
|
track.setStyle(LineStyle(color, width));
|
||||||
}
|
}
|
||||||
@ -81,8 +80,10 @@ 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())
|
QColor color(0x7e, 0x7e, 0x7e);
|
||||||
return;
|
int size = MARKER_SIZE_MEDIUM;
|
||||||
|
|
||||||
|
if (!properties.isObject()) {
|
||||||
QJsonObject o(properties.toObject());
|
QJsonObject o(properties.toObject());
|
||||||
|
|
||||||
if (o["name"].isString())
|
if (o["name"].isString())
|
||||||
@ -92,17 +93,15 @@ static void setWaypointProperties(Waypoint &waypoint,
|
|||||||
if (o["description"].isString())
|
if (o["description"].isString())
|
||||||
waypoint.setDescription(o["description"].toString());
|
waypoint.setDescription(o["description"].toString());
|
||||||
|
|
||||||
QColor color(0x7e, 0x7e, 0x7e);
|
|
||||||
int size = MARKER_SIZE_MEDIUM;
|
|
||||||
|
|
||||||
if (o["marker-color"].isString())
|
if (o["marker-color"].isString())
|
||||||
color = QColor(o["marker-color"].toString());
|
color = QColor(o["marker-color"].toString());
|
||||||
if (o["marker-symbol"].isString())
|
if (o["marker-symbol"].isString())
|
||||||
waypoint.setSymbol(o["marker-symbol"].toString());
|
waypoint.setSymbol(o["marker-symbol"].toString());
|
||||||
if (o["marker-size"].isString())
|
if (o["marker-size"].isString())
|
||||||
size = markerSize(o["marker-size"].toString());
|
size = markerSize(o["marker-size"].toString());
|
||||||
|
}
|
||||||
|
|
||||||
waypoint.setStyle(PointStyle(QPixmap(), color, size));
|
waypoint.setStyle(PointStyle(color, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user