修复了无法读取line的bug
parent
4360fad504
commit
8230a98d58
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue