mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-01 00:49:58 +01:00
Multi-level terminal can be created.
This commit is contained in:
@@ -45,8 +45,10 @@ TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
|
||||
m_project(project)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->m_table_widget->setItemDelegate(new TerminalStripModelDelegate(ui->m_terminal_strip_tw));
|
||||
ui->m_remove_terminal_strip_pb->setDisabled(true);
|
||||
ui->m_group_terminals_pb->setDisabled(true);
|
||||
buildTree();
|
||||
ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex());
|
||||
setUpUndoConnections();
|
||||
@@ -307,11 +309,51 @@ void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_)
|
||||
|
||||
m_model = new TerminalStripModel(strip_, this);
|
||||
ui->m_table_widget->setModel(m_model);
|
||||
spanMultiLevelTerminals();
|
||||
|
||||
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
|
||||
* 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);
|
||||
void addFreeTerminal();
|
||||
void setCurrentStrip(TerminalStrip *strip_);
|
||||
void spanMultiLevelTerminals();
|
||||
void selectionChanged();
|
||||
|
||||
private slots:
|
||||
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_dialog_button_box_clicked(QAbstractButton *button);
|
||||
void on_m_auto_ordering_pb_clicked();
|
||||
void on_m_group_terminals_pb_clicked();
|
||||
|
||||
private:
|
||||
Ui::TerminalStripEditor *ui;
|
||||
|
||||
@@ -178,14 +178,7 @@
|
||||
<item row="1" column="1">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<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">
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@@ -198,6 +191,20 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -89,7 +89,7 @@ QVariant TerminalStripModel::data(const QModelIndex &index, int role) const
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
switch (index.column()) {
|
||||
case POS_CELL : return index.row();
|
||||
case POS_CELL : return physicalDataAtIndex(index.row()).pos_;
|
||||
case LEVEL_CELL : return rtd.level_;
|
||||
case LABEL_CELL : return rtd.label_;
|
||||
case XREF_CELL : return rtd.Xref_;
|
||||
@@ -270,6 +270,35 @@ bool TerminalStripModel::isXrefCell(const QModelIndex &index, Element **element)
|
||||
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()
|
||||
{
|
||||
//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
|
||||
* and a spinbox to edit the level of a terminal
|
||||
|
||||
@@ -43,11 +43,13 @@ class TerminalStripModel : public QAbstractTableModel
|
||||
QVector<RealTerminalData> modifiedRealTerminalData() const;
|
||||
|
||||
bool isXrefCell(const QModelIndex &index, Element **element = nullptr);
|
||||
QVector<PhysicalTerminalData> terminalsForIndex(QModelIndexList index_list) const;
|
||||
|
||||
private:
|
||||
void fillRealTerminalData();
|
||||
RealTerminalData dataAtRow(int row) const;
|
||||
void replaceDataAtRow(RealTerminalData data, int row);
|
||||
PhysicalTerminalData physicalDataAtIndex(int index) const;
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_terminal_strip;
|
||||
|
||||
Reference in New Issue
Block a user