mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Merge branch 'terminal_strip' into merge_confli_master_terminal_strip
* terminal_strip: User can edit the label of terminal inside the terminal strip editor Code refactoring Double click on Xref cell show the terminal in the diagram terminal function can be edited, edted value is applied to element Table widget : led and type is editable Minor gui change Remove position section of terminalStripModel
This commit is contained in:
commit
5ef073b6c1
@ -85,12 +85,28 @@ class RealTerminal
|
||||
|
||||
ElementData::TerminalType type() const {
|
||||
if (m_element) {
|
||||
return m_element->elementData().m_terminal_type;
|
||||
return m_element->elementData().terminalType();
|
||||
} else {
|
||||
return ElementData::TTGeneric;
|
||||
}
|
||||
}
|
||||
|
||||
ElementData::TerminalFunction function() const {
|
||||
if (m_element) {
|
||||
return m_element->elementData().terminalFunction();
|
||||
} else {
|
||||
return ElementData::TFGeneric;
|
||||
}
|
||||
}
|
||||
|
||||
bool led() const {
|
||||
if (m_element) {
|
||||
return m_element->elementData().terminalLed();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief elementUuid
|
||||
* @return if this real terminal is an element
|
||||
@ -452,16 +468,6 @@ int TerminalStrip::physicalTerminalCount() const {
|
||||
return m_physical_terminals.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::realTerminalCount
|
||||
* @return the number of real terminal.
|
||||
* A real terminal is a part of a physical terminal.
|
||||
*/
|
||||
int TerminalStrip::realTerminalCount() const
|
||||
{
|
||||
return m_real_terminals.size();
|
||||
}
|
||||
|
||||
TerminalStripIndex TerminalStrip::index(int index)
|
||||
{
|
||||
TerminalStripIndex tsi_;
|
||||
@ -484,6 +490,29 @@ TerminalStripIndex TerminalStrip::index(int index)
|
||||
return tsi_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::physicalTerminalData
|
||||
* @param index
|
||||
* @return The data of the physical terminal at index \p index
|
||||
*/
|
||||
PhysicalTerminalData TerminalStrip::physicalTerminalData(int index)
|
||||
{
|
||||
PhysicalTerminalData ptd;
|
||||
|
||||
if (index < m_physical_terminals.size())
|
||||
{
|
||||
auto physical_terminal = m_physical_terminals.at(index);
|
||||
ptd.physical_terminal = physical_terminal;
|
||||
ptd.pos_ = index;
|
||||
for (auto real_terminal : physical_terminal->terminals()) {
|
||||
auto rtd = realTerminalData(real_terminal);
|
||||
ptd.real_terminals_vector.append(rtd);
|
||||
}
|
||||
}
|
||||
|
||||
return ptd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::terminalElement
|
||||
* @return A vector of all terminal element owned by this strip
|
||||
@ -566,31 +595,6 @@ bool TerminalStrip::fromXml(QDomElement &xml_element)
|
||||
return true;
|
||||
}
|
||||
|
||||
RealTerminalData TerminalStrip::realTerminalData(int real_terminal_index)
|
||||
{
|
||||
RealTerminalData rtd;
|
||||
if (m_real_terminals.isEmpty() ||
|
||||
real_terminal_index >= m_real_terminals.size()) {
|
||||
return rtd;
|
||||
}
|
||||
|
||||
auto real_terminal = m_real_terminals.at(real_terminal_index);
|
||||
auto physical_terminal = physicalTerminal(real_terminal);
|
||||
|
||||
rtd.m_real_terminal = m_real_terminals.at(real_terminal_index);
|
||||
rtd.pos_ = m_physical_terminals.indexOf(physical_terminal);
|
||||
rtd.level_ = physical_terminal->levelOf(real_terminal);
|
||||
rtd.label_ = real_terminal->label();
|
||||
|
||||
if (real_terminal->isElement()) {
|
||||
rtd.Xref_ = autonum::AssignVariables::genericXref(real_terminal->element());
|
||||
}
|
||||
rtd.type_ = real_terminal->type();
|
||||
rtd.is_element = real_terminal->isElement();
|
||||
|
||||
return rtd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::realTerminal
|
||||
* @param terminal
|
||||
@ -632,6 +636,36 @@ QSharedPointer<PhysicalTerminal> TerminalStrip::physicalTerminal(QSharedPointer<
|
||||
return pt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::elementForRealTerminal
|
||||
* @param rt
|
||||
* @return the element associated to \p rt, the returned element can be nullptr;
|
||||
*/
|
||||
Element *TerminalStrip::elementForRealTerminal(QSharedPointer<RealTerminal> rt) const {
|
||||
return rt.data()->element();
|
||||
}
|
||||
|
||||
RealTerminalData TerminalStrip::realTerminalData(QSharedPointer<RealTerminal> real_terminal)
|
||||
{
|
||||
RealTerminalData rtd;
|
||||
|
||||
auto physical_terminal = physicalTerminal(real_terminal);
|
||||
|
||||
rtd.m_real_terminal = real_terminal;
|
||||
rtd.level_ = physical_terminal->levelOf(real_terminal);
|
||||
rtd.label_ = real_terminal->label();
|
||||
|
||||
if (real_terminal->isElement()) {
|
||||
rtd.Xref_ = autonum::AssignVariables::genericXref(real_terminal->element());
|
||||
}
|
||||
rtd.type_ = real_terminal->type();
|
||||
rtd.function_ = real_terminal->function();
|
||||
rtd.led_ = real_terminal->led();
|
||||
rtd.is_element = real_terminal->isElement();
|
||||
|
||||
return rtd;
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
/************************************************************************************/
|
||||
/************************************************************************************/
|
||||
|
@ -31,12 +31,12 @@ class TerminalStripIndex;
|
||||
class TerminalElement;
|
||||
|
||||
|
||||
|
||||
struct RealTerminalData
|
||||
{
|
||||
QSharedPointer<RealTerminal> m_real_terminal;
|
||||
|
||||
int pos_ = 0,
|
||||
level_ = 0;
|
||||
int level_ = 0;
|
||||
|
||||
QString label_,
|
||||
Xref_,
|
||||
@ -45,9 +45,18 @@ struct RealTerminalData
|
||||
conductor_;
|
||||
|
||||
ElementData::TerminalType type_;
|
||||
ElementData::TerminalFunction function_;
|
||||
|
||||
bool led_ = false,
|
||||
is_element = false;
|
||||
|
||||
};
|
||||
|
||||
struct PhysicalTerminalData
|
||||
{
|
||||
QVector<RealTerminalData> real_terminals_vector;
|
||||
int pos_ = -1;
|
||||
QSharedPointer<PhysicalTerminal> physical_terminal;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -90,9 +99,9 @@ class TerminalStrip : public QObject
|
||||
bool haveTerminal (Element *terminal);
|
||||
|
||||
int physicalTerminalCount() const;
|
||||
int realTerminalCount() const;
|
||||
TerminalStripIndex index(int index = 0);
|
||||
RealTerminalData realTerminalData(int real_terminal_index);
|
||||
|
||||
PhysicalTerminalData physicalTerminalData(int index);
|
||||
|
||||
QVector<QPointer<Element>> terminalElement() const;
|
||||
|
||||
@ -100,9 +109,12 @@ class TerminalStrip : public QObject
|
||||
QDomElement toXml(QDomDocument &parent_document);
|
||||
bool fromXml(QDomElement &xml_element);
|
||||
|
||||
Element *elementForRealTerminal(QSharedPointer<RealTerminal> rt) const;
|
||||
|
||||
private:
|
||||
QSharedPointer<RealTerminal> realTerminal(Element *terminal);
|
||||
QSharedPointer<PhysicalTerminal> physicalTerminal(QSharedPointer<RealTerminal> terminal);
|
||||
RealTerminalData realTerminalData(QSharedPointer<RealTerminal> real_terminal);
|
||||
|
||||
private:
|
||||
TerminalStripData m_data;
|
||||
|
@ -25,9 +25,11 @@
|
||||
#include "../UndoCommand/addterminalstripcommand.h"
|
||||
#include "../UndoCommand/addterminaltostripcommand.h"
|
||||
#include "../UndoCommand/changeterminalstripdata.h"
|
||||
#include "../undocommand/changeelementdatacommand.h"
|
||||
#include "terminalstriptreewidget.h"
|
||||
#include "../../qeticons.h"
|
||||
#include "terminalstripmodel.h"
|
||||
#include "../diagram.h"
|
||||
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
@ -42,10 +44,34 @@ TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
|
||||
m_project(project)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->m_table_widget->setItemDelegate(new TerminalStripModelDelegate(ui->m_terminal_strip_tw));
|
||||
ui->m_remove_terminal_strip_pb->setDisabled(true);
|
||||
buildTree();
|
||||
ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex());
|
||||
setUpUndoConnections();
|
||||
|
||||
//Go the diagram of double clicked terminal
|
||||
connect(ui->m_table_widget, &QAbstractItemView::doubleClicked, [this](auto index)
|
||||
{
|
||||
Element *elmt = nullptr;
|
||||
if (this->m_model->isXrefCell(index, &elmt))
|
||||
{
|
||||
auto diagram = elmt->diagram();
|
||||
if (diagram)
|
||||
{
|
||||
diagram->showMe();
|
||||
if (diagram->views().size())
|
||||
{
|
||||
auto fit_view = elmt->sceneBoundingRect();
|
||||
fit_view.adjust(-200,-200,200,200);
|
||||
diagram->views().first()->fitInView(fit_view, Qt::KeepAspectRatioByExpanding);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
connect(ui->m_table_widget, &QAbstractItemView::entered, [this](auto index) {
|
||||
qDebug() <<"entered";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -385,20 +411,46 @@ void TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetI
|
||||
setCurrentStrip(strip_);
|
||||
}
|
||||
|
||||
void TerminalStripEditor::on_m_apply_data_pb_clicked(QAbstractButton *button)
|
||||
void TerminalStripEditor::on_m_dialog_button_box_clicked(QAbstractButton *button)
|
||||
{
|
||||
Q_UNUSED(button)
|
||||
|
||||
if (m_current_strip)
|
||||
{
|
||||
TerminalStripData data;
|
||||
data.m_installation = ui->m_installation_le->text();
|
||||
data.m_location = ui->m_location_le->text();
|
||||
data.m_name = ui->m_name_le->text();
|
||||
data.m_comment = ui->m_comment_le->text();
|
||||
data.m_description = ui->m_description_te->toPlainText();
|
||||
auto role = ui->m_dialog_button_box->buttonRole(button);
|
||||
|
||||
m_project->undoStack()->push(new ChangeTerminalStripData(m_current_strip, data, nullptr));
|
||||
if (role == QDialogButtonBox::ApplyRole)
|
||||
{
|
||||
if (m_current_strip)
|
||||
{
|
||||
m_project->undoStack()->beginMacro(tr("Modifier des propriétés de borniers"));
|
||||
|
||||
TerminalStripData data;
|
||||
data.m_installation = ui->m_installation_le->text();
|
||||
data.m_location = ui->m_location_le->text();
|
||||
data.m_name = ui->m_name_le->text();
|
||||
data.m_comment = ui->m_comment_le->text();
|
||||
data.m_description = ui->m_description_te->toPlainText();
|
||||
|
||||
m_project->undoStack()->push(new ChangeTerminalStripData(m_current_strip, data, nullptr));
|
||||
|
||||
if (m_model)
|
||||
{
|
||||
for (auto modified_data : m_model->modifiedRealTerminalData())
|
||||
{
|
||||
auto element = m_current_strip->elementForRealTerminal(modified_data.m_real_terminal);
|
||||
if (element) {
|
||||
auto current_data = element->elementData();
|
||||
current_data.setTerminalType(modified_data.type_);
|
||||
current_data.setTerminalFunction(modified_data.function_);
|
||||
current_data.setTerminalLED(modified_data.led_);
|
||||
current_data.m_informations.addValue(QStringLiteral("label"), modified_data.label_);
|
||||
|
||||
m_project->undoStack()->push(new ChangeElementDataCommand(element, current_data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_project->undoStack()->endMacro();
|
||||
}
|
||||
}
|
||||
|
||||
on_m_reload_pb_clicked();
|
||||
|
@ -56,7 +56,7 @@ class TerminalStripEditor : public QDialog
|
||||
void on_m_remove_terminal_strip_pb_clicked();
|
||||
void on_m_reload_pb_clicked();
|
||||
void on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
void on_m_apply_data_pb_clicked(QAbstractButton *button);
|
||||
void on_m_dialog_button_box_clicked(QAbstractButton *button);
|
||||
|
||||
private:
|
||||
Ui::TerminalStripEditor *ui;
|
||||
|
@ -6,15 +6,15 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>951</width>
|
||||
<height>491</height>
|
||||
<width>1260</width>
|
||||
<height>579</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Gestionnaire de borniers</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" rowstretch="0,1" columnstretch="0">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,1">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
@ -78,17 +78,11 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="handleWidth">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="childrenCollapsible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<widget class="TerminalStripTreeWidget" name="m_terminal_strip_tw">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
@ -114,141 +108,134 @@
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
<widget class="QTabWidget" name="m_tab_widget">
|
||||
<widget class="QWidget" name="widget_3" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_layout_tab">
|
||||
<attribute name="title">
|
||||
<string>Disposition</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTableView" name="m_table_widget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="m_tab_widget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_layout_tab">
|
||||
<attribute name="title">
|
||||
<string>Disposition</string>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="m_data_tab">
|
||||
<attribute name="title">
|
||||
<string>Propriétés</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Installation :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Commentaire</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="m_name_le"/>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QPlainTextEdit" name="m_description_te"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Nom :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="m_location_le"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="m_installation_le"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Localisation :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="m_comment_le"/>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<widget class="QTableView" name="m_table_widget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="m_data_tab">
|
||||
<attribute name="title">
|
||||
<string>Propriétés</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Nom :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="m_name_le"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QPlainTextEdit" name="m_description_te"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="m_installation_le"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Commentaire</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="m_comment_le"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Installation :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="m_apply_data_pb">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply</set>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="m_location_le"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Localisation :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="m_dialog_button_box">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Reset</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2021 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@ -17,7 +17,31 @@
|
||||
*/
|
||||
#include "terminalstripmodel.h"
|
||||
#include "../terminalstrip.h"
|
||||
#include "../../qetgraphicsitem/element.h"
|
||||
#include <QDebug>
|
||||
#include <QBrush>
|
||||
#include <QVector>
|
||||
#include <QComboBox>
|
||||
#include <QSpinBox>
|
||||
|
||||
/**
|
||||
* Some const int who describe what a column contain
|
||||
*/
|
||||
const int POS_CELL = 0;
|
||||
const int LEVEL_CELL = 1;
|
||||
const int LABEL_CELL = 2;
|
||||
const int XREF_CELL = 3;
|
||||
const int CABLE_CELL = 4;
|
||||
const int CABLE_WIRE_CELL = 5;
|
||||
const int TYPE_CELL = 6;
|
||||
const int FUNCTION_CELL = 7;
|
||||
const int LED_CELL = 8;
|
||||
const int CONDUCTOR_CELL = 9;
|
||||
|
||||
const int ROW_COUNT = 9;
|
||||
|
||||
static QVector<bool> UNMODIFIED_CELL_VECTOR{false, false, false, false, false, false, false, false, false, false};
|
||||
|
||||
|
||||
/**
|
||||
* @brief TerminalStripModel::TerminalStripModel
|
||||
@ -39,63 +63,336 @@ int TerminalStripModel::rowCount(const QModelIndex &parent) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_terminal_strip->realTerminalCount();
|
||||
auto count = 0;
|
||||
for (const auto &ptd : m_physical_terminal_data) {
|
||||
count += ptd.real_terminals_vector.size();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int TerminalStripModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return 9;
|
||||
return ROW_COUNT;
|
||||
}
|
||||
|
||||
QVariant TerminalStripModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole ||
|
||||
index.row() >= m_real_terminal_data.size()) {
|
||||
if (index.row() >= rowCount(QModelIndex())) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
auto rtd = m_real_terminal_data.at(index.row());
|
||||
switch (index.column()) {
|
||||
case 0 : return rtd.pos_;
|
||||
case 1 : return rtd.level_;
|
||||
case 2 : return rtd.label_;
|
||||
case 3 : return rtd.Xref_;
|
||||
case 4 : return rtd.cable_;
|
||||
case 5 : return rtd.cable_wire_;
|
||||
case 6 : return ElementData::translatedTerminalType(rtd.type_);
|
||||
case 7 : return rtd.led_;
|
||||
case 8 : return rtd.conductor_;
|
||||
default : return QVariant();
|
||||
const auto rtd = dataAtRow(index.row());
|
||||
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
switch (index.column()) {
|
||||
case POS_CELL : return index.row();
|
||||
case LEVEL_CELL : return rtd.level_;
|
||||
case LABEL_CELL : return rtd.label_;
|
||||
case XREF_CELL : return rtd.Xref_;
|
||||
case CABLE_CELL : return rtd.cable_;
|
||||
case CABLE_WIRE_CELL : return rtd.cable_wire_;
|
||||
case TYPE_CELL : return ElementData::translatedTerminalType(rtd.type_);
|
||||
case FUNCTION_CELL : return ElementData::translatedTerminalFunction(rtd.function_);
|
||||
case CONDUCTOR_CELL : return rtd.conductor_;
|
||||
default : return QVariant();
|
||||
}
|
||||
}
|
||||
else if (role == Qt::EditRole)
|
||||
{
|
||||
switch (index.column()) {
|
||||
case LABEL_CELL : return rtd.label_;
|
||||
default: return QVariant();
|
||||
|
||||
}
|
||||
}
|
||||
else if (role == Qt::CheckStateRole &&
|
||||
index.column() == LED_CELL)
|
||||
{
|
||||
return rtd.led_ ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
else if (role == Qt::BackgroundRole && index.column() <= CONDUCTOR_CELL )
|
||||
{
|
||||
if (m_modified_cell.contains(rtd.m_real_terminal) &&
|
||||
m_modified_cell.value(rtd.m_real_terminal).at(index.column()))
|
||||
{
|
||||
return QBrush(Qt::yellow);
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool TerminalStripModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
auto rtd = dataAtRow(index.row());
|
||||
bool modified_ = false;
|
||||
int modified_cell = -1;
|
||||
auto column_ = index.column();
|
||||
|
||||
if (column_ == LED_CELL &&
|
||||
role == Qt::CheckStateRole)
|
||||
{
|
||||
rtd.led_ = value.toBool();
|
||||
modified_ = true;
|
||||
modified_cell = LED_CELL;
|
||||
}
|
||||
else if (column_ == TYPE_CELL &&
|
||||
role == Qt::EditRole)
|
||||
{
|
||||
rtd.type_ = value.value<ElementData::TerminalType>();
|
||||
modified_ = true;
|
||||
modified_cell = TYPE_CELL;
|
||||
}
|
||||
else if (column_ == FUNCTION_CELL &&
|
||||
role == Qt::EditRole)
|
||||
{
|
||||
rtd.function_ = value.value<ElementData::TerminalFunction>();
|
||||
modified_ = true;
|
||||
modified_cell = FUNCTION_CELL;
|
||||
}
|
||||
else if (column_ == LABEL_CELL &&
|
||||
role == Qt::EditRole)
|
||||
{
|
||||
rtd.label_ = value.toString();
|
||||
modified_ = true;
|
||||
modified_cell = LABEL_CELL;
|
||||
}
|
||||
|
||||
//Set the modification to the terminal data
|
||||
if (modified_)
|
||||
{
|
||||
replaceDataAtRow(rtd, index.row());
|
||||
|
||||
if (rtd.m_real_terminal)
|
||||
{
|
||||
QVector<bool> vector_;
|
||||
if (m_modified_cell.contains(rtd.m_real_terminal)) {
|
||||
vector_ = m_modified_cell.value(rtd.m_real_terminal);
|
||||
} else {
|
||||
vector_ = UNMODIFIED_CELL_VECTOR;
|
||||
}
|
||||
|
||||
vector_.replace(modified_cell, true);
|
||||
m_modified_cell.insert(rtd.m_real_terminal, vector_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant TerminalStripModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation != Qt::Horizontal ||
|
||||
role != Qt::DisplayRole) {
|
||||
return QVariant();
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
if (orientation == Qt::Horizontal)
|
||||
{
|
||||
switch (section) {
|
||||
case POS_CELL: return tr("Position");
|
||||
case LEVEL_CELL: return tr("Étage");
|
||||
case LABEL_CELL: return tr("Label");
|
||||
case XREF_CELL: return tr("Référence croisé");
|
||||
case CABLE_CELL: return tr("Câble");
|
||||
case CABLE_WIRE_CELL: return tr("Couleur / numéro de fil câble");
|
||||
case TYPE_CELL: return tr("Type");
|
||||
case FUNCTION_CELL : return tr("Fonction");
|
||||
case LED_CELL: return tr("led");
|
||||
case CONDUCTOR_CELL: return tr("Numéro de conducteur");
|
||||
default : return QVariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (section) {
|
||||
case 0: return tr("Position");
|
||||
case 1: return tr("Étage");
|
||||
case 2: return tr("Label");
|
||||
case 3: return tr("Référence croisé");
|
||||
case 4: return tr("Câble");
|
||||
case 5: return tr("Couleur / numéro de fil câble");
|
||||
case 6: return tr("Type");
|
||||
case 7: return tr("led");
|
||||
case 8: return tr("Numéro de conducteur");
|
||||
default : return QVariant();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags TerminalStripModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
|
||||
auto c = index.column();
|
||||
if (c == LABEL_CELL || c == TYPE_CELL || c == FUNCTION_CELL)
|
||||
flags = flags | Qt::ItemIsEditable;
|
||||
if (c == LED_CELL) {
|
||||
flags = flags | Qt::ItemIsUserCheckable;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStripModel::modifiedRealTerminalData
|
||||
* @return the modified real terminal data
|
||||
*/
|
||||
QVector<RealTerminalData> TerminalStripModel::modifiedRealTerminalData() const
|
||||
{
|
||||
QVector<RealTerminalData> returned_vector;
|
||||
|
||||
const auto modified_real_terminal = m_modified_cell.keys();
|
||||
|
||||
for (const auto &ptd : m_physical_terminal_data) {
|
||||
for (const auto &rtd : ptd.real_terminals_vector) {
|
||||
if (modified_real_terminal.contains(rtd.m_real_terminal)) {
|
||||
returned_vector.append(rtd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returned_vector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStripModel::isXrefCell
|
||||
* @param index
|
||||
* @param elmt : Pointer of a pointer element
|
||||
* @return true if the index is the Xref cell, if true the pointer \p element
|
||||
* will be set to the element associated to the cell.
|
||||
*/
|
||||
bool TerminalStripModel::isXrefCell(const QModelIndex &index, Element **element)
|
||||
{
|
||||
if (index.model() == this && index.isValid())
|
||||
{
|
||||
if (index.column() == XREF_CELL)
|
||||
{
|
||||
if (index.row() < rowCount())
|
||||
{
|
||||
const auto data = dataAtRow(index.row());
|
||||
*element = m_terminal_strip->elementForRealTerminal(data.m_real_terminal);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TerminalStripModel::fillRealTerminalData()
|
||||
{
|
||||
//Get all physical terminal
|
||||
if (m_terminal_strip) {
|
||||
for (int i=0 ; i < m_terminal_strip->realTerminalCount() ; ++i) {
|
||||
m_real_terminal_data.append(m_terminal_strip->realTerminalData(i));
|
||||
for (auto i=0 ; i < m_terminal_strip->physicalTerminalCount() ; ++i) {
|
||||
m_physical_terminal_data.append(m_terminal_strip->physicalTerminalData(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RealTerminalData TerminalStripModel::dataAtRow(int row) const
|
||||
{
|
||||
if (row > rowCount(QModelIndex())) {
|
||||
return RealTerminalData();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto current_row = 0;
|
||||
for (const auto &physical_data : m_physical_terminal_data)
|
||||
{
|
||||
for (const auto &real_data : physical_data.real_terminals_vector)
|
||||
{
|
||||
if (current_row == row) {
|
||||
return real_data;
|
||||
} else {
|
||||
++current_row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return RealTerminalData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStripModel::replaceDataAtRow
|
||||
* Replace the data at row \p row by \p data
|
||||
* @param data
|
||||
* @param row
|
||||
*/
|
||||
void TerminalStripModel::replaceDataAtRow(RealTerminalData data, int row)
|
||||
{
|
||||
if (row > rowCount(QModelIndex())) {
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto current_row = 0;
|
||||
auto current_physical = 0;
|
||||
|
||||
for (const auto &physical_data : qAsConst(m_physical_terminal_data))
|
||||
{
|
||||
auto current_real = 0;
|
||||
for (int i=0 ; i<physical_data.real_terminals_vector.count() ; ++i)
|
||||
{
|
||||
if (current_row == row) {
|
||||
auto physical_data = m_physical_terminal_data.at(current_physical);
|
||||
physical_data.real_terminals_vector.replace(current_real, data);
|
||||
m_physical_terminal_data.replace(current_physical, physical_data);
|
||||
return;
|
||||
} else {
|
||||
++current_real;
|
||||
++current_row;
|
||||
}
|
||||
}
|
||||
++current_physical;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
* Alittle delegate for add a combobox to edit type
|
||||
* and a spinbox to edit the level of a terminal
|
||||
**********************************************************/
|
||||
|
||||
TerminalStripModelDelegate::TerminalStripModelDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
{}
|
||||
|
||||
QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
if (index.column() == TYPE_CELL) {
|
||||
auto qcb = new QComboBox(parent);
|
||||
qcb->setObjectName("terminal_type");
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTGeneric), ElementData::TTGeneric);
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTFuse), ElementData::TTFuse);
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTSectional), ElementData::TTSectional);
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTDiode), ElementData::TTDiode);
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTGround), ElementData::TTGround);
|
||||
|
||||
return qcb;
|
||||
}
|
||||
if (index.column() == FUNCTION_CELL) {
|
||||
auto qcb = new QComboBox(parent);
|
||||
qcb->setObjectName("terminal_function");
|
||||
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFGeneric), ElementData::TFGeneric);
|
||||
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFPhase), ElementData::TFPhase);
|
||||
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFNeutral), ElementData::TFNeutral);
|
||||
|
||||
return qcb;
|
||||
}
|
||||
|
||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||
}
|
||||
|
||||
void TerminalStripModelDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid())
|
||||
{
|
||||
if (editor->objectName() == QLatin1String("terminal_type"))
|
||||
{
|
||||
if (auto qcb = dynamic_cast<QComboBox *>(editor)) {
|
||||
model->setData(index, qcb->currentData(), Qt::EditRole);
|
||||
}
|
||||
}
|
||||
else if (editor->objectName() == QLatin1String("terminal_function"))
|
||||
{
|
||||
if (auto qcb = dynamic_cast<QComboBox *>(editor)) {
|
||||
model->setData(index, qcb->currentData(), Qt::EditRole);
|
||||
}
|
||||
}
|
||||
else {
|
||||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include <QAbstractTableModel>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include "../terminalstrip.h"
|
||||
|
||||
class TerminalStrip;
|
||||
@ -34,14 +36,40 @@ class TerminalStripModel : public QAbstractTableModel
|
||||
virtual int rowCount (const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual int columnCount (const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
virtual bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
virtual Qt::ItemFlags flags (const QModelIndex &index) const override;
|
||||
|
||||
QVector<RealTerminalData> modifiedRealTerminalData() const;
|
||||
|
||||
bool isXrefCell(const QModelIndex &index, Element **element = nullptr);
|
||||
|
||||
private:
|
||||
void fillRealTerminalData();
|
||||
RealTerminalData dataAtRow(int row) const;
|
||||
void replaceDataAtRow(RealTerminalData data, int row);
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_terminal_strip;
|
||||
QVector<RealTerminalData> m_real_terminal_data;
|
||||
QVector<PhysicalTerminalData> m_physical_terminal_data;
|
||||
QHash<QSharedPointer<RealTerminal>, QVector<bool>> m_modified_cell;
|
||||
};
|
||||
|
||||
class TerminalStripModelDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TerminalStripModelDelegate(QObject *parent = Q_NULLPTR);
|
||||
|
||||
QWidget *createEditor(
|
||||
QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
void setModelData(
|
||||
QWidget *editor,
|
||||
QAbstractItemModel *model,
|
||||
const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
#endif // TERMINALSTRIPMODEL_H
|
||||
|
@ -122,6 +122,84 @@ QDomElement ElementData::kindInfoToXml(QDomDocument &document)
|
||||
return returned_elmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementData::setTerminalType
|
||||
* Override the terminal type by \p t_type
|
||||
* @param t_type
|
||||
*/
|
||||
void ElementData::setTerminalType(ElementData::TerminalType t_type)
|
||||
{
|
||||
if (t_type == m_terminal_type) {
|
||||
m_terminal_type_is_override = false;
|
||||
} else {
|
||||
m_override_terminal_type = t_type;
|
||||
m_terminal_type_is_override = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementData::terminalType
|
||||
* @return the terminal type or overrided terminal type if set
|
||||
*/
|
||||
ElementData::TerminalType ElementData::terminalType() const
|
||||
{
|
||||
return m_terminal_type_is_override ?
|
||||
m_override_terminal_type :
|
||||
m_terminal_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementData::setTerminalFunction
|
||||
* Override the terminal function by \p t_function
|
||||
* @param t_function
|
||||
*/
|
||||
void ElementData::setTerminalFunction(ElementData::TerminalFunction t_function)
|
||||
{
|
||||
if (t_function == m_terminal_function) {
|
||||
m_terminal_function_is_override = false;
|
||||
} else {
|
||||
m_override_terminal_function = t_function;
|
||||
m_terminal_function_is_override = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementData::terminalFunction
|
||||
* @return the terminal function or overrided terminal function if set
|
||||
*/
|
||||
ElementData::TerminalFunction ElementData::terminalFunction() const
|
||||
{
|
||||
return m_terminal_function_is_override ?
|
||||
m_override_terminal_function :
|
||||
m_terminal_function;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementData::setTerminalLED
|
||||
* Override the terminal led by \p led
|
||||
* @param led
|
||||
*/
|
||||
void ElementData::setTerminalLED(bool led)
|
||||
{
|
||||
if (led == m_terminal_led) {
|
||||
m_terminal_led_is_override = false;
|
||||
} else {
|
||||
m_override_terminal_led = led;
|
||||
m_terminal_led_is_override = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementData::terminalLed
|
||||
* @return if terminal have led or overrided led if set
|
||||
*/
|
||||
bool ElementData::terminalLed() const
|
||||
{
|
||||
return m_terminal_led_is_override ?
|
||||
m_override_terminal_led :
|
||||
m_terminal_led;
|
||||
}
|
||||
|
||||
bool ElementData::operator==(const ElementData &data) const
|
||||
{
|
||||
if (data.m_type != m_type) {
|
||||
@ -141,8 +219,41 @@ bool ElementData::operator==(const ElementData &data) const
|
||||
}
|
||||
}
|
||||
else if (data.m_type == ElementData::Terminale) {
|
||||
if (data.m_terminal_type != m_terminal_type ||
|
||||
data.m_terminal_function != m_terminal_function) {
|
||||
//Check terminal type or overrided terminal type
|
||||
if (data.m_terminal_type_is_override != m_terminal_type_is_override) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_terminal_type_is_override) {
|
||||
if(data.m_override_terminal_type != m_override_terminal_type) {
|
||||
return false;
|
||||
}
|
||||
} else if (data.m_terminal_type != m_terminal_type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check terminal led or override terminal led
|
||||
if (data.m_terminal_led_is_override != m_terminal_led_is_override) {
|
||||
return false;
|
||||
}
|
||||
if (m_terminal_led_is_override) {
|
||||
if (data.m_override_terminal_led != m_override_terminal_led) {
|
||||
return false;
|
||||
}
|
||||
} else if (data.m_terminal_led != m_terminal_led) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check terminal function or overrided terminal function
|
||||
if (data.m_terminal_function_is_override != m_terminal_function_is_override) {
|
||||
return false;
|
||||
}
|
||||
if (m_terminal_function_is_override) {
|
||||
if (data.m_override_terminal_function != m_override_terminal_function) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (data.m_terminal_function != m_terminal_function) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -343,15 +454,15 @@ QString ElementData::translatedTerminalType(ElementData::TerminalType type)
|
||||
{
|
||||
switch (type) {
|
||||
case ElementData::TTGeneric :
|
||||
return QObject::tr("generique", "generic terminal element type");
|
||||
return QObject::tr("Générique", "generic terminal element type");
|
||||
case ElementData::TTFuse :
|
||||
return QObject::tr("fusible", "fuse terminal element type");
|
||||
return QObject::tr("Fusible", "fuse terminal element type");
|
||||
case ElementData::TTSectional:
|
||||
return QObject::tr("sectionable", "sectional terminal element type");
|
||||
return QObject::tr("Sectionable", "sectional terminal element type");
|
||||
case ElementData::TTDiode:
|
||||
return QObject::tr("diode", "diode terminal element type");
|
||||
return QObject::tr("Diode", "diode terminal element type");
|
||||
case ElementData::TTGround:
|
||||
return QObject::tr("terre", "ground terminal element type");
|
||||
return QObject::tr("Terre", "ground terminal element type");
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,6 +494,15 @@ ElementData::TerminalFunction ElementData::terminalFunctionFromString(const QStr
|
||||
return ElementData::TFGeneric;
|
||||
}
|
||||
|
||||
QString ElementData::translatedTerminalFunction(ElementData::TerminalFunction function)
|
||||
{
|
||||
switch (function) {
|
||||
case TFGeneric : return QObject::tr("Générique", "generic terminal element function");
|
||||
case TFPhase : return QObject::tr("Phase", "phase terminal element function" );
|
||||
case TFNeutral : return QObject::tr("Neutre", "neutral terminal element function");
|
||||
}
|
||||
}
|
||||
|
||||
void ElementData::kindInfoFromXml(const QDomElement &xml_element)
|
||||
{
|
||||
if (m_type == ElementData::Master ||
|
||||
|
@ -91,6 +91,15 @@ class ElementData : public PropertiesInterface
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
QDomElement kindInfoToXml(QDomDocument &document);
|
||||
|
||||
void setTerminalType(ElementData::TerminalType t_type);
|
||||
ElementData::TerminalType terminalType() const;
|
||||
|
||||
void setTerminalFunction(ElementData::TerminalFunction t_function);
|
||||
ElementData::TerminalFunction terminalFunction() const;
|
||||
|
||||
void setTerminalLED(bool led);
|
||||
bool terminalLed() const;
|
||||
|
||||
bool operator==(const ElementData &data) const;
|
||||
bool operator!=(const ElementData &data) const;
|
||||
|
||||
@ -112,6 +121,7 @@ class ElementData : public PropertiesInterface
|
||||
|
||||
static QString terminalFunctionToString(ElementData::TerminalFunction function);
|
||||
static ElementData::TerminalFunction terminalFunctionFromString(const QString &string);
|
||||
static QString translatedTerminalFunction(ElementData::TerminalFunction function);
|
||||
|
||||
// must be public, because this class is a private member
|
||||
// of Element/ element editor and they must access this data
|
||||
@ -130,6 +140,17 @@ class ElementData : public PropertiesInterface
|
||||
NamesList m_names_list;
|
||||
QString m_drawing_information;
|
||||
|
||||
private:
|
||||
ElementData::TerminalType m_override_terminal_type = ElementData::TTGeneric;
|
||||
bool m_terminal_type_is_override = false;
|
||||
|
||||
ElementData::TerminalFunction m_override_terminal_function = ElementData::TFGeneric;
|
||||
bool m_terminal_function_is_override = false;
|
||||
|
||||
bool m_terminal_led = false;
|
||||
bool m_terminal_led_is_override = false;
|
||||
bool m_override_terminal_led = false;
|
||||
|
||||
private:
|
||||
void kindInfoFromXml(const QDomElement &xml_element);
|
||||
};
|
||||
|
@ -1314,6 +1314,26 @@ ElementData Element::elementData() const
|
||||
return m_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Element::setElementData
|
||||
* Set new data for this element.
|
||||
* If m_information of \p data is changed, emit elementInfoChange
|
||||
* @param data
|
||||
*/
|
||||
void Element::setElementData(ElementData data)
|
||||
{
|
||||
auto old_info = m_data.m_informations;
|
||||
m_data = data;
|
||||
|
||||
if (old_info != m_data.m_informations) {
|
||||
m_data.m_informations.addValue(QStringLiteral("label"), actualLabel()); //Update the label if there is a formula
|
||||
if (diagram()) {
|
||||
diagram()->project()->dataBase()->elementInfoChanged(this);
|
||||
}
|
||||
emit elementInfoChange(old_info, m_data.m_informations);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief comparPos
|
||||
Compare position of the two elements. Compare 3 points:
|
||||
|
@ -105,6 +105,7 @@ class Element : public QetGraphicsItem
|
||||
virtual void setElementInformations(DiagramContext dc);
|
||||
|
||||
ElementData elementData() const;
|
||||
void setElementData (ElementData data);
|
||||
|
||||
/**
|
||||
* @brief kindInformations
|
||||
|
39
sources/undocommand/changeelementdatacommand.cpp
Normal file
39
sources/undocommand/changeelementdatacommand.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright 2006-2021 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "changeelementdatacommand.h"
|
||||
#include "../qetgraphicsitem/element.h"
|
||||
|
||||
ChangeElementDataCommand::ChangeElementDataCommand(Element *element, ElementData new_data) :
|
||||
m_element(element),
|
||||
m_old_data(element->elementData()),
|
||||
m_new_data(new_data)
|
||||
{
|
||||
setText(QObject::tr("Modifier les propriétés d'un élement"));
|
||||
}
|
||||
|
||||
void ChangeElementDataCommand::undo() {
|
||||
if (m_element) {
|
||||
m_element.data()->setElementData(m_old_data);
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeElementDataCommand::redo() {
|
||||
if (m_element) {
|
||||
m_element.data()->setElementData(m_new_data);
|
||||
}
|
||||
}
|
38
sources/undocommand/changeelementdatacommand.h
Normal file
38
sources/undocommand/changeelementdatacommand.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright 2006-2021 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef CHANGEELEMENTDATACOMMAND_H
|
||||
#define CHANGEELEMENTDATACOMMAND_H
|
||||
|
||||
#include <../properties/elementdata.h>
|
||||
#include <QUndoCommand>
|
||||
|
||||
class Element;
|
||||
|
||||
class ChangeElementDataCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
ChangeElementDataCommand(Element *element, ElementData new_data);
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
QPointer<Element> m_element;
|
||||
ElementData m_old_data, m_new_data;
|
||||
};
|
||||
|
||||
#endif // CHANGEELEMENTDATACOMMAND_H
|
Loading…
x
Reference in New Issue
Block a user