Merge branch 'master' into qt6_cmake_joshua

This commit is contained in:
joshua
2026-07-31 21:15:21 +02:00
parent f16cf7dac8
commit e6d29cf345
297 changed files with 82691 additions and 27463 deletions
+411 -14
View File
@@ -49,18 +49,7 @@ bool ElementData::fromXml(const QDomElement &xml_element)
return false;
}
// --- HIER STARTET UNSER DEBUG-BLOCK ---
// Wir holen den String aus der XML und speichern ihn kurz zwischen
QString raw_type_string = xml_element.attribute(QStringLiteral("link_type"), QStringLiteral("simple"));
qDebug() << "\n=== NEUES BAUTEIL WIRD GELADEN ===";
qDebug() << "[XML Parser] Roher 'link_type' String aus der .elmt Datei:" << raw_type_string;
// Jetzt übergeben wir ihn an deine Übersetzungs-Funktion
m_type = typeFromString(raw_type_string);
qDebug() << "[XML Parser] Übersetzter ElementData-Typ:" << typeToString(m_type);
// --- HIER ENDET UNSER DEBUG-BLOCK ---
m_type = typeFromString(xml_element.attribute(QStringLiteral("link_type"), QStringLiteral("simple")));
kindInfoFromXml(xml_element);
m_informations.fromXml(xml_element.firstChildElement(QStringLiteral("elementInformations")),
@@ -98,6 +87,140 @@ QDomElement ElementData::kindInfoToXml(QDomDocument &document)
returned_elmt.appendChild(xml_max_slaves);
}
// Save slave contact groups if enabled
if (m_slave_contact_groups_enabled) {
auto xml_groups = document.createElement(QStringLiteral("slaveContactGroups"));
for (const auto &group : m_slave_contact_groups) {
auto xml_group = document.createElement(QStringLiteral("group"));
xml_group.setAttribute(QStringLiteral("type"),
slaveStateToString(group.type));
xml_group.setAttribute(QStringLiteral("subtype"),
slaveTypeToString(group.subtype));
xml_group.setAttribute(QStringLiteral("contactCount"),
group.contactCount);
xml_group.setAttribute(QStringLiteral("terminalCount"),
group.terminalCount);
for (const auto &label : group.labels) {
auto xml_label = document.createElement(QStringLiteral("label"));
auto label_txt = document.createTextNode(label);
xml_label.appendChild(label_txt);
xml_group.appendChild(xml_label);
}
xml_groups.appendChild(xml_group);
}
returned_elmt.appendChild(xml_groups);
}
// Save PLC master data if type is PLC
if (m_master_type == ElementData::PLC) {
auto xml_plc = document.createElement(QStringLiteral("plcMasterData"));
xml_plc.setAttribute(QStringLiteral("rowHeight"),
QString::number(m_plc_master_data.rowHeight, 'f', 2));
// Save break positions
{
auto xml_breaks = document.createElement(QStringLiteral("breakPositions"));
for (int bp : m_plc_master_data.breakPositions) {
auto xml_bp = document.createElement(QStringLiteral("break"));
xml_bp.appendChild(document.createTextNode(QString::number(bp)));
xml_breaks.appendChild(xml_bp);
}
xml_plc.appendChild(xml_breaks);
}
// Save column widths
auto xml_col_widths = document.createElement(QStringLiteral("columnWidths"));
for (auto it = m_plc_master_data.colWidths.constBegin();
it != m_plc_master_data.colWidths.constEnd(); ++it) {
auto xml_col = document.createElement(QStringLiteral("column"));
xml_col.setAttribute(QStringLiteral("index"), it.key());
xml_col.setAttribute(QStringLiteral("width"), QString::number(it.value(), 'f', 2));
xml_col_widths.appendChild(xml_col);
}
xml_plc.appendChild(xml_col_widths);
// Save column visibility
auto xml_col_vis = document.createElement(QStringLiteral("columnVisibility"));
for (auto it = m_plc_master_data.colVisible.constBegin();
it != m_plc_master_data.colVisible.constEnd(); ++it) {
auto xml_col = document.createElement(QStringLiteral("column"));
xml_col.setAttribute(QStringLiteral("index"), it.key());
xml_col.setAttribute(QStringLiteral("visible"), it.value() ? "true" : "false");
xml_col_vis.appendChild(xml_col);
}
xml_plc.appendChild(xml_col_vis);
// Save fonts
if (!m_plc_master_data.headerFont.family().isEmpty()) {
auto xml_hfont = document.createElement(QStringLiteral("headerFont"));
xml_hfont.setAttribute(QStringLiteral("family"), m_plc_master_data.headerFont.family());
xml_hfont.setAttribute(QStringLiteral("size"), m_plc_master_data.headerFont.pointSize());
xml_hfont.setAttribute(QStringLiteral("bold"), m_plc_master_data.headerFont.bold() ? "true" : "false");
xml_plc.appendChild(xml_hfont);
}
if (!m_plc_master_data.cellFont.family().isEmpty()) {
auto xml_cfont = document.createElement(QStringLiteral("cellFont"));
xml_cfont.setAttribute(QStringLiteral("family"), m_plc_master_data.cellFont.family());
xml_cfont.setAttribute(QStringLiteral("size"), m_plc_master_data.cellFont.pointSize());
xml_cfont.setAttribute(QStringLiteral("bold"), m_plc_master_data.cellFont.bold() ? "true" : "false");
xml_plc.appendChild(xml_cfont);
}
// Save custom column names
if (!m_plc_master_data.columnNames.isEmpty()) {
auto xml_names = document.createElement(QStringLiteral("columnNames"));
for (int i = 0; i < m_plc_master_data.columnNames.size(); ++i) {
auto xml_name = document.createElement(QStringLiteral("column"));
xml_name.setAttribute(QStringLiteral("index"), i);
xml_name.appendChild(document.createTextNode(m_plc_master_data.columnNames.at(i)));
xml_names.appendChild(xml_name);
}
xml_plc.appendChild(xml_names);
}
// Save column order
if (!m_plc_master_data.columnOrder.isEmpty()) {
auto xml_order = document.createElement(QStringLiteral("columnOrder"));
QString order_str;
for (int i = 0; i < m_plc_master_data.columnOrder.size(); ++i) {
if (i > 0) order_str += QStringLiteral(",");
order_str += QString::number(m_plc_master_data.columnOrder.at(i));
}
xml_order.appendChild(document.createTextNode(order_str));
xml_plc.appendChild(xml_order);
}
// Save showHeaders
{
auto xml_sh = document.createElement(QStringLiteral("showHeaders"));
xml_sh.appendChild(document.createTextNode(
m_plc_master_data.showHeaders ? QStringLiteral("1") : QStringLiteral("0")));
xml_plc.appendChild(xml_sh);
}
// Save IO entries
auto xml_ios = document.createElement(QStringLiteral("plcIOs"));
for (const auto &io : m_plc_master_data.ios) {
auto xml_io = document.createElement(QStringLiteral("plcIO"));
xml_io.setAttribute(QStringLiteral("type"), plcIOTypeToString(io.type));
xml_io.setAttribute(QStringLiteral("address"), io.address);
xml_io.setAttribute(QStringLiteral("functionText"), io.functionText);
xml_io.setAttribute(QStringLiteral("comment"), io.comment);
xml_io.setAttribute(QStringLiteral("crossRef"), io.crossRef);
xml_io.setAttribute(QStringLiteral("terminalCount"), io.terminalCount);
for (const auto &t : io.terminals) {
auto xml_term = document.createElement(QStringLiteral("terminal"));
xml_term.appendChild(document.createTextNode(t));
xml_io.appendChild(xml_term);
}
xml_ios.appendChild(xml_io);
}
xml_plc.appendChild(xml_ios);
returned_elmt.appendChild(xml_plc);
}
}
else if (m_type == ElementData::Slave)
{
@@ -247,6 +370,20 @@ bool ElementData::operator==(const ElementData &data) const
if(data.m_master_type != m_master_type) {
return false;
}
if (data.m_max_slaves != m_max_slaves) {
return false;
}
if (data.m_slave_contact_groups_enabled != m_slave_contact_groups_enabled) {
return false;
}
if (data.m_slave_contact_groups != m_slave_contact_groups) {
return false;
}
if (data.m_master_type == ElementData::PLC) {
if (data.m_plc_master_data != m_plc_master_data) {
return false;
}
}
}
else if (data.m_type == ElementData::Slave) {
if (data.m_slave_state != m_slave_state ||
@@ -387,6 +524,8 @@ QString ElementData::masterTypeToString(ElementData::MasterType type)
return QStringLiteral("protection");
case ElementData::Commutator:
return QStringLiteral("commutator");
case ElementData::PLC:
return QStringLiteral("plc");
}
return QStringLiteral("coil");
}
@@ -399,6 +538,8 @@ ElementData::MasterType ElementData::masterTypeFromString(const QString &string)
return ElementData::Protection;
} else if (string == QLatin1String("commutator")) {
return ElementData::Commutator;
} else if (string == QLatin1String("plc")) {
return ElementData::PLC;
}
qDebug() << "ElementData::masterTypeFromString : string "
@@ -420,6 +561,8 @@ QString ElementData::slaveTypeToString(ElementData::SlaveType type)
return QStringLiteral("delayOff");
case ElementData::delayOnOff:
return QStringLiteral("delayOnOff");
case ElementData::PLCSlave:
return QStringLiteral("plc");
}
return QStringLiteral("simple");
}
@@ -436,6 +579,8 @@ ElementData::SlaveType ElementData::slaveTypeFromString(const QString &string)
return ElementData::DelayOff;
} else if (string == QLatin1String("delayOnOff")) {
return ElementData::delayOnOff;
} else if (string == QLatin1String("plc")) {
return ElementData::PLCSlave;
}
qDebug() << "ElementData::slaveTypeFromSting : string "
@@ -591,7 +736,7 @@ void ElementData::kindInfoFromXml(const QDomElement &xml_element)
m_max_slaves = dom_elmt.text().toInt();
}
}
else if (m_type == ElementData::Slave ) {
else if (m_type == ElementData::Slave) {
if (name == QLatin1String("type")) {
m_slave_type = slaveTypeFromString(dom_elmt.text());
} else if (name == QLatin1String("state")) {
@@ -606,8 +751,260 @@ void ElementData::kindInfoFromXml(const QDomElement &xml_element)
} else if (name == QLatin1String("function")) {
m_terminal_function = terminalFunctionFromString(dom_elmt.text());
}
}
}
}
// Parse slave contact groups for Master elements
if (m_type == ElementData::Master) {
auto xml_kind = xml_element.firstChildElement(QStringLiteral("kindInformations"));
auto xml_groups = xml_kind.firstChildElement(QStringLiteral("slaveContactGroups"));
if (!xml_groups.isNull()) {
m_slave_contact_groups_enabled = true;
auto group_list = QETXML::findInDomElement(xml_groups, QStringLiteral("group"));
for (const auto &xml_group : group_list) {
SlaveContactGroup group;
group.type = slaveStateFromString(
xml_group.attribute(QStringLiteral("type"), QStringLiteral("NO")));
group.subtype = slaveTypeFromString(
xml_group.attribute(QStringLiteral("subtype"), QStringLiteral("simple")));
group.contactCount = xml_group.attribute(
QStringLiteral("contactCount"), QStringLiteral("1")).toInt();
group.terminalCount = xml_group.attribute(
QStringLiteral("terminalCount"), QStringLiteral("1")).toInt();
auto label_list = QETXML::findInDomElement(xml_group, QStringLiteral("label"));
for (const auto &xml_label : label_list) {
group.labels.append(xml_label.text());
}
m_slave_contact_groups.append(group);
}
}
// Parse PLC master data
auto xml_plc = xml_kind.firstChildElement(QStringLiteral("plcMasterData"));
if (!xml_plc.isNull()) {
m_plc_master_data.rowHeight = xml_plc.attribute(
QStringLiteral("rowHeight"), QStringLiteral("8.00")).toDouble();
// Parse break positions (new format: child elements)
auto xml_breaks = xml_plc.firstChildElement(QStringLiteral("breakPositions"));
if (!xml_breaks.isNull()) {
for (const auto &xml_bp : QETXML::findInDomElement(xml_breaks, QStringLiteral("break"))) {
m_plc_master_data.breakPositions.append(xml_bp.text().toInt());
}
} else {
// Backward compat: old format was breakAfter attribute
int old_break = xml_plc.attribute(
QStringLiteral("breakAfter"), QStringLiteral("0")).toInt();
m_plc_master_data.breakPositions.append(old_break > 0 ? old_break : 0);
}
// Parse column widths
auto xml_col_widths = xml_plc.firstChildElement(QStringLiteral("columnWidths"));
for (const auto &xml_col : QETXML::findInDomElement(xml_col_widths, QStringLiteral("column"))) {
int index = xml_col.attribute(QStringLiteral("index")).toInt();
qreal width = xml_col.attribute(QStringLiteral("width")).toDouble();
m_plc_master_data.colWidths[index] = width;
}
// Parse column visibility
auto xml_col_vis = xml_plc.firstChildElement(QStringLiteral("columnVisibility"));
for (const auto &xml_col : QETXML::findInDomElement(xml_col_vis, QStringLiteral("column"))) {
int index = xml_col.attribute(QStringLiteral("index")).toInt();
bool visible = xml_col.attribute(QStringLiteral("visible")) == QLatin1String("true");
m_plc_master_data.colVisible[index] = visible;
}
// Parse fonts
auto xml_hfont = xml_plc.firstChildElement(QStringLiteral("headerFont"));
if (!xml_hfont.isNull()) {
m_plc_master_data.headerFont.setFamily(xml_hfont.attribute(QStringLiteral("family")));
m_plc_master_data.headerFont.setPointSize(xml_hfont.attribute(QStringLiteral("size"), QStringLiteral("8")).toInt());
m_plc_master_data.headerFont.setBold(xml_hfont.attribute(QStringLiteral("bold")) == QLatin1String("true"));
}
auto xml_cfont = xml_plc.firstChildElement(QStringLiteral("cellFont"));
if (!xml_cfont.isNull()) {
m_plc_master_data.cellFont.setFamily(xml_cfont.attribute(QStringLiteral("family")));
m_plc_master_data.cellFont.setPointSize(xml_cfont.attribute(QStringLiteral("size"), QStringLiteral("8")).toInt());
m_plc_master_data.cellFont.setBold(xml_cfont.attribute(QStringLiteral("bold")) == QLatin1String("true"));
}
// Parse custom column names
auto xml_names = xml_plc.firstChildElement(QStringLiteral("columnNames"));
if (!xml_names.isNull()) {
for (const auto &xml_col : QETXML::findInDomElement(xml_names, QStringLiteral("column"))) {
int index = xml_col.attribute(QStringLiteral("index")).toInt();
if (index < 0 || index >= 5)
continue;
while (m_plc_master_data.columnNames.size() <= index)
m_plc_master_data.columnNames.append(QString());
m_plc_master_data.columnNames[index] = xml_col.text();
}
}
// Parse column order
auto xml_order = xml_plc.firstChildElement(QStringLiteral("columnOrder"));
if (!xml_order.isNull()) {
QStringList parts = xml_order.text().split(',');
for (const auto &p : parts) {
if (m_plc_master_data.columnOrder.size() >= 5)
break;
bool ok;
int val = p.trimmed().toInt(&ok);
if (ok)
m_plc_master_data.columnOrder.append(val);
}
}
// Parse showHeaders
auto xml_sh = xml_plc.firstChildElement(QStringLiteral("showHeaders"));
if (!xml_sh.isNull())
m_plc_master_data.showHeaders = (xml_sh.text().trimmed() != QStringLiteral("0"));
// Parse IO entries
auto xml_ios = xml_plc.firstChildElement(QStringLiteral("plcIOs"));
for (const auto &xml_io : QETXML::findInDomElement(xml_ios, QStringLiteral("plcIO"))) {
if (m_plc_master_data.ios.size() >= 128)
break;
PlcIO io;
io.type = plcIOTypeFromString(
xml_io.attribute(QStringLiteral("type"), QStringLiteral("entree_digitale")));
io.address = xml_io.attribute(QStringLiteral("address"));
io.functionText = xml_io.attribute(QStringLiteral("functionText"));
io.comment = xml_io.attribute(QStringLiteral("comment"));
io.crossRef = xml_io.attribute(QStringLiteral("crossRef"));
io.terminalCount = xml_io.attribute(
QStringLiteral("terminalCount"), QStringLiteral("0")).toInt();
for (const auto &xml_term : QETXML::findInDomElement(xml_io, QStringLiteral("terminal"))) {
io.terminals.append(xml_term.text());
}
m_plc_master_data.ios.append(io);
}
}
}
}
/**
* @brief ElementData::slaveContactGroupTypeToString
* Convert a SlaveState to string for XML storage in slave contact groups.
* Maps: NO -> "NO", NC -> "NC", SW -> "SW", Other -> "Other"
*/
QString ElementData::slaveContactGroupTypeToString(ElementData::SlaveState type)
{
return slaveStateToString(type);
}
/**
* @brief ElementData::slaveContactGroupTypeFromString
* Convert a string from XML to SlaveState for slave contact groups.
*/
ElementData::SlaveState ElementData::slaveContactGroupTypeFromString(const QString &string)
{
return slaveStateFromString(string);
}
/**
* @brief ElementData::slaveContactGroupSubtypeToString
* Convert a SlaveType to string for XML storage in slave contact groups.
*/
QString ElementData::slaveContactGroupSubtypeToString(ElementData::SlaveType type)
{
return slaveTypeToString(type);
}
/**
* @brief ElementData::slaveContactGroupSubtypeFromString
* Convert a string from XML to SlaveType for slave contact groups.
*/
ElementData::SlaveType ElementData::slaveContactGroupSubtypeFromString(const QString &string)
{
return slaveTypeFromString(string);
}
/**
* @brief ElementData::plcIOTypeToString
* Convert a PlcIOType to string for XML storage.
*/
QString ElementData::plcIOTypeToString(PlcIOType type)
{
switch (type) {
case EntreeDigitale:
return QStringLiteral("entree_digitale");
case SortieDigitale:
return QStringLiteral("sortie_digitale");
case EntreeAnalogique:
return QStringLiteral("entree_analogique");
case SortieAnalogique:
return QStringLiteral("sortie_analogique");
case EntreeUniverselle:
return QStringLiteral("entree_universelle");
case SortieUniverselle:
return QStringLiteral("sortie_universelle");
}
return QStringLiteral("entree_digitale");
}
/**
* @brief ElementData::plcIOTypeFromString
* Convert a string from XML to PlcIOType.
*/
ElementData::PlcIOType ElementData::plcIOTypeFromString(const QString &string)
{
if (string == QLatin1String("entree_digitale")) {
return ElementData::EntreeDigitale;
} else if (string == QLatin1String("sortie_digitale")) {
return ElementData::SortieDigitale;
} else if (string == QLatin1String("entree_analogique")) {
return ElementData::EntreeAnalogique;
} else if (string == QLatin1String("sortie_analogique")) {
return ElementData::SortieAnalogique;
} else if (string == QLatin1String("entree_universelle")) {
return ElementData::EntreeUniverselle;
} else if (string == QLatin1String("sortie_universelle")) {
return ElementData::SortieUniverselle;
}
qDebug() << "ElementData::plcIOTypeFromString : string "
<< string
<< " don't exist, return failsafe value 'entree_digitale'";
return ElementData::EntreeDigitale;
}
/**
* @brief ElementData::translatedPlcIOType
* Return translated string for PlcIOType.
*/
QString ElementData::translatedPlcIOType(PlcIOType type)
{
switch (type) {
case EntreeDigitale:
return QObject::tr("Entrée digitale");
case SortieDigitale:
return QObject::tr("Sortie digitale");
case EntreeAnalogique:
return QObject::tr("Entrée analogique");
case SortieAnalogique:
return QObject::tr("Sortie analogique");
case EntreeUniverselle:
return QObject::tr("Entrée universelle");
case SortieUniverselle:
return QObject::tr("Sortie universelle");
}
return QObject::tr("Entrée digitale");
}
/**
* @brief ElementData::plcIOTypeList
* Return list of all translated PLC IO type strings (for combo boxes).
*/
QStringList ElementData::plcIOTypeList()
{
return QStringList()
<< translatedPlcIOType(EntreeDigitale)
<< translatedPlcIOType(SortieDigitale)
<< translatedPlcIOType(EntreeAnalogique)
<< translatedPlcIOType(SortieAnalogique)
<< translatedPlcIOType(EntreeUniverselle)
<< translatedPlcIOType(SortieUniverselle);
}
+120 -2
View File
@@ -22,6 +22,10 @@
#include "../diagramcontext.h"
#include "../NameList/nameslist.h"
#include <QStringList>
#include <QVector>
#include <QFont>
/**
* @brief The ElementData class
* WARNING
@@ -49,7 +53,8 @@ class ElementData : public PropertiesInterface
enum MasterType {
Coil,
Protection,
Commutator
Commutator,
PLC
};
Q_ENUM(MasterType)
@@ -58,7 +63,8 @@ class ElementData : public PropertiesInterface
Power,
DelayOn,
DelayOff,
delayOnOff
delayOnOff,
PLCSlave
};
Q_ENUM(SlaveType)
@@ -70,6 +76,82 @@ class ElementData : public PropertiesInterface
};
Q_ENUM(SlaveState)
enum PlcIOType {
EntreeDigitale,
SortieDigitale,
EntreeAnalogique,
SortieAnalogique,
EntreeUniverselle,
SortieUniverselle
};
Q_ENUM(PlcIOType)
/**
* @brief The PlcIO struct
* Represents a single IO entry in a PLC master element.
*/
struct PlcIO {
PlcIOType type = EntreeDigitale;
QString address; ///< e.g. "1.0", "1.1"
QString functionText; ///< e.g. "Motor K1"
QString comment; ///< Optional comment
QString crossRef; ///< Auto-filled: slave reference
int terminalCount = 1; ///< Number of terminals for this IO (1-4)
QStringList terminals; ///< Terminal values T1, T2, ... (size = terminalCount)
bool operator==(const PlcIO &other) const {
return type == other.type
&& address == other.address
&& functionText == other.functionText
&& comment == other.comment
&& crossRef == other.crossRef
&& terminalCount == other.terminalCount
&& terminals == other.terminals;
}
bool operator!=(const PlcIO &other) const {
return !(*this == other);
}
};
/**
* @brief The PlcMasterData struct
* Stores all PLC master configuration: IO table, display settings, column visibility.
* All data is stored in the .elmt file for easy sharing between users.
*/
struct PlcMasterData {
QVector<PlcIO> ios; ///< All IO entries
QList<int> breakPositions; ///< Up to 4 break positions (IO index after which to break, 0 = disabled)
QMap<int, qreal> colWidths; ///< Column widths (key: column index)
qreal rowHeight = 8.0; ///< Row height in mm
QMap<int, bool> colVisible; ///< Column visibility (key: column index)
QFont headerFont; ///< Font for column headers
QFont cellFont; ///< Font for cell content
QStringList columnNames; ///< Custom column header names
QList<int> columnOrder; ///< Column display order (logical indices)
bool showHeaders = true; ///< Show column headers on sheet
bool operator==(const PlcMasterData &other) const {
return ios == other.ios
&& breakPositions == other.breakPositions
&& colWidths == other.colWidths
&& qFuzzyCompare(rowHeight, other.rowHeight)
&& colVisible == other.colVisible
&& headerFont == other.headerFont
&& cellFont == other.cellFont
&& columnNames == other.columnNames
&& columnOrder == other.columnOrder
&& showHeaders == other.showHeaders;
}
bool operator!=(const PlcMasterData &other) const {
return !(*this == other);
}
};
static QString plcIOTypeToString(PlcIOType type);
static PlcIOType plcIOTypeFromString(const QString &string);
static QString translatedPlcIOType(PlcIOType type);
static QStringList plcIOTypeList();
enum TerminalType {
TTGeneric,
TTFuse,
@@ -86,6 +168,31 @@ class ElementData : public PropertiesInterface
};
Q_ENUM(TerminalFunction)
/**
* @brief The SlaveContactGroup struct
* Defines a contact group that a master element provides for slave elements.
* Each group specifies the type, subtype, number of displayed contacts,
* number of terminals, and the labels for each terminal (T1-T20).
*/
struct SlaveContactGroup {
SlaveState type = NO; ///< Contact type (NO/NC/SW/Other)
SlaveType subtype = SSimple; ///< Contact subtype (Simple/Power/Delay*)
int contactCount = 1; ///< Number of displayed contacts
int terminalCount = 1; ///< Number of terminals (Anschlüsse)
QStringList labels; ///< Terminal labels (T1-T20), max 20 entries
bool operator==(const SlaveContactGroup &other) const {
return type == other.type
&& subtype == other.subtype
&& contactCount == other.contactCount
&& terminalCount == other.terminalCount
&& labels == other.labels;
}
bool operator!=(const SlaveContactGroup &other) const {
return !(*this == other);
}
};
ElementData() {}
~ElementData() override {}
@@ -130,12 +237,23 @@ class ElementData : public PropertiesInterface
static ElementData::TerminalFunction terminalFunctionFromString(const QString &string);
static QString translatedTerminalFunction(ElementData::TerminalFunction function);
static QString slaveContactGroupTypeToString(ElementData::SlaveState type);
static ElementData::SlaveState slaveContactGroupTypeFromString(const QString &string);
static QString slaveContactGroupSubtypeToString(ElementData::SlaveType type);
static ElementData::SlaveType slaveContactGroupSubtypeFromString(const QString &string);
PlcMasterData plcMasterData() const { return m_plc_master_data; }
void setPlcMasterData(const PlcMasterData &data) { m_plc_master_data = data; }
// must be public, because this class is a private member
// of Element/ element editor and they must access this data
ElementData::Type m_type = ElementData::Simple;
ElementData::MasterType m_master_type = ElementData::Coil;
int m_max_slaves{-1};
bool m_slave_contact_groups_enabled{false}; ///< Whether slave contact groups table is active
QVector<SlaveContactGroup> m_slave_contact_groups; ///< Contact groups defined by master
PlcMasterData m_plc_master_data; ///< PLC master IO table and display settings
ElementData::SlaveType m_slave_type = ElementData::SSimple;
ElementData::SlaveState m_slave_state = ElementData::NO;
+52
View File
@@ -17,7 +17,10 @@
*/
#include "terminaldata.h"
#include "../utils/qetutils.h"
#include <QGraphicsObject>
#include <QDebug>
TerminalData::TerminalData():
@@ -110,6 +113,26 @@ 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", QETUtils::fontToString(m_label_font));
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());
}
// Save master label override settings
if (m_use_master_label) {
xml_element.setAttribute("use_master_label", "true");
xml_element.setAttribute("master_label_index", m_master_label_index);
}
return(xml_element);
}
@@ -157,6 +180,35 @@ 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())
QETUtils::fontFromString(m_label_font, 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);
}
// Read master label override settings
m_use_master_label = (xml_element.attribute("use_master_label") == QLatin1String("true"));
m_master_label_index = xml_element.attribute("master_label_index", "0").toInt();
return true;
}
+24
View File
@@ -21,6 +21,8 @@
#include "../qet.h"
#include "propertiesinterface.h"
#include <QColor>
#include <QFont>
#include <QPointF>
#include <QUuid>
@@ -115,6 +117,28 @@ 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;
/// Whether this terminal uses a label from the master's contact group
bool m_use_master_label = false;
/// Index into the master's contact group labels (T1=0, T2=1, ..., T20=19)
int m_master_label_index = 0;
private:
QGraphicsObject* q{nullptr};
};
+6 -6
View File
@@ -44,17 +44,17 @@ QDomElement UserProperties::toXml(QDomDocument &xml_document) const
for (auto i = m_properties.begin(); i != m_properties.end(); ++i)
{
auto type = i.value().type();
auto type = i.value().userType();
switch(type) {
case QVariant::Type::String:
case QMetaType::QString:
up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toString())); break;
case QVariant::Type::Int:
case QMetaType::Int:
up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toInt())); break;
case QVariant::Type::Double:
case QMetaType::Double:
up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toDouble())); break;
case QVariant::Type::Bool:
case QMetaType::Bool:
up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toBool())); break;
case QVariant::Type::Color:
case QMetaType::QColor:
up.appendChild(QETXML::createXmlProperty(i.key(), QColor(i.value().value<QColor>()))); break;
default:
break;
+1 -1
View File
@@ -176,7 +176,7 @@ QHash<QString, XRefProperties> XRefProperties::defaultProperties()
{
QHash <QString, XRefProperties> hash;
QStringList keys;
keys << "coil" << "protection" << "commutator";
keys << "coil" << "protection" << "commutator" << "plc";
QSettings settings;