Skip to content

Commit

Permalink
Markers: Add the frequency text in the marker line
Browse files Browse the repository at this point in the history
Now when the user adds a marker, the program adds a little text at the top of the marker line indicating the frequency.
  • Loading branch information
andresmmera committed Oct 23, 2024
1 parent 588d1ed commit 1ce2092
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
32 changes: 32 additions & 0 deletions qucs-s-spar-viewer/qucs-s-spar-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,13 @@ void Qucs_S_SPAR_Viewer::updateTraces()
}


// Remove all custom labels
for (QGraphicsItem* label : textLabels) {
chart->scene()->removeItem(label);
delete label;
}
textLabels.clear();

double freq_scale = getFreqScale();

// User settings
Expand Down Expand Up @@ -1671,6 +1678,31 @@ void Qucs_S_SPAR_Viewer::updateTraces()
verticalLine->setName(verticalLine_name);

seriesList.append(verticalLine);

QGraphicsTextItem *textItem = new QGraphicsTextItem(chart);
QString freq_marker = tableMarkers->item(r,0)->text();
textItem->setPlainText(QString("%1").arg(freq_marker));
textItem->setFont(QFont("Arial", 8));

// Get the axes
auto axes = chart->axes(Qt::Horizontal);
QValueAxis *xAxis = qobject_cast<QValueAxis*>(axes.first());
qreal xRatio = (x - xAxis->min()) / (xAxis->max() - xAxis->min());

// Calculate the position
QRectF plotArea = chart->plotArea();
qreal xPixel = plotArea.left() + xRatio * plotArea.width();

// Center the text horizontally
QFontMetrics fm(textItem->font());
int textWidth = fm.horizontalAdvance(textItem->toPlainText());
qreal textX = xPixel - textWidth / 2;

// Position above the chart area
qreal textY = plotArea.top() - fm.height() - 5; // 5 pixels above the plot area

textItem->setPos(textX, textY);
textLabels.append(textItem);
}
}

Expand Down
7 changes: 7 additions & 0 deletions qucs-s-spar-viewer/qucs-s-spar-viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class Qucs_S_SPAR_Viewer : public QMainWindow
Qucs_S_SPAR_Viewer();
~Qucs_S_SPAR_Viewer();

protected:
void resizeEvent(QResizeEvent *event) override {
QMainWindow::resizeEvent(event);
updateTraces();
}

private slots:
void slotHelpIntro();
void slotHelpAbout();
Expand Down Expand Up @@ -166,6 +172,7 @@ class Qucs_S_SPAR_Viewer : public QMainWindow
QValueAxis *xAxis, *yAxis;
double f_min, f_max, y_min, y_max; // Minimum (maximum) values of the display
QList<QColor> default_colors;
QList<QGraphicsItem*> textLabels;
bool removeSeriesByName(QChart*, const QString&);

// Markers
Expand Down

0 comments on commit 1ce2092

Please sign in to comment.