From 8230a98d585edf7ee568d49e832f1e53a5c07596 Mon Sep 17 00:00:00 2001 From: "yang.yongquan" <3395816735@qq.com> Date: Thu, 30 Mar 2023 23:31:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=AF=BB=E5=8F=96line=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/util/SvgFileLoader.cpp | 41 +++++++++++++++++++ .../src/Editor/util/SvgFileLoader.h | 1 + 2 files changed, 42 insertions(+) diff --git a/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.cpp b/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.cpp index cf1d718..e5acabc 100644 --- a/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.cpp @@ -29,6 +29,9 @@ bool SvgFileLoader::loadSvgFile(const QString& filePath, QPainterPath& painterPa if (xmlReader->name() == "rect") { handleLabelRect(painterPath); } + if (xmlReader->name() == "line") { + handleLabelLine(painterPath); + } if (xmlReader->name() == "circle ") { handleLabelCircle(painterPath); } @@ -167,6 +170,44 @@ void SvgFileLoader::handleLabelPath(QPainterPath& painterPath) { painterPath.addPath(elementPainterPath); } +void SvgFileLoader::handleLabelLine(QPainterPath& painterPath) { + QMap labelStyle; + QPainterPath elementPainterPath; + double xBegin = 0, yBegin = 0, xEnd = 0, yEnd = 0; + QString transformStyle = ""; + for (auto& attr : xmlReader->attributes()) { + if (attr.name().toString() == QLatin1String("x1")) { + xBegin = attr.value().toDouble(); + } + else if (attr.name().toString() == QLatin1String("y1")) { + yBegin = attr.value().toDouble(); + } + else if (attr.name().toString() == QLatin1String("x2")) { + xEnd = attr.value().toDouble(); + } + else if (attr.name().toString() == QLatin1String("y2")) { + yEnd = attr.value().toDouble(); + } + else if (attr.name().toString() == QLatin1String("style")) { + labelStyle = handleAttrStyle(attr.value().toLatin1()); + } + else if (attr.name().toString() == QLatin1String("transform")) { + transformStyle = attr.value().toLatin1(); + } + else { + labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1()); + } + } + QPolygonF points; + points.push_back({ xBegin, yBegin }); + points.push_back({ xEnd, yEnd }); + elementPainterPath.addPolygon(points); + if (!transformStyle.isEmpty()) { + handleAttrTransform(transformStyle, elementPainterPath); + } + painterPath.addPath(elementPainterPath); +} + void SvgFileLoader::handleLabelRect(QPainterPath& painterPath) { QMap labelStyle; QPainterPath elementPainterPath; diff --git a/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.h b/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.h index 3bdcd8a..5094bc5 100644 --- a/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.h +++ b/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.h @@ -20,6 +20,7 @@ private: void handleLabelG(QPainterPath& painterPath); void handleLabelPath(QPainterPath& painterPath); void handleLabelRect(QPainterPath& painterPath); + void handleLabelLine(QPainterPath& painterPath); void handleLabelCircle(QPainterPath& painterPath); void handleLabelEllipse(QPainterPath& painterPath); void handleLabelPolyline(QPainterPath& painterPath);