diff --git a/ArchitectureColoredPainting/src/Editor/third-party modules/util/SvgFileLoader.cpp b/ArchitectureColoredPainting/src/Editor/third-party modules/util/SvgFileLoader.cpp index 3e01994..6ccf71f 100644 --- a/ArchitectureColoredPainting/src/Editor/third-party modules/util/SvgFileLoader.cpp +++ b/ArchitectureColoredPainting/src/Editor/third-party modules/util/SvgFileLoader.cpp @@ -62,14 +62,20 @@ QMap SvgFileLoader::transformStyle(QString style) { return resStyleMap; } -QVector SvgFileLoader::transformPoints(QString points) { - QVector resPointVector; - QPointF pointBegin(0, 0); +QPolygonF SvgFileLoader::transformPoints(QString points) { + QPolygonF resPointVector; + QPointF point(0, 0); + bool isX = true; for (auto& onePoint : points.split(' ')) { - QString x = *(onePoint.split(',').begin()); - QString y = *(onePoint.split(',').rbegin()); - resPointVector.push_back(QPointF(x.toDouble(), y.toDouble())); - + for (auto& value : onePoint.split(',')) { + if (value.trimmed().isEmpty()) continue; + if (isX) point.setX(value.toDouble()); + else { + point.setY(value.toDouble()); + resPointVector.push_back(point); + } + isX = !isX; + } } return resPointVector; } @@ -79,6 +85,9 @@ void SvgFileLoader::handleLabelG(QPainterPath& painterPath) { if (attr.name().toString() == QLatin1String("style")) { styleMap = transformStyle(attr.value().toLatin1()); } + else { + styleMap.insert(attr.name().toLatin1(), attr.value().toLatin1()); + } } existFatherLabelG = true; qDebug() << styleMap; @@ -90,9 +99,12 @@ void SvgFileLoader::handleLabelPath(QPainterPath& painterPath) { if (attr.name().toString() == QLatin1String("d")) { QQuickSvgParser::parsePathDataFast(attr.value().toLatin1(), painterPath); } - if (attr.name().toString() == QLatin1String("style")) { + else if (attr.name().toString() == QLatin1String("style")) { labelStyle = transformStyle(attr.value().toLatin1()); } + else { + labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1()); + } } } @@ -102,20 +114,21 @@ void SvgFileLoader::handleLabelRect(QPainterPath& painterPath) { for (auto& attr : xmlReader->attributes()) { if (attr.name().toString() == QLatin1String("x")) { xBegin = attr.value().toDouble(); - } - if (attr.name().toString() == QLatin1String("y")) { + } else if (attr.name().toString() == QLatin1String("y")) { yBegin = attr.value().toDouble(); - } - if (attr.name().toString() == QLatin1String("width")) { + } else if (attr.name().toString() == QLatin1String("width")) { width = attr.value().toDouble(); - } - if (attr.name().toString() == QLatin1String("height")) { + } else if (attr.name().toString() == QLatin1String("height")) { height = attr.value().toDouble(); } - if (attr.name().toString() == QLatin1String("style")) { + else if (attr.name().toString() == QLatin1String("style")) { labelStyle = transformStyle(attr.value().toLatin1()); } + else { + labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1()); + } } + qDebug() << labelStyle; painterPath.addRect(xBegin, yBegin, xBegin + width, yBegin + height); } @@ -125,17 +138,19 @@ void SvgFileLoader::handleLabelCircle(QPainterPath& painterPath) { for (auto& attr : xmlReader->attributes()) { if (attr.name().toString() == QLatin1String("cx")) { cx = attr.value().toDouble(); - } - if (attr.name().toString() == QLatin1String("cy")) { + } else if (attr.name().toString() == QLatin1String("cy")) { cy = attr.value().toDouble(); - } - if (attr.name().toString() == QLatin1String("r")) { + } else if (attr.name().toString() == QLatin1String("r")) { r = attr.value().toDouble(); } - if (attr.name().toString() == QLatin1String("style")) { + else if (attr.name().toString() == QLatin1String("style")) { labelStyle = transformStyle(attr.value().toLatin1()); } + else { + labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1()); + } } + qDebug() << labelStyle; painterPath.addEllipse(cx, cy, r, r); } @@ -145,20 +160,20 @@ void SvgFileLoader::handleLabelEllipse(QPainterPath& painterPath) { for (auto& attr : xmlReader->attributes()) { if (attr.name().toString() == QLatin1String("cx")) { cx = attr.value().toDouble(); - } - if (attr.name().toString() == QLatin1String("cy")) { + } else if (attr.name().toString() == QLatin1String("cy")) { cy = attr.value().toDouble(); - } - if (attr.name().toString() == QLatin1String("rx")) { + } else if (attr.name().toString() == QLatin1String("rx")) { rx = attr.value().toDouble(); - } - if (attr.name().toString() == QLatin1String("ry")) { + } else if (attr.name().toString() == QLatin1String("ry")) { rx = attr.value().toDouble(); - } - if (attr.name().toString() == QLatin1String("style")) { + } else if (attr.name().toString() == QLatin1String("style")) { labelStyle = transformStyle(attr.value().toLatin1()); } + else { + labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1()); + } } + qDebug() << labelStyle; painterPath.addEllipse(cx, cy, rx, ry); } @@ -169,10 +184,14 @@ void SvgFileLoader::handleLabelPolyline(QPainterPath& painterPath) { QPolygonF points = transformPoints(attr.value().toLatin1()); painterPath.addPolygon(points); } - if (attr.name().toString() == QLatin1String("style")) { + else if (attr.name().toString() == QLatin1String("style")) { labelStyle = transformStyle(attr.value().toLatin1()); } + else { + labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1()); + } } + qDebug() << labelStyle; } void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) { @@ -182,9 +201,13 @@ void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) { QPolygonF points = transformPoints(attr.value().toLatin1()); points.push_back(*points.begin()); painterPath.addPolygon(points); - } - if (attr.name().toString() == QLatin1String("style")) { + } + else if (attr.name().toString() == QLatin1String("style")) { labelStyle = transformStyle(attr.value().toLatin1()); } + else { + labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1()); + } } + qDebug() << labelStyle; } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/third-party modules/util/SvgFileLoader.h b/ArchitectureColoredPainting/src/Editor/third-party modules/util/SvgFileLoader.h index 55086bb..7420c7c 100644 --- a/ArchitectureColoredPainting/src/Editor/third-party modules/util/SvgFileLoader.h +++ b/ArchitectureColoredPainting/src/Editor/third-party modules/util/SvgFileLoader.h @@ -13,7 +13,7 @@ private: bool existFatherLabelG; QMap styleMap; std::shared_ptr xmlReader; - QVector transformPoints(QString points); + QPolygonF transformPoints(QString points); QMap transformStyle(QString style); void handleLabelG(QPainterPath& painterPath); void handleLabelPath(QPainterPath& painterPath); diff --git a/ArchitectureColoredPainting/src/main.cpp b/ArchitectureColoredPainting/src/main.cpp index 0960cf7..1f9fe9e 100644 --- a/ArchitectureColoredPainting/src/main.cpp +++ b/ArchitectureColoredPainting/src/main.cpp @@ -2,7 +2,6 @@ #include "Renderer/Painting/CubicBezier.h" #include #include -#include "Editor/third-party modules/util/SvgFileLoader.h" using Renderer::CubicBezier; @@ -11,11 +10,12 @@ extern "C" _declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { - SvgFileLoader svgLoader; - QPainterPath painterPath; - svgLoader.loadSvgFile("D:/login.svg", painterPath); - qDebug() << painterPath; - return 0; + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); }