From 2af24647458868e90f37d7a4ad5e0e8b524f2834 Mon Sep 17 00:00:00 2001 From: "yang.yongquan" <3395816735@qq.com> Date: Sat, 4 Feb 2023 20:20:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86QPainterPath?= =?UTF-8?q?=E8=BD=AC=E4=B8=BAvector<>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchitectureColoredPainting.vcxproj | 2 + ...rchitectureColoredPainting.vcxproj.filters | 12 +++--- .../src/Editor/GraphicElement.cpp | 2 +- .../src/Editor/util/PainterPathUtil.cpp | 41 +++++++++++++++++++ .../src/Editor/util/PainterPathUtil.h | 13 ++++++ .../src/Editor/util/SvgFileLoader.cpp | 6 ++- .../src/Editor/util/SvgFileLoader.h | 1 + .../src/Renderer/Painting/Line.h | 5 +++ 8 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 ArchitectureColoredPainting/src/Editor/util/PainterPathUtil.cpp create mode 100644 ArchitectureColoredPainting/src/Editor/util/PainterPathUtil.h diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index 5f5e54c..6fa88c1 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -110,6 +110,7 @@ + @@ -180,6 +181,7 @@ + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index d6f4019..b747240 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -192,6 +192,9 @@ Source Files\Editor\util + + Source Files\Editor\util + @@ -360,9 +363,6 @@ Header Files\Renderer\Painting - - Header Files\Editor\util - Header Files\Renderer\Painting @@ -387,12 +387,12 @@ Header Files\Renderer\Painting - - Header Files\Renderer\Painting - Header Files\Renderer\Painting + + Header Files\Editor\util + diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 47f4ee1..87711c1 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -1,5 +1,5 @@ #include "GraphicElement.h" -#include "third-party modules/util/SvgFileLoader.h" +#include using namespace std; QPainterPath SimpleElement::getPaintObject() const { diff --git a/ArchitectureColoredPainting/src/Editor/util/PainterPathUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PainterPathUtil.cpp new file mode 100644 index 0000000..148906e --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/util/PainterPathUtil.cpp @@ -0,0 +1,41 @@ +#include "PainterPathUtil.h" +#include + +using Renderer::Point; +using std::vector; + +vector > PainterPathUtil::transformToLines(QPainterPath& painterPath) { + vector line; line.clear(); + vector > lines; lines.clear(); + QPointF startPoint(0, 0); + Point point(0, 0); + for (int elementIndex = 0; elementIndex < painterPath.elementCount(); elementIndex++) { + auto element = painterPath.elementAt(elementIndex); + point = element; + qDebug() << element; + if (element.isMoveTo()) { + if (line.size() >= 2) { + lines.push_back(line); + } + line.clear(); + line.push_back(point); + } + else { + line.push_back(point); + if (element.isLineTo()) { + lines.push_back(line); + } + if (element.isCurveTo()) { + point = painterPath.elementAt(++elementIndex); + line.push_back(point); + point = painterPath.elementAt(++elementIndex); + line.push_back(point); + lines.push_back(line); + } + line.clear(); + line.push_back(point); + } + } + line.clear(); + return lines; +} diff --git a/ArchitectureColoredPainting/src/Editor/util/PainterPathUtil.h b/ArchitectureColoredPainting/src/Editor/util/PainterPathUtil.h new file mode 100644 index 0000000..3e1fd13 --- /dev/null +++ b/ArchitectureColoredPainting/src/Editor/util/PainterPathUtil.h @@ -0,0 +1,13 @@ +#pragma once +#include +#include +#include "../Renderer/Painting/Line.h" + +using Renderer::Point; + +class PainterPathUtil +{ +public: + static std::vector > transformToLines(QPainterPath& painterPath); +}; + diff --git a/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.cpp b/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.cpp index da7dbe4..30f0ae6 100644 --- a/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.cpp @@ -151,7 +151,8 @@ void SvgFileLoader::handleLabelCircle(QPainterPath& painterPath) { } } qDebug() << labelStyle; - addEllipse(cx, cy, r, r, painterPath); + //addEllipse(cx, cy, r, r, painterPath); + painterPath.addEllipse(cx, cy, r, r); } void SvgFileLoader::handleLabelEllipse(QPainterPath& painterPath) { @@ -174,7 +175,8 @@ void SvgFileLoader::handleLabelEllipse(QPainterPath& painterPath) { } } qDebug() << labelStyle; - addEllipse(cx, cy, rx, ry, painterPath); + //addEllipse(cx, cy, rx, ry, painterPath); + painterPath.addEllipse(cx, cy, rx, ry); } void SvgFileLoader::handleLabelPolyline(QPainterPath& painterPath) { diff --git a/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.h b/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.h index 93c2751..352b9b0 100644 --- a/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.h +++ b/ArchitectureColoredPainting/src/Editor/util/SvgFileLoader.h @@ -23,4 +23,5 @@ private: void handleLabelEllipse(QPainterPath& painterPath); void handleLabelPolyline(QPainterPath& painterPath); void handleLabelPolygon(QPainterPath& painterPath); + }; diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Line.h b/ArchitectureColoredPainting/src/Renderer/Painting/Line.h index 7730fa6..b1caf2b 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Line.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Line.h @@ -25,6 +25,11 @@ namespace Renderer bool operator< (const Point& a) const { return fabs(x - a.x) <= eps ? y < a.y : x < a.x; } + Point& operator= (const QPointF p){ + x = p.x(); + y = p.y(); + return *this; + } operator glm::dvec2() { return glm::dvec2(x, y); }