mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-07 22:22:33 +01:00
Multi-level terminal can be created.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2021 The QElectroTech Team
|
Copyright 2006-2021 The QElectroTech Team
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
@@ -251,6 +251,16 @@ class PhysicalTerminal
|
|||||||
m_real_terminal = terminals;
|
m_real_terminal = terminals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief addTerminals
|
||||||
|
* Append the real terminal \p terminal
|
||||||
|
* to this physical terminal.
|
||||||
|
* @param terminal
|
||||||
|
*/
|
||||||
|
void addTerminal(shared_real_terminal terminal) {
|
||||||
|
m_real_terminal.append(terminal);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief levelCount
|
* @brief levelCount
|
||||||
* @return the number of level of this terminal
|
* @return the number of level of this terminal
|
||||||
@@ -541,6 +551,47 @@ bool TerminalStrip::setOrderTo(QVector<PhysicalTerminalData> sorted_vector)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStrip::groupTerminal
|
||||||
|
* Add \p added_terminal to \p receiver_terminal.
|
||||||
|
* At the end of this method, the physical terminal represented by \p added_terminal is removed
|
||||||
|
* and \p receiver_terminal become a multi-level terminal.
|
||||||
|
* Emit the signal orderChanged();
|
||||||
|
* @param added_terminal
|
||||||
|
* @param receiver_terminal
|
||||||
|
* @return true if success
|
||||||
|
*/
|
||||||
|
bool TerminalStrip::groupTerminal(const PhysicalTerminalData &receiver_terminal, const QVector<PhysicalTerminalData> &added_terminals)
|
||||||
|
{
|
||||||
|
if (!m_physical_terminals.contains(receiver_terminal.physical_terminal)) {
|
||||||
|
qDebug() << "TerminalStrip::groupTerminal : Arguments terminals don't belong to this strip. Operation aborted.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto physical_receiver_terminal = receiver_terminal.physical_terminal;
|
||||||
|
|
||||||
|
for (const auto &ptd : qAsConst(added_terminals))
|
||||||
|
{
|
||||||
|
if (!m_physical_terminals.contains(ptd.physical_terminal)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add every real terminal of ptd to receiver terminal
|
||||||
|
for (auto const &rtd_ : qAsConst(ptd.real_terminals_vector))
|
||||||
|
{
|
||||||
|
if (auto rt = realTerminal(rtd_.element_)) {
|
||||||
|
physical_receiver_terminal->addTerminal(rt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Remove ptd
|
||||||
|
m_physical_terminals.removeOne(ptd.physical_terminal);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit orderChanged();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStrip::terminalElement
|
* @brief TerminalStrip::terminalElement
|
||||||
* @return A vector of all terminal element owned by this strip
|
* @return A vector of all terminal element owned by this strip
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ class TerminalStrip : public QObject
|
|||||||
PhysicalTerminalData physicalTerminalData(int index) const;
|
PhysicalTerminalData physicalTerminalData(int index) const;
|
||||||
QVector<PhysicalTerminalData> physicalTerminalData() const;
|
QVector<PhysicalTerminalData> physicalTerminalData() const;
|
||||||
bool setOrderTo(QVector<PhysicalTerminalData> sorted_vector);
|
bool setOrderTo(QVector<PhysicalTerminalData> sorted_vector);
|
||||||
|
bool groupTerminal(const PhysicalTerminalData &receiver_terminal, const QVector<PhysicalTerminalData> &added_terminals);
|
||||||
|
|
||||||
QVector<QPointer<Element>> terminalElement() const;
|
QVector<QPointer<Element>> terminalElement() const;
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,10 @@ TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
|
|||||||
m_project(project)
|
m_project(project)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->m_table_widget->setItemDelegate(new TerminalStripModelDelegate(ui->m_terminal_strip_tw));
|
ui->m_table_widget->setItemDelegate(new TerminalStripModelDelegate(ui->m_terminal_strip_tw));
|
||||||
ui->m_remove_terminal_strip_pb->setDisabled(true);
|
ui->m_remove_terminal_strip_pb->setDisabled(true);
|
||||||
|
ui->m_group_terminals_pb->setDisabled(true);
|
||||||
buildTree();
|
buildTree();
|
||||||
ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex());
|
ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex());
|
||||||
setUpUndoConnections();
|
setUpUndoConnections();
|
||||||
@@ -307,11 +309,51 @@ void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_)
|
|||||||
|
|
||||||
m_model = new TerminalStripModel(strip_, this);
|
m_model = new TerminalStripModel(strip_, this);
|
||||||
ui->m_table_widget->setModel(m_model);
|
ui->m_table_widget->setModel(m_model);
|
||||||
|
spanMultiLevelTerminals();
|
||||||
|
|
||||||
connect(m_current_strip, &TerminalStrip::orderChanged, this, &TerminalStripEditor::on_m_reload_pb_clicked);
|
connect(m_current_strip, &TerminalStrip::orderChanged, this, &TerminalStripEditor::on_m_reload_pb_clicked);
|
||||||
|
connect(ui->m_table_widget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TerminalStripEditor::selectionChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripEditor::spanMultiLevelTerminals
|
||||||
|
* Span row of m_table_widget for multi-level terminal
|
||||||
|
*/
|
||||||
|
void TerminalStripEditor::spanMultiLevelTerminals()
|
||||||
|
{
|
||||||
|
if (!m_current_strip) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->m_table_widget->clearSpans();
|
||||||
|
auto current_row = 0;
|
||||||
|
for (auto i = 0 ; i < m_current_strip->physicalTerminalCount() ; ++i)
|
||||||
|
{
|
||||||
|
const auto level_count = m_current_strip->physicalTerminalData(i).real_terminals_vector.size();
|
||||||
|
if (level_count > 1) {
|
||||||
|
ui->m_table_widget->setSpan(current_row, 0, level_count, 1);
|
||||||
|
}
|
||||||
|
current_row += level_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripEditor::selectionChanged
|
||||||
|
* Update the editor according to the current selection
|
||||||
|
*/
|
||||||
|
void TerminalStripEditor::selectionChanged()
|
||||||
|
{
|
||||||
|
if (!m_model) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto index_list = ui->m_table_widget->selectionModel()->selectedIndexes();
|
||||||
|
auto terminal_vector = m_model->terminalsForIndex(index_list);
|
||||||
|
|
||||||
|
ui->m_group_terminals_pb->setEnabled(terminal_vector.size() > 1 ? true : false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStripEditor::on_m_add_terminal_strip_pb_clicked
|
* @brief TerminalStripEditor::on_m_add_terminal_strip_pb_clicked
|
||||||
* Action when user click on add terminal strip button
|
* Action when user click on add terminal strip button
|
||||||
@@ -474,3 +516,19 @@ void TerminalStripEditor::on_m_auto_ordering_pb_clicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripEditor::on_m_group_terminals_pb_clicked
|
||||||
|
*/
|
||||||
|
void TerminalStripEditor::on_m_group_terminals_pb_clicked()
|
||||||
|
{
|
||||||
|
if (m_model && m_current_strip)
|
||||||
|
{
|
||||||
|
auto ptd_vector = m_model->terminalsForIndex(ui->m_table_widget->selectionModel()->selectedIndexes());
|
||||||
|
if (ptd_vector.size() >= 2)
|
||||||
|
{
|
||||||
|
auto receiver_ = ptd_vector.takeFirst();
|
||||||
|
m_current_strip->groupTerminal(receiver_, ptd_vector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ class TerminalStripEditor : public QDialog
|
|||||||
QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip);
|
QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip);
|
||||||
void addFreeTerminal();
|
void addFreeTerminal();
|
||||||
void setCurrentStrip(TerminalStrip *strip_);
|
void setCurrentStrip(TerminalStrip *strip_);
|
||||||
|
void spanMultiLevelTerminals();
|
||||||
|
void selectionChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_m_add_terminal_strip_pb_clicked();
|
void on_m_add_terminal_strip_pb_clicked();
|
||||||
@@ -58,6 +60,7 @@ class TerminalStripEditor : public QDialog
|
|||||||
void on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
void on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||||
void on_m_dialog_button_box_clicked(QAbstractButton *button);
|
void on_m_dialog_button_box_clicked(QAbstractButton *button);
|
||||||
void on_m_auto_ordering_pb_clicked();
|
void on_m_auto_ordering_pb_clicked();
|
||||||
|
void on_m_group_terminals_pb_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TerminalStripEditor *ui;
|
Ui::TerminalStripEditor *ui;
|
||||||
|
|||||||
@@ -178,14 +178,7 @@
|
|||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QWidget" name="widget" native="true">
|
<widget class="QWidget" name="widget" native="true">
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<item row="0" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QPushButton" name="m_auto_ordering_pb">
|
|
||||||
<property name="text">
|
|
||||||
<string>Position automatique</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@@ -198,6 +191,20 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPushButton" name="m_auto_ordering_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Position automatique</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QPushButton" name="m_group_terminals_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Grouper les bornes</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ QVariant TerminalStripModel::data(const QModelIndex &index, int role) const
|
|||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
{
|
{
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case POS_CELL : return index.row();
|
case POS_CELL : return physicalDataAtIndex(index.row()).pos_;
|
||||||
case LEVEL_CELL : return rtd.level_;
|
case LEVEL_CELL : return rtd.level_;
|
||||||
case LABEL_CELL : return rtd.label_;
|
case LABEL_CELL : return rtd.label_;
|
||||||
case XREF_CELL : return rtd.Xref_;
|
case XREF_CELL : return rtd.Xref_;
|
||||||
@@ -270,6 +270,35 @@ bool TerminalStripModel::isXrefCell(const QModelIndex &index, Element **element)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripModel::terminalsForIndex
|
||||||
|
* @param index_list
|
||||||
|
* @return A vector of PhysicalTerminalData represented by index_list.
|
||||||
|
* If sereval index point to the same terminal the vector have only one PhysicalTerminalData
|
||||||
|
*/
|
||||||
|
QVector<PhysicalTerminalData> TerminalStripModel::terminalsForIndex(QModelIndexList index_list) const
|
||||||
|
{
|
||||||
|
QVector<PhysicalTerminalData> vector_;
|
||||||
|
if (index_list.isEmpty()) {
|
||||||
|
return vector_;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSet<int> set_;
|
||||||
|
|
||||||
|
//We use a QSet to avoid insert several time the same terminal.
|
||||||
|
for (auto index : index_list) {
|
||||||
|
if (index.isValid()) {
|
||||||
|
set_.insert(index.row());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i : set_) {
|
||||||
|
vector_.append(physicalDataAtIndex(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return vector_;
|
||||||
|
}
|
||||||
|
|
||||||
void TerminalStripModel::fillRealTerminalData()
|
void TerminalStripModel::fillRealTerminalData()
|
||||||
{
|
{
|
||||||
//Get all physical terminal
|
//Get all physical terminal
|
||||||
@@ -340,6 +369,43 @@ void TerminalStripModel::replaceDataAtRow(RealTerminalData data, int row)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripModel::physicalDataAtIndex
|
||||||
|
* @param index
|
||||||
|
* @return the physical terminal data at \p index.
|
||||||
|
* We need to use this method because the model can have more index than physical
|
||||||
|
* terminal, because physical terminal can be multi-level and each level
|
||||||
|
* have is own row.
|
||||||
|
* If \p index is out of range, return a default PhysicalTerminalData (pos_ is set to -1 by default)
|
||||||
|
*/
|
||||||
|
PhysicalTerminalData TerminalStripModel::physicalDataAtIndex(int index) const
|
||||||
|
{
|
||||||
|
if (m_physical_terminal_data.isEmpty()) {
|
||||||
|
return PhysicalTerminalData();
|
||||||
|
}
|
||||||
|
|
||||||
|
int current_checked_index = -1;
|
||||||
|
int current_phy = -1;
|
||||||
|
bool match_ = false;
|
||||||
|
|
||||||
|
for (const auto &ptd_ : qAsConst(m_physical_terminal_data))
|
||||||
|
{
|
||||||
|
current_checked_index += ptd_.real_terminals_vector.size();
|
||||||
|
++current_phy;
|
||||||
|
|
||||||
|
if (current_checked_index >= index) {
|
||||||
|
match_ = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match_) {
|
||||||
|
return m_physical_terminal_data.at(current_phy);
|
||||||
|
} else {
|
||||||
|
return PhysicalTerminalData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
* Alittle delegate for add a combobox to edit type
|
* Alittle delegate for add a combobox to edit type
|
||||||
* and a spinbox to edit the level of a terminal
|
* and a spinbox to edit the level of a terminal
|
||||||
|
|||||||
@@ -43,11 +43,13 @@ class TerminalStripModel : public QAbstractTableModel
|
|||||||
QVector<RealTerminalData> modifiedRealTerminalData() const;
|
QVector<RealTerminalData> modifiedRealTerminalData() const;
|
||||||
|
|
||||||
bool isXrefCell(const QModelIndex &index, Element **element = nullptr);
|
bool isXrefCell(const QModelIndex &index, Element **element = nullptr);
|
||||||
|
QVector<PhysicalTerminalData> terminalsForIndex(QModelIndexList index_list) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fillRealTerminalData();
|
void fillRealTerminalData();
|
||||||
RealTerminalData dataAtRow(int row) const;
|
RealTerminalData dataAtRow(int row) const;
|
||||||
void replaceDataAtRow(RealTerminalData data, int row);
|
void replaceDataAtRow(RealTerminalData data, int row);
|
||||||
|
PhysicalTerminalData physicalDataAtIndex(int index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<TerminalStrip> m_terminal_strip;
|
QPointer<TerminalStrip> m_terminal_strip;
|
||||||
|
|||||||
Reference in New Issue
Block a user