修复了无法读取line的bug

main
yang.yongquan 2023-03-30 23:31:27 +08:00
parent 4360fad504
commit 8230a98d58
2 changed files with 42 additions and 0 deletions

View File

@ -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<QString, QString> 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<QString, QString> labelStyle;
QPainterPath elementPainterPath;

View File

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