1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-05 23:22:51 +02:00

Compare commits

...

16 Commits
7.10 ... 7.11

Author SHA1 Message Date
a11b926a98 Version++ 2019-07-18 08:14:47 +02:00
70b5371a6e Improved error handling 2019-07-18 00:26:27 +02:00
d07b6c6a9d Load TRE subdivs on demand, not all on tile load 2019-07-16 22:08:23 +02:00
c9a62e8b61 Removed obsolete stuff 2019-07-16 00:23:08 +02:00
aa3579c0be Fixed QT4 build 2019-07-13 15:14:29 +02:00
297177ad41 Cosmetics 2019-07-13 14:42:44 +02:00
0e9720f68b Optimization 2019-07-13 14:18:16 +02:00
c1f36e5fbb Improved shields layout algorithm 2019-07-13 08:36:04 +02:00
a20fd3e474 Fixed cut&paste error 2019-07-11 18:55:12 +02:00
aba78f3baa Properly handle self-asignments 2019-07-10 23:08:58 +02:00
2f24bb5462 Some more code cleanup 2019-07-10 21:49:46 +02:00
c1fdb21fad Cosmetics 2019-07-10 21:37:03 +02:00
6bea3b7ebf Suppress QT's deprecated functions warnings 2019-07-10 21:17:52 +02:00
a7efa80e8f Merge branch 'master' of https://github.com/tumic0/GPXSee 2019-07-08 21:19:54 +02:00
4e9faf3a23 Code cleanup 2019-07-08 21:19:25 +02:00
d4e153d10f Updated PL translation (#217) 2019-07-08 08:31:43 +02:00
15 changed files with 403 additions and 315 deletions

View File

@ -1,4 +1,4 @@
version: 7.10.{build}
version: 7.11.{build}
configuration: Release
platform: Any CPU
environment:

View File

@ -3,7 +3,7 @@ unix:!macx {
} else {
TARGET = GPXSee
}
VERSION = 7.10
VERSION = 7.11
QT += core \
gui \
@ -319,7 +319,8 @@ greaterThan(QT_MAJOR_VERSION, 4) {
SOURCES += src/data/geojsonparser.cpp
}
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
DEFINES += APP_VERSION=\\\"$$VERSION\\\" \
QT_NO_DEPRECATED_WARNINGS
DEFINES *= QT_USE_QSTRINGBUILDER
RESOURCES += gpxsee.qrc

View File

@ -64,7 +64,7 @@
<message>
<location filename="../src/data/data.cpp" line="152"/>
<source>GeoJSON files</source>
<translation type="unfinished"></translation>
<translation>Pliki GeoJSON</translation>
</message>
<message>
<location filename="../src/data/data.cpp" line="154"/>
@ -79,7 +79,7 @@
<message>
<location filename="../src/data/data.cpp" line="156"/>
<source>JPEG images</source>
<translation type="unfinished"></translation>
<translation>Pliki JPEG</translation>
</message>
<message>
<location filename="../src/data/data.cpp" line="157"/>
@ -439,7 +439,7 @@
<message>
<location filename="../src/GUI/gui.cpp" line="315"/>
<source>Show cursor coordinates</source>
<translation type="unfinished"></translation>
<translation>Pokaż współrzędne kursora</translation>
</message>
<message>
<location filename="../src/GUI/gui.cpp" line="322"/>
@ -459,7 +459,7 @@
<message>
<location filename="../src/GUI/gui.cpp" line="337"/>
<source>Show areas</source>
<translation type="unfinished"></translation>
<translation>Pokaż obszary</translation>
</message>
<message>
<location filename="../src/GUI/gui.cpp" line="342"/>
@ -469,7 +469,7 @@
<message>
<location filename="../src/GUI/gui.cpp" line="352"/>
<source>km/mi markers</source>
<translation type="unfinished"></translation>
<translation>Znaczniki km/mi</translation>
</message>
<message>
<location filename="../src/GUI/gui.cpp" line="359"/>
@ -489,7 +489,7 @@
<message>
<location filename="../src/GUI/gui.cpp" line="393"/>
<source>Show path markers</source>
<translation type="unfinished"></translation>
<translation>Pokaż znaczniki ścieżki</translation>
</message>
<message>
<location filename="../src/GUI/gui.cpp" line="400"/>
@ -651,18 +651,18 @@
<message>
<location filename="../src/GUI/gui.cpp" line="731"/>
<source>DEM directory:</source>
<translation type="unfinished"></translation>
<translation>Katalog z danymi DEM:</translation>
</message>
<message>
<location filename="../src/GUI/gui.cpp" line="733"/>
<source>Styles directory:</source>
<translation type="unfinished"></translation>
<translation>Katalog ze stylami:</translation>
</message>
<message>
<location filename="../src/GUI/gui.cpp" line="1037"/>
<location filename="../src/GUI/gui.cpp" line="1105"/>
<source>Areas</source>
<translation type="unfinished"></translation>
<translation>Obszary</translation>
</message>
<message>
<location filename="../src/GUI/gui.cpp" line="1080"/>
@ -736,7 +736,7 @@
<message>
<location filename="../src/GUI/gui.cpp" line="735"/>
<source>Tile cache directory:</source>
<translation type="unfinished"></translation>
<translation>Katalog pamięci podręcznej kafelków:</translation>
</message>
<message>
<location filename="../src/GUI/gui.cpp" line="1031"/>
@ -1018,7 +1018,7 @@
<message>
<location filename="../src/map/maplist.cpp" line="123"/>
<source>Garmin IMG maps</source>
<translation type="unfinished"></translation>
<translation>Mapy Garmin IMG</translation>
</message>
<message>
<location filename="../src/map/maplist.cpp" line="125"/>
@ -1038,7 +1038,7 @@
<message>
<location filename="../src/map/maplist.cpp" line="129"/>
<source>TwoNav maps</source>
<translation type="unfinished"></translation>
<translation>Mapy TwoNav</translation>
</message>
<message>
<location filename="../src/map/maplist.cpp" line="130"/>
@ -1309,18 +1309,18 @@
<location filename="../src/GUI/optionsdialog.cpp" line="378"/>
<location filename="../src/GUI/optionsdialog.cpp" line="436"/>
<source>GPS data</source>
<translation type="unfinished"></translation>
<translation>Dane GPS</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="379"/>
<location filename="../src/GUI/optionsdialog.cpp" line="437"/>
<source>DEM data</source>
<translation type="unfinished"></translation>
<translation>Dane DEM</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="416"/>
<source>Elevation</source>
<translation type="unfinished">Wysokość</translation>
<translation>Wysokość</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="427"/>
@ -1330,7 +1330,7 @@
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="428"/>
<source>Sources</source>
<translation type="unfinished"></translation>
<translation>Źródła</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="429"/>
@ -1340,7 +1340,7 @@
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="462"/>
<source>Radius:</source>
<translation type="unfinished"></translation>
<translation>Promień:</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="410"/>
@ -1350,37 +1350,37 @@
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="72"/>
<source>Projection:</source>
<translation type="unfinished"></translation>
<translation>Odwzorowanie:</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="94"/>
<source>Vector maps</source>
<translation type="unfinished"></translation>
<translation>Mapy wektorowe</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="147"/>
<source>Area border width:</source>
<translation type="unfinished"></translation>
<translation>Szerokość granicy obszaru:</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="148"/>
<source>Area border style:</source>
<translation type="unfinished"></translation>
<translation>Styl obramowania obszaru:</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="149"/>
<source>Area fill opacity:</source>
<translation type="unfinished"></translation>
<translation>Nieprzezroczystość wypełnienia obszaru:</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="153"/>
<source>Fill opacity:</source>
<translation type="unfinished"></translation>
<translation>Nieprzezroczystość wypełnienia:</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="154"/>
<source>Areas</source>
<translation type="unfinished"></translation>
<translation>Obszary</translation>
</message>
<message>
<location filename="../src/GUI/optionsdialog.cpp" line="448"/>
@ -1530,12 +1530,12 @@
<message>
<location filename="../src/GUI/areaitem.cpp" line="15"/>
<source>Name</source>
<translation type="unfinished">Nazwa</translation>
<translation>Nazwa</translation>
</message>
<message>
<location filename="../src/GUI/areaitem.cpp" line="17"/>
<source>Description</source>
<translation type="unfinished">Opis</translation>
<translation>Opis</translation>
</message>
</context>
<context>

View File

@ -7,7 +7,7 @@
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "7.10"
!define VERSION "7.11"
; The file to write
OutFile "GPXSee-${VERSION}.exe"

View File

@ -7,7 +7,7 @@
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "7.10"
!define VERSION "7.11"
; The file to write
OutFile "GPXSee-${VERSION}_x64.exe"

View File

@ -4,6 +4,9 @@
#include <QString>
#include <QDebug>
#define FIRST_SHIELD Label::Shield::USInterstate
#define LAST_SHIELD Label::Shield::Oval
class Label {
public:
class Shield

View File

@ -102,7 +102,8 @@ Label LBLFile::label6b(Handle &hdl, quint32 offset) const
else if (c[cpt] == 0x1b)
curCharSet = Special;
else if (c[cpt] >= 0x2a && c[cpt] <= 0x2f) {
shieldType = (Label::Shield::Type)(c[cpt] - 0x29);
shieldType = static_cast<Label::Shield::Type>
(c[cpt] - 0x29);
bap = &shieldLabel;
} else if (bap == &shieldLabel
&& NORMAL_CHARS[c[cpt]] == ' ')
@ -145,7 +146,7 @@ Label LBLFile::label8b(Handle &hdl, quint32 offset) const
else
bap->append(' ');
} else if (c <= 0x07) {
shieldType = (Label::Shield::Type)c;
shieldType = static_cast<Label::Shield::Type>(c);
bap = &shieldLabel;
} else if (bap == &shieldLabel && QChar(c).isSpace()) {
bap = &label;

View File

@ -459,7 +459,7 @@ void RGNFile::extObjects(const RectC &rect, const SubDiv *subdiv, LBLFile *lbl,
quint32 start = _pointsOffset + subdiv->pointsOffset();
quint32 end = subdiv->pointsEnd()
? _pointsOffset + subdiv->pointsEnd()
: _pointsOffset + _linesSize;
: _pointsOffset + _pointsSize;
extPointObjects(rect, rgnHdl, subdiv, Segment(start, end,
Segment::Point), lbl, lblHdl, points);
}

View File

@ -17,18 +17,18 @@ static void expand(QRect &rect, int width)
TextPointItem::TextPointItem(const QPoint &point, const QString *text,
const QFont *font, const QImage *img, const QColor *color,
const QColor *bgColor) : _text(text), _font(font), _img(img), _color(color),
_bgColor(bgColor)
const QColor *bgColor) : _text(font ? text : 0), _font(font), _img(img),
_color(color), _bgColor(bgColor)
{
if (text) {
QFontMetrics fm(*font);
int limit = font->pixelSize() * MAX_TEXT_WIDTH;
_textRect = fm.boundingRect(QRect(0, 0, limit, 0), FLAGS, *text);
if (_text) {
QFontMetrics fm(*_font);
int limit = _font->pixelSize() * MAX_TEXT_WIDTH;
_textRect = fm.boundingRect(QRect(0, 0, limit, 0), FLAGS, *_text);
_textRect.adjust(0, 0, 1, 1);
}
if (_bgColor && _textRect.width() < font->pixelSize() * MIN_BOX_WIDTH)
expand(_textRect, font->pixelSize() * MIN_BOX_WIDTH);
if (_bgColor && _textRect.width() < _font->pixelSize() * MIN_BOX_WIDTH)
expand(_textRect, _font->pixelSize() * MIN_BOX_WIDTH);
}
setPos(point);
}
@ -58,41 +58,44 @@ void TextPointItem::paint(QPainter *painter) const
- _img->height()/2), *_img);
if (_text) {
QImage img(_textRect.size(), QImage::Format_ARGB32_Premultiplied);
img.fill(Qt::transparent);
QPainter ip(&img);
ip.setPen(Qt::white);
ip.setFont(*_font);
ip.drawText(img.rect(), FLAGS, *_text);
painter->drawImage(_textRect.x() - 1, _textRect.y() - 1, img);
painter->drawImage(_textRect.x() + 1, _textRect.y() + 1, img);
painter->drawImage(_textRect.x() - 1, _textRect.y() + 1, img);
painter->drawImage(_textRect.x(), _textRect.y() - 1, img);
painter->drawImage(_textRect.x(), _textRect.y() + 1, img);
painter->drawImage(_textRect.x() - 1, _textRect.y(), img);
painter->drawImage(_textRect.x() + 1, _textRect.y(), img);
if (_bgColor) {
painter->setPen(*_color);
painter->setBrush(*_bgColor);
painter->drawRect(_textRect);
painter->setBrush(Qt::NoBrush);
}
if (_color) {
painter->setFont(*_font);
painter->setPen(*_color);
painter->drawText(_textRect, FLAGS, *_text);
} else {
QImage img(_textRect.size(), QImage::Format_ARGB32_Premultiplied);
img.fill(Qt::transparent);
QPainter ip(&img);
ip.setPen(Qt::white);
ip.setFont(*_font);
ip.drawText(img.rect(), FLAGS, *_text);
painter->drawImage(_textRect.x() - 1, _textRect.y() - 1, img);
painter->drawImage(_textRect.x() + 1, _textRect.y() + 1, img);
painter->drawImage(_textRect.x() - 1, _textRect.y() + 1, img);
painter->drawImage(_textRect.x() + 1, _textRect.y() - 1, img);
painter->drawImage(_textRect.x(), _textRect.y() - 1, img);
painter->drawImage(_textRect.x(), _textRect.y() + 1, img);
painter->drawImage(_textRect.x() - 1, _textRect.y(), img);
painter->drawImage(_textRect.x() + 1, _textRect.y(), img);
if (_color) {
painter->setFont(*_font);
painter->setPen(*_color);
painter->drawText(_textRect, FLAGS, *_text);
} else {
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
img.invertPixels();
painter->drawImage(_textRect, img);
img.invertPixels();
painter->drawImage(_textRect, img);
#else // QT >= 5.4
QImage iimg(img.convertToFormat(QImage::Format_ARGB32));
iimg.invertPixels();
painter->drawImage(_textRect, iimg);
QImage iimg(img.convertToFormat(QImage::Format_ARGB32));
iimg.invertPixels();
painter->drawImage(_textRect, iimg);
#endif // QT >= 5.4
}
}
}

View File

@ -3,12 +3,6 @@
#include "trefile.h"
struct MapLevel {
quint8 level;
quint8 bits;
quint16 subdivs;
};
static void unlock(quint8 *dst, const quint8 *src, quint32 size, quint32 key)
{
static const unsigned char shuf[] = {
@ -46,6 +40,12 @@ TREFile::~TREFile()
bool TREFile::init()
{
Handle hdl;
quint8 locked;
quint16 hdrLen;
if (!(seek(hdl, 0) && readUInt16(hdl, hdrLen)
&& seek(hdl, 0x0D) && readByte(hdl, locked)))
return false;
// Tile bounds
qint32 north, east, south, west;
@ -55,30 +55,18 @@ bool TREFile::init()
_bounds = RectC(Coordinates(toWGS84(west), toWGS84(north)),
Coordinates(toWGS84(east), toWGS84(south)));
return true;
}
bool TREFile::load()
{
Handle hdl;
quint8 locked;
quint16 hdrLen;
if (!(seek(hdl, 0) && readUInt16(hdl, hdrLen)
&& seek(hdl, 0x0D) && readByte(hdl, locked)))
return false;
quint32 levelsOffset, levelsSize, subdivOffset, subdivSize;
// Levels & subdivs info
quint32 levelsOffset, levelsSize, subdivSize;
if (!(seek(hdl, 0x21) && readUInt32(hdl, levelsOffset)
&& readUInt32(hdl, levelsSize) && readUInt32(hdl, subdivOffset)
&& readUInt32(hdl, levelsSize) && readUInt32(hdl, _subdivOffset)
&& readUInt32(hdl, subdivSize)))
return false;
quint32 extOffset, extSize = 0;
quint16 extItemSize = 0;
// TRE7 info
if (hdrLen > 0x9A) {
if (!(seek(hdl, 0x7C) && readUInt32(hdl, extOffset)
&& readUInt32(hdl, extSize) && readUInt16(hdl, extItemSize)))
if (!(seek(hdl, 0x7C) && readUInt32(hdl, _extended.offset)
&& readUInt32(hdl, _extended.size)
&& readUInt16(hdl, _extended.itemSize)))
return false;
}
@ -99,96 +87,134 @@ bool TREFile::load()
}
quint32 levelsCount = levelsSize / 4;
QVector<MapLevel> ml(levelsCount);
QMap<int, int> level2bits;
_levels = QVector<MapLevel>(levelsCount);
for (quint32 i = 0; i < levelsCount; i++) {
quint8 *zoom = levels + (i * 4);
ml[i].level = *zoom;
ml[i].bits = *(zoom + 1);
ml[i].subdivs = *(zoom + 2) | (quint16)(*(zoom + 3)) << 8;
if ((ml[i].level & 0xF) > 15 || ml[i].bits > 24)
_levels[i].level = *zoom;
_levels[i].bits = *(zoom + 1);
_levels[i].subdivs = *(zoom + 2) | (quint16)(*(zoom + 3)) << 8;
if (_levels[i].bits > 24 || !_levels[i].subdivs)
return false;
level2bits.insert(ml[i].level & 0xF, ml[i].bits);
}
// Subdivisions
if (!seek(hdl, subdivOffset))
return false;
SubDiv *s = 0;
QList<SubDiv*> sl;
for (int i = 0; i < ml.size(); i++) {
if (!(ml.at(i).level & 0x80))
_subdivs.insert(ml.at(i).bits, new SubDivTree());
for (int j = 0; j < ml.at(i).subdivs; j++) {
quint32 offset;
qint32 lon, lat;
quint8 objects;
quint16 width, height, nextLevel;
if (!(readUInt24(hdl, offset) && readByte(hdl, objects)
&& readInt24(hdl, lon) && readInt24(hdl, lat)
&& readUInt16(hdl, width) && readUInt16(hdl, height)))
return false;
if (i != (int)levelsCount - 1)
if (!readUInt16(hdl, nextLevel))
return false;
if (s)
s->setEnd(offset);
if (ml.at(i).level & 0x80) {
sl.append(0);
s = 0;
continue;
}
width &= 0x7FFF;
width <<= (24 - ml.at(i).bits);
height <<= (24 - ml.at(i).bits);
s = new SubDiv(offset, lon, lat, ml.at(i).bits, objects);
sl.append(s);
double min[2], max[2];
RectC bounds(Coordinates(toWGS84(lon - width),
toWGS84(lat + height + 1)), Coordinates(toWGS84(lon + width + 1),
toWGS84(lat - height)));
min[0] = bounds.left();
min[1] = bounds.bottom();
max[0] = bounds.right();
max[1] = bounds.top();
_subdivs[ml.at(i).bits]->Insert(min, max, s);
// Get first non-inherited level
_firstLevel = -1;
for (int i = 0; i < _levels.size(); i++) {
if (!(_levels.at(i).level & 0x80)) {
_firstLevel = i;
break;
}
}
// objects with extended types (TRE7)
if (extSize && extItemSize >= 12
&& (sl.size() - (int)(extSize/extItemSize) + 1 >= 0)) {
quint32 polygons, lines, points;
if (!seek(hdl, extOffset))
return false;
return (_firstLevel >= 0);
}
for (int i = sl.size() - (extSize/extItemSize) + 1; i < sl.size(); i++) {
bool TREFile::load(int idx)
{
Handle hdl;
QList<SubDiv*> sl;
SubDiv *s = 0;
SubDivTree *tree = new SubDivTree();
_subdivs.insert(_levels.at(idx).bits, tree);
quint32 skip = 0;
for (int i = 0; i < idx; i++)
skip += _levels.at(i).subdivs;
if (!seek(hdl, _subdivOffset + skip * 16))
return false;
for (int j = 0; j < _levels.at(idx).subdivs; j++) {
quint32 offset;
qint32 lon, lat;
quint8 objects;
quint16 width, height, nextLevel;
if (!(readUInt24(hdl, offset) && readByte(hdl, objects)
&& readInt24(hdl, lon) && readInt24(hdl, lat)
&& readUInt16(hdl, width) && readUInt16(hdl, height)))
goto error;
if (idx != _levels.size() - 1)
if (!readUInt16(hdl, nextLevel))
goto error;
if (s)
s->setEnd(offset);
width &= 0x7FFF;
width <<= (24 - _levels.at(idx).bits);
height <<= (24 - _levels.at(idx).bits);
s = new SubDiv(offset, lon, lat, _levels.at(idx).bits, objects);
sl.append(s);
double min[2], max[2];
RectC bounds(Coordinates(toWGS84(lon - width),
toWGS84(lat + height + 1)), Coordinates(toWGS84(lon + width + 1),
toWGS84(lat - height)));
min[0] = bounds.left();
min[1] = bounds.bottom();
max[0] = bounds.right();
max[1] = bounds.top();
tree->Insert(min, max, s);
}
if (idx != _levels.size() - 1) {
quint32 offset;
if (!readUInt24(hdl, offset))
goto error;
s->setEnd(offset);
}
// Objects with extended types (TRE7)
if (_extended.size && _extended.itemSize >= 12) {
/* Some maps skip entries for the inherited levels, some don't. Our
decision is based on the difference between the extended subdivs
count and the total subdivs count. */
quint32 totalSubdivs = 0;
for (int i = 0; i < _levels.size(); i++)
totalSubdivs += _levels.at(i).subdivs;
quint32 extendedSubdivs = _extended.size / _extended.itemSize;
quint32 diff = totalSubdivs - extendedSubdivs + 1;
quint32 polygons, lines, points;
if (!seek(hdl, _extended.offset + (skip - diff) * _extended.itemSize))
goto error;
for (int i = 0; i < sl.size(); i++) {
if (!(readUInt32(hdl, polygons) && readUInt32(hdl, lines)
&& readUInt32(hdl, points)))
return false;
if (!seek(hdl, hdl.pos + extItemSize - 12))
return false;
if (i && sl.at(i-1))
goto error;
sl.at(i)->setExtOffsets(polygons, lines, points);
if (i)
sl.at(i-1)->setExtEnds(polygons, lines, points);
if (sl.at(i))
sl.at(i)->setExtOffsets(polygons, lines, points);
if (!seek(hdl, hdl.pos + _extended.itemSize - 12))
goto error;
}
if (idx != _levels.size() - 1) {
if (!(readUInt32(hdl, polygons) && readUInt32(hdl, lines)
&& readUInt32(hdl, points)))
goto error;
sl.last()->setExtEnds(polygons, lines, points);
}
}
_levels = _subdivs.keys();
return true;
error:
qDeleteAll(sl);
tree->RemoveAll();
return false;
}
void TREFile::clear()
@ -205,23 +231,22 @@ void TREFile::clear()
qDeleteAll(_subdivs);
_subdivs.clear();
_levels.clear();
}
int TREFile::level(int bits)
{
if (_levels.isEmpty() && !load())
return -1;
int idx = _firstLevel;
int l = _levels.first();
for (int i = 0; i < _levels.size(); i++) {
if (_levels.at(i) > bits)
for (int i = idx + 1; i < _levels.size(); i++) {
if (_levels.at(i).bits > bits)
break;
else
l = _levels.at(i);
idx++;
}
return l;
if (!_subdivs.contains(_levels.at(idx).bits) && !load(idx))
return -1;
return _levels.at(idx).bits;
}
static bool cb(SubDiv *subdiv, void *context)
@ -247,3 +272,12 @@ QList<SubDiv*> TREFile::subdivs(const RectC &rect, int bits)
return list;
}
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const TREFile::MapLevel &level)
{
dbg.nospace() << "MapLevel(" << level.level << ", " << level.bits << ", "
<< level.subdivs << ")";
return dbg.space();
}
#endif // QT_NO_DEBUG

View File

@ -23,17 +23,39 @@ public:
QList<SubDiv*> subdivs(const RectC &rect, int bits);
private:
struct MapLevel {
quint8 level;
quint8 bits;
quint16 subdivs;
};
struct Extended {
quint32 offset;
quint32 size;
quint16 itemSize;
Extended() : offset(0), size(0), itemSize(0) {}
};
typedef RTree<SubDiv*, double, 2> SubDivTree;
bool load();
bool load(int idx);
int level(int bits);
bool parsePoly(Handle hdl, quint32 pos, const QMap<int, int> &level2bits,
QMap<quint32, int> &map);
bool parsePoints(Handle hdl, quint32 pos, const QMap<int, int> &level2bits);
friend QDebug operator<<(QDebug dbg, const MapLevel &level);
RectC _bounds;
QList<int> _levels;
QVector<MapLevel> _levels;
quint32 _subdivOffset;
Extended _extended;
int _firstLevel;
QMap<int, SubDivTree*> _subdivs;
};
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const TREFile::MapLevel &level);
#endif // QT_NO_DEBUG
#endif // TREFILE_H

View File

@ -18,7 +18,9 @@
#define TILE_SIZE 256
#define TEXT_EXTENT 256
#define LINE_TEXT_MIN_ZOOM 22
#define AREA(rect) \
(rect.size().width() * rect.size().height())
class RasterTile
{
@ -35,13 +37,14 @@ public:
QList<IMG::Poly> &lines() {return _lines;}
QList<IMG::Point> &points() {return _points;}
void load()
void render()
{
QList<TextItem*> textItems;
_map->processPolygons(_polygons);
_map->processPoints(_points, textItems);
_map->processLines(_lines, _xy, textItems);
_map->processLines(_lines, QRect(_xy, QSize(TILE_SIZE, TILE_SIZE)),
textItems);
_img.fill(Qt::transparent);
@ -53,6 +56,8 @@ public:
_map->drawPolygons(&painter, _polygons);
_map->drawLines(&painter, _lines);
_map->drawTextItems(&painter, textItems);
//painter.setPen(Qt::red);
//painter.drawRect(QRect(_xy, QSize(TILE_SIZE, TILE_SIZE)));
qDeleteAll(textItems);
}
@ -68,12 +73,13 @@ private:
};
static Range zooms(12, 28);
static QColor shieldColor(Qt::white);
static QColor shieldBgColor1("#dd3e3e");
static QColor shieldBgColor2("#379947");
static QColor shieldBgColor3("#4a7fc1");
static QString convertUnits(const QString &str)
{
bool ok;
@ -102,26 +108,47 @@ static int minPOIZoom(Style::POIClass cl)
}
}
static QFont font(int pixelSize)
static QFont pixelSizeFont(int pixelSize)
{
QFont f;
f.setPixelSize(pixelSize);
return f;
}
/* The fonts must be initialized on first usage (after the QGuiApplication
instance is created) */
#define FONT(name, size) \
static const QFont *name() \
{ \
static QFont f = font(size); \
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);
switch (size) {
case Style::None:
return 0;
case Style::Large:
return &large;
case Style::Normal:
return &normal;
case Style::Small:
return &small;
default:
return font(defaultSize);
}
}
FONT(largeFont, 16)
FONT(normalFont, 14)
FONT(smallFont, 12)
FONT(poiFont, 10)
static QFont *poiFont(Style::FontSize size = Style::Normal)
{
static QFont poi = pixelSizeFont(10);
switch (size) {
case Style::None:
return 0;
default:
return &poi;
}
}
static const QColor *shieldBgColor(Label::Shield::Type type)
{
@ -153,7 +180,7 @@ static int minShieldZoom(Label::Shield::Type type)
case Label::Shield::Oval:
return 20;
default:
return INT_MAX;
return 0;
}
}
@ -166,9 +193,7 @@ IMGMap::IMGMap(const QString &fileName, QObject *parent)
return;
}
_zooms = Range(12, 28);
_zoom = _zooms.min();
_zoom = zooms.min();
updateTransform();
_valid = true;
@ -196,8 +221,8 @@ int IMGMap::zoomFit(const QSize &size, const RectC &rect)
if (rect.isValid()) {
RectD pr(rect, _projection, 10);
_zoom = _zooms.min();
for (int i = _zooms.min() + 1; i <= _zooms.max(); i++) {
_zoom = zooms.min();
for (int i = zooms.min() + 1; i <= zooms.max(); i++) {
Transform t(transform(i));
QRectF r(t.proj2img(pr.topLeft()), t.proj2img(pr.bottomRight()));
if (size.width() < r.width() || size.height() < r.height())
@ -205,7 +230,7 @@ int IMGMap::zoomFit(const QSize &size, const RectC &rect)
_zoom = i;
}
} else
_zoom = _zooms.max();
_zoom = zooms.max();
updateTransform();
@ -214,14 +239,14 @@ int IMGMap::zoomFit(const QSize &size, const RectC &rect)
int IMGMap::zoomIn()
{
_zoom = qMin(_zoom + 1, _zooms.max());
_zoom = qMin(_zoom + 1, zooms.max());
updateTransform();
return _zoom;
}
int IMGMap::zoomOut()
{
_zoom = qMax(_zoom - 1, _zooms.min());
_zoom = qMax(_zoom - 1, zooms.min());
updateTransform();
return _zoom;
}
@ -318,11 +343,9 @@ void IMGMap::processPolygons(QList<IMG::Poly> &polygons)
}
}
void IMGMap::processLines(QList<IMG::Poly> &lines, const QPoint &tile,
void IMGMap::processLines(QList<IMG::Poly> &lines, const QRect &tileRect,
QList<TextItem*> &textItems)
{
QRect tileRect(tile, QSize(TILE_SIZE, TILE_SIZE));
qStableSort(lines);
for (int i = 0; i < lines.size(); i++) {
@ -333,86 +356,100 @@ void IMGMap::processLines(QList<IMG::Poly> &lines, const QPoint &tile,
}
}
if (_zoom >= LINE_TEXT_MIN_ZOOM) {
for (int i = 0; i < lines.size(); i++) {
IMG::Poly &poly = lines[i];
const Style::Line &style = _img.style()->line(poly.type);
if (_zoom >= 22)
processStreetNames(lines, tileRect, textItems);
processShields(lines, tileRect, textItems);
}
if (style.img().isNull() && style.foreground() == Qt::NoPen)
continue;
if (poly.label.text().isEmpty()
|| style.textFontSize() == Style::None)
continue;
void IMGMap::processStreetNames(QList<IMG::Poly> &lines, const QRect &tileRect,
QList<TextItem*> &textItems)
{
for (int i = 0; i < lines.size(); i++) {
IMG::Poly &poly = lines[i];
const Style::Line &style = _img.style()->line(poly.type);
if (Style::isContourLine(poly.type))
poly.label.setText(convertUnits(poly.label.text()));
const QFont *font;
switch (style.textFontSize()) {
case Style::Large:
font = largeFont();
break;
case Style::Normal:
font = normalFont();
break;
default:
font = smallFont();
}
const QColor *color = style.textColor().isValid()
? &style.textColor() : 0;
TextPathItem *item = new TextPathItem(poly.points,
&poly.label.text(), tileRect, font, color);
if (item->isValid() && !item->collides(textItems))
textItems.append(item);
else
delete item;
}
}
for (int type = 1; type < 7; type++) {
if (minShieldZoom((Label::Shield::Type)type) > _zoom)
if (style.img().isNull() && style.foreground() == Qt::NoPen)
continue;
if (poly.label.text().isEmpty()
|| style.textFontSize() == Style::None)
continue;
QSet<Label::Shield> shields;
if (Style::isContourLine(poly.type))
poly.label.setText(convertUnits(poly.label.text()));
const QFont *fnt = font(style.textFontSize(), Style::Small);
const QColor *color = style.textColor().isValid()
? &style.textColor() : 0;
TextPathItem *item = new TextPathItem(poly.points,
&poly.label.text(), tileRect, fnt, color);
if (item->isValid() && !item->collides(textItems))
textItems.append(item);
else
delete item;
}
}
void IMGMap::processShields(QList<IMG::Poly> &lines, const QRect &tileRect,
QList<TextItem*> &textItems)
{
for (int type = FIRST_SHIELD; type <= LAST_SHIELD; type++) {
if (minShieldZoom(static_cast<Label::Shield::Type>(type)) > _zoom)
continue;
QHash<Label::Shield, QPolygonF> shields;
QHash<Label::Shield, const Label::Shield*> sp;
for (int i = 0; i < lines.size(); i++) {
const IMG::Poly &poly = lines.at(i);
const Label::Shield &shield = poly.label.shield();
if (shield.type() != type || !Style::isMajorRoad(poly.type))
if (!shield.isValid() || shield.type() != type
|| !Style::isMajorRoad(poly.type))
continue;
if (poly.label.shield().isValid() && !shields.contains(shield)) {
bool valid = false;
int idx = poly.points.size()/2, inc = 0, sign = 1;
QPolygonF &p = shields[shield];
for (int j = 0; j < poly.points.size(); j++)
p.append(poly.points.at(j));
TextPointItem *item = new TextPointItem(
poly.points.at(idx).toPoint(), &shield.text(), poiFont(),
0, &shieldColor, shieldBgColor(shield.type()));
sp.insert(shield, &shield);
}
while (1) {
if (!item->collides(textItems)
&& tileRect.contains(item->boundingRect().toRect())) {
valid = true;
break;
}
inc++;
sign = (sign < 0) ? 1 : -1;
idx += inc * sign;
for (QHash<Label::Shield, QPolygonF>::const_iterator it
= shields.constBegin(); it != shields.constEnd(); ++it) {
const QPolygonF &p = it.value();
QRectF rect(p.boundingRect() & tileRect);
if (qSqrt(AREA(rect)) < 32)
continue;
if (!(idx >= 0 && idx < poly.points.size()))
break;
item->setPos(poly.points.at(idx).toPoint());
}
if (valid) {
textItems.append(item);
shields.insert(shield);
} else
delete item;
QMap<qreal, int> map;
QPointF center = rect.center();
for (int j = 0; j < p.size(); j++) {
QLineF l(p.at(j), center);
map.insert(l.length(), j);
}
QMap<qreal, int>::const_iterator jt = map.constBegin();
TextPointItem *item = new TextPointItem(
p.at(jt.value()).toPoint(), &(sp.value(it.key())->text()),
poiFont(), 0, &shieldColor, shieldBgColor(it.key().type()));
bool valid = false;
while (true) {
if (!item->collides(textItems)
&& tileRect.contains(item->boundingRect().toRect())) {
valid = true;
break;
}
if (++jt == map.constEnd())
break;
item->setPos(p.at(jt.value()).toPoint());
}
if (valid)
textItems.append(item);
else
delete item;
}
}
}
@ -424,7 +461,6 @@ void IMGMap::processPoints(QList<IMG::Point> &points,
for (int i = 0; i < points.size(); i++) {
IMG::Point &point = points[i];
const Style::Point &style = _img.style()->point(point.type);
if (point.poi && _zoom < minPOIZoom(Style::poiClass(point.type)))
@ -433,31 +469,12 @@ void IMGMap::processPoints(QList<IMG::Point> &points,
const QString *label = point.label.text().isEmpty()
? 0 : &(point.label.text());
const QImage *img = style.img().isNull() ? 0 : &style.img();
const QFont *font = 0;
if (point.poi) {
if (style.textFontSize() == Style::None)
label = 0;
else
font = poiFont();
} else {
switch (style.textFontSize()) {
case Style::None:
label = 0;
break;
case Style::Small:
font = smallFont();
break;
case Style::Large:
font = largeFont();
break;
default:
font = normalFont();
}
}
const QFont *fnt = point.poi
? poiFont(style.textFontSize()) : font(style.textFontSize());
const QColor *color = style.textColor().isValid()
? &style.textColor() : 0;
if (!label && !img)
if ((!label || !fnt) && !img)
continue;
if (Style::isSpot(point.type))
@ -469,7 +486,7 @@ void IMGMap::processPoints(QList<IMG::Point> &points,
}
TextPointItem *item = new TextPointItem(
ll2xy(point.coordinates).toPoint(), label, font, img, color);
ll2xy(point.coordinates).toPoint(), label, fnt, img, color);
if (item->isValid() && !item->collides(textItems))
textItems.append(item);
else
@ -479,7 +496,7 @@ void IMGMap::processPoints(QList<IMG::Point> &points,
static void render(RasterTile &tile)
{
tile.load();
tile.render();
}
void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags)

View File

@ -50,13 +50,16 @@ private:
void drawTextItems(QPainter *painter, const QList<TextItem*> &textItems);
void processPolygons(QList<IMG::Poly> &polygons);
void processLines(QList<IMG::Poly> &lines, const QPoint &tile,
void processLines(QList<IMG::Poly> &lines, const QRect &tileRect,
QList<TextItem*> &textItems);
void processPoints(QList<IMG::Point> &points, QList<TextItem*> &textItems);
void processShields(QList<IMG::Poly> &lines, const QRect &tileRect,
QList<TextItem*> &textItems);
void processStreetNames(QList<IMG::Poly> &lines, const QRect &tileRect,
QList<TextItem*> &textItems);
IMG _img;
int _zoom;
Range _zooms;
Projection _projection;
Transform _transform;

View File

@ -37,21 +37,23 @@ Matrix::Matrix(const Matrix& M)
Matrix &Matrix::operator=(const Matrix &M)
{
if (_h != M._h || _w != M._w) {
if (!isNull())
delete[] _m;
if (this != &M) {
if (_h != M._h || _w != M._w) {
if (!isNull())
delete[] _m;
_h = M._h; _w = M._w;
if (isNull())
_m = 0;
else
_m = new double[_h * _w];
_h = M._h; _w = M._w;
if (isNull())
_m = 0;
else
_m = new double[_h * _w];
}
for (size_t i = 0; i < _h; i++)
for (size_t j = 0; j < _w; j++)
m(i,j) = M.m(i,j);
}
for (size_t i = 0; i < _h; i++)
for (size_t j = 0; j < _w; j++)
m(i,j) = M.m(i,j);
return *this;
}

View File

@ -128,13 +128,15 @@ Projection::~Projection()
Projection &Projection::operator=(const Projection &p)
{
delete _ct;
if (this != &p) {
delete _ct;
_gcs = p._gcs;
_units = p._units;
_ct = p._ct ? p._ct->clone() : 0;
_geographic = p._geographic;
_cs = p._cs;
_gcs = p._gcs;
_units = p._units;
_ct = p._ct ? p._ct->clone() : 0;
_geographic = p._geographic;
_cs = p._cs;
}
return *this;
}