mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 23:20:52 +01:00
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:
@@ -22,6 +22,8 @@
|
|||||||
#include "../../diagram.h"
|
#include "../../diagram.h"
|
||||||
#include "../../elementprovider.h"
|
#include "../../elementprovider.h"
|
||||||
#include "freeterminalmodel.h"
|
#include "freeterminalmodel.h"
|
||||||
|
#include "../terminalstrip.h"
|
||||||
|
#include "../UndoCommand/addterminaltostripcommand.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief FreeTerminalEditor::FreeTerminalEditor
|
* @brief FreeTerminalEditor::FreeTerminalEditor
|
||||||
@@ -40,6 +42,11 @@ FreeTerminalEditor::FreeTerminalEditor(QETProject *project, QWidget *parent) :
|
|||||||
ui->m_table_view->setModel(m_model);
|
ui->m_table_view->setModel(m_model);
|
||||||
ui->m_table_view->setCurrentIndex(m_model->index(0,0));
|
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)
|
connect(ui->m_table_view, &QAbstractItemView::doubleClicked, this, [=](const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if (m_model->columnTypeForIndex(index) == FreeTerminalModel::XRef)
|
if (m_model->columnTypeForIndex(index) == FreeTerminalModel::XRef)
|
||||||
@@ -78,8 +85,21 @@ FreeTerminalEditor::~FreeTerminalEditor()
|
|||||||
* the current state of the project.
|
* the current state of the project.
|
||||||
* Every not applied change will be lost.
|
* Every not applied change will be lost.
|
||||||
*/
|
*/
|
||||||
void FreeTerminalEditor::reload() {
|
void FreeTerminalEditor::reload()
|
||||||
|
{
|
||||||
m_model->clear();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,11 @@ class FreeTerminalEditor : public QWidget
|
|||||||
void on_m_type_cb_activated(int index);
|
void on_m_type_cb_activated(int index);
|
||||||
void on_m_function_cb_activated(int index);
|
void on_m_function_cb_activated(int index);
|
||||||
void on_m_led_cb_activated(int index);
|
void on_m_led_cb_activated(int index);
|
||||||
|
void on_m_move_pb_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void selectionChanged();
|
void selectionChanged();
|
||||||
|
void setDisabledMove(bool b=true);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FreeTerminalEditor *ui;
|
Ui::FreeTerminalEditor *ui;
|
||||||
|
|||||||
@@ -6,48 +6,97 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>751</width>
|
<width>727</width>
|
||||||
<height>333</height>
|
<height>279</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<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">
|
<item row="0" column="1">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="m_move_label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Déplacer dans :</string>
|
<string>Déplacer dans :</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<widget class="Line" name="line">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
<item row="2" column="2" colspan="2">
|
||||||
<widget class="QComboBox" name="m_type_cb">
|
<widget class="QComboBox" name="m_type_cb">
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -76,28 +125,26 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="3" column="2" colspan="2">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QComboBox" name="m_function_cb">
|
||||||
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Fonction :</string>
|
<string>Générique</string>
|
||||||
</property>
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Phase</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Neutre</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="4" column="2" colspan="2">
|
||||||
<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">
|
|
||||||
<widget class="QComboBox" name="m_led_cb">
|
<widget class="QComboBox" name="m_led_cb">
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -111,31 +158,10 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="../../../qelectrotech.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
@@ -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
|
* @brief FreeTerminalModel::fillTerminalVector
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class FreeTerminalModel : public QAbstractTableModel
|
|||||||
void clear();
|
void clear();
|
||||||
QVector<modelRealTerminalData> modifiedModelRealTerminalData() const;
|
QVector<modelRealTerminalData> modifiedModelRealTerminalData() const;
|
||||||
modelRealTerminalData dataAtRow(int row) const;
|
modelRealTerminalData dataAtRow(int row) const;
|
||||||
|
QVector<QSharedPointer<RealTerminal>> realTerminalForIndex(const QModelIndexList &index_list) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fillTerminalVector();
|
void fillTerminalVector();
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ void TerminalStripTreeDockWidget::reload()
|
|||||||
m_uuid_terminal_H.clear();
|
m_uuid_terminal_H.clear();
|
||||||
m_uuid_strip_H.clear();
|
m_uuid_strip_H.clear();
|
||||||
|
|
||||||
|
for (const auto &connection_ : qAsConst(m_strip_changed_connection)) {
|
||||||
|
disconnect(connection_);
|
||||||
|
}
|
||||||
|
m_strip_changed_connection.clear();
|
||||||
|
|
||||||
|
|
||||||
buildTree();
|
buildTree();
|
||||||
|
|
||||||
@@ -285,6 +290,8 @@ QTreeWidgetItem* TerminalStripTreeDockWidget::addTerminalStrip(TerminalStrip *te
|
|||||||
|
|
||||||
m_item_strip_H.insert(strip_item, terminal_strip);
|
m_item_strip_H.insert(strip_item, terminal_strip);
|
||||||
m_uuid_strip_H.insert(terminal_strip->uuid(), 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;
|
return strip_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class TerminalStripTreeDockWidget : public QDockWidget
|
|||||||
QHash<QTreeWidgetItem *, TerminalStrip *> m_item_strip_H;
|
QHash<QTreeWidgetItem *, TerminalStrip *> m_item_strip_H;
|
||||||
QHash<QUuid, QSharedPointer<RealTerminal>> m_uuid_terminal_H;
|
QHash<QUuid, QSharedPointer<RealTerminal>> m_uuid_terminal_H;
|
||||||
QHash<QUuid, QPointer<TerminalStrip>> m_uuid_strip_H;
|
QHash<QUuid, QPointer<TerminalStrip>> m_uuid_strip_H;
|
||||||
|
QVector<QMetaObject::Connection> m_strip_changed_connection;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TERMINALSTRIPTREEDOCKWIDGET_H
|
#endif // TERMINALSTRIPTREEDOCKWIDGET_H
|
||||||
|
|||||||
Reference in New Issue
Block a user