diff --git a/cmake/qet_compilation_vars.cmake b/cmake/qet_compilation_vars.cmake index 803aa6dee..e3aad8da9 100644 --- a/cmake/qet_compilation_vars.cmake +++ b/cmake/qet_compilation_vars.cmake @@ -475,6 +475,8 @@ set(QET_SRC_FILES ${QET_DIR}/sources/project/projectusagetracker.cpp ${QET_DIR}/sources/project/projectusagetracker.h + ${QET_DIR}/sources/properties/deviceinformation.cpp + ${QET_DIR}/sources/properties/deviceinformation.h ${QET_DIR}/sources/properties/elementdata.cpp ${QET_DIR}/sources/properties/elementdata.h ${QET_DIR}/sources/properties/propertiesinterface.cpp diff --git a/sources/dataBase/projectdatabase.cpp b/sources/dataBase/projectdatabase.cpp index 08286b6ba..bc3711737 100644 --- a/sources/dataBase/projectdatabase.cpp +++ b/sources/dataBase/projectdatabase.cpp @@ -600,6 +600,11 @@ void projectDataBase::createElementNomenclatureView() "ei.designation AS designation," "ei.manufacturer AS manufacturer," "ei.manufacturer_reference AS manufacturer_reference," + "ei.model AS model," + "ei.category AS category," + "ei.voltage_rating AS voltage_rating," + "ei.current_rating AS current_rating," + "ei.notes AS notes," "ei.machine_manufacturer_reference AS machine_manufacturer_reference," "ei.supplier AS supplier," "ei.quantity AS quantity," diff --git a/sources/properties/deviceinformation.cpp b/sources/properties/deviceinformation.cpp new file mode 100644 index 000000000..80010087a --- /dev/null +++ b/sources/properties/deviceinformation.cpp @@ -0,0 +1,65 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "deviceinformation.h" + +#include "../qetinformation.h" + +namespace { +struct DeviceField +{ + QString m_key; + QString DeviceInformation::*m_member; +}; + +const DeviceField fields[] = { + {QETInformation::ELMT_LABEL, &DeviceInformation::m_device_tag}, + {QETInformation::ELMT_MANUFACTURER, &DeviceInformation::m_manufacturer}, + {QETInformation::ELMT_MANUFACTURER_REF, &DeviceInformation::m_part_number}, + {QETInformation::ELMT_MODEL, &DeviceInformation::m_model}, + {QETInformation::ELMT_DESCRIPTION, &DeviceInformation::m_description}, + {QETInformation::ELMT_CATEGORY, &DeviceInformation::m_category}, + {QETInformation::ELMT_QUANTITY, &DeviceInformation::m_quantity}, + {QETInformation::ELMT_VOLTAGE_RATING, &DeviceInformation::m_voltage_rating}, + {QETInformation::ELMT_CURRENT_RATING, &DeviceInformation::m_current_rating}, + {QETInformation::ELMT_NOTES, &DeviceInformation::m_notes} +}; +} + +DeviceInformation DeviceInformation::fromContext(const DiagramContext &context) +{ + DeviceInformation info; + for (const auto &field : fields) { + info.*(field.m_member) = context.value(field.m_key).toString(); + } + return info; +} + +DiagramContext DeviceInformation::toContext(DiagramContext context) const +{ + for (const auto &field : fields) + { + const auto &value = this->*(field.m_member); + if (value.isEmpty()) { + context.remove(field.m_key); + } else { + const bool show = !context.contains(field.m_key) || context.keyMustShow(field.m_key); + context.addValue(field.m_key, value, show); + } + } + return context; +} diff --git a/sources/properties/deviceinformation.h b/sources/properties/deviceinformation.h new file mode 100644 index 000000000..6e355bb9b --- /dev/null +++ b/sources/properties/deviceinformation.h @@ -0,0 +1,47 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef DEVICEINFORMATION_H +#define DEVICEINFORMATION_H + +#include "../diagramcontext.h" + +#include + +/** + * Device properties backed by ElementData::m_informations, not a second store. + * Missing properties remain empty. Quantity and ratings retain the existing + * free-text representation (including decimal quantities and units). + */ +struct DeviceInformation +{ + QString m_device_tag; + QString m_manufacturer; + QString m_part_number; + QString m_model; + QString m_description; + QString m_category; + QString m_quantity; + QString m_voltage_rating; + QString m_current_rating; + QString m_notes; + + static DeviceInformation fromContext(const DiagramContext &context); + DiagramContext toContext(DiagramContext context = DiagramContext()) const; +}; + +#endif // DEVICEINFORMATION_H diff --git a/sources/qetinformation.cpp b/sources/qetinformation.cpp index 05a246d47..8da329bbf 100644 --- a/sources/qetinformation.cpp +++ b/sources/qetinformation.cpp @@ -150,6 +150,11 @@ QStringList QETInformation::elementInfoKeys() ELMT_DESIGNATION, ELMT_MANUFACTURER, ELMT_MANUFACTURER_REF, + ELMT_MODEL, + ELMT_CATEGORY, + ELMT_VOLTAGE_RATING, + ELMT_CURRENT_RATING, + ELMT_NOTES, ELMT_MACHINE_MANUFACTURER_REF, ELMT_SUPPLIER, ELMT_QUANTITY, @@ -234,7 +239,12 @@ QString QETInformation::infoToVar(const QString &info) */ QString QETInformation::translatedInfoKey(const QString &info) { - if (info == DIA_AUTHOR) return QObject::tr("Auteur"); + if (info == ELMT_MODEL) return QObject::tr("Modèle"); + else if (info == ELMT_CATEGORY) return QObject::tr("Catégorie"); + else if (info == ELMT_VOLTAGE_RATING) return QObject::tr("Tension nominale"); + else if (info == ELMT_CURRENT_RATING) return QObject::tr("Courant nominal"); + else if (info == ELMT_NOTES) return QObject::tr("Notes"); + else if (info == DIA_AUTHOR) return QObject::tr("Auteur"); else if (info == DIA_DATE) return QObject::tr("Date"); else if (info == DIA_TITLE) return QObject::tr("Titre"); else if (info == DIA_FILENAME) return QObject::tr("Fichier"); @@ -332,6 +342,11 @@ QStringList QETInformation::elementEditorElementInfoKeys() ELMT_DESIGNATION, ELMT_MANUFACTURER, ELMT_MANUFACTURER_REF, + ELMT_MODEL, + ELMT_CATEGORY, + ELMT_VOLTAGE_RATING, + ELMT_CURRENT_RATING, + ELMT_NOTES, ELMT_MACHINE_MANUFACTURER_REF, ELMT_SUPPLIER, ELMT_QUANTITY, diff --git a/sources/qetinformation.h b/sources/qetinformation.h index 9fee0cdf3..ee144a301 100644 --- a/sources/qetinformation.h +++ b/sources/qetinformation.h @@ -44,6 +44,11 @@ namespace QETInformation static QString ELMT_MACHINE_MANUFACTURER_REF = "machine_manufacturer_reference"; static QString ELMT_SUPPLIER = "supplier"; static QString ELMT_QUANTITY = "quantity"; + static QString ELMT_MODEL = "model"; + static QString ELMT_CATEGORY = "category"; + static QString ELMT_VOLTAGE_RATING = "voltage_rating"; + static QString ELMT_CURRENT_RATING = "current_rating"; + static QString ELMT_NOTES = "notes"; static QString ELMT_UNITY = "unity"; static QString ELMT_PLANT = "plant"; static QString ELMT_LOCATION = "location";