diff --git a/qelectrotech.pro b/qelectrotech.pro
index 9d848fea3..8915d1daf 100644
--- a/qelectrotech.pro
+++ b/qelectrotech.pro
@@ -162,7 +162,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
$$files(sources/factory/ui/*.h) \
$$files(sources/print/*.h) \
$$files(sources/TerminalStrip/*.h) \
- $$files(sources/TerminalStrip/ui/*.h)
+ $$files(sources/TerminalStrip/ui/*.h) \
+ $$files(sources/TerminalStrip/UndoCommand/*.h)
SOURCES += $$files(sources/*.cpp) \
$$files(sources/editor/*.cpp) \
@@ -197,7 +198,8 @@ SOURCES += $$files(sources/*.cpp) \
$$files(sources/factory/ui/*.cpp) \
$$files(sources/print/*.cpp) \
$$files(sources/TerminalStrip/*.cpp) \
- $$files(sources/TerminalStrip/ui/*.cpp)
+ $$files(sources/TerminalStrip/ui/*.cpp) \
+ $$files(sources/TerminalStrip/UndoCommand/*.cpp)
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
RESOURCES += qelectrotech.qrc
diff --git a/sources/TerminalStrip/UndoCommand/addterminalstripcommand.cpp b/sources/TerminalStrip/UndoCommand/addterminalstripcommand.cpp
new file mode 100644
index 000000000..fc88b41c6
--- /dev/null
+++ b/sources/TerminalStrip/UndoCommand/addterminalstripcommand.cpp
@@ -0,0 +1,50 @@
+/*
+ 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 .
+*/
+#include "addterminalstripcommand.h"
+#include "../../qetproject.h"
+#include "../terminalstrip.h"
+
+#include
+
+/**
+ * @brief AddTerminalStripCommand::AddTerminalStripCommand
+ * @param strip
+ * @param parent
+ */
+AddTerminalStripCommand::AddTerminalStripCommand(TerminalStrip *strip, QETProject *project, QUndoCommand *parent) :
+ QUndoCommand(parent),
+ m_strip(strip),
+ m_project(project)
+{
+ setText(QObject::tr("Ajouter un groupe de bornes"));
+}
+
+AddTerminalStripCommand::~AddTerminalStripCommand()
+{}
+
+void AddTerminalStripCommand::undo() {
+ if (m_project && m_strip) {
+ m_project->addTerminalStrip(m_strip);
+ }
+}
+
+void AddTerminalStripCommand::redo() {
+ if (m_project && m_strip) {
+ m_project->removeTerminalStrip(m_strip);
+ }
+}
diff --git a/sources/TerminalStrip/UndoCommand/addterminalstripcommand.h b/sources/TerminalStrip/UndoCommand/addterminalstripcommand.h
new file mode 100644
index 000000000..218e45599
--- /dev/null
+++ b/sources/TerminalStrip/UndoCommand/addterminalstripcommand.h
@@ -0,0 +1,41 @@
+/*
+ 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 .
+*/
+#ifndef ADDTERMINALSTRIPCOMMAND_H
+#define ADDTERMINALSTRIPCOMMAND_H
+
+#include
+#include
+
+class TerminalStrip;
+class QETProject;
+
+class AddTerminalStripCommand : public QUndoCommand
+{
+ public:
+ AddTerminalStripCommand(TerminalStrip *strip, QETProject *project, QUndoCommand *parent);
+ ~AddTerminalStripCommand() override;
+
+ void undo() override;
+ void redo() override;
+
+ private:
+ QPointer m_strip;
+ QPointer m_project;
+};
+
+#endif // ADDTERMINALSTRIPCOMMAND_H
diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp
index 2f555d906..8b9ab3cb2 100644
--- a/sources/qetproject.cpp
+++ b/sources/qetproject.cpp
@@ -1845,6 +1845,36 @@ TerminalStrip *QETProject::newTerminalStrip(QString installation, QString locati
return ts;
}
+/**
+ * @brief QETProject::addTerminalStrip
+ * Add \p strip to the terminal strip list of the project.
+ * The project of \p strip must this project
+ * @param strip
+ * @return true if successfully added
+ */
+bool QETProject::addTerminalStrip(TerminalStrip *strip)
+{
+ if (strip->parent() != this)
+ return false;
+
+ if (!m_terminal_strip_vector.contains(strip))
+ return true;
+
+ m_terminal_strip_vector.append(strip);
+ return true;
+}
+
+/**
+ * @brief QETProject::removeTerminalStrip
+ * Remove \p strip from the terminal strip list of this project.
+ * Strip is removed from the list but not deleted.
+ * @param strip
+ * @return true if successfully removed.
+ */
+bool QETProject::removeTerminalStrip(TerminalStrip *strip) {
+ return m_terminal_strip_vector.removeOne(strip);
+}
+
/**
Cette methode sert a reperer un projet vide, c-a-d un projet identique a ce
que l'on obtient en faisant Fichier > Nouveau.
diff --git a/sources/qetproject.h b/sources/qetproject.h
index f7cec3e0a..190383164 100644
--- a/sources/qetproject.h
+++ b/sources/qetproject.h
@@ -180,6 +180,8 @@ class QETProject : public QObject
QVector terminalStrip() const;
TerminalStrip * newTerminalStrip(QString installation = QString(), QString location = QString(), QString name = QString());
+ bool addTerminalStrip(TerminalStrip *strip);
+ bool removeTerminalStrip(TerminalStrip *strip);
public slots:
Diagram *addNewDiagram(int pos = -1);