mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Add undo command for add/remove a terminal strip
This commit is contained in:
parent
63429ab087
commit
573c0c236a
@ -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
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "addterminalstripcommand.h"
|
||||
#include "../../qetproject.h"
|
||||
#include "../terminalstrip.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
41
sources/TerminalStrip/UndoCommand/addterminalstripcommand.h
Normal file
41
sources/TerminalStrip/UndoCommand/addterminalstripcommand.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef ADDTERMINALSTRIPCOMMAND_H
|
||||
#define ADDTERMINALSTRIPCOMMAND_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include <QPointer>
|
||||
|
||||
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<TerminalStrip> m_strip;
|
||||
QPointer<QETProject> m_project;
|
||||
};
|
||||
|
||||
#endif // ADDTERMINALSTRIPCOMMAND_H
|
@ -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.
|
||||
|
@ -180,6 +180,8 @@ class QETProject : public QObject
|
||||
|
||||
QVector<TerminalStrip *> 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user