Skip to content

Commit

Permalink
Refactored text svg transformation into function towards solving #3186
Browse files Browse the repository at this point in the history
…for power labels.
  • Loading branch information
Kjell Morgenstern authored and KjellMorgenstern committed Apr 25, 2023
1 parent 0f1ddb6 commit 5d9c6df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/items/symbolpaletteitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,24 @@ QString SymbolPaletteItem::replaceTextElement(QString svg) {
return TextUtils::replaceTextElement(svg, "label", QString::number(v) + "V");
}

QString SymbolPaletteItem::transformTextSvg(const QString & testSvg) {
QString svg = testSvg;
SchematicTextLayerKinPaletteItem * schemItem = nullptr;
Q_FOREACH (ItemBase * lkpi, m_layerKin) {
auto * schemLayerItem = qobject_cast<SchematicTextLayerKinPaletteItem *>(lkpi);
if (schemLayerItem != nullptr) {
schemItem = schemLayerItem;
break;
}
}

if (schemItem != nullptr) {
double rotation;
svg = schemItem->getTransformedSvg(svg, rotation);
}
return svg;
}

QString SymbolPaletteItem::getProperty(const QString & key) {
if (key.compare("voltage", Qt::CaseInsensitive) == 0) {
return QString::number(m_voltage);
Expand Down Expand Up @@ -619,19 +637,7 @@ QString NetLabel::makeSvg(ViewLayer::ViewLayerID viewLayerID) {
svg += "</g>\n</svg>\n";

if (viewLayerID == ViewLayer::SchematicText) {
SchematicTextLayerKinPaletteItem * schemItem = nullptr;
Q_FOREACH (ItemBase * lkpi, m_layerKin) {
auto * schemLayerItem = qobject_cast<SchematicTextLayerKinPaletteItem *>(lkpi);
if (schemLayerItem != nullptr) {
schemItem = schemLayerItem;
break;
}
}

if (schemItem != nullptr) {
double rotation;
svg = schemItem->getTransformedSvg(svg, rotation);
}
svg = transformTextSvg(svg);
}

return svg;
Expand Down
1 change: 1 addition & 0 deletions src/items/symbolpaletteitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public Q_SLOTS:
double useVoltage(ConnectorItem * connectorItem);
virtual QString makeSvg(ViewLayer::ViewLayerID);
QString replaceTextElement(QString svg);
QString transformTextSvg(const QString & testSvg);
ViewLayer::ViewID useViewIDForPixmap(ViewLayer::ViewID, bool swappingEnabled);
void resetLayerKin();

Expand Down

0 comments on commit 5d9c6df

Please sign in to comment.