diff --git a/sources/TerminalStrip/terminalstrip.cpp b/sources/TerminalStrip/terminalstrip.cpp index b66daa0eb..ff0fb6262 100644 --- a/sources/TerminalStrip/terminalstrip.cpp +++ b/sources/TerminalStrip/terminalstrip.cpp @@ -74,6 +74,14 @@ void TerminalStrip::setDescription(const QString &description) { m_data.m_description = description; } +/** + * @brief TerminalStrip::project + * @return the project of this terminal strip or nullptr + */ +QETProject *TerminalStrip::project() const { + return m_project.data(); +} + /** * @brief TerminalStrip::data * @return The internal data of this strip diff --git a/sources/TerminalStrip/terminalstrip.h b/sources/TerminalStrip/terminalstrip.h index da4765a22..2934ee999 100644 --- a/sources/TerminalStrip/terminalstrip.h +++ b/sources/TerminalStrip/terminalstrip.h @@ -73,6 +73,7 @@ class TerminalStrip : public QObject void setDescription(const QString &description); QString description() const {return m_data.m_description;} QUuid uuid() const {return m_data.m_uuid;} + QETProject *project() const; TerminalStripData data() const; void setData(const TerminalStripData &data); diff --git a/sources/TerminalStrip/ui/terminalstripeditor.cpp b/sources/TerminalStrip/ui/terminalstripeditor.cpp index e40a51a87..eed16a029 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.cpp +++ b/sources/TerminalStrip/ui/terminalstripeditor.cpp @@ -17,6 +17,7 @@ */ #include "terminalstripeditor.h" #include "ui_terminalstripeditor.h" +#include "../UndoCommand/addterminaltostripcommand.h" #include "../../qetproject.h" #include "../terminalstrip.h" #include "../UndoCommand/changeterminalstripdata.h" @@ -99,6 +100,8 @@ void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_) disconnect(m_current_strip, &TerminalStrip::bridgeChanged, this, &TerminalStripEditor::reload); } + ui->m_move_to_cb->clear(); + if (!strip_) { ui->m_installation_le ->clear(); @@ -112,7 +115,7 @@ void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_) if (m_model) { m_model->deleteLater(); m_model = nullptr; - } + } } else { @@ -121,18 +124,34 @@ void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_) ui->m_name_le ->setText(strip_->name()); ui->m_comment_le ->setText(strip_->comment()); ui->m_description_te ->setPlainText(strip_->description()); + ui->m_move_to_cb->addItem(tr("Bornes indépendantes"), QUuid()); + + const auto project_{strip_->project()}; + if (project_) + { + const auto strip_vector = project_->terminalStrip(); + for (const auto &strip : strip_vector) + { + if (strip == strip_) { + continue; + } + + ui->m_move_to_cb->addItem(QString{strip->installation() + " " + strip->location() + " " + strip->name()}, + strip->uuid()); + } + } + m_current_strip = strip_; - if (m_model) - { + if (m_model) { m_model->setTerminalStrip(strip_); - connect(ui->m_table_widget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TerminalStripEditor::selectionChanged); } else { m_model = new TerminalStripModel{strip_, this}; ui->m_table_widget->setModel(m_model); m_model->buildBridgePixmap(setUpBridgeCellWidth()); + connect(ui->m_table_widget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TerminalStripEditor::selectionChanged); } spanMultiLevelTerminals(); @@ -321,6 +340,22 @@ void TerminalStripEditor::selectionChanged() ui->m_bridge_terminals_pb->setEnabled(enable_bridge); ui->m_unbridge_terminals_pb->setEnabled(enable_unbridge); ui->m_bridge_color_cb->setEnabled(enable_bridge_color); + + //Enable or not the 'move to' buttons + bool enabled_move_to{!model_physical_terminal_vector.isEmpty()}; + for (const auto &model_physical : model_physical_terminal_vector) + { + for (const auto &model_real_data : model_physical.real_data) + { + if (model_real_data.bridged_) { + enabled_move_to = false; + break; + } + } + } + ui->m_move_to_label->setEnabled(enabled_move_to); + ui->m_move_to_cb->setEnabled(enabled_move_to); + ui->m_move_to_pb->setEnabled(enabled_move_to); } QSize TerminalStripEditor::setUpBridgeCellWidth() @@ -653,3 +688,59 @@ void TerminalStripEditor::on_m_bridge_color_cb_activated(const QColor &col) } } + +void TerminalStripEditor::on_m_move_to_pb_clicked() +{ + if (!m_model || !m_current_strip || !m_current_strip->project()) { + return; + } + + //Get selected physical terminal + const auto index_vector = m_model->modelPhysicalTerminalDataForIndex(ui->m_table_widget->selectionModel()->selectedIndexes()); + QVector> phy_vector; + for (const auto &index : index_vector) + { + const auto shared_{m_current_strip->physicalTerminal(index.uuid_)}; + if (shared_) + phy_vector.append(shared_); + } + + if (phy_vector.isEmpty()) { + return; + } + + auto undo_stack{m_current_strip->project()->undoStack()}; + const auto uuid_{ui->m_move_to_cb->currentData().toUuid()}; + //Uuid is null we move the selected terminal to indepandant terminal + if (uuid_.isNull()) + { + undo_stack->beginMacro(tr("Retirer des bornes d'un bornier")); + for (const auto &phy_ : phy_vector) { + undo_stack->push(new RemoveTerminalFromStripCommand(phy_, m_current_strip)); + } + undo_stack->endMacro(); + } + else + { + TerminalStrip *receiver_strip{nullptr}; + const auto strip_vector = m_current_strip->project()->terminalStrip(); + for (const auto &strip_ : strip_vector) + { + if (strip_->uuid() == uuid_) { + receiver_strip = strip_; + break; + } + } + + if (!receiver_strip) { + return; + } + + undo_stack->beginMacro(tr("Déplacer des bornes d'un bornier à un autre")); + for (const auto &phy_ : phy_vector) { + undo_stack->push(new MoveTerminalCommand(phy_, m_current_strip, receiver_strip)); + } + undo_stack->endMacro(); + } +} + diff --git a/sources/TerminalStrip/ui/terminalstripeditor.h b/sources/TerminalStrip/ui/terminalstripeditor.h index 1a6b11c77..f7b701bd3 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.h +++ b/sources/TerminalStrip/ui/terminalstripeditor.h @@ -63,6 +63,7 @@ class TerminalStripEditor : public QWidget void on_m_bridge_terminals_pb_clicked(); void on_m_unbridge_terminals_pb_clicked(); void on_m_bridge_color_cb_activated(const QColor &col); + void on_m_move_to_pb_clicked(); private: Ui::TerminalStripEditor *ui; diff --git a/sources/TerminalStrip/ui/terminalstripeditor.ui b/sources/TerminalStrip/ui/terminalstripeditor.ui index f6fb25552..29f6854e3 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.ui +++ b/sources/TerminalStrip/ui/terminalstripeditor.ui @@ -6,8 +6,8 @@ 0 0 - 922 - 516 + 873 + 483 @@ -23,10 +23,234 @@ Disposition - + + + + + + 0 + + + + + + Sans + + + + + Avec + + + + + + + + Qt::Horizontal + + + + + + + Effectuer le déplacement + + + + + + + :/ico/16x16/dialog-ok.png:/ico/16x16/dialog-ok.png + + + + + + + + + + Étage : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Type : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Couleur pont : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + Générique + + + + + Fusible + + + + + Sectionnable + + + + + Diode + + + + + Terre + + + + + + + + LED : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Fonction : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Déplacer dans : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + Générique + + + + + Phase + + + + + Neutre + + + + + + + + QComboBox::AdjustToContents + + + + + + + 6 + + + + + + + Position automatique + + + + + + + Grouper les bornes + + + + + + + Degrouper les bornes + + + + + + + Ponter les bornes + + + + + + + Déponter les bornes + + + + + + @@ -95,174 +319,6 @@ - - - - - - - Type : - - - - - - - Fonction : - - - - - - - Ponter les bornes - - - - - - - Position automatique - - - - - - - Déponter les bornes - - - - - - - Grouper les bornes - - - - - - - Étage : - - - - - - - - - - LED : - - - - - - - - Générique - - - - - Fusible - - - - - Sectionnable - - - - - Diode - - - - - Terre - - - - - - - - - Générique - - - - - Phase - - - - - Neutre - - - - - - - - Qt::Horizontal - - - - - - - 6 - - - - - - - Degrouper les bornes - - - - - - - - Sans - - - - - Avec - - - - - - - - Couleur pont : - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - @@ -272,6 +328,8 @@
kcolorcombo.h
- + + +