diff --git a/sources/TerminalStrip/ui/terminalstripeditorwindow.cpp b/sources/TerminalStrip/ui/terminalstripeditorwindow.cpp
new file mode 100644
index 000000000..4add7fd06
--- /dev/null
+++ b/sources/TerminalStrip/ui/terminalstripeditorwindow.cpp
@@ -0,0 +1,53 @@
+/*
+ Copyright 2006-2022 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 .
+*/
+#include "terminalstripeditorwindow.h"
+#include "ui_terminalstripeditorwindow.h"
+#include "terminalstriptreedockwidget.h"
+
+/**
+ * @brief TerminalStripEditorWindow::TerminalStripEditorWindow
+ * @param project
+ * @param parent
+ */
+TerminalStripEditorWindow::TerminalStripEditorWindow(QETProject *project, QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::TerminalStripEditorWindow),
+ m_project(project)
+{
+ ui->setupUi(this);
+ addTreeDockWidget();
+}
+
+/**
+ * @brief TerminalStripEditorWindow::~TerminalStripEditorWindow
+ */
+TerminalStripEditorWindow::~TerminalStripEditorWindow()
+{
+ delete ui;
+}
+
+/**
+ * @brief TerminalStripEditorWindow::addTreeDockWidget
+ */
+void TerminalStripEditorWindow::addTreeDockWidget()
+{
+ m_tree_dock = new TerminalStripTreeDockWidget(m_project, this);
+ m_tree_dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+
+ addDockWidget(Qt::LeftDockWidgetArea, m_tree_dock);
+}
diff --git a/sources/TerminalStrip/ui/terminalstripeditorwindow.h b/sources/TerminalStrip/ui/terminalstripeditorwindow.h
new file mode 100644
index 000000000..ef0c06fb6
--- /dev/null
+++ b/sources/TerminalStrip/ui/terminalstripeditorwindow.h
@@ -0,0 +1,47 @@
+/*
+ Copyright 2006-2022 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 .
+*/
+#ifndef TERMINALSTRIPEDITORWINDOW_H
+#define TERMINALSTRIPEDITORWINDOW_H
+
+#include
+
+class QETProject;
+class TerminalStripTreeDockWidget;
+
+namespace Ui {
+ class TerminalStripEditorWindow;
+}
+
+class TerminalStripEditorWindow : public QMainWindow
+{
+ Q_OBJECT
+
+ public:
+ explicit TerminalStripEditorWindow(QETProject *project, QWidget *parent = nullptr);
+ ~TerminalStripEditorWindow();
+
+ private:
+ void addTreeDockWidget();
+
+ private:
+ Ui::TerminalStripEditorWindow *ui;
+ QETProject *m_project = nullptr;
+ TerminalStripTreeDockWidget *m_tree_dock;
+};
+
+#endif // TERMINALSTRIPEDITORWINDOW_H
diff --git a/sources/TerminalStrip/ui/terminalstripeditorwindow.ui b/sources/TerminalStrip/ui/terminalstripeditorwindow.ui
new file mode 100644
index 000000000..e655de457
--- /dev/null
+++ b/sources/TerminalStrip/ui/terminalstripeditorwindow.ui
@@ -0,0 +1,31 @@
+
+
+ TerminalStripEditorWindow
+
+
+
+ 0
+ 0
+ 800
+ 600
+
+
+
+ Gestionnaire de borniers
+
+
+
+
+
+
+
+
diff --git a/sources/TerminalStrip/ui/terminalstriptreedockwidget.cpp b/sources/TerminalStrip/ui/terminalstriptreedockwidget.cpp
new file mode 100644
index 000000000..d4c95a9a1
--- /dev/null
+++ b/sources/TerminalStrip/ui/terminalstriptreedockwidget.cpp
@@ -0,0 +1,234 @@
+/*
+ Copyright 2006-2022 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 .
+*/
+#include "terminalstriptreedockwidget.h"
+#include "ui_terminalstriptreedockwidget.h"
+
+#include "../UndoCommand/addterminaltostripcommand.h"
+#include "../../elementprovider.h"
+#include "../physicalterminal.h"
+#include "../../qeticons.h"
+#include "../../qetproject.h"
+#include "../realterminal.h"
+#include "../../qetgraphicsitem/terminalelement.h"
+#include "../terminalstrip.h"
+
+TerminalStripTreeDockWidget::TerminalStripTreeDockWidget(QETProject *project, QWidget *parent) :
+ QDockWidget(parent),
+ ui(new Ui::TerminalStripTreeDockWidget),
+ m_project(project)
+{
+ ui->setupUi(this);
+ buildTree();
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
+ ui->m_tree_view->expandRecursively(ui->m_tree_view->rootIndex());
+#else
+ ui->m_tree_view->expandAll();
+#endif
+
+ setupUndoConnections();
+}
+
+TerminalStripTreeDockWidget::~TerminalStripTreeDockWidget()
+{
+ delete ui;
+}
+
+/**
+ * @brief TerminalStripTreeDockWidget::buildTree
+ */
+void TerminalStripTreeDockWidget::buildTree()
+{
+ ui->m_tree_view->clear();
+
+ auto title_ = m_project->title();
+ if (title_.isEmpty()) {
+ title_ = tr("Projet sans titre");
+ }
+
+ QStringList strl{title_};
+ new QTreeWidgetItem(ui->m_tree_view, strl, TerminalStripTreeWidget::Root);
+
+ QStringList ftstrl(tr("Bornes indépendante"));
+ new QTreeWidgetItem(ui->m_tree_view, ftstrl, TerminalStripTreeWidget::FreeTerminal);
+
+ auto ts_vector = m_project->terminalStrip();
+ std::sort(ts_vector.begin(), ts_vector.end(), [](TerminalStrip *a, TerminalStrip *b) {
+ return a->name() < b->name();
+ });
+
+ for (const auto &ts : qAsConst(ts_vector)) {
+ addTerminalStrip(ts);
+ }
+ addFreeTerminal();
+}
+
+QTreeWidgetItem* TerminalStripTreeDockWidget::addTerminalStrip(TerminalStrip *terminal_strip)
+{
+ if (auto item = m_item_strip_H.key(terminal_strip)) {
+ return item;
+ }
+
+ auto root_item = ui->m_tree_view->topLevelItem(0);
+
+ //Check if installation already exist
+ //if not create a new one
+ auto installation_str = terminal_strip->installation();
+ QTreeWidgetItem *inst_qtwi = nullptr;
+ for (int i = 0 ; ichildCount() ; ++i) {
+ auto child_inst = root_item->child(i);
+ if (child_inst->data(0, Qt::DisplayRole).toString() == installation_str) {
+ inst_qtwi = child_inst;
+ break;
+ }
+ }
+ if (!inst_qtwi) {
+ QStringList inst_strl{installation_str};
+ inst_qtwi = new QTreeWidgetItem(root_item, inst_strl, TerminalStripTreeWidget::Installation);
+ }
+
+ //Check if location already exist
+ //if not create a new one
+ auto location_str = terminal_strip->location();
+ QTreeWidgetItem *loc_qtwi = nullptr;
+ for (int i = 0 ; ichildCount() ; ++i) {
+ auto child_loc = inst_qtwi->child(i);
+ if (child_loc->data(0, Qt::DisplayRole).toString() == location_str) {
+ loc_qtwi = child_loc;
+ break;
+ }
+ }
+ if (!loc_qtwi) {
+ QStringList loc_strl{location_str};
+ loc_qtwi = new QTreeWidgetItem(inst_qtwi, loc_strl, TerminalStripTreeWidget::Location);
+ }
+
+ //Add the terminal strip
+ QStringList name{terminal_strip->name()};
+ auto strip_item = new QTreeWidgetItem(loc_qtwi, name, TerminalStripTreeWidget::Strip);
+ strip_item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, terminal_strip->uuid());
+ strip_item->setIcon(0, QET::Icons::TerminalStrip);
+
+ //Add child terminal of the strip
+ for (auto i=0 ; iphysicalTerminalCount() ; ++i)
+ {
+ auto phy_t = terminal_strip->physicalTerminal(i);
+ if (phy_t->realTerminalCount())
+ {
+ QString text_;
+ for (const auto &real_t : phy_t->realTerminals())
+ {
+ if (text_.isEmpty())
+ text_ = real_t->label();
+ else
+ text_.append(QStringLiteral(", ")).append(real_t->label());
+ }
+ const auto real_t = phy_t->realTerminals().at(0);
+ auto terminal_item = new QTreeWidgetItem(strip_item, QStringList(text_), TerminalStripTreeWidget::Terminal);
+ terminal_item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, phy_t->uuid());
+ terminal_item->setIcon(0, QET::Icons::ElementTerminal);
+ }
+ }
+
+ m_item_strip_H.insert(strip_item, terminal_strip);
+ m_uuid_strip_H.insert(terminal_strip->uuid(), terminal_strip);
+ return strip_item;
+}
+
+/**
+ * @brief TerminalStripTreeDockWidget::addFreeTerminal
+ */
+void TerminalStripTreeDockWidget::addFreeTerminal()
+{
+ ElementProvider ep(m_project);
+ auto vector_ = ep.freeTerminal();
+
+ if (vector_.isEmpty()) {
+ return;
+ }
+
+ //Sort the terminal element by label
+ std::sort(vector_.begin(), vector_.end(), [](TerminalElement *a, TerminalElement *b) {
+ return a->actualLabel() < b->actualLabel();
+ });
+
+ auto free_terminal_item = ui->m_tree_view->topLevelItem(1);
+
+ for (const auto terminal : qAsConst(vector_))
+ {
+ QUuid uuid_ = terminal->uuid();
+ QStringList strl{terminal->actualLabel()};
+ auto item = new QTreeWidgetItem(free_terminal_item, strl, TerminalStripTreeWidget::Terminal);
+ item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, uuid_.toString());
+ item->setIcon(0, QET::Icons::ElementTerminal);
+
+ 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);
+ });
+}
diff --git a/sources/TerminalStrip/ui/terminalstriptreedockwidget.h b/sources/TerminalStrip/ui/terminalstriptreedockwidget.h
new file mode 100644
index 000000000..31d2f1015
--- /dev/null
+++ b/sources/TerminalStrip/ui/terminalstriptreedockwidget.h
@@ -0,0 +1,56 @@
+/*
+ Copyright 2006-2022 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 .
+*/
+#ifndef TERMINALSTRIPTREEDOCKWIDGET_H
+#define TERMINALSTRIPTREEDOCKWIDGET_H
+
+#include
+
+class QETProject;
+class QTreeWidgetItem;
+class TerminalStrip;
+class RealTerminal;
+
+namespace Ui {
+ class TerminalStripTreeDockWidget;
+}
+
+class TerminalStripTreeDockWidget : public QDockWidget
+{
+ Q_OBJECT
+
+ public:
+ explicit TerminalStripTreeDockWidget(QETProject *project, QWidget *parent = nullptr);
+ ~TerminalStripTreeDockWidget();
+
+ void buildTree();
+
+ private:
+ QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip);
+ void addFreeTerminal();
+ void setupUndoConnections();
+
+ private:
+ Ui::TerminalStripTreeDockWidget *ui;
+ QETProject *m_project = nullptr;
+
+ QHash m_item_strip_H;
+ QHash> m_uuid_terminal_H;
+ QHash> m_uuid_strip_H;
+};
+
+#endif // TERMINALSTRIPTREEDOCKWIDGET_H
diff --git a/sources/TerminalStrip/ui/terminalstriptreedockwidget.ui b/sources/TerminalStrip/ui/terminalstriptreedockwidget.ui
new file mode 100644
index 000000000..f04b5df29
--- /dev/null
+++ b/sources/TerminalStrip/ui/terminalstriptreedockwidget.ui
@@ -0,0 +1,48 @@
+
+
+ TerminalStripTreeDockWidget
+
+
+
+ 0
+ 0
+ 397
+ 542
+
+
+
+ Explorateur de bornier
+
+
+
+ -
+
+
+ QAbstractItemView::InternalMove
+
+
+ true
+
+
+ false
+
+
+
+ 1
+
+
+
+
+
+
+
+
+
+ TerminalStripTreeWidget
+ QTreeWidget
+ terminalstriptreewidget.h
+
+
+
+
+
diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp
index 64f8ebe4b..c3b19f058 100644
--- a/sources/qetdiagrameditor.cpp
+++ b/sources/qetdiagrameditor.cpp
@@ -43,6 +43,7 @@
#include "undocommand/rotatetextscommand.h"
#include "diagram.h"
#include "TerminalStrip/ui/terminalstripeditor.h"
+#include "TerminalStrip/ui/terminalstripeditorwindow.h"
#include "ui/diagrameditorhandlersizewidget.h"
#ifdef BUILD_WITHOUT_KF5
@@ -448,6 +449,9 @@ void QETDiagramEditor::setUpActions()
{
auto str = new TerminalStripEditor(project, this);
str->show();
+
+ auto tsew = new TerminalStripEditorWindow(project, this);
+ tsew->show();
}
});