Feature: Add terminal name label display in element editor

This commit is contained in:
Kellermorph
2026-07-09 14:02:27 +02:00
parent 99ad9aa459
commit c884d32dbe
8 changed files with 753 additions and 82 deletions
+40
View File
@@ -18,6 +18,7 @@
#include "terminaldata.h"
#include <QGraphicsObject>
#include <QDebug>
TerminalData::TerminalData():
@@ -110,6 +111,20 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const
xml_element.setAttribute("type", typeToString(m_type));
if (m_show_name) {
xml_element.setAttribute("show_name", "true");
xml_element.setAttribute("label_x", QString::number(m_label_pos.x()));
xml_element.setAttribute("label_y", QString::number(m_label_pos.y()));
xml_element.setAttribute("label_font", m_label_font.toString());
xml_element.setAttribute("label_rotation", QString::number(m_label_rotation));
xml_element.setAttribute("label_halign", static_cast<int>(m_label_halignment));
xml_element.setAttribute("label_valign", static_cast<int>(m_label_valignment));
if (m_label_frame)
xml_element.setAttribute("label_frame", "true");
if (m_label_color != QColor(Qt::black))
xml_element.setAttribute("label_color", m_label_color.name());
}
return(xml_element);
}
@@ -157,6 +172,31 @@ bool TerminalData::fromXml (const QDomElement &xml_element)
m_type = typeFromString(xml_element.attribute("type"));
m_show_name = (xml_element.attribute("show_name") == QLatin1String("true"));
if (m_show_name) {
qreal lx = xml_element.attribute("label_x", "0").toDouble();
qreal ly = xml_element.attribute("label_y", "0").toDouble();
m_label_pos = QPointF(lx, ly);
QString font_str = xml_element.attribute("label_font");
if (!font_str.isEmpty())
m_label_font.fromString(font_str);
m_label_rotation = xml_element.attribute("label_rotation", "0").toDouble();
int ha = xml_element.attribute("label_halign", "0").toInt();
m_label_halignment = static_cast<Qt::Alignment>(ha);
int va = xml_element.attribute("label_valign", "0").toInt();
m_label_valignment = static_cast<Qt::Alignment>(va);
m_label_frame = (xml_element.attribute("label_frame") == QLatin1String("true"));
QString color_str = xml_element.attribute("label_color");
if (!color_str.isEmpty())
m_label_color = QColor(color_str);
}
return true;
}
+19
View File
@@ -21,6 +21,8 @@
#include "../qet.h"
#include "propertiesinterface.h"
#include <QColor>
#include <QFont>
#include <QPointF>
#include <QUuid>
@@ -115,6 +117,23 @@ class TerminalData : public PropertiesInterface
TerminalData::Type m_type = TerminalData::Generic;
/// Whether to display the terminal name as a text label
bool m_show_name = false;
/// Position of the text label relative to the terminal
QPointF m_label_pos{0.0, 0.0};
/// Font used for the text label
QFont m_label_font;
/// Rotation of the text label in degrees
qreal m_label_rotation = 0.0;
/// Horizontal alignment of the text label
Qt::Alignment m_label_halignment = Qt::AlignHCenter;
/// Vertical alignment of the text label
Qt::Alignment m_label_valignment = Qt::AlignVCenter;
/// Whether to draw a frame around the text label
bool m_label_frame = false;
/// Color of the text label
QColor m_label_color = Qt::black;
private:
QGraphicsObject* q{nullptr};
};