mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Include default style in resources + use application specific style load path
This commit is contained in:
parent
a8cbc962f5
commit
0edb1f0f06
@ -30,6 +30,7 @@ SOURCES += src/pbfplugin.cpp \
|
||||
src/function.cpp \
|
||||
src/textpathitem.cpp \
|
||||
src/textitem.cpp
|
||||
RESOURCES += pbfplugin.qrc
|
||||
|
||||
LIBS += -lprotobuf-lite
|
||||
|
||||
|
5
pbfplugin.qrc
Normal file
5
pbfplugin.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>style/style.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -1,20 +1,20 @@
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QStandardPaths>
|
||||
#include "pbfplugin.h"
|
||||
#include "pbfhandler.h"
|
||||
#include "style.h"
|
||||
|
||||
|
||||
#define GLOBAL_CONFIG "/usr/share/pbf/style.json"
|
||||
#define USER_CONFIG QDir::homePath() + "/.pbf/style.json"
|
||||
|
||||
PBFPlugin::PBFPlugin()
|
||||
{
|
||||
_style = new Style(this);
|
||||
|
||||
if (!_style->load(USER_CONFIG))
|
||||
if (!_style->load(GLOBAL_CONFIG))
|
||||
qCritical() << "Map style not found";
|
||||
QString style(QStandardPaths::locate(QStandardPaths::AppDataLocation,
|
||||
"style/style.json"));
|
||||
|
||||
if (style.isEmpty() || !_style->load(style)) {
|
||||
Q_INIT_RESOURCE(pbfplugin);
|
||||
_style->load(":/style/style.json");
|
||||
}
|
||||
}
|
||||
|
||||
QImageIOPlugin::Capabilities PBFPlugin::capabilities(QIODevice *device,
|
||||
|
@ -415,12 +415,21 @@ void Style::Layer::drawSymbol(int zoom, const QPainterPath &path,
|
||||
bool Style::load(const QString &fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qCritical() << fileName << ": error opening file";
|
||||
return false;
|
||||
}
|
||||
QByteArray ba(file.readAll());
|
||||
file.close();
|
||||
|
||||
QJsonObject json(QJsonDocument::fromJson(ba).object());
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc(QJsonDocument::fromJson(ba, &error));
|
||||
if (doc.isNull()) {
|
||||
qCritical() << fileName << ":" << error.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonObject json(doc.object());
|
||||
if (json.contains("layers") && json["layers"].isArray()) {
|
||||
QJsonArray layers = json["layers"].toArray();
|
||||
for (int i = 0; i < layers.size(); i++)
|
||||
|
1681
style/style.json
Normal file
1681
style/style.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user