mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Level terminals can be disassembled
This commit is contained in:
parent
dca643f7aa
commit
828424cae8
@ -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.
|
||||||
|
|
||||||
@ -261,6 +261,16 @@ class PhysicalTerminal
|
|||||||
m_real_terminal.append(terminal);
|
m_real_terminal.append(terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief removeTerminal
|
||||||
|
* Remove \p terminal from the list of real terminal
|
||||||
|
* @param terminal
|
||||||
|
* @return true if sucessfully removed
|
||||||
|
*/
|
||||||
|
bool removeTerminal(shared_real_terminal terminal) {
|
||||||
|
return m_real_terminal.removeOne(terminal);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief levelCount
|
* @brief levelCount
|
||||||
* @return the number of level of this terminal
|
* @return the number of level of this terminal
|
||||||
@ -561,7 +571,7 @@ bool TerminalStrip::setOrderTo(QVector<PhysicalTerminalData> sorted_vector)
|
|||||||
* @param receiver_terminal
|
* @param receiver_terminal
|
||||||
* @return true if success
|
* @return true if success
|
||||||
*/
|
*/
|
||||||
bool TerminalStrip::groupTerminal(const PhysicalTerminalData &receiver_terminal, const QVector<PhysicalTerminalData> &added_terminals)
|
bool TerminalStrip::groupTerminals(const PhysicalTerminalData &receiver_terminal, const QVector<PhysicalTerminalData> &added_terminals)
|
||||||
{
|
{
|
||||||
if (!m_physical_terminals.contains(receiver_terminal.physical_terminal)) {
|
if (!m_physical_terminals.contains(receiver_terminal.physical_terminal)) {
|
||||||
qDebug() << "TerminalStrip::groupTerminal : Arguments terminals don't belong to this strip. Operation aborted.";
|
qDebug() << "TerminalStrip::groupTerminal : Arguments terminals don't belong to this strip. Operation aborted.";
|
||||||
@ -592,6 +602,39 @@ bool TerminalStrip::groupTerminal(const PhysicalTerminalData &receiver_terminal,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStrip::unGroupTerminals
|
||||||
|
* Ungroup all real terminals of \p terminals_to_ungroup
|
||||||
|
* from this terminal strip
|
||||||
|
* @param terminals_to_ungroup
|
||||||
|
*/
|
||||||
|
void TerminalStrip::unGroupTerminals(const QVector<RealTerminalData> &terminals_to_ungroup)
|
||||||
|
{
|
||||||
|
bool ungrouped = false;
|
||||||
|
for (const auto &rtd_ : terminals_to_ungroup)
|
||||||
|
{
|
||||||
|
if (auto real_terminal = realTerminal(rtd_.element_)) //Get the shared real terminal
|
||||||
|
{
|
||||||
|
if (auto physical_terminal = physicalTerminal(real_terminal)) //Get the physical terminal
|
||||||
|
{
|
||||||
|
if (physical_terminal->terminals().size() > 1) //Check if physical have more than one real terminal
|
||||||
|
{
|
||||||
|
physical_terminal->removeTerminal(real_terminal);
|
||||||
|
shared_physical_terminal new_physical_terminal (
|
||||||
|
new PhysicalTerminal(this, QVector<shared_real_terminal>{real_terminal}));
|
||||||
|
|
||||||
|
m_physical_terminals.append(new_physical_terminal);
|
||||||
|
ungrouped = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ungrouped) {
|
||||||
|
emit orderChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
|
@ -34,7 +34,7 @@ class TerminalElement;
|
|||||||
|
|
||||||
struct RealTerminalData
|
struct RealTerminalData
|
||||||
{
|
{
|
||||||
int level_ = 0;
|
int level_ = -1;
|
||||||
|
|
||||||
QString label_,
|
QString label_,
|
||||||
Xref_,
|
Xref_,
|
||||||
@ -107,7 +107,8 @@ 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);
|
bool groupTerminals(const PhysicalTerminalData &receiver_terminal, const QVector<PhysicalTerminalData> &added_terminals);
|
||||||
|
void unGroupTerminals(const QVector<RealTerminalData> &terminals_to_ungroup);
|
||||||
|
|
||||||
QVector<QPointer<Element>> terminalElement() const;
|
QVector<QPointer<Element>> terminalElement() const;
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
|
|||||||
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);
|
ui->m_group_terminals_pb->setDisabled(true);
|
||||||
|
ui->m_ungroup_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();
|
||||||
@ -348,10 +349,24 @@ void TerminalStripEditor::selectionChanged()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto index_list = ui->m_table_widget->selectionModel()->selectedIndexes();
|
const auto index_list = ui->m_table_widget->selectionModel()->selectedIndexes();
|
||||||
auto terminal_vector = m_model->terminalsForIndex(index_list);
|
const auto terminal_vector = m_model->physicalTerminalDataForIndex(index_list);
|
||||||
|
|
||||||
ui->m_group_terminals_pb->setEnabled(terminal_vector.size() > 1 ? true : false);
|
ui->m_group_terminals_pb->setEnabled(terminal_vector.size() > 1 ? true : false);
|
||||||
|
|
||||||
|
|
||||||
|
auto it_= std::find_if(terminal_vector.constBegin(), terminal_vector.constEnd(), [](auto &data)
|
||||||
|
{
|
||||||
|
if (data.real_terminals_vector.size() >= 2) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui->m_ungroup_pb->setDisabled(it_ == terminal_vector.constEnd());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -523,12 +538,24 @@ void TerminalStripEditor::on_m_group_terminals_pb_clicked()
|
|||||||
{
|
{
|
||||||
if (m_model && m_current_strip)
|
if (m_model && m_current_strip)
|
||||||
{
|
{
|
||||||
auto ptd_vector = m_model->terminalsForIndex(ui->m_table_widget->selectionModel()->selectedIndexes());
|
auto ptd_vector = m_model->physicalTerminalDataForIndex(ui->m_table_widget->selectionModel()->selectedIndexes());
|
||||||
if (ptd_vector.size() >= 2)
|
if (ptd_vector.size() >= 2)
|
||||||
{
|
{
|
||||||
auto receiver_ = ptd_vector.takeFirst();
|
auto receiver_ = ptd_vector.takeFirst();
|
||||||
m_current_strip->groupTerminal(receiver_, ptd_vector);
|
m_current_strip->groupTerminals(receiver_, ptd_vector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripEditor::on_m_ungroup_pb_clicked
|
||||||
|
*/
|
||||||
|
void TerminalStripEditor::on_m_ungroup_pb_clicked()
|
||||||
|
{
|
||||||
|
if (m_model && m_current_strip)
|
||||||
|
{
|
||||||
|
const auto rtd_vector = m_model->realTerminalDataForIndex(ui->m_table_widget->selectionModel()->selectedIndexes());
|
||||||
|
m_current_strip->unGroupTerminals(rtd_vector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,8 @@ class TerminalStripEditor : public QDialog
|
|||||||
void on_m_auto_ordering_pb_clicked();
|
void on_m_auto_ordering_pb_clicked();
|
||||||
void on_m_group_terminals_pb_clicked();
|
void on_m_group_terminals_pb_clicked();
|
||||||
|
|
||||||
|
void on_m_ungroup_pb_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TerminalStripEditor *ui;
|
Ui::TerminalStripEditor *ui;
|
||||||
QETProject *m_project = nullptr;
|
QETProject *m_project = nullptr;
|
||||||
|
@ -178,7 +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="2" column="0">
|
<item row="3" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -205,6 +205,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QPushButton" name="m_ungroup_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Degrouper les bornes</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -276,7 +276,7 @@ bool TerminalStripModel::isXrefCell(const QModelIndex &index, Element **element)
|
|||||||
* @return A vector of PhysicalTerminalData represented by 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
|
* If sereval index point to the same terminal the vector have only one PhysicalTerminalData
|
||||||
*/
|
*/
|
||||||
QVector<PhysicalTerminalData> TerminalStripModel::terminalsForIndex(QModelIndexList index_list) const
|
QVector<PhysicalTerminalData> TerminalStripModel::physicalTerminalDataForIndex(QModelIndexList index_list) const
|
||||||
{
|
{
|
||||||
QVector<PhysicalTerminalData> vector_;
|
QVector<PhysicalTerminalData> vector_;
|
||||||
if (index_list.isEmpty()) {
|
if (index_list.isEmpty()) {
|
||||||
@ -299,6 +299,36 @@ QVector<PhysicalTerminalData> TerminalStripModel::terminalsForIndex(QModelIndexL
|
|||||||
return vector_;
|
return vector_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripModel::realTerminalDataForIndex
|
||||||
|
* @param index_list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
QVector<RealTerminalData> TerminalStripModel::realTerminalDataForIndex(QModelIndexList index_list) const
|
||||||
|
{
|
||||||
|
QVector<RealTerminalData> 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_) {
|
||||||
|
const auto rtd_ = realDataAtIndex(i);
|
||||||
|
if (rtd_.level_ > -1) {
|
||||||
|
vector_.append(realDataAtIndex(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return vector_;
|
||||||
|
}
|
||||||
|
|
||||||
void TerminalStripModel::fillRealTerminalData()
|
void TerminalStripModel::fillRealTerminalData()
|
||||||
{
|
{
|
||||||
//Get all physical terminal
|
//Get all physical terminal
|
||||||
@ -406,6 +436,32 @@ PhysicalTerminalData TerminalStripModel::physicalDataAtIndex(int index) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripModel::realDataAtIndex
|
||||||
|
* @param index
|
||||||
|
* @return the realTerminalData at index \p index.
|
||||||
|
*/
|
||||||
|
RealTerminalData TerminalStripModel::realDataAtIndex(int index) const
|
||||||
|
{
|
||||||
|
if (m_physical_terminal_data.isEmpty()) {
|
||||||
|
return RealTerminalData();
|
||||||
|
}
|
||||||
|
|
||||||
|
int current_checked_index = -1;
|
||||||
|
|
||||||
|
for (const auto & ptd_ : qAsConst(m_physical_terminal_data))
|
||||||
|
{
|
||||||
|
for (const auto & rtd_ : qAsConst(ptd_.real_terminals_vector)) {
|
||||||
|
++current_checked_index;
|
||||||
|
if (current_checked_index == index) {
|
||||||
|
return rtd_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RealTerminalData();
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
* 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,13 +43,15 @@ 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;
|
QVector<PhysicalTerminalData> physicalTerminalDataForIndex(QModelIndexList index_list) const;
|
||||||
|
QVector<RealTerminalData> realTerminalDataForIndex(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;
|
PhysicalTerminalData physicalDataAtIndex(int index) const;
|
||||||
|
RealTerminalData realDataAtIndex(int index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<TerminalStrip> m_terminal_strip;
|
QPointer<TerminalStrip> m_terminal_strip;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user