mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Overridden properties of terminal elements are now saved/loaded from project
The overridden properties of terminal elements made in the terminal strip dialog are now saved and loaded from/to the project file.
This commit is contained in:
@@ -629,14 +629,13 @@ RealTerminalData TerminalStrip::realTerminalData(QSharedPointer<RealTerminal> re
|
|||||||
|
|
||||||
auto physical_terminal = physicalTerminal(real_terminal);
|
auto physical_terminal = physicalTerminal(real_terminal);
|
||||||
|
|
||||||
rtd.m_real_terminal = real_terminal;
|
|
||||||
rtd.level_ = physical_terminal->levelOf(real_terminal);
|
rtd.level_ = physical_terminal->levelOf(real_terminal);
|
||||||
rtd.label_ = real_terminal->label();
|
rtd.label_ = real_terminal->label();
|
||||||
|
|
||||||
if (real_terminal->isElement()) {
|
if (real_terminal->isElement()) {
|
||||||
rtd.Xref_ = autonum::AssignVariables::genericXref(real_terminal->element());
|
rtd.Xref_ = autonum::AssignVariables::genericXref(real_terminal->element());
|
||||||
rtd.uuid_ = real_terminal->elementUuid();
|
rtd.uuid_ = real_terminal->elementUuid();
|
||||||
rtd.element_ = qgraphicsitem_cast<TerminalElement *>(real_terminal->element());
|
rtd.element_ = real_terminal->element();
|
||||||
}
|
}
|
||||||
rtd.type_ = real_terminal->type();
|
rtd.type_ = real_terminal->type();
|
||||||
rtd.function_ = real_terminal->function();
|
rtd.function_ = real_terminal->function();
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ class TerminalElement;
|
|||||||
|
|
||||||
struct RealTerminalData
|
struct RealTerminalData
|
||||||
{
|
{
|
||||||
QSharedPointer<RealTerminal> m_real_terminal;
|
|
||||||
|
|
||||||
int level_ = 0;
|
int level_ = 0;
|
||||||
|
|
||||||
QString label_,
|
QString label_,
|
||||||
@@ -52,8 +50,7 @@ struct RealTerminalData
|
|||||||
bool led_ = false,
|
bool led_ = false,
|
||||||
is_element = false;
|
is_element = false;
|
||||||
|
|
||||||
TerminalElement *element_ = nullptr;
|
QPointer<Element> element_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PhysicalTerminalData
|
struct PhysicalTerminalData
|
||||||
|
|||||||
@@ -69,9 +69,6 @@ TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(ui->m_table_widget, &QAbstractItemView::entered, [this](auto index) {
|
|
||||||
qDebug() <<"entered";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -221,8 +218,8 @@ QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_s
|
|||||||
terminal_item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, real_t.uuid_.toString());
|
terminal_item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, real_t.uuid_.toString());
|
||||||
terminal_item->setIcon(0, QET::Icons::ElementTerminal);
|
terminal_item->setIcon(0, QET::Icons::ElementTerminal);
|
||||||
|
|
||||||
if (real_t.is_element) {
|
if (real_t.element_) {
|
||||||
m_uuid_terminal_H.insert(real_t.uuid_, real_t.element_);
|
m_uuid_terminal_H.insert(real_t.uuid_, qgraphicsitem_cast<TerminalElement *>(real_t.element_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -440,7 +437,7 @@ void TerminalStripEditor::on_m_dialog_button_box_clicked(QAbstractButton *button
|
|||||||
{
|
{
|
||||||
for (auto modified_data : m_model->modifiedRealTerminalData())
|
for (auto modified_data : m_model->modifiedRealTerminalData())
|
||||||
{
|
{
|
||||||
auto element = m_current_strip->elementForRealTerminal(modified_data.m_real_terminal);
|
auto element = modified_data.element_;
|
||||||
if (element) {
|
if (element) {
|
||||||
auto current_data = element->elementData();
|
auto current_data = element->elementData();
|
||||||
current_data.setTerminalType(modified_data.type_);
|
current_data.setTerminalType(modified_data.type_);
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ QVariant TerminalStripModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
else if (role == Qt::BackgroundRole && index.column() <= CONDUCTOR_CELL )
|
else if (role == Qt::BackgroundRole && index.column() <= CONDUCTOR_CELL )
|
||||||
{
|
{
|
||||||
if (m_modified_cell.contains(rtd.m_real_terminal) &&
|
if (m_modified_cell.contains(rtd.element_) &&
|
||||||
m_modified_cell.value(rtd.m_real_terminal).at(index.column()))
|
m_modified_cell.value(rtd.element_).at(index.column()))
|
||||||
{
|
{
|
||||||
return QBrush(Qt::yellow);
|
return QBrush(Qt::yellow);
|
||||||
}
|
}
|
||||||
@@ -168,17 +168,17 @@ bool TerminalStripModel::setData(const QModelIndex &index, const QVariant &value
|
|||||||
{
|
{
|
||||||
replaceDataAtRow(rtd, index.row());
|
replaceDataAtRow(rtd, index.row());
|
||||||
|
|
||||||
if (rtd.m_real_terminal)
|
if (rtd.element_)
|
||||||
{
|
{
|
||||||
QVector<bool> vector_;
|
QVector<bool> vector_;
|
||||||
if (m_modified_cell.contains(rtd.m_real_terminal)) {
|
if (m_modified_cell.contains(rtd.element_)) {
|
||||||
vector_ = m_modified_cell.value(rtd.m_real_terminal);
|
vector_ = m_modified_cell.value(rtd.element_);
|
||||||
} else {
|
} else {
|
||||||
vector_ = UNMODIFIED_CELL_VECTOR;
|
vector_ = UNMODIFIED_CELL_VECTOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector_.replace(modified_cell, true);
|
vector_.replace(modified_cell, true);
|
||||||
m_modified_cell.insert(rtd.m_real_terminal, vector_);
|
m_modified_cell.insert(rtd.element_, vector_);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -236,7 +236,7 @@ QVector<RealTerminalData> TerminalStripModel::modifiedRealTerminalData() const
|
|||||||
|
|
||||||
for (const auto &ptd : m_physical_terminal_data) {
|
for (const auto &ptd : m_physical_terminal_data) {
|
||||||
for (const auto &rtd : ptd.real_terminals_vector) {
|
for (const auto &rtd : ptd.real_terminals_vector) {
|
||||||
if (modified_real_terminal.contains(rtd.m_real_terminal)) {
|
if (modified_real_terminal.contains(rtd.element_)) {
|
||||||
returned_vector.append(rtd);
|
returned_vector.append(rtd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,18 +254,17 @@ QVector<RealTerminalData> TerminalStripModel::modifiedRealTerminalData() const
|
|||||||
*/
|
*/
|
||||||
bool TerminalStripModel::isXrefCell(const QModelIndex &index, Element **element)
|
bool TerminalStripModel::isXrefCell(const QModelIndex &index, Element **element)
|
||||||
{
|
{
|
||||||
if (index.model() == this && index.isValid())
|
if (index.model() == this
|
||||||
|
&& index.isValid()
|
||||||
|
&& index.column() == XREF_CELL)
|
||||||
{
|
{
|
||||||
if (index.column() == XREF_CELL)
|
if (index.row() < rowCount())
|
||||||
{
|
{
|
||||||
if (index.row() < rowCount())
|
if (auto data = dataAtRow(index.row()) ; data.element_) {
|
||||||
{
|
*element = data.element_.data();
|
||||||
const auto data = dataAtRow(index.row());
|
|
||||||
*element = m_terminal_strip->elementForRealTerminal(data.m_real_terminal);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class TerminalStripModel : public QAbstractTableModel
|
|||||||
private:
|
private:
|
||||||
QPointer<TerminalStrip> m_terminal_strip;
|
QPointer<TerminalStrip> m_terminal_strip;
|
||||||
QVector<PhysicalTerminalData> m_physical_terminal_data;
|
QVector<PhysicalTerminalData> m_physical_terminal_data;
|
||||||
QHash<QSharedPointer<RealTerminal>, QVector<bool>> m_modified_cell;
|
QHash<Element *, QVector<bool>> m_modified_cell;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TerminalStripModelDelegate : public QStyledItemDelegate
|
class TerminalStripModelDelegate : public QStyledItemDelegate
|
||||||
|
|||||||
@@ -200,6 +200,21 @@ bool ElementData::terminalLed() const
|
|||||||
m_terminal_led;
|
m_terminal_led;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementData::terminalPropertiesIsOverrided
|
||||||
|
* @return true if at least one sub properties of terminal type is overrided
|
||||||
|
*/
|
||||||
|
bool ElementData::terminalPropertiesIsOverrided() const
|
||||||
|
{
|
||||||
|
if (m_terminal_type_is_override
|
||||||
|
|| m_terminal_function_is_override
|
||||||
|
|| m_terminal_led_is_override) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool ElementData::operator==(const ElementData &data) const
|
bool ElementData::operator==(const ElementData &data) const
|
||||||
{
|
{
|
||||||
if (data.m_type != m_type) {
|
if (data.m_type != m_type) {
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ class ElementData : public PropertiesInterface
|
|||||||
|
|
||||||
void setTerminalLED(bool led);
|
void setTerminalLED(bool led);
|
||||||
bool terminalLed() const;
|
bool terminalLed() const;
|
||||||
|
bool terminalPropertiesIsOverrided() const;
|
||||||
|
|
||||||
bool operator==(const ElementData &data) const;
|
bool operator==(const ElementData &data) const;
|
||||||
bool operator!=(const ElementData &data) const;
|
bool operator!=(const ElementData &data) const;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "dynamicelementtextitem.h"
|
#include "dynamicelementtextitem.h"
|
||||||
#include "elementtextitemgroup.h"
|
#include "elementtextitemgroup.h"
|
||||||
#include "iostream"
|
#include "iostream"
|
||||||
|
#include "../qetxml.h"
|
||||||
|
|
||||||
#include <QDomElement>
|
#include <QDomElement>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -846,6 +847,28 @@ bool Element::fromXml(QDomElement &e,
|
|||||||
dc.fromXml(e.firstChildElement(QStringLiteral("elementInformations")),
|
dc.fromXml(e.firstChildElement(QStringLiteral("elementInformations")),
|
||||||
QStringLiteral("elementInformation"));
|
QStringLiteral("elementInformation"));
|
||||||
|
|
||||||
|
//Load override properties (For now, only used when the element is a terminal)
|
||||||
|
if (m_data.m_type == ElementData::Terminale)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (auto elmt_type_list = QETXML::subChild(e, QStringLiteral("properties"), QStringLiteral("element_type")) ;
|
||||||
|
elmt_type_list.size())
|
||||||
|
{
|
||||||
|
auto elmt_type = elmt_type_list.first();
|
||||||
|
m_data.setTerminalType(
|
||||||
|
m_data.terminalTypeFromString(
|
||||||
|
elmt_type.attribute(QStringLiteral("terminal_type"))));
|
||||||
|
|
||||||
|
m_data.setTerminalFunction(
|
||||||
|
m_data.terminalFunctionFromString(
|
||||||
|
elmt_type.attribute(QStringLiteral("terminal_function"))));
|
||||||
|
|
||||||
|
m_data.setTerminalLED(
|
||||||
|
QETXML::boolFromString(
|
||||||
|
elmt_type.attribute(QStringLiteral("terminal_led")), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//We must to block the update of the alignment when load the information
|
//We must to block the update of the alignment when load the information
|
||||||
//otherwise the pos of the text will not be the same as it was at save time.
|
//otherwise the pos of the text will not be the same as it was at save time.
|
||||||
for(DynamicElementTextItem *deti : m_dynamic_text_list)
|
for(DynamicElementTextItem *deti : m_dynamic_text_list)
|
||||||
@@ -955,6 +978,23 @@ QDomElement Element::toXml(
|
|||||||
element.appendChild(infos);
|
element.appendChild(infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Save override properties (For now, only used when the element is a terminal)
|
||||||
|
if (m_data.m_type == ElementData::Terminale)
|
||||||
|
{
|
||||||
|
QDomElement properties = document.createElement(QStringLiteral("properties"));
|
||||||
|
QDomElement element_type = document.createElement(QStringLiteral("element_type"));
|
||||||
|
|
||||||
|
element_type.setAttribute(QStringLiteral("terminal_type"),
|
||||||
|
m_data.terminalTypeToString(m_data.terminalType()));
|
||||||
|
element_type.setAttribute(QStringLiteral("terminal_function"),
|
||||||
|
m_data.terminalFunctionToString(m_data.terminalFunction()));
|
||||||
|
element_type.setAttribute(QStringLiteral("terminal_led"),
|
||||||
|
QETXML::boolToString(m_data.terminalLed()));
|
||||||
|
|
||||||
|
properties.appendChild(element_type);
|
||||||
|
element.appendChild(properties);
|
||||||
|
}
|
||||||
|
|
||||||
//Dynamic texts
|
//Dynamic texts
|
||||||
QDomElement dyn_text = document.createElement(QStringLiteral("dynamic_texts"));
|
QDomElement dyn_text = document.createElement(QStringLiteral("dynamic_texts"));
|
||||||
for (DynamicElementTextItem *deti : m_dynamic_text_list)
|
for (DynamicElementTextItem *deti : m_dynamic_text_list)
|
||||||
|
|||||||
@@ -584,6 +584,50 @@ QVector<QDomElement> QETXML::findInDomElement(const QDomElement &dom_elmt, const
|
|||||||
|
|
||||||
namespace QETXML {
|
namespace QETXML {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief boolToString
|
||||||
|
* @param value
|
||||||
|
* @return \p value converted to string
|
||||||
|
*/
|
||||||
|
QString boolToString(bool value)
|
||||||
|
{
|
||||||
|
return value ? QStringLiteral("true") :
|
||||||
|
QStringLiteral("false");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief boolFromString return \p value converted to bool
|
||||||
|
* @param value : value to convert
|
||||||
|
* @param default_value : default value
|
||||||
|
* @param conv_ok : true if \p value is successfully converted
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool boolFromString(const QString &value, bool default_value, bool *conv_ok)
|
||||||
|
{
|
||||||
|
if (value == QStringLiteral("true") ||
|
||||||
|
value == QStringLiteral("1")) {
|
||||||
|
if (conv_ok) {
|
||||||
|
*conv_ok = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == QStringLiteral("false") ||
|
||||||
|
value == QStringLiteral("0")) {
|
||||||
|
if (conv_ok) {
|
||||||
|
*conv_ok = true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(conv_ok) {
|
||||||
|
*conv_ok = false;
|
||||||
|
}
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PropertyFlags debugReadXml(PropertyFlags flag, const QDomElement &e, const QString& attribute_name, const QString& attr, const QString& type)
|
PropertyFlags debugReadXml(PropertyFlags flag, const QDomElement &e, const QString& attribute_name, const QString& attr, const QString& type)
|
||||||
{
|
{
|
||||||
if (flag == QETXML::PropertyFlags::NoValidConversion)
|
if (flag == QETXML::PropertyFlags::NoValidConversion)
|
||||||
@@ -873,7 +917,7 @@ bool validXmlProperty(const QDomElement& e) {
|
|||||||
if (!e.hasAttribute("value"))
|
if (!e.hasAttribute("value"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,10 @@ namespace QETXML
|
|||||||
|
|
||||||
QVector<QDomElement> findInDomElement(const QDomElement &dom_elmt,
|
QVector<QDomElement> findInDomElement(const QDomElement &dom_elmt,
|
||||||
const QString &tag_name);
|
const QString &tag_name);
|
||||||
|
QString boolToString(bool value);
|
||||||
|
bool boolFromString(const QString &value,
|
||||||
|
bool default_value = true,
|
||||||
|
bool *conv_ok = nullptr);
|
||||||
|
|
||||||
const QString integerS = "int";
|
const QString integerS = "int";
|
||||||
const QString doubleS = "double";
|
const QString doubleS = "double";
|
||||||
|
|||||||
Reference in New Issue
Block a user