diff --git a/sources/TerminalStrip/UndoCommand/changeterminallevel.cpp b/sources/TerminalStrip/UndoCommand/changeterminallevel.cpp
new file mode 100644
index 000000000..42c5dceba
--- /dev/null
+++ b/sources/TerminalStrip/UndoCommand/changeterminallevel.cpp
@@ -0,0 +1,43 @@
+/*
+ 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 .
+*/
+#include "changeterminallevel.h"
+
+ChangeTerminalLevel::ChangeTerminalLevel(TerminalStrip *strip,
+ const RealTerminalData &real_terminal,
+ int level,
+ QUndoCommand *parent) :
+ QUndoCommand(parent),
+ m_strip(strip),
+ m_real_terminal(real_terminal),
+ m_new_level(level),
+ m_old_level(real_terminal.level_)
+{}
+
+void ChangeTerminalLevel::undo()
+{
+ if (m_strip) {
+ m_strip->setLevel(m_real_terminal, m_old_level);
+ }
+}
+
+void ChangeTerminalLevel::redo()
+{
+ if (m_strip) {
+ m_strip->setLevel(m_real_terminal, m_new_level);
+ }
+}
diff --git a/sources/TerminalStrip/UndoCommand/changeterminallevel.h b/sources/TerminalStrip/UndoCommand/changeterminallevel.h
new file mode 100644
index 000000000..39b9a3c1a
--- /dev/null
+++ b/sources/TerminalStrip/UndoCommand/changeterminallevel.h
@@ -0,0 +1,42 @@
+/*
+ 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 .
+*/
+#ifndef CHANGETERMINALLEVEL_H
+#define CHANGETERMINALLEVEL_H
+
+#include
+#include
+#include "../terminalstrip.h"
+
+class ChangeTerminalLevel : public QUndoCommand
+{
+ public:
+ ChangeTerminalLevel(TerminalStrip *strip,
+ const RealTerminalData &real_terminal,
+ int level,
+ QUndoCommand *parent = nullptr);
+
+ void undo() override;
+ void redo() override;
+
+ private:
+ QPointer m_strip;
+ RealTerminalData m_real_terminal;
+ int m_new_level, m_old_level;
+};
+
+#endif // CHANGETERMINALLEVEL_H
diff --git a/sources/TerminalStrip/terminalstrip.cpp b/sources/TerminalStrip/terminalstrip.cpp
index d202f2d51..d6ec3a17c 100644
--- a/sources/TerminalStrip/terminalstrip.cpp
+++ b/sources/TerminalStrip/terminalstrip.cpp
@@ -289,6 +289,23 @@ class PhysicalTerminal
return m_real_terminal.indexOf(terminal);
}
+ /**
+ * @brief setLevelOf
+ * Change the level of \p terminal
+ * @param terminal
+ * @param level
+ */
+ bool setLevelOf(shared_real_terminal terminal, int level)
+ {
+ const int i = m_real_terminal.indexOf(terminal);
+ if (i >= 0)
+ {
+ m_real_terminal.swapItemsAt(i, std::min(level, m_real_terminal.size()-1));
+ return true;
+ }
+ return false;
+ }
+
/**
* @brief terminals
* @return A vector of real terminal who compose this physical terminal
@@ -570,14 +587,14 @@ QVector TerminalStrip::physicalTerminalData() const
* @param sorted_vector
* @return true is successfully sorted.
*/
-bool TerminalStrip::setOrderTo(QVector sorted_vector)
+bool TerminalStrip::setOrderTo(const QVector &sorted_vector)
{
if (sorted_vector.size() != m_physical_terminals.size()) {
return false;
}
QVector> new_order;
- for (auto ptd : sorted_vector)
+ for (const auto &ptd : sorted_vector)
{
const auto physical_t = physicalTerminalForUuid(ptd.uuid_);
if (physical_t.isNull()) {
@@ -677,6 +694,32 @@ void TerminalStrip::unGroupTerminals(const QVector &terminals_
}
}
+/**
+ * @brief TerminalStrip::setLevel
+ * @param real_terminal_data
+ * @param level
+ * @return
+ */
+bool TerminalStrip::setLevel(const RealTerminalData &real_terminal_data, int level)
+{
+ auto real_terminal = realTerminalForUuid(real_terminal_data.real_terminal_uuid);
+ if (real_terminal)
+ {
+ auto physical_terminal = physicalTerminal(real_terminal);
+ if (physical_terminal)
+ {
+ if (physical_terminal->terminals().size() > 1 &&
+ physical_terminal->setLevelOf(real_terminal, level))
+ {
+ emit orderChanged();
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
/**
* @brief TerminalStrip::terminalElement
* @return A vector of all terminal element owned by this strip
diff --git a/sources/TerminalStrip/terminalstrip.h b/sources/TerminalStrip/terminalstrip.h
index b2f165a58..dd24cd5cb 100644
--- a/sources/TerminalStrip/terminalstrip.h
+++ b/sources/TerminalStrip/terminalstrip.h
@@ -117,9 +117,10 @@ class TerminalStrip : public QObject
PhysicalTerminalData physicalTerminalData(int index) const;
PhysicalTerminalData physicalTerminalData (const RealTerminalData &real_data) const;
QVector physicalTerminalData() const;
- bool setOrderTo(QVector sorted_vector);
+ bool setOrderTo(const QVector &sorted_vector);
bool groupTerminals(const PhysicalTerminalData &receiver_terminal, const QVector &added_terminals);
void unGroupTerminals(const QVector &terminals_to_ungroup);
+ bool setLevel(const RealTerminalData &real_terminal_data, int level);
QVector> terminalElement() const;
diff --git a/sources/TerminalStrip/ui/terminalstripeditor.cpp b/sources/TerminalStrip/ui/terminalstripeditor.cpp
index 3b70c3262..b878d1340 100644
--- a/sources/TerminalStrip/ui/terminalstripeditor.cpp
+++ b/sources/TerminalStrip/ui/terminalstripeditor.cpp
@@ -32,6 +32,7 @@
#include "../diagram.h"
#include "../UndoCommand/sortterminalstripcommand.h"
#include "../UndoCommand/groupterminalscommand.h"
+#include "../UndoCommand/changeterminallevel.h"
#include
@@ -352,10 +353,12 @@ void TerminalStripEditor::selectionChanged()
const auto index_list = ui->m_table_widget->selectionModel()->selectedIndexes();
const auto terminal_vector = m_model->physicalTerminalDataForIndex(index_list);
+ const auto real_terminal_vector = m_model->realTerminalDataForIndex(index_list);
+ //Enable/disable group button
ui->m_group_terminals_pb->setEnabled(terminal_vector.size() > 1 ? true : false);
-
+ //Enable/disable ungroup button
auto it_= std::find_if(terminal_vector.constBegin(), terminal_vector.constEnd(), [](auto &data)
{
if (data.real_terminals_vector.size() >= 2) {
@@ -500,17 +503,22 @@ void TerminalStripEditor::on_m_dialog_button_box_clicked(QAbstractButton *button
if (m_model)
{
- for (auto modified_data : m_model->modifiedRealTerminalData())
+ for (const auto &data_ : m_model->modifiedRealTerminalData())
{
- auto element = modified_data.element_;
+ auto original_ = data_.first;
+ auto edited_ = data_.second;
+ auto element = original_.element_;
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_);
+ current_data.setTerminalType(edited_.type_);
+ current_data.setTerminalFunction(edited_.function_);
+ current_data.setTerminalLED(edited_.led_);
+ current_data.m_informations.addValue(QStringLiteral("label"), edited_.label_);
- m_project->undoStack()->push(new ChangeElementDataCommand(element, current_data));
+ if (element->elementData() != current_data)
+ m_project->undoStack()->push(new ChangeElementDataCommand(element, current_data));
+ if (edited_.level_)
+ m_project->undoStack()->push(new ChangeTerminalLevel(m_current_strip, original_, edited_.level_));
}
}
}
@@ -560,3 +568,24 @@ void TerminalStripEditor::on_m_ungroup_pb_clicked()
}
}
+/**
+ * @brief TerminalStripEditor::on_m_level_sb_valueChanged
+ * @param arg1
+ */
+void TerminalStripEditor::on_m_level_sb_valueChanged(int arg1)
+{
+ if (m_model)
+ {
+ const auto index_list = ui->m_table_widget->selectionModel()->selectedIndexes();
+
+ for (auto index : index_list)
+ {
+ auto level_index = m_model->index(index.row(), 1, index.parent());
+ if (level_index.isValid())
+ {
+ m_model->setData(level_index, arg1);
+ }
+ }
+ }
+}
+
diff --git a/sources/TerminalStrip/ui/terminalstripeditor.h b/sources/TerminalStrip/ui/terminalstripeditor.h
index cde20120b..8115b470e 100644
--- a/sources/TerminalStrip/ui/terminalstripeditor.h
+++ b/sources/TerminalStrip/ui/terminalstripeditor.h
@@ -62,6 +62,7 @@ class TerminalStripEditor : public QDialog
void on_m_auto_ordering_pb_clicked();
void on_m_group_terminals_pb_clicked();
void on_m_ungroup_pb_clicked();
+ void on_m_level_sb_valueChanged(int arg1);
private:
Ui::TerminalStripEditor *ui;
diff --git a/sources/TerminalStrip/ui/terminalstripeditor.ui b/sources/TerminalStrip/ui/terminalstripeditor.ui
index 912f3d271..e9cd723ba 100644
--- a/sources/TerminalStrip/ui/terminalstripeditor.ui
+++ b/sources/TerminalStrip/ui/terminalstripeditor.ui
@@ -6,8 +6,8 @@
0
0
- 1260
- 579
+ 1289
+ 645
@@ -179,6 +179,13 @@
-
+
+
+ Étage :
+
+
+
+ -
Qt::Vertical
@@ -191,24 +198,27 @@
- -
-
+
-
+
+
+ -
+
- Position automatique
+ Degrouper les bornes
- -
+
-
Grouper les bornes
- -
-
+
-
+
- Degrouper les bornes
+ Position automatique
@@ -289,13 +299,21 @@
+ m_add_terminal_strip_pb
+ m_remove_terminal_strip_pb
+ m_reload_pb
+ m_auto_ordering_pb
+ m_group_terminals_pb
+ m_ungroup_pb
+ m_level_sb
+ m_terminal_strip_tw
+ m_table_widget
+ m_description_te
+ m_comment_le
+ m_name_le
m_tab_widget
m_installation_le
m_location_le
- m_name_le
- m_comment_le
- m_description_te
- m_table_widget
diff --git a/sources/TerminalStrip/ui/terminalstripmodel.cpp b/sources/TerminalStrip/ui/terminalstripmodel.cpp
index 9d318fa41..c089dce64 100644
--- a/sources/TerminalStrip/ui/terminalstripmodel.cpp
+++ b/sources/TerminalStrip/ui/terminalstripmodel.cpp
@@ -52,7 +52,7 @@ TerminalStripModel::TerminalStripModel(TerminalStrip *terminal_strip, QObject *p
QAbstractTableModel(parent),
m_terminal_strip(terminal_strip)
{
- fillRealTerminalData();
+ fillPhysicalTerminalData();
}
int TerminalStripModel::rowCount(const QModelIndex &parent) const
@@ -64,7 +64,7 @@ int TerminalStripModel::rowCount(const QModelIndex &parent) const
}
auto count = 0;
- for (const auto &ptd : m_physical_terminal_data) {
+ for (const auto &ptd : m_edited_terminal_data) {
count += ptd.real_terminals_vector.size();
}
@@ -133,7 +133,14 @@ bool TerminalStripModel::setData(const QModelIndex &index, const QVariant &value
int modified_cell = -1;
auto column_ = index.column();
- if (column_ == LED_CELL &&
+ if (column_ == LEVEL_CELL &&
+ role == Qt::EditRole)
+ {
+ rtd.level_ = value.toInt();
+ modified_ = true;
+ modified_cell = LEVEL_CELL;
+ }
+ else if (column_ == LED_CELL &&
role == Qt::CheckStateRole)
{
rtd.led_ = value.toBool();
@@ -180,6 +187,7 @@ bool TerminalStripModel::setData(const QModelIndex &index, const QVariant &value
vector_.replace(modified_cell, true);
m_modified_cell.insert(rtd.element_, vector_);
}
+ emit dataChanged(index, index);
return true;
}
@@ -226,18 +234,25 @@ Qt::ItemFlags TerminalStripModel::flags(const QModelIndex &index) const
/**
* @brief TerminalStripModel::modifiedRealTerminalData
- * @return the modified real terminal data
+ * @return a vector of QPair of modified terminal.
+ * the first value of the QPair is the original data, the second value is the edited data
*/
-QVector TerminalStripModel::modifiedRealTerminalData() const
+QVector> TerminalStripModel::modifiedRealTerminalData() const
{
- QVector returned_vector;
+ QVector> 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.element_)) {
- returned_vector.append(rtd);
+ for (auto i = 0 ; i TerminalStripModel::realTerminalDataForIndex(QModelInd
return vector_;
}
-void TerminalStripModel::fillRealTerminalData()
+void TerminalStripModel::fillPhysicalTerminalData()
{
//Get all physical terminal
if (m_terminal_strip) {
for (auto i=0 ; i < m_terminal_strip->physicalTerminalCount() ; ++i) {
- m_physical_terminal_data.append(m_terminal_strip->physicalTerminalData(i));
+ m_original_terminal_data.append(m_terminal_strip->physicalTerminalData(i));
}
+ m_edited_terminal_data = m_original_terminal_data;
}
}
@@ -347,7 +363,7 @@ RealTerminalData TerminalStripModel::dataAtRow(int row) const
else
{
auto current_row = 0;
- for (const auto &physical_data : m_physical_terminal_data)
+ for (const auto &physical_data : m_edited_terminal_data)
{
for (const auto &real_data : physical_data.real_terminals_vector)
{
@@ -379,15 +395,15 @@ void TerminalStripModel::replaceDataAtRow(RealTerminalData data, int row)
auto current_row = 0;
auto current_physical = 0;
- for (const auto &physical_data : qAsConst(m_physical_terminal_data))
+ for (const auto &physical_data : qAsConst(m_edited_terminal_data))
{
auto current_real = 0;
for (int i=0 ; i
#include
#include
+#include
#include "../terminalstrip.h"
@@ -40,14 +41,14 @@ class TerminalStripModel : public QAbstractTableModel
virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
virtual Qt::ItemFlags flags (const QModelIndex &index) const override;
- QVector modifiedRealTerminalData() const;
+ QVector> modifiedRealTerminalData() const;
bool isXrefCell(const QModelIndex &index, Element **element = nullptr);
QVector physicalTerminalDataForIndex(QModelIndexList index_list) const;
QVector realTerminalDataForIndex(QModelIndexList index_list) const;
private:
- void fillRealTerminalData();
+ void fillPhysicalTerminalData();
RealTerminalData dataAtRow(int row) const;
void replaceDataAtRow(RealTerminalData data, int row);
PhysicalTerminalData physicalDataAtIndex(int index) const;
@@ -55,7 +56,7 @@ class TerminalStripModel : public QAbstractTableModel
private:
QPointer m_terminal_strip;
- QVector m_physical_terminal_data;
+ QVector m_edited_terminal_data, m_original_terminal_data;
QHash> m_modified_cell;
};
diff --git a/sources/undocommand/changeelementdatacommand.cpp b/sources/undocommand/changeelementdatacommand.cpp
index ca70809f5..a3f5fc043 100644
--- a/sources/undocommand/changeelementdatacommand.cpp
+++ b/sources/undocommand/changeelementdatacommand.cpp
@@ -18,7 +18,8 @@
#include "changeelementdatacommand.h"
#include "../qetgraphicsitem/element.h"
-ChangeElementDataCommand::ChangeElementDataCommand(Element *element, ElementData new_data) :
+ChangeElementDataCommand::ChangeElementDataCommand(Element *element, ElementData new_data, QUndoCommand *parent) :
+ QUndoCommand(parent),
m_element(element),
m_old_data(element->elementData()),
m_new_data(new_data)
diff --git a/sources/undocommand/changeelementdatacommand.h b/sources/undocommand/changeelementdatacommand.h
index ecc4c590f..fe8526d75 100644
--- a/sources/undocommand/changeelementdatacommand.h
+++ b/sources/undocommand/changeelementdatacommand.h
@@ -26,7 +26,7 @@ class Element;
class ChangeElementDataCommand : public QUndoCommand
{
public:
- ChangeElementDataCommand(Element *element, ElementData new_data);
+ ChangeElementDataCommand(Element *element, ElementData new_data, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;