Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dsm committed Dec 11, 2024
1 parent 0fe4bc4 commit 8a9c640
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
19 changes: 19 additions & 0 deletions qucs/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,22 @@ void misc::draw_resize_handle(QPainter* painter, const QPointF& center) {
painter->drawRect(resize_handle);
painter->restore();
}

QString misc::formatValue(const QString& input, int precision) {
QRegularExpression regex(R"(([+-]?\d*\.?\d+)([a-zA-Z%]+)?)");
QRegularExpressionMatch match = regex.match(input);

if (match.hasMatch()) {
QString numberPart = match.captured(1);
QString unitPart = match.captured(2);

double value = numberPart.toDouble();
QString formattedNumber = QString::number(value, 'f', precision);

formattedNumber = formattedNumber.remove(QRegularExpression(R"(0+$)"));
formattedNumber = formattedNumber.remove(QRegularExpression(R"(\.$)"));

return formattedNumber + unitPart;
}
return input;
}
2 changes: 2 additions & 0 deletions qucs/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ namespace misc {
void draw_resize_handle(QPainter* painter, const QPointF& center);

void getSymbolPatternsList(QStringList &symbols);
QString formatValue(const QString& input, int precision);

}

/*! handle the application version string
Expand Down
44 changes: 31 additions & 13 deletions qucs/schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <QUrl>
#include <QWheelEvent>
#include <qt3_compat/qt_compat.h>
#include <QRegularExpression>

#include "components/vafile.h"
#include "components/verilogfile.h"
Expand Down Expand Up @@ -516,30 +517,47 @@ void Schematic::drawElements(QPainter* painter) {
void Schematic::drawDcBiasPoints(QPainter* painter) {
painter->save();
int x, y, z;

const int xOffset = 10;
const int yOffset = 10;

for (auto* pn : *a_Nodes) {
if (pn->Name.isEmpty())
continue;

QString value = misc::formatValue(pn->Name, 4);

x = pn->cx;
y = pn->cy + 4;
z = pn->x1;
if (z & 1)
x -= painter->fontMetrics().boundingRect(pn->Name).width();
if (!(z & 2)) {
y -= (painter->fontMetrics().lineSpacing() >> 1) + 4;
if (z & 1)
x -= 4;
else
x += 4;

QRect textRect = painter->fontMetrics().boundingRect(value);
int rectWidth = textRect.width() + 6;
int rectHeight = textRect.height() + 4;

if (z & 0x10) {
x += xOffset;
y -= yOffset;
} else {
x -= xOffset;
y -= yOffset;
}
if (z & 0x10)
painter->setPen(Qt::darkGreen); // green for currents
else
painter->setPen(Qt::blue); // blue for voltages
painter->drawText(x, y, pn->Name);

int rectX = x - rectWidth / 2;
int rectY = y - rectHeight / 2;

painter->setBrush(QBrush(QColor(230,230,230)));
painter->setPen(Qt::NoPen);
painter->drawRoundedRect( QRectF(rectX, rectY, rectWidth, rectHeight),15,15,Qt::RelativeSize);

painter->setPen(z & 0x10 ? Qt::darkGreen : Qt::blue);
painter->drawText(x - textRect.width() / 2, y + textRect.height() / 4, value);
}
painter->restore();
}



void Schematic::drawPostPaintEvents(QPainter* painter) {
painter->save();
/*
Expand Down

0 comments on commit 8a9c640

Please sign in to comment.