mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Merge branch 'terminal_strip'
* terminal_strip: Remove terminal strip widget Several terminals can be removed or moved from strip in one shot
This commit is contained in:
commit
f0694f0daf
@ -74,6 +74,14 @@ void TerminalStrip::setDescription(const QString &description) {
|
|||||||
m_data.m_description = description;
|
m_data.m_description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStrip::project
|
||||||
|
* @return the project of this terminal strip or nullptr
|
||||||
|
*/
|
||||||
|
QETProject *TerminalStrip::project() const {
|
||||||
|
return m_project.data();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStrip::data
|
* @brief TerminalStrip::data
|
||||||
* @return The internal data of this strip
|
* @return The internal data of this strip
|
||||||
|
@ -73,6 +73,7 @@ class TerminalStrip : public QObject
|
|||||||
void setDescription(const QString &description);
|
void setDescription(const QString &description);
|
||||||
QString description() const {return m_data.m_description;}
|
QString description() const {return m_data.m_description;}
|
||||||
QUuid uuid() const {return m_data.m_uuid;}
|
QUuid uuid() const {return m_data.m_uuid;}
|
||||||
|
QETProject *project() const;
|
||||||
|
|
||||||
TerminalStripData data() const;
|
TerminalStripData data() const;
|
||||||
void setData(const TerminalStripData &data);
|
void setData(const TerminalStripData &data);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "terminalstripeditor.h"
|
#include "terminalstripeditor.h"
|
||||||
#include "ui_terminalstripeditor.h"
|
#include "ui_terminalstripeditor.h"
|
||||||
|
#include "../UndoCommand/addterminaltostripcommand.h"
|
||||||
#include "../../qetproject.h"
|
#include "../../qetproject.h"
|
||||||
#include "../terminalstrip.h"
|
#include "../terminalstrip.h"
|
||||||
#include "../UndoCommand/changeterminalstripdata.h"
|
#include "../UndoCommand/changeterminalstripdata.h"
|
||||||
@ -99,6 +100,8 @@ void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_)
|
|||||||
disconnect(m_current_strip, &TerminalStrip::bridgeChanged, this, &TerminalStripEditor::reload);
|
disconnect(m_current_strip, &TerminalStrip::bridgeChanged, this, &TerminalStripEditor::reload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui->m_move_to_cb->clear();
|
||||||
|
|
||||||
if (!strip_)
|
if (!strip_)
|
||||||
{
|
{
|
||||||
ui->m_installation_le ->clear();
|
ui->m_installation_le ->clear();
|
||||||
@ -121,18 +124,34 @@ void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_)
|
|||||||
ui->m_name_le ->setText(strip_->name());
|
ui->m_name_le ->setText(strip_->name());
|
||||||
ui->m_comment_le ->setText(strip_->comment());
|
ui->m_comment_le ->setText(strip_->comment());
|
||||||
ui->m_description_te ->setPlainText(strip_->description());
|
ui->m_description_te ->setPlainText(strip_->description());
|
||||||
|
ui->m_move_to_cb->addItem(tr("Bornes indépendantes"), QUuid());
|
||||||
|
|
||||||
|
const auto project_{strip_->project()};
|
||||||
|
if (project_)
|
||||||
|
{
|
||||||
|
const auto strip_vector = project_->terminalStrip();
|
||||||
|
for (const auto &strip : strip_vector)
|
||||||
|
{
|
||||||
|
if (strip == strip_) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->m_move_to_cb->addItem(QString{strip->installation() + " " + strip->location() + " " + strip->name()},
|
||||||
|
strip->uuid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_current_strip = strip_;
|
m_current_strip = strip_;
|
||||||
|
|
||||||
if (m_model)
|
if (m_model) {
|
||||||
{
|
|
||||||
m_model->setTerminalStrip(strip_);
|
m_model->setTerminalStrip(strip_);
|
||||||
connect(ui->m_table_widget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TerminalStripEditor::selectionChanged);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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);
|
||||||
m_model->buildBridgePixmap(setUpBridgeCellWidth());
|
m_model->buildBridgePixmap(setUpBridgeCellWidth());
|
||||||
|
connect(ui->m_table_widget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TerminalStripEditor::selectionChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
spanMultiLevelTerminals();
|
spanMultiLevelTerminals();
|
||||||
@ -321,6 +340,22 @@ void TerminalStripEditor::selectionChanged()
|
|||||||
ui->m_bridge_terminals_pb->setEnabled(enable_bridge);
|
ui->m_bridge_terminals_pb->setEnabled(enable_bridge);
|
||||||
ui->m_unbridge_terminals_pb->setEnabled(enable_unbridge);
|
ui->m_unbridge_terminals_pb->setEnabled(enable_unbridge);
|
||||||
ui->m_bridge_color_cb->setEnabled(enable_bridge_color);
|
ui->m_bridge_color_cb->setEnabled(enable_bridge_color);
|
||||||
|
|
||||||
|
//Enable or not the 'move to' buttons
|
||||||
|
bool enabled_move_to{!model_physical_terminal_vector.isEmpty()};
|
||||||
|
for (const auto &model_physical : model_physical_terminal_vector)
|
||||||
|
{
|
||||||
|
for (const auto &model_real_data : model_physical.real_data)
|
||||||
|
{
|
||||||
|
if (model_real_data.bridged_) {
|
||||||
|
enabled_move_to = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui->m_move_to_label->setEnabled(enabled_move_to);
|
||||||
|
ui->m_move_to_cb->setEnabled(enabled_move_to);
|
||||||
|
ui->m_move_to_pb->setEnabled(enabled_move_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize TerminalStripEditor::setUpBridgeCellWidth()
|
QSize TerminalStripEditor::setUpBridgeCellWidth()
|
||||||
@ -653,3 +688,59 @@ void TerminalStripEditor::on_m_bridge_color_cb_activated(const QColor &col)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TerminalStripEditor::on_m_move_to_pb_clicked()
|
||||||
|
{
|
||||||
|
if (!m_model || !m_current_strip || !m_current_strip->project()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get selected physical terminal
|
||||||
|
const auto index_vector = m_model->modelPhysicalTerminalDataForIndex(ui->m_table_widget->selectionModel()->selectedIndexes());
|
||||||
|
QVector<QSharedPointer<PhysicalTerminal>> phy_vector;
|
||||||
|
for (const auto &index : index_vector)
|
||||||
|
{
|
||||||
|
const auto shared_{m_current_strip->physicalTerminal(index.uuid_)};
|
||||||
|
if (shared_)
|
||||||
|
phy_vector.append(shared_);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phy_vector.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto undo_stack{m_current_strip->project()->undoStack()};
|
||||||
|
const auto uuid_{ui->m_move_to_cb->currentData().toUuid()};
|
||||||
|
//Uuid is null we move the selected terminal to indepandant terminal
|
||||||
|
if (uuid_.isNull())
|
||||||
|
{
|
||||||
|
undo_stack->beginMacro(tr("Retirer des bornes d'un bornier"));
|
||||||
|
for (const auto &phy_ : phy_vector) {
|
||||||
|
undo_stack->push(new RemoveTerminalFromStripCommand(phy_, m_current_strip));
|
||||||
|
}
|
||||||
|
undo_stack->endMacro();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TerminalStrip *receiver_strip{nullptr};
|
||||||
|
const auto strip_vector = m_current_strip->project()->terminalStrip();
|
||||||
|
for (const auto &strip_ : strip_vector)
|
||||||
|
{
|
||||||
|
if (strip_->uuid() == uuid_) {
|
||||||
|
receiver_strip = strip_;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!receiver_strip) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
undo_stack->beginMacro(tr("Déplacer des bornes d'un bornier à un autre"));
|
||||||
|
for (const auto &phy_ : phy_vector) {
|
||||||
|
undo_stack->push(new MoveTerminalCommand(phy_, m_current_strip, receiver_strip));
|
||||||
|
}
|
||||||
|
undo_stack->endMacro();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ class TerminalStripEditor : public QWidget
|
|||||||
void on_m_bridge_terminals_pb_clicked();
|
void on_m_bridge_terminals_pb_clicked();
|
||||||
void on_m_unbridge_terminals_pb_clicked();
|
void on_m_unbridge_terminals_pb_clicked();
|
||||||
void on_m_bridge_color_cb_activated(const QColor &col);
|
void on_m_bridge_color_cb_activated(const QColor &col);
|
||||||
|
void on_m_move_to_pb_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TerminalStripEditor *ui;
|
Ui::TerminalStripEditor *ui;
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>922</width>
|
<width>873</width>
|
||||||
<height>516</height>
|
<height>483</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -23,10 +23,234 @@
|
|||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Disposition</string>
|
<string>Disposition</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="m_table_widget"/>
|
<widget class="QTableView" name="m_table_widget"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="8" column="1" colspan="2">
|
||||||
|
<widget class="QComboBox" name="m_led_cb">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Sans</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Avec</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="3">
|
||||||
|
<widget class="Line" name="line_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QPushButton" name="m_move_to_pb">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Effectuer le déplacement</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/dialog-ok.png</normaloff>:/ico/16x16/dialog-ok.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="12" column="1" colspan="2">
|
||||||
|
<widget class="KColorCombo" name="m_bridge_color_cb"/>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="text">
|
||||||
|
<string>Étage :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="0">
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>Type :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="12" column="0">
|
||||||
|
<widget class="QLabel" name="label_10">
|
||||||
|
<property name="text">
|
||||||
|
<string>Couleur pont :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="1" colspan="2">
|
||||||
|
<widget class="QComboBox" name="m_type_cb">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Générique</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Fusible</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Sectionnable</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Diode</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Terre</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="8" column="0">
|
||||||
|
<widget class="QLabel" name="label_9">
|
||||||
|
<property name="text">
|
||||||
|
<string>LED :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="9" column="0" colspan="3">
|
||||||
|
<widget class="Line" name="line_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="13" column="0">
|
||||||
|
<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="7" column="0">
|
||||||
|
<widget class="QLabel" name="label_8">
|
||||||
|
<property name="text">
|
||||||
|
<string>Fonction :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="m_move_to_label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Déplacer dans :</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="1" 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="0" column="1">
|
||||||
|
<widget class="QComboBox" name="m_move_to_cb">
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QComboBox::AdjustToContents</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1" colspan="2">
|
||||||
|
<widget class="QSpinBox" name="m_level_sb">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1" colspan="2">
|
||||||
|
<widget class="QPushButton" name="m_auto_ordering_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Position automatique</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1" colspan="2">
|
||||||
|
<widget class="QPushButton" name="m_group_terminals_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Grouper les bornes</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1" colspan="2">
|
||||||
|
<widget class="QPushButton" name="m_ungroup_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Degrouper les bornes</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="10" column="1" colspan="2">
|
||||||
|
<widget class="QPushButton" name="m_bridge_terminals_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Ponter les bornes</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="11" column="1" colspan="2">
|
||||||
|
<widget class="QPushButton" name="m_unbridge_terminals_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Déponter les bornes</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="m_data_tab">
|
<widget class="QWidget" name="m_data_tab">
|
||||||
@ -95,174 +319,6 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QWidget" name="widget" native="true">
|
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
|
||||||
<item row="4" column="0">
|
|
||||||
<widget class="QLabel" name="label_7">
|
|
||||||
<property name="text">
|
|
||||||
<string>Type :</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0">
|
|
||||||
<widget class="QLabel" name="label_8">
|
|
||||||
<property name="text">
|
|
||||||
<string>Fonction :</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="8" column="0" colspan="2">
|
|
||||||
<widget class="QPushButton" name="m_bridge_terminals_pb">
|
|
||||||
<property name="text">
|
|
||||||
<string>Ponter les bornes</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0" colspan="2">
|
|
||||||
<widget class="QPushButton" name="m_auto_ordering_pb">
|
|
||||||
<property name="text">
|
|
||||||
<string>Position automatique</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="9" column="0" colspan="2">
|
|
||||||
<widget class="QPushButton" name="m_unbridge_terminals_pb">
|
|
||||||
<property name="text">
|
|
||||||
<string>Déponter les bornes</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0" colspan="2">
|
|
||||||
<widget class="QPushButton" name="m_group_terminals_pb">
|
|
||||||
<property name="text">
|
|
||||||
<string>Grouper les bornes</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QLabel" name="label_6">
|
|
||||||
<property name="text">
|
|
||||||
<string>Étage :</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="10" column="1">
|
|
||||||
<widget class="KColorCombo" name="m_bridge_color_cb"/>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="0">
|
|
||||||
<widget class="QLabel" name="label_9">
|
|
||||||
<property name="text">
|
|
||||||
<string>LED :</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="QComboBox" name="m_type_cb">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Générique</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Fusible</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Sectionnable</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Diode</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Terre</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="1">
|
|
||||||
<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="7" column="0" colspan="2">
|
|
||||||
<widget class="Line" name="line_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QSpinBox" name="m_level_sb">
|
|
||||||
<property name="maximum">
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0" colspan="2">
|
|
||||||
<widget class="QPushButton" name="m_ungroup_pb">
|
|
||||||
<property name="text">
|
|
||||||
<string>Degrouper les bornes</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="1">
|
|
||||||
<widget class="QComboBox" name="m_led_cb">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Sans</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Avec</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="10" column="0">
|
|
||||||
<widget class="QLabel" name="label_10">
|
|
||||||
<property name="text">
|
|
||||||
<string>Couleur pont :</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="11" column="0">
|
|
||||||
<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>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
@ -272,6 +328,8 @@
|
|||||||
<header>kcolorcombo.h</header>
|
<header>kcolorcombo.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="../../../qelectrotech.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#include "../realterminal.h"
|
#include "../realterminal.h"
|
||||||
#include "../../qetgraphicsitem/terminalelement.h"
|
#include "../../qetgraphicsitem/terminalelement.h"
|
||||||
#include "../terminalstrip.h"
|
#include "../terminalstrip.h"
|
||||||
#include "terminalstriptreewidget.h"
|
|
||||||
|
|
||||||
TerminalStripTreeDockWidget::TerminalStripTreeDockWidget(QETProject *project, QWidget *parent) :
|
TerminalStripTreeDockWidget::TerminalStripTreeDockWidget(QETProject *project, QWidget *parent) :
|
||||||
QDockWidget(parent),
|
QDockWidget(parent),
|
||||||
@ -41,8 +40,6 @@ TerminalStripTreeDockWidget::TerminalStripTreeDockWidget(QETProject *project, QW
|
|||||||
#else
|
#else
|
||||||
ui->m_tree_view->expandAll();
|
ui->m_tree_view->expandAll();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
setupUndoConnections();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalStripTreeDockWidget::~TerminalStripTreeDockWidget()
|
TerminalStripTreeDockWidget::~TerminalStripTreeDockWidget()
|
||||||
@ -112,10 +109,10 @@ QString TerminalStripTreeDockWidget::currentInstallation() const
|
|||||||
|
|
||||||
if (auto item = ui->m_tree_view->currentItem())
|
if (auto item = ui->m_tree_view->currentItem())
|
||||||
{
|
{
|
||||||
if (item->type() == TerminalStripTreeWidget::Location) {
|
if (item->type() == Location) {
|
||||||
item = item->parent();
|
item = item->parent();
|
||||||
}
|
}
|
||||||
if (item->type() == TerminalStripTreeWidget::Installation) {
|
if (item->type() == Installation) {
|
||||||
return item->data(0, Qt::DisplayRole).toString();
|
return item->data(0, Qt::DisplayRole).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +131,7 @@ QString TerminalStripTreeDockWidget::currentLocation() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (auto item = ui->m_tree_view->currentItem()) {
|
if (auto item = ui->m_tree_view->currentItem()) {
|
||||||
if (item->type() == TerminalStripTreeWidget::Location) {
|
if (item->type() == Location) {
|
||||||
return item->data(0, Qt::DisplayRole).toString();
|
return item->data(0, Qt::DisplayRole).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,8 +154,8 @@ void TerminalStripTreeDockWidget::setSelectedStrip(TerminalStrip *strip) {
|
|||||||
QSharedPointer<RealTerminal> TerminalStripTreeDockWidget::currentRealTerminal() const
|
QSharedPointer<RealTerminal> TerminalStripTreeDockWidget::currentRealTerminal() const
|
||||||
{
|
{
|
||||||
if (auto item = ui->m_tree_view->currentItem()) {
|
if (auto item = ui->m_tree_view->currentItem()) {
|
||||||
if (item->type() == TerminalStripTreeWidget::Terminal) {
|
if (item->type() == Terminal) {
|
||||||
return m_uuid_terminal_H.value(item->data(0,TerminalStripTreeWidget::UUID_USER_ROLE).toUuid());
|
return m_uuid_terminal_H.value(item->data(0,UUID_USER_ROLE).toUuid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QSharedPointer<RealTerminal>();
|
return QSharedPointer<RealTerminal>();
|
||||||
@ -179,12 +176,12 @@ void TerminalStripTreeDockWidget::on_m_tree_view_currentItemChanged(QTreeWidgetI
|
|||||||
}
|
}
|
||||||
|
|
||||||
TerminalStrip *strip_ = nullptr;
|
TerminalStrip *strip_ = nullptr;
|
||||||
if (current->type() == TerminalStripTreeWidget::Strip) {
|
if (current->type() == Strip) {
|
||||||
strip_ = m_item_strip_H.value(current);
|
strip_ = m_item_strip_H.value(current);
|
||||||
}
|
}
|
||||||
else if (current->type() == TerminalStripTreeWidget::Terminal
|
else if (current->type() == Terminal
|
||||||
&& current->parent()
|
&& current->parent()
|
||||||
&& current->parent()->type() == TerminalStripTreeWidget::Strip) {
|
&& current->parent()->type() == Strip) {
|
||||||
strip_ = m_item_strip_H.value(current->parent());
|
strip_ = m_item_strip_H.value(current->parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,10 +202,10 @@ void TerminalStripTreeDockWidget::buildTree()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QStringList strl{title_};
|
QStringList strl{title_};
|
||||||
new QTreeWidgetItem(ui->m_tree_view, strl, TerminalStripTreeWidget::Root);
|
new QTreeWidgetItem(ui->m_tree_view, strl, Root);
|
||||||
|
|
||||||
QStringList ftstrl(tr("Bornes indépendante"));
|
QStringList ftstrl(tr("Bornes indépendante"));
|
||||||
new QTreeWidgetItem(ui->m_tree_view, ftstrl, TerminalStripTreeWidget::FreeTerminal);
|
new QTreeWidgetItem(ui->m_tree_view, ftstrl, FreeTerminal);
|
||||||
|
|
||||||
auto ts_vector = m_project->terminalStrip();
|
auto ts_vector = m_project->terminalStrip();
|
||||||
std::sort(ts_vector.begin(), ts_vector.end(), [](TerminalStrip *a, TerminalStrip *b) {
|
std::sort(ts_vector.begin(), ts_vector.end(), [](TerminalStrip *a, TerminalStrip *b) {
|
||||||
@ -242,7 +239,7 @@ QTreeWidgetItem* TerminalStripTreeDockWidget::addTerminalStrip(TerminalStrip *te
|
|||||||
}
|
}
|
||||||
if (!inst_qtwi) {
|
if (!inst_qtwi) {
|
||||||
QStringList inst_strl{installation_str};
|
QStringList inst_strl{installation_str};
|
||||||
inst_qtwi = new QTreeWidgetItem(root_item, inst_strl, TerminalStripTreeWidget::Installation);
|
inst_qtwi = new QTreeWidgetItem(root_item, inst_strl, Installation);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if location already exist
|
//Check if location already exist
|
||||||
@ -258,13 +255,13 @@ QTreeWidgetItem* TerminalStripTreeDockWidget::addTerminalStrip(TerminalStrip *te
|
|||||||
}
|
}
|
||||||
if (!loc_qtwi) {
|
if (!loc_qtwi) {
|
||||||
QStringList loc_strl{location_str};
|
QStringList loc_strl{location_str};
|
||||||
loc_qtwi = new QTreeWidgetItem(inst_qtwi, loc_strl, TerminalStripTreeWidget::Location);
|
loc_qtwi = new QTreeWidgetItem(inst_qtwi, loc_strl, Location);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add the terminal strip
|
//Add the terminal strip
|
||||||
QStringList name{terminal_strip->name()};
|
QStringList name{terminal_strip->name()};
|
||||||
auto strip_item = new QTreeWidgetItem(loc_qtwi, name, TerminalStripTreeWidget::Strip);
|
auto strip_item = new QTreeWidgetItem(loc_qtwi, name, Strip);
|
||||||
strip_item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, terminal_strip->uuid());
|
strip_item->setData(0, UUID_USER_ROLE, terminal_strip->uuid());
|
||||||
strip_item->setIcon(0, QET::Icons::TerminalStrip);
|
strip_item->setIcon(0, QET::Icons::TerminalStrip);
|
||||||
|
|
||||||
//Add child terminal of the strip
|
//Add child terminal of the strip
|
||||||
@ -282,8 +279,8 @@ QTreeWidgetItem* TerminalStripTreeDockWidget::addTerminalStrip(TerminalStrip *te
|
|||||||
text_.append(QStringLiteral(", ")).append(real_t->label());
|
text_.append(QStringLiteral(", ")).append(real_t->label());
|
||||||
}
|
}
|
||||||
const auto real_t = phy_t->realTerminals().at(0);
|
const auto real_t = phy_t->realTerminals().at(0);
|
||||||
auto terminal_item = new QTreeWidgetItem(strip_item, QStringList(text_), TerminalStripTreeWidget::Terminal);
|
auto terminal_item = new QTreeWidgetItem(strip_item, QStringList(text_), Terminal);
|
||||||
terminal_item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, phy_t->uuid());
|
terminal_item->setData(0, UUID_USER_ROLE, phy_t->uuid());
|
||||||
terminal_item->setIcon(0, QET::Icons::ElementTerminal);
|
terminal_item->setIcon(0, QET::Icons::ElementTerminal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,66 +315,14 @@ void TerminalStripTreeDockWidget::addFreeTerminal()
|
|||||||
{
|
{
|
||||||
QUuid uuid_ = terminal->uuid();
|
QUuid uuid_ = terminal->uuid();
|
||||||
QStringList strl{terminal->actualLabel()};
|
QStringList strl{terminal->actualLabel()};
|
||||||
auto item = new QTreeWidgetItem(free_terminal_item, strl, TerminalStripTreeWidget::Terminal);
|
auto item = new QTreeWidgetItem(free_terminal_item, strl, Terminal);
|
||||||
item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, uuid_.toString());
|
item->setData(0, UUID_USER_ROLE, uuid_.toString());
|
||||||
item->setIcon(0, QET::Icons::ElementTerminal);
|
item->setIcon(0, QET::Icons::ElementTerminal);
|
||||||
|
|
||||||
m_uuid_terminal_H.insert(uuid_, terminal->realTerminal());
|
m_uuid_terminal_H.insert(uuid_, terminal->realTerminal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalStripTreeDockWidget::setupUndoConnections()
|
|
||||||
{
|
|
||||||
connect(ui->m_tree_view, &TerminalStripTreeWidget::terminalAddedToStrip, this,
|
|
||||||
[=](QUuid terminal_uuid, QUuid strip_uuid)
|
|
||||||
{
|
|
||||||
auto terminal = m_uuid_terminal_H.value(terminal_uuid);
|
|
||||||
auto strip = m_uuid_strip_H.value(strip_uuid);
|
|
||||||
|
|
||||||
if (!terminal || !strip) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto undo = new AddTerminalToStripCommand(terminal, strip);
|
|
||||||
m_project->undoStack()->push(undo);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(ui->m_tree_view, &TerminalStripTreeWidget::terminalMovedFromStripToStrip, this,
|
|
||||||
[=] (QUuid terminal_uuid, QUuid old_strip_uuid, QUuid new_strip_uuid)
|
|
||||||
{
|
|
||||||
auto old_strip = m_uuid_strip_H.value(old_strip_uuid);
|
|
||||||
auto new_strip = m_uuid_strip_H.value(new_strip_uuid);
|
|
||||||
|
|
||||||
if (!old_strip || !new_strip) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto terminal = old_strip->physicalTerminal(terminal_uuid);
|
|
||||||
if (!terminal) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto undo = new MoveTerminalCommand(terminal, old_strip, new_strip);
|
|
||||||
m_project->undoStack()->push(undo);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(ui->m_tree_view, &TerminalStripTreeWidget::terminalRemovedFromStrip, this,
|
|
||||||
[=] (QUuid terminal_uuid, QUuid old_strip_uuid)
|
|
||||||
{
|
|
||||||
auto strip_ = m_uuid_strip_H.value(old_strip_uuid);
|
|
||||||
if (!strip_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto terminal_ = strip_->physicalTerminal(terminal_uuid);
|
|
||||||
if (!terminal_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto undo = new RemoveTerminalFromStripCommand(terminal_, strip_);
|
|
||||||
m_project->undoStack()->push(undo);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalStripTreeDockWidget::setCurrentStrip(TerminalStrip *strip)
|
void TerminalStripTreeDockWidget::setCurrentStrip(TerminalStrip *strip)
|
||||||
{
|
{
|
||||||
m_current_strip = strip;
|
m_current_strip = strip;
|
||||||
|
@ -33,6 +33,17 @@ namespace Ui {
|
|||||||
class TerminalStripTreeDockWidget : public QDockWidget
|
class TerminalStripTreeDockWidget : public QDockWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
enum TreeWidgetType{
|
||||||
|
Root,
|
||||||
|
Terminal,
|
||||||
|
FreeTerminal,
|
||||||
|
Installation,
|
||||||
|
Location,
|
||||||
|
Strip
|
||||||
|
};
|
||||||
|
//Role used for data in QTreeWidgetItem
|
||||||
|
static constexpr int UUID_USER_ROLE{Qt::UserRole + 1};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TerminalStripTreeDockWidget(QETProject *project, QWidget *parent = nullptr);
|
explicit TerminalStripTreeDockWidget(QETProject *project, QWidget *parent = nullptr);
|
||||||
@ -56,7 +67,6 @@ class TerminalStripTreeDockWidget : public QDockWidget
|
|||||||
void buildTree();
|
void buildTree();
|
||||||
QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip);
|
QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip);
|
||||||
void addFreeTerminal();
|
void addFreeTerminal();
|
||||||
void setupUndoConnections();
|
|
||||||
void setCurrentStrip(TerminalStrip *strip);
|
void setCurrentStrip(TerminalStrip *strip);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -16,10 +16,7 @@
|
|||||||
<widget class="QWidget" name="dockWidgetContents">
|
<widget class="QWidget" name="dockWidgetContents">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="TerminalStripTreeWidget" name="m_tree_view">
|
<widget class="QTreeWidget" name="m_tree_view">
|
||||||
<property name="dragDropMode">
|
|
||||||
<enum>QAbstractItemView::InternalMove</enum>
|
|
||||||
</property>
|
|
||||||
<property name="animated">
|
<property name="animated">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -36,13 +33,6 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>TerminalStripTreeWidget</class>
|
|
||||||
<extends>QTreeWidget</extends>
|
|
||||||
<header location="global">terminalstriptreewidget.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -1,137 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2021 The QElectroTech Team
|
|
||||||
This file is part of QElectroTech.
|
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
QElectroTech is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
#include "terminalstriptreewidget.h"
|
|
||||||
#include "../../qeticons.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QDrag>
|
|
||||||
#include <QMimeData>
|
|
||||||
#include <QDragMoveEvent>
|
|
||||||
|
|
||||||
TerminalStripTreeWidget::TerminalStripTreeWidget(QWidget *parent) :
|
|
||||||
QTreeWidget(parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
QStringList TerminalStripTreeWidget::mimeTypes() const
|
|
||||||
{
|
|
||||||
QStringList strl(QStringLiteral("application/x-qet-terminal-strip-tree-terminal-uuid"));
|
|
||||||
|
|
||||||
return strl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalStripTreeWidget::startDrag(Qt::DropActions supportedActions)
|
|
||||||
{
|
|
||||||
Q_UNUSED(supportedActions)
|
|
||||||
|
|
||||||
auto item = currentItem();
|
|
||||||
|
|
||||||
if (!item ||
|
|
||||||
item->type() != TerminalStripTreeWidget::Terminal) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDrag drag(this);
|
|
||||||
auto mime_data = new QMimeData();
|
|
||||||
mime_data->setData("application/x-qet-terminal-strip-tree-terminal-uuid", item->data(0, UUID_USER_ROLE).toString().toLatin1());
|
|
||||||
|
|
||||||
drag.setMimeData(mime_data);
|
|
||||||
drag.setPixmap(QET::Icons::ElementTerminal.pixmap(16,16));
|
|
||||||
drag.exec(Qt::MoveAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalStripTreeWidget::dragMoveEvent(QDragMoveEvent *event)
|
|
||||||
{
|
|
||||||
auto strl = event->mimeData()->formats();
|
|
||||||
if (strl.size() != 1 ||
|
|
||||||
strl.first() != "application/x-qet-terminal-strip-tree-terminal-uuid") {
|
|
||||||
event->ignore();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//Accepted move are :
|
|
||||||
//free terminal to terminal strip
|
|
||||||
//terminal strip to another terminal strip
|
|
||||||
//terminal strip to free terminal
|
|
||||||
//All other other move is ignored
|
|
||||||
QTreeWidget::dragMoveEvent(event);
|
|
||||||
|
|
||||||
auto overred_item = itemAt(event->pos());
|
|
||||||
auto dragged_item = currentItem();
|
|
||||||
if (!overred_item ||
|
|
||||||
!dragged_item ||
|
|
||||||
!dragged_item->parent()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//Ignore the event by default, we confirm it bellow if needed.
|
|
||||||
event->ignore();
|
|
||||||
|
|
||||||
//Move terminal
|
|
||||||
if (dragged_item->parent()->type() == FreeTerminal && //From free to strip
|
|
||||||
overred_item->type() == Strip) {
|
|
||||||
event->accept();
|
|
||||||
}
|
|
||||||
else if (dragged_item->parent()->type() == Strip) //From strip to ...
|
|
||||||
{
|
|
||||||
if (overred_item->type() == FreeTerminal) { //Free terminal
|
|
||||||
event->accept();
|
|
||||||
} else if (overred_item->type() == Strip && //Another strip
|
|
||||||
dragged_item->parent() != overred_item) {
|
|
||||||
event->accept();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalStripTreeWidget::dropEvent(QDropEvent *event)
|
|
||||||
{
|
|
||||||
auto overred_item = itemAt(event->pos());
|
|
||||||
auto dragged_item = currentItem();
|
|
||||||
if (!overred_item ||
|
|
||||||
!dragged_item ||
|
|
||||||
!dragged_item->parent()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto old_parent = dragged_item->parent();
|
|
||||||
old_parent->removeChild(dragged_item);
|
|
||||||
overred_item->addChild(dragged_item);
|
|
||||||
|
|
||||||
//Move terminal
|
|
||||||
if (old_parent->type() == FreeTerminal && //From free to strip
|
|
||||||
overred_item->type() == Strip) {
|
|
||||||
emit terminalAddedToStrip(QUuid(dragged_item->data(0, UUID_USER_ROLE).toString()),
|
|
||||||
QUuid(overred_item->data(0, UUID_USER_ROLE).toString()));
|
|
||||||
}
|
|
||||||
else if (old_parent->type() == Strip) //From strip to ...
|
|
||||||
{
|
|
||||||
if (overred_item->type() == FreeTerminal) //Free terminal
|
|
||||||
{
|
|
||||||
emit terminalRemovedFromStrip(QUuid(dragged_item->data(0, UUID_USER_ROLE).toString()),
|
|
||||||
QUuid(old_parent->data(0, UUID_USER_ROLE).toString()));
|
|
||||||
}
|
|
||||||
else if (overred_item->type() == Strip) //To another strip
|
|
||||||
{
|
|
||||||
emit terminalMovedFromStripToStrip(QUuid(dragged_item->data(0, UUID_USER_ROLE).toString()),
|
|
||||||
QUuid(old_parent->data(0, UUID_USER_ROLE).toString()),
|
|
||||||
QUuid(overred_item->data(0, UUID_USER_ROLE).toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Qt::DropActions TerminalStripTreeWidget::supportedDropActions() const {
|
|
||||||
return Qt::MoveAction;
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2006-2021 The QElectroTech Team
|
|
||||||
This file is part of QElectroTech.
|
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
QElectroTech is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
#ifndef TERMINALSTRIPTREEWIDGET_H
|
|
||||||
#define TERMINALSTRIPTREEWIDGET_H
|
|
||||||
|
|
||||||
#include <QTreeWidget>
|
|
||||||
#include <QUuid>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The TerminalStripTreeWidget class
|
|
||||||
* Derived class use to implement custom drag and drop
|
|
||||||
*/
|
|
||||||
class TerminalStripTreeWidget : public QTreeWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public :
|
|
||||||
enum TreeWidgetType{
|
|
||||||
Root,
|
|
||||||
Terminal,
|
|
||||||
FreeTerminal,
|
|
||||||
Installation,
|
|
||||||
Location,
|
|
||||||
Strip
|
|
||||||
};
|
|
||||||
|
|
||||||
//Role used for data in QTreeWidgetItem
|
|
||||||
static constexpr int UUID_USER_ROLE{Qt::UserRole + 1};
|
|
||||||
|
|
||||||
signals:
|
|
||||||
/**
|
|
||||||
* @brief terminalAddedToStrip
|
|
||||||
* Signal emited when a terminal is moved from free terminal to a terminals trip
|
|
||||||
*/
|
|
||||||
void terminalAddedToStrip(QUuid terminal_uuid, QUuid strip_uuid);
|
|
||||||
/**
|
|
||||||
* @brief terminalMovedFromStripToStrip
|
|
||||||
* Signam emitted when a terminal is moved from from a terminal stip to another one
|
|
||||||
*/
|
|
||||||
void terminalMovedFromStripToStrip(QUuid terminal_uuid, QUuid old_strip_uuid, QUuid new_strip_uuid);
|
|
||||||
/**
|
|
||||||
* @brief terminalRemovedFromStrip
|
|
||||||
* Signal emitted when a terminal is moved from a terminal strip to free terminal
|
|
||||||
*/
|
|
||||||
void terminalRemovedFromStrip(QUuid terminal_uuid, QUuid old_strip_uuid);
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
TerminalStripTreeWidget(QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
QStringList mimeTypes() const override;
|
|
||||||
void startDrag(Qt::DropActions supportedActions) override;
|
|
||||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
|
||||||
void dropEvent(QDropEvent *event) override;
|
|
||||||
Qt::DropActions supportedDropActions() const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TERMINALSTRIPTREEWIDGET_H
|
|
Loading…
x
Reference in New Issue
Block a user