mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-07-30 07:44:13 +02:00
Implement slave contact groups — label transfer, terminal assignment and UI fixes
This commit is contained in:
@@ -85,11 +85,14 @@ ElementData ElementScene::elementData() {
|
||||
void ElementScene::setElementData(ElementData data)
|
||||
{
|
||||
bool emit_ = m_element_data.m_informations != data.m_informations;
|
||||
bool type_changed = m_element_data.m_type != data.m_type;
|
||||
|
||||
m_element_data = data;
|
||||
|
||||
if (emit_)
|
||||
emit elementInfoChanged();
|
||||
if (type_changed)
|
||||
emit elementTypeChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -177,6 +177,8 @@ class ElementScene : public QGraphicsScene
|
||||
/// Signal emitted when need zoomFit
|
||||
void needZoomFit();
|
||||
void elementInfoChanged();
|
||||
/// Signal emitted when the element type changes
|
||||
void elementTypeChanged();
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
|
||||
|
||||
@@ -460,6 +460,22 @@ void PartTerminal::setLabelColor(QColor color)
|
||||
emit labelColorChanged();
|
||||
}
|
||||
|
||||
void PartTerminal::setUseMasterLabel(bool use)
|
||||
{
|
||||
if (d->m_use_master_label == use) return;
|
||||
d->m_use_master_label = use;
|
||||
update();
|
||||
emit useMasterLabelChanged();
|
||||
}
|
||||
|
||||
void PartTerminal::setMasterLabelIndex(int index)
|
||||
{
|
||||
if (d->m_master_label_index == index) return;
|
||||
d->m_master_label_index = index;
|
||||
update();
|
||||
emit masterLabelIndexChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
Updates the position of the second point according to the position
|
||||
and orientation of the terminal.
|
||||
|
||||
@@ -42,6 +42,8 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
Q_PROPERTY(Qt::Alignment label_valignment READ labelVAlignment WRITE setLabelVAlignment)
|
||||
Q_PROPERTY(bool label_frame READ labelFrame WRITE setLabelFrame)
|
||||
Q_PROPERTY(QColor label_color READ labelColor WRITE setLabelColor)
|
||||
Q_PROPERTY(bool use_master_label READ useMasterLabel WRITE setUseMasterLabel)
|
||||
Q_PROPERTY(int master_label_index READ masterLabelIndex WRITE setMasterLabelIndex)
|
||||
|
||||
public:
|
||||
// constructors, destructor
|
||||
@@ -62,6 +64,8 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
void labelVAlignmentChanged();
|
||||
void labelFrameChanged();
|
||||
void labelColorChanged();
|
||||
void useMasterLabelChanged();
|
||||
void masterLabelIndexChanged();
|
||||
|
||||
// methods
|
||||
public:
|
||||
@@ -130,6 +134,12 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
QColor labelColor() const { return d->m_label_color; }
|
||||
void setLabelColor(QColor color);
|
||||
|
||||
bool useMasterLabel() const { return d->m_use_master_label; }
|
||||
void setUseMasterLabel(bool use);
|
||||
|
||||
int masterLabelIndex() const { return d->m_master_label_index; }
|
||||
void setMasterLabelIndex(int index);
|
||||
|
||||
void setNewUuid();
|
||||
|
||||
QRectF labelRect() const;
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
#include "../../qetinformation.h"
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <QComboBox>
|
||||
#include <QSpinBox>
|
||||
#include <QSignalBlocker>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QHeaderView>
|
||||
|
||||
/**
|
||||
@brief The EditorDelegate class
|
||||
@@ -108,6 +113,13 @@ void ElementPropertiesEditorWidget::upDateInterface()
|
||||
ui->max_slaves_spinbox->setEnabled(true);
|
||||
ui->max_slaves_spinbox->setValue(m_data.m_max_slaves);
|
||||
}
|
||||
|
||||
// Slave contact groups checkbox
|
||||
ui->m_slave_groups_checkbox->setChecked(m_data.m_slave_contact_groups_enabled);
|
||||
ui->m_slave_groups_table->setEnabled(m_data.m_slave_contact_groups_enabled);
|
||||
if (m_data.m_slave_contact_groups_enabled) {
|
||||
populateSlaveGroupsTable();
|
||||
}
|
||||
} else if (m_data.m_type == ElementData::Terminal) {
|
||||
ui->m_terminal_type_cb->setCurrentIndex(
|
||||
ui->m_terminal_type_cb->findData(
|
||||
@@ -168,6 +180,11 @@ void ElementPropertiesEditorWidget::setUpInterface()
|
||||
|
||||
// NEU: Checkbox mit der Zahlenbox verbinden (Aktivieren/Deaktivieren)
|
||||
connect(ui->max_slaves_checkbox, SIGNAL(toggled(bool)), ui->max_slaves_spinbox, SLOT(setEnabled(bool)));
|
||||
connect(ui->max_slaves_spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this](int) {
|
||||
if (ui->m_slave_groups_checkbox->isChecked()) {
|
||||
populateSlaveGroupsTable();
|
||||
}
|
||||
});
|
||||
|
||||
populateTree();
|
||||
}
|
||||
@@ -241,7 +258,7 @@ void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
|
||||
m_data.m_slave_type = ui->m_type_cb->currentData().value<ElementData::SlaveType>();
|
||||
m_data.m_contact_count = ui->m_number_ctc->value();
|
||||
}
|
||||
else if (m_data.m_type == ElementData::Master) {
|
||||
else if (m_data.m_type == ElementData::Master) {
|
||||
m_data.m_master_type = ui->m_master_type_cb->currentData().value<ElementData::MasterType>();
|
||||
|
||||
//If the checkbox is checked, save the number; otherwise, -1 (infinity)
|
||||
@@ -250,6 +267,8 @@ void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
|
||||
} else {
|
||||
m_data.m_max_slaves = -1;
|
||||
}
|
||||
|
||||
readSlaveGroupsFromTable();
|
||||
}
|
||||
else if (m_data.m_type == ElementData::Terminal)
|
||||
{
|
||||
@@ -299,3 +318,217 @@ void ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged(int in
|
||||
|
||||
updateTree();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementPropertiesEditorWidget::on_max_slaves_checkbox_toggled
|
||||
* When max_slaves checkbox is unchecked, also uncheck slave groups checkbox
|
||||
*/
|
||||
void ElementPropertiesEditorWidget::on_max_slaves_checkbox_toggled(bool checked)
|
||||
{
|
||||
if (!checked && ui->m_slave_groups_checkbox->isChecked()) {
|
||||
ui->m_slave_groups_checkbox->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementPropertiesEditorWidget::on_m_slave_groups_checkbox_toggled
|
||||
* When slave groups checkbox is toggled, enable/disable the table
|
||||
* Also ensure max_slaves checkbox is checked when enabling groups
|
||||
*/
|
||||
void ElementPropertiesEditorWidget::on_m_slave_groups_checkbox_toggled(bool checked)
|
||||
{
|
||||
ui->m_slave_groups_table->setEnabled(checked);
|
||||
|
||||
if (checked && !ui->max_slaves_checkbox->isChecked()) {
|
||||
ui->max_slaves_checkbox->setChecked(true);
|
||||
}
|
||||
|
||||
if (checked) {
|
||||
populateSlaveGroupsTable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementPropertiesEditorWidget::populateSlaveGroupsTable
|
||||
* Fill the slave contact groups table from m_data
|
||||
*/
|
||||
void ElementPropertiesEditorWidget::populateSlaveGroupsTable()
|
||||
{
|
||||
QSignalBlocker blocker_table(ui->m_slave_groups_table);
|
||||
QSignalBlocker blocker_spinbox(ui->max_slaves_spinbox);
|
||||
ui->m_slave_groups_table->setRowCount(0);
|
||||
|
||||
int row_count = ui->max_slaves_checkbox->isChecked()
|
||||
? ui->max_slaves_spinbox->value() : 0;
|
||||
|
||||
// If we have existing groups, use their count (up to max_slaves)
|
||||
int existing_groups = m_data.m_slave_contact_groups.size();
|
||||
|
||||
// Adjust the groups list to match the spinbox value
|
||||
while (m_data.m_slave_contact_groups.size() < row_count) {
|
||||
ElementData::SlaveContactGroup group;
|
||||
group.type = ElementData::NO;
|
||||
group.subtype = ElementData::SSimple;
|
||||
group.contactCount = 1;
|
||||
group.terminalCount = 2;
|
||||
m_data.m_slave_contact_groups.append(group);
|
||||
}
|
||||
while (m_data.m_slave_contact_groups.size() > row_count) {
|
||||
m_data.m_slave_contact_groups.removeLast();
|
||||
}
|
||||
|
||||
// Find max terminal count across all groups to determine T columns
|
||||
int max_tc = 0;
|
||||
for (const auto &g : m_data.m_slave_contact_groups) {
|
||||
max_tc = qMax(max_tc, g.terminalCount);
|
||||
}
|
||||
max_tc = qMax(max_tc, 2); // at least T1, T2
|
||||
|
||||
// Set up 4 fixed columns + max_tc label columns
|
||||
int total_cols = 4 + max_tc;
|
||||
ui->m_slave_groups_table->setColumnCount(total_cols);
|
||||
|
||||
// Set T column headers
|
||||
for (int t = 0; t < max_tc; ++t) {
|
||||
ui->m_slave_groups_table->setHorizontalHeaderItem(
|
||||
4 + t, new QTableWidgetItem(tr("T%1").arg(t + 1)));
|
||||
}
|
||||
|
||||
// Set column widths for readability
|
||||
ui->m_slave_groups_table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
ui->m_slave_groups_table->horizontalHeader()->setMinimumSectionSize(60);
|
||||
ui->m_slave_groups_table->setColumnWidth(0, 180); // Type
|
||||
ui->m_slave_groups_table->setColumnWidth(1, 180); // Subtype
|
||||
ui->m_slave_groups_table->setColumnWidth(2, 80); // Contacts
|
||||
ui->m_slave_groups_table->setColumnWidth(3, 80); // Bornes
|
||||
|
||||
ui->m_slave_groups_table->setRowCount(m_data.m_slave_contact_groups.size());
|
||||
|
||||
for (int i = 0; i < m_data.m_slave_contact_groups.size(); ++i) {
|
||||
auto &group = m_data.m_slave_contact_groups[i];
|
||||
|
||||
// Type column
|
||||
auto *type_cb = new QComboBox(ui->m_slave_groups_table);
|
||||
type_cb->addItem(tr("Normalement ouvert"), ElementData::NO);
|
||||
type_cb->addItem(tr("Normalement fermé"), ElementData::NC);
|
||||
type_cb->addItem(tr("Inverseur"), ElementData::SW);
|
||||
type_cb->addItem(tr("Autre"), ElementData::Other);
|
||||
type_cb->setCurrentIndex(type_cb->findData(group.type));
|
||||
ui->m_slave_groups_table->setCellWidget(i, 0, type_cb);
|
||||
|
||||
// Subtype column
|
||||
auto *subtype_cb = new QComboBox(ui->m_slave_groups_table);
|
||||
subtype_cb->addItem(tr("Simple"), ElementData::SSimple);
|
||||
subtype_cb->addItem(tr("Puissance"), ElementData::Power);
|
||||
subtype_cb->addItem(tr("Temporisé travail"), ElementData::DelayOn);
|
||||
subtype_cb->addItem(tr("Temporisé repos"), ElementData::DelayOff);
|
||||
subtype_cb->addItem(tr("Temporisé travail & repos"), ElementData::delayOnOff);
|
||||
subtype_cb->setCurrentIndex(subtype_cb->findData(group.subtype));
|
||||
ui->m_slave_groups_table->setCellWidget(i, 1, subtype_cb);
|
||||
|
||||
// Contact count
|
||||
auto *contact_ct = new QSpinBox(ui->m_slave_groups_table);
|
||||
contact_ct->setMinimum(1);
|
||||
contact_ct->setMaximum(20);
|
||||
contact_ct->setValue(group.contactCount);
|
||||
ui->m_slave_groups_table->setCellWidget(i, 2, contact_ct);
|
||||
|
||||
// Terminal count
|
||||
auto *terminal_ct = new QSpinBox(ui->m_slave_groups_table);
|
||||
terminal_ct->setMinimum(1);
|
||||
terminal_ct->setMaximum(20);
|
||||
terminal_ct->setValue(group.terminalCount);
|
||||
ui->m_slave_groups_table->setCellWidget(i, 3, terminal_ct);
|
||||
|
||||
// When terminal count changes, rebuild the table to update T columns
|
||||
connect(terminal_ct, QOverload<int>::of(&QSpinBox::valueChanged),
|
||||
this, [this, terminal_ct, i](int val) {
|
||||
if (i < m_data.m_slave_contact_groups.size()) {
|
||||
m_data.m_slave_contact_groups[i].terminalCount = val;
|
||||
readSlaveGroupsFromTable();
|
||||
populateSlaveGroupsTable();
|
||||
}
|
||||
});
|
||||
|
||||
// Auto-generate labels if empty
|
||||
QStringList labels = group.labels;
|
||||
while (labels.size() < group.terminalCount) {
|
||||
labels << tr("T%1").arg(labels.size() + 1);
|
||||
}
|
||||
|
||||
// Fill T1..TN columns
|
||||
for (int t = 0; t < max_tc; ++t) {
|
||||
auto *item = new QTableWidgetItem(
|
||||
t < labels.size() ? labels.at(t) : QString());
|
||||
if (t >= group.terminalCount) {
|
||||
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
||||
item->setBackground(QBrush(QColor(240, 240, 240)));
|
||||
}
|
||||
ui->m_slave_groups_table->setItem(i, 4 + t, item);
|
||||
}
|
||||
|
||||
// Store updated labels back
|
||||
group.labels = labels;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementPropertiesEditorWidget::readSlaveGroupsFromTable
|
||||
* Read the slave contact groups from the table back into m_data
|
||||
*/
|
||||
void ElementPropertiesEditorWidget::readSlaveGroupsFromTable()
|
||||
{
|
||||
m_data.m_slave_contact_groups.clear();
|
||||
|
||||
if (!ui->m_slave_groups_checkbox->isChecked()) {
|
||||
m_data.m_slave_contact_groups_enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
m_data.m_slave_contact_groups_enabled = true;
|
||||
|
||||
for (int i = 0; i < ui->m_slave_groups_table->rowCount(); ++i) {
|
||||
ElementData::SlaveContactGroup group;
|
||||
|
||||
auto *type_cb = qobject_cast<QComboBox *>(
|
||||
ui->m_slave_groups_table->cellWidget(i, 0));
|
||||
if (type_cb) {
|
||||
group.type = type_cb->currentData().value<ElementData::SlaveState>();
|
||||
}
|
||||
|
||||
auto *subtype_cb = qobject_cast<QComboBox *>(
|
||||
ui->m_slave_groups_table->cellWidget(i, 1));
|
||||
if (subtype_cb) {
|
||||
group.subtype = subtype_cb->currentData().value<ElementData::SlaveType>();
|
||||
}
|
||||
|
||||
auto *contact_ct = qobject_cast<QSpinBox *>(
|
||||
ui->m_slave_groups_table->cellWidget(i, 2));
|
||||
if (contact_ct) {
|
||||
group.contactCount = contact_ct->value();
|
||||
}
|
||||
|
||||
auto *terminal_ct = qobject_cast<QSpinBox *>(
|
||||
ui->m_slave_groups_table->cellWidget(i, 3));
|
||||
if (terminal_ct) {
|
||||
group.terminalCount = terminal_ct->value();
|
||||
}
|
||||
|
||||
// Read labels from T1..TN columns
|
||||
for (int t = 0; t < group.terminalCount; ++t) {
|
||||
int col = 4 + t;
|
||||
if (col < ui->m_slave_groups_table->columnCount()) {
|
||||
auto *item = ui->m_slave_groups_table->item(i, col);
|
||||
if (item && !item->text().isEmpty()) {
|
||||
group.labels.append(item->text());
|
||||
} else {
|
||||
group.labels << tr("T%1").arg(t + 1);
|
||||
}
|
||||
} else {
|
||||
group.labels << tr("T%1").arg(t + 1);
|
||||
}
|
||||
}
|
||||
|
||||
m_data.m_slave_contact_groups.append(group);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,11 +49,15 @@ class ElementPropertiesEditorWidget : public QDialog
|
||||
void setUpInterface();
|
||||
void updateTree();
|
||||
void populateTree();
|
||||
void populateSlaveGroupsTable();
|
||||
void readSlaveGroupsFromTable();
|
||||
|
||||
//SLOTS
|
||||
private slots:
|
||||
void on_m_buttonBox_accepted();
|
||||
void on_m_base_type_cb_currentIndexChanged(int index);
|
||||
void on_m_slave_groups_checkbox_toggled(bool checked);
|
||||
void on_max_slaves_checkbox_toggled(bool checked);
|
||||
|
||||
//ATTRIBUTES
|
||||
private:
|
||||
|
||||
@@ -121,6 +121,55 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="m_slave_groups_checkbox">
|
||||
<property name="text">
|
||||
<string>Définir les éléments esclave</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QTableWidget" name="m_slave_groups_table">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>150</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Contact</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Nb. contacts</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Nb. bornes</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -1192,6 +1192,12 @@ void QETElementEditor::initGui()
|
||||
updateInformations();
|
||||
fillPartsList();
|
||||
|
||||
// When the element type changes, update the terminal editor master label visibility
|
||||
connect(m_elmt_scene, &ElementScene::elementTypeChanged, this, [this]() {
|
||||
auto *te = static_cast<TerminalEditor *>(m_editors["terminal"]);
|
||||
if (te) te->refreshMasterLabelVisibility();
|
||||
});
|
||||
|
||||
statusBar()->showMessage(tr("Éditeur d'éléments", "status bar message"));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QFontDialog>
|
||||
#include "../elementscene.h"
|
||||
#include "qetelementeditor.h"
|
||||
|
||||
/**
|
||||
* @brief TerminalEditor::TerminalEditor
|
||||
@@ -101,6 +103,26 @@ void TerminalEditor::updateForm()
|
||||
|
||||
ui->m_text_props_gb->setEnabled(m_part->showName());
|
||||
|
||||
// Update master label fields
|
||||
bool is_slave = updateMasterLabelVisibility();
|
||||
if (is_slave) {
|
||||
PartTerminal *pt = m_part;
|
||||
if (pt) {
|
||||
ui->m_use_master_label_cb->setChecked(pt->useMasterLabel());
|
||||
ui->m_master_label_cb->setEnabled(pt->useMasterLabel());
|
||||
ui->m_name_le->setEnabled(!pt->useMasterLabel());
|
||||
int idx = ui->m_master_label_cb->findData(pt->masterLabelIndex());
|
||||
if (idx >= 0) {
|
||||
ui->m_master_label_cb->setCurrentIndex(idx);
|
||||
}
|
||||
// Show T-label in name field when master label is active
|
||||
if (pt->useMasterLabel()) {
|
||||
int label_idx = pt->masterLabelIndex();
|
||||
ui->m_name_le->setText(tr("T%1").arg(label_idx + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activeConnections(true);
|
||||
}
|
||||
|
||||
@@ -165,6 +187,14 @@ void TerminalEditor::init()
|
||||
ui->m_type_cb->addItem(tr("Commun (contact SW)"), TerminalData::Common);
|
||||
|
||||
ui->m_text_props_gb->setEnabled(false);
|
||||
|
||||
// Populate master label dropdown (T1-T20)
|
||||
for (int i = 1; i <= 20; ++i) {
|
||||
ui->m_master_label_cb->addItem(tr("T%1").arg(i), i - 1);
|
||||
}
|
||||
|
||||
// Check if parent element is a Slave to show/hide master label group
|
||||
updateMasterLabelVisibility();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -427,6 +457,10 @@ void TerminalEditor::activeConnections(bool active)
|
||||
this, &TerminalEditor::labelAlignClicked);
|
||||
m_editor_connections << connect(ui->m_label_frame_cb, &QCheckBox::toggled,
|
||||
this, &TerminalEditor::labelFrameEdited);
|
||||
m_editor_connections << connect(ui->m_use_master_label_cb, &QCheckBox::toggled,
|
||||
this, &TerminalEditor::useMasterLabelEdited);
|
||||
m_editor_connections << connect(ui->m_master_label_cb, QOverload<int>::of(&QComboBox::activated),
|
||||
this, &TerminalEditor::masterLabelIndexEdited);
|
||||
} else {
|
||||
for (auto const & con : qAsConst(m_editor_connections)) {
|
||||
QObject::disconnect(con);
|
||||
@@ -452,6 +486,8 @@ void TerminalEditor::activeChangeConnections(bool active)
|
||||
m_change_connections << connect(m_part, &PartTerminal::labelVAlignmentChanged, this, &TerminalEditor::updateForm);
|
||||
m_change_connections << connect(m_part, &PartTerminal::labelFrameChanged, this, &TerminalEditor::updateForm);
|
||||
m_change_connections << connect(m_part, &PartTerminal::labelColorChanged, this, &TerminalEditor::updateForm);
|
||||
m_change_connections << connect(m_part, &PartTerminal::useMasterLabelChanged, this, &TerminalEditor::updateForm);
|
||||
m_change_connections << connect(m_part, &PartTerminal::masterLabelIndexChanged, this, &TerminalEditor::updateForm);
|
||||
} else {
|
||||
for (auto &con : m_change_connections) {
|
||||
QObject::disconnect(con);
|
||||
@@ -459,3 +495,95 @@ void TerminalEditor::activeChangeConnections(bool active)
|
||||
m_change_connections.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void TerminalEditor::useMasterLabelEdited()
|
||||
{
|
||||
if (m_locked) return;
|
||||
m_locked = true;
|
||||
|
||||
bool use = ui->m_use_master_label_cb->isChecked();
|
||||
ui->m_master_label_cb->setEnabled(use);
|
||||
|
||||
QSignalBlocker name_blocker(ui->m_name_le);
|
||||
|
||||
if (m_part->useMasterLabel() != use) {
|
||||
auto undo = new QPropertyUndoCommand(m_part, "use_master_label",
|
||||
m_part->useMasterLabel(), use);
|
||||
undo->setText(tr("Modifier l'étiquette du maître"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
if (use) {
|
||||
int idx = ui->m_master_label_cb->currentData().toInt();
|
||||
QString t_label = tr("T%1").arg(idx + 1);
|
||||
ui->m_name_le->setText(t_label);
|
||||
ui->m_name_le->setEnabled(false);
|
||||
if (m_part->terminalName() != t_label) {
|
||||
auto undo = new QPropertyUndoCommand(m_part, "terminal_name",
|
||||
m_part->terminalName(), t_label);
|
||||
undo->setText(tr("Modifier le nom de la borne"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
} else {
|
||||
ui->m_name_le->setEnabled(true);
|
||||
if (!m_part->terminalName().isEmpty()) {
|
||||
auto undo = new QPropertyUndoCommand(m_part, "terminal_name",
|
||||
m_part->terminalName(), QString());
|
||||
undo->setText(tr("Modifier le nom de la borne"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
ui->m_name_le->clear();
|
||||
}
|
||||
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
void TerminalEditor::masterLabelIndexEdited()
|
||||
{
|
||||
if (m_locked) return;
|
||||
m_locked = true;
|
||||
|
||||
int idx = ui->m_master_label_cb->currentData().toInt();
|
||||
|
||||
if (m_part->masterLabelIndex() != idx) {
|
||||
auto undo = new QPropertyUndoCommand(m_part, "master_label_index",
|
||||
m_part->masterLabelIndex(), idx);
|
||||
undo->setText(tr("Modifier l'index de l'étiquette du maître"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
if (ui->m_use_master_label_cb->isChecked()) {
|
||||
QString t_label = tr("T%1").arg(idx + 1);
|
||||
ui->m_name_le->setText(t_label);
|
||||
if (m_part->terminalName() != t_label) {
|
||||
auto undo = new QPropertyUndoCommand(m_part, "terminal_name",
|
||||
m_part->terminalName(), t_label);
|
||||
undo->setText(tr("Modifier le nom de la borne"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
bool TerminalEditor::updateMasterLabelVisibility()
|
||||
{
|
||||
QETElementEditor *editor = elementEditor();
|
||||
if (!editor || !editor->elementScene()) {
|
||||
ui->m_master_label_gb->setVisible(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
ElementData data = editor->elementScene()->elementData();
|
||||
bool is_slave = (data.m_type == ElementData::Slave);
|
||||
ui->m_master_label_gb->setVisible(is_slave);
|
||||
return is_slave;
|
||||
}
|
||||
|
||||
void TerminalEditor::refreshMasterLabelVisibility()
|
||||
{
|
||||
updateMasterLabelVisibility();
|
||||
if (m_part) {
|
||||
updateForm();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ class TerminalEditor : public ElementItemEditor
|
||||
bool setPart(CustomElementPart *new_part) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart *> currentParts() const override {return QList<CustomElementPart *>();}
|
||||
public slots:
|
||||
void refreshMasterLabelVisibility();
|
||||
|
||||
private:
|
||||
void init();
|
||||
@@ -62,10 +64,13 @@ class TerminalEditor : public ElementItemEditor
|
||||
void labelSizeEdited();
|
||||
void labelRotationEdited();
|
||||
void labelAlignClicked();
|
||||
void labelFrameEdited();
|
||||
void labelColorClicked();
|
||||
void activeConnections(bool active);
|
||||
void activeChangeConnections(bool active);
|
||||
void labelFrameEdited();
|
||||
void labelColorClicked();
|
||||
void activeConnections(bool active);
|
||||
void activeChangeConnections(bool active);
|
||||
void useMasterLabelEdited();
|
||||
void masterLabelIndexEdited();
|
||||
bool updateMasterLabelVisibility();
|
||||
|
||||
private:
|
||||
Ui::TerminalEditor *ui;
|
||||
|
||||
@@ -214,6 +214,32 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="m_master_label_gb">
|
||||
<property name="title">
|
||||
<string>Étiquette du maître</string>
|
||||
</property>
|
||||
<property name="visible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="m_use_master_label_cb">
|
||||
<property name="text">
|
||||
<string>Reprendre du maître</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="m_master_label_cb">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
Reference in New Issue
Block a user