1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-28 03:59:15 +02:00

Fixed race conditions on local static data

This commit is contained in:
2023-12-21 01:13:36 +01:00
parent 11ac5da640
commit bff27df10c
13 changed files with 145 additions and 132 deletions

View File

@ -28,57 +28,6 @@ static const QColor shieldBgColor1("#dd3e3e");
static const QColor shieldBgColor2("#379947");
static const QColor shieldBgColor3("#4a7fc1");
static QFont pixelSizeFont(int pixelSize)
{
QFont f;
f.setPixelSize(pixelSize);
return f;
}
static QFont *font(Style::FontSize size, Style::FontSize defaultSize
= Style::Normal)
{
/* The fonts must be initialized on first usage (after the QGuiApplication
instance is created) */
static QFont large = pixelSizeFont(16);
static QFont normal = pixelSizeFont(14);
static QFont small = pixelSizeFont(12);
static QFont extraSmall = pixelSizeFont(10);
switch (size) {
case Style::None:
return 0;
case Style::Large:
return &large;
case Style::Normal:
return &normal;
case Style::Small:
return &small;
case Style::ExtraSmall:
return &extraSmall;
default:
return font(defaultSize);
}
}
static QFont *poiFont(Style::FontSize size = Style::Normal, int zoom = -1,
bool extended = false)
{
static QFont poi = pixelSizeFont(10);
if (zoom > 25)
size = Style::Normal;
else if (extended)
size = Style::None;
switch (size) {
case Style::None:
return 0;
default:
return &poi;
}
}
static const QColor *shieldBgColor(Shield::Type type)
{
switch (type) {
@ -152,6 +101,21 @@ static bool rectNearPolygon(const QPolygonF &polygon, const QRectF &rect)
|| polygon.containsPoint(rect.bottomRight(), Qt::OddEvenFill)));
}
const QFont *RasterTile::poiFont(Style::FontSize size, int zoom, bool extended)
{
if (zoom > 25)
size = Style::Normal;
else if (extended)
size = Style::None;
switch (size) {
case Style::None:
return 0;
default:
return _data->style()->font(Style::ExtraSmall);
}
}
void RasterTile::ll2xy(QList<MapData::Poly> &polys)
{
for (int i = 0; i < polys.size(); i++) {
@ -324,7 +288,8 @@ void RasterTile::processStreetNames(const QList<MapData::Poly> &lines,
if (style.img().isNull() && style.foreground() == Qt::NoPen)
continue;
const QFont *fnt = font(style.textFontSize(), Style::Small);
const QFont *fnt = _data->style()->font(style.textFontSize(),
Style::Small);
const QColor *color = style.textColor().isValid()
? &style.textColor() : 0;
const QColor *hColor = Style::isContourLine(poly.type) ? 0 : &haloColor;
@ -435,7 +400,7 @@ void RasterTile::processPoints(QList<MapData::Point> &points,
const QImage *img = style.img().isNull() ? 0 : &style.img();
const QFont *fnt = poi
? poiFont(style.textFontSize(), _zoom, point.classLabel)
: font(style.textFontSize());
: _data->style()->font(style.textFontSize());
const QColor *color = style.textColor().isValid()
? &style.textColor() : &textColor;
const QColor *hcolor = Style::isDepthPoint(point.type)

View File

@ -5,6 +5,7 @@
#include "mapdata.h"
#include "map/projection.h"
#include "map/transform.h"
#include "style.h"
class QPainter;
class IMGMap;
@ -12,8 +13,6 @@ class TextItem;
namespace IMG {
class Style;
class RasterTile
{
public:
@ -53,6 +52,9 @@ private:
void processStreetNames(const QList<MapData::Poly> &lines,
QList<TextItem*> &textItems, const QImage (&arrows)[2]);
const QFont *poiFont(Style::FontSize size = Style::Normal,
int zoom = -1, bool extended = false);
Projection _proj;
Transform _transform;
MapData *_data;

View File

@ -4,6 +4,13 @@
using namespace IMG;
static QFont pixelSizeFont(int pixelSize)
{
QFont f;
f.setPixelSize(pixelSize);
return f;
}
static bool readColor(SubFile *file, SubFile::Handle &hdl, QColor &color)
{
quint8 b, g, r;
@ -1226,6 +1233,11 @@ bool Style::parseTYPFile(SubFile *file)
Style::Style(SubFile *typ)
{
_large = pixelSizeFont(16);
_normal = pixelSizeFont(14);
_small = pixelSizeFont(12);
_extraSmall = pixelSizeFont(10);
defaultLineStyle();
defaultPolygonStyle();
defaultPointStyle();
@ -1258,6 +1270,24 @@ const Style::Point &Style::point(quint32 type) const
return (it == _points.constEnd()) ? null : *it;
}
const QFont *Style::font(Style::FontSize size, Style::FontSize defaultSize) const
{
switch (size) {
case Style::None:
return 0;
case Style::Large:
return &_large;
case Style::Normal:
return &_normal;
case Style::Small:
return &_small;
case Style::ExtraSmall:
return &_extraSmall;
default:
return font(defaultSize);
}
}
#ifndef QT_NO_DEBUG
static QString penColor(const QPen &pen)
{

View File

@ -3,6 +3,7 @@
#include <QPen>
#include <QBrush>
#include <QFont>
#include <QDebug>
#include "subfile.h"
@ -94,6 +95,8 @@ public:
const Polygon &polygon(quint32 type) const;
const Point &point(quint32 type) const;
const QList<quint32> &drawOrder() const {return _drawOrder;}
const QFont *font(Style::FontSize size, Style::FontSize defaultSize
= Style::Normal) const;
static bool isPOI(quint32 type)
{return !((type >= TYPE(0x01) && type <= TYPE(0x1f))
@ -172,6 +175,8 @@ private:
QMap<quint32, Polygon> _polygons;
QMap<quint32, Point> _points;
QList<quint32> _drawOrder;
QFont _large, _normal, _small, _extraSmall;
};
}