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);