Several real terminal can be added to terminal strip in one shot

User can select several real terminals in the free terminal editor
and add it with one operation on a terminal strip.
This commit is contained in:
joshua 2022-04-08 20:48:32 +02:00
parent a38d97896d
commit 6197d0215a
7 changed files with 192 additions and 70 deletions

View File

@ -22,6 +22,8 @@
#include "../../diagram.h"
#include "../../elementprovider.h"
#include "freeterminalmodel.h"
#include "../terminalstrip.h"
#include "../UndoCommand/addterminaltostripcommand.h"
/**
* @brief FreeTerminalEditor::FreeTerminalEditor
@ -40,6 +42,11 @@ FreeTerminalEditor::FreeTerminalEditor(QETProject *project, QWidget *parent) :
ui->m_table_view->setModel(m_model);
ui->m_table_view->setCurrentIndex(m_model->index(0,0));
//Disabled the move if the table is currently edited (yellow cell)
connect(m_model, &FreeTerminalModel::dataChanged, this, [=] {
this->setDisabledMove();
});
connect(ui->m_table_view, &QAbstractItemView::doubleClicked, this, [=](const QModelIndex &index)
{
if (m_model->columnTypeForIndex(index) == FreeTerminalModel::XRef)
@ -78,8 +85,21 @@ FreeTerminalEditor::~FreeTerminalEditor()
* the current state of the project.
* Every not applied change will be lost.
*/
void FreeTerminalEditor::reload() {
void FreeTerminalEditor::reload()
{
m_model->clear();
ui->m_move_in_cb->clear();
if (m_project)
{
const auto strip_vector = m_project->terminalStrip();
for (const auto &strip : strip_vector)
{
QString str(strip->installation() + " " + strip->location() + " " + strip->name());
ui->m_move_in_cb->addItem(str, strip->uuid());
}
setDisabledMove(false);
}
}
/**
@ -141,7 +161,7 @@ void FreeTerminalEditor::on_m_type_cb_activated(int index)
default:
override_type = ElementData::TTGeneric; break;
}
m_model->setData(type_index, override_type);
m_model->setData(type_index, override_type);
}
}
}
@ -195,3 +215,44 @@ void FreeTerminalEditor::on_m_led_cb_activated(int index)
}
}
void FreeTerminalEditor::on_m_move_pb_clicked()
{
//Get the selected real terminal
const auto index_list = ui->m_table_view->selectionModel()->selectedIndexes();
const auto real_t_vector = m_model->realTerminalForIndex(index_list);
if (real_t_vector.isEmpty()) {
return;
}
//Get the terminal strip who receive the real terminal
const auto strip_uuid = ui->m_move_in_cb->currentData().toUuid();
TerminalStrip *terminal_strip{nullptr};
for (const auto &strip : m_project->terminalStrip()) {
if (strip->uuid() == strip_uuid) {
terminal_strip = strip;
break;
}
}
if (!terminal_strip) {
return;
}
//Apply action with an undo command
auto parent_undo = new QUndoCommand(tr("Déplacer des bornes à un groupe de bornes"));
for (const auto &rt_ : real_t_vector) {
new AddTerminalToStripCommand(rt_, terminal_strip, parent_undo);
}
m_project->undoStack()->push(parent_undo);
reload();
}
void FreeTerminalEditor::setDisabledMove(bool b)
{
ui->m_move_label->setDisabled(b);
ui->m_move_in_cb->setDisabled(b);
ui->m_move_pb->setDisabled(b);
}

View File

@ -44,9 +44,11 @@ class FreeTerminalEditor : public QWidget
void on_m_type_cb_activated(int index);
void on_m_function_cb_activated(int index);
void on_m_led_cb_activated(int index);
void on_m_move_pb_clicked();
private:
void selectionChanged();
void setDisabledMove(bool b=true);
private:
Ui::FreeTerminalEditor *ui;

View File

@ -6,48 +6,97 @@
<rect>
<x>0</x>
<y>0</y>
<width>751</width>
<height>333</height>
<width>727</width>
<height>279</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="2">
<widget class="QComboBox" name="m_function_cb">
<item>
<property name="text">
<string>Générique</string>
</property>
</item>
<item>
<property name="text">
<string>Phase</string>
</property>
</item>
<item>
<property name="text">
<string>Neutre</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="m_move_label">
<property name="text">
<string>Déplacer dans :</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<item row="0" column="2">
<widget class="QComboBox" name="m_move_in_cb">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="5" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" rowspan="6">
<widget class="QTableView" name="m_table_view">
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Type :</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Fonction :</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>LED :</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="m_move_pb">
<property name="toolTip">
<string>Appliquer le déplacement</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../qelectrotech.qrc">
<normaloff>:/ico/22x22/dialog-ok.png</normaloff>:/ico/22x22/dialog-ok.png</iconset>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="2">
<item row="2" column="2" colspan="2">
<widget class="QComboBox" name="m_type_cb">
<item>
<property name="text">
@ -76,28 +125,26 @@
</item>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Fonction :</string>
</property>
<item row="3" column="2" colspan="2">
<widget class="QComboBox" name="m_function_cb">
<item>
<property name="text">
<string>Générique</string>
</property>
</item>
<item>
<property name="text">
<string>Phase</string>
</property>
</item>
<item>
<property name="text">
<string>Neutre</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Type :</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>LED :</string>
</property>
</widget>
</item>
<item row="4" column="2">
<item row="4" column="2" colspan="2">
<widget class="QComboBox" name="m_led_cb">
<item>
<property name="text">
@ -111,31 +158,10 @@
</item>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="m_move_in_cb"/>
</item>
<item row="5" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" rowspan="6">
<widget class="QTableView" name="m_table_view">
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../../../qelectrotech.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -275,6 +275,30 @@ modelRealTerminalData FreeTerminalModel::dataAtRow(int row) const
}
}
/**
* @brief FreeTerminalModel::realTerminalForIndex
* @param index_list
* @return The QSharedPointer<RealTerminal> associated with the index found in @a index_list
*/
QVector<QSharedPointer<RealTerminal> > FreeTerminalModel::realTerminalForIndex(const QModelIndexList &index_list) const
{
QVector<QSharedPointer<RealTerminal>> vector_;
for (const auto &index : index_list)
{
if (index.isValid()
&& index.model() == this
&& index.row() < m_terminal_vector.size())
{
const auto rt_ = m_terminal_vector.at(index.row());
if (!vector_.contains(rt_)) {
vector_.append(m_terminal_vector.at(index.row()));
}
}
}
return vector_;
}
/**
* @brief FreeTerminalModel::fillTerminalVector
*/

View File

@ -58,6 +58,7 @@ class FreeTerminalModel : public QAbstractTableModel
void clear();
QVector<modelRealTerminalData> modifiedModelRealTerminalData() const;
modelRealTerminalData dataAtRow(int row) const;
QVector<QSharedPointer<RealTerminal>> realTerminalForIndex(const QModelIndexList &index_list) const;
private:
void fillTerminalVector();

View File

@ -62,6 +62,11 @@ void TerminalStripTreeDockWidget::reload()
m_uuid_terminal_H.clear();
m_uuid_strip_H.clear();
for (const auto &connection_ : qAsConst(m_strip_changed_connection)) {
disconnect(connection_);
}
m_strip_changed_connection.clear();
buildTree();
@ -285,6 +290,8 @@ QTreeWidgetItem* TerminalStripTreeDockWidget::addTerminalStrip(TerminalStrip *te
m_item_strip_H.insert(strip_item, terminal_strip);
m_uuid_strip_H.insert(terminal_strip->uuid(), terminal_strip);
m_strip_changed_connection.append(connect(terminal_strip, &TerminalStrip::orderChanged, this, &TerminalStripTreeDockWidget::reload));
return strip_item;
}

View File

@ -67,6 +67,7 @@ class TerminalStripTreeDockWidget : public QDockWidget
QHash<QTreeWidgetItem *, TerminalStrip *> m_item_strip_H;
QHash<QUuid, QSharedPointer<RealTerminal>> m_uuid_terminal_H;
QHash<QUuid, QPointer<TerminalStrip>> m_uuid_strip_H;
QVector<QMetaObject::Connection> m_strip_changed_connection;
};
#endif // TERMINALSTRIPTREEDOCKWIDGET_H