Revert "Merge branch 'master' of ssh://git.tuxfamily.org/gitroot/qet/qet into terminal_strip"

This reverts commit 364bce618c, reversing
changes made to efb4a8dd71.
This commit is contained in:
joshua
2021-06-07 20:00:52 +02:00
parent 4615e6d060
commit bb26954bd4
27 changed files with 12 additions and 2814 deletions

View File

@@ -160,10 +160,7 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
$$files(sources/dataBase/*.h) \ $$files(sources/dataBase/*.h) \
$$files(sources/dataBase/ui/*.h) \ $$files(sources/dataBase/ui/*.h) \
$$files(sources/factory/ui/*.h) \ $$files(sources/factory/ui/*.h) \
$$files(sources/print/*.h) \ $$files(sources/print/*.h)
$$files(sources/TerminalStrip/*.h) \
$$files(sources/TerminalStrip/ui/*.h) \
$$files(sources/TerminalStrip/UndoCommand/*.h)
SOURCES += $$files(sources/*.cpp) \ SOURCES += $$files(sources/*.cpp) \
$$files(sources/editor/*.cpp) \ $$files(sources/editor/*.cpp) \
@@ -196,13 +193,7 @@ SOURCES += $$files(sources/*.cpp) \
$$files(sources/dataBase/*.cpp) \ $$files(sources/dataBase/*.cpp) \
$$files(sources/dataBase/ui/*.cpp) \ $$files(sources/dataBase/ui/*.cpp) \
$$files(sources/factory/ui/*.cpp) \ $$files(sources/factory/ui/*.cpp) \
$$files(sources/print/*.cpp) \ $$files(sources/print/*.cpp)
$$files(sources/TerminalStrip/*.cpp) \
$$files(sources/TerminalStrip/ui/*.cpp) \
$$files(sources/TerminalStrip/UndoCommand/*.cpp)
# Needed for use promote QTreeWidget in terminalstripeditor.ui
INCLUDEPATH += sources/TerminalStrip/ui
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
RESOURCES += qelectrotech.qrc RESOURCES += qelectrotech.qrc
@@ -228,8 +219,7 @@ FORMS += $$files(sources/richtext/*.ui) \
$$files(sources/qetgraphicsitem/ViewItem/ui/*.ui) \ $$files(sources/qetgraphicsitem/ViewItem/ui/*.ui) \
$$files(sources/dataBase/ui/*.ui) \ $$files(sources/dataBase/ui/*.ui) \
$$files(sources/factory/ui/*.ui) \ $$files(sources/factory/ui/*.ui) \
$$files(sources/print/*.ui) \ $$files(sources/print/*.ui)
$$files(sources/TerminalStrip/ui/*.ui)
UI_SOURCES_DIR = sources/ui/ UI_SOURCES_DIR = sources/ui/
UI_HEADERS_DIR = sources/ui/ UI_HEADERS_DIR = sources/ui/

View File

@@ -1,87 +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 "addterminalstripcommand.h"
#include "../../qetproject.h"
#include "../terminalstrip.h"
#include "../qetgraphicsitem/element.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->removeTerminalStrip(m_strip);
}
}
void AddTerminalStripCommand::redo() {
if (m_project && m_strip) {
m_project->addTerminalStrip(m_strip);
}
}
RemoveTerminalStripCommand::RemoveTerminalStripCommand(TerminalStrip *strip,
QETProject *project,
QUndoCommand *parent) :
QUndoCommand(parent),
m_strip(strip),
m_project(project),
m_elements(strip->terminalElement())
{
setText(QObject::tr("Supprimer un groupe de bornes"));
}
RemoveTerminalStripCommand::~RemoveTerminalStripCommand()
{}
void RemoveTerminalStripCommand::undo()
{
if (m_project && m_strip) {
for (auto elmt : m_elements) {
m_strip->addTerminal(elmt);
}
m_project->addTerminalStrip(m_strip);
}
}
void RemoveTerminalStripCommand::redo()
{
if (m_project && m_strip) {
for (auto elmt : m_elements) {
m_strip->removeTerminal(elmt);
}
m_project->removeTerminalStrip(m_strip);
}
}

View File

@@ -1,57 +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 ADDTERMINALSTRIPCOMMAND_H
#define ADDTERMINALSTRIPCOMMAND_H
#include <QUndoCommand>
#include <QPointer>
class TerminalStrip;
class QETProject;
class Element;
class AddTerminalStripCommand : public QUndoCommand
{
public:
AddTerminalStripCommand(TerminalStrip *strip, QETProject *project, QUndoCommand *parent = nullptr);
~AddTerminalStripCommand() override;
void undo() override;
void redo() override;
private:
QPointer<TerminalStrip> m_strip;
QPointer<QETProject> m_project;
};
class RemoveTerminalStripCommand : public QUndoCommand
{
public:
RemoveTerminalStripCommand(TerminalStrip *strip, QETProject *project, QUndoCommand *parent = nullptr);
~RemoveTerminalStripCommand() override;
void undo() override;
void redo() override;
private:
QPointer<TerminalStrip> m_strip;
QPointer<QETProject> m_project;
QVector<QPointer<Element>> m_elements;
};
#endif // ADDTERMINALSTRIPCOMMAND_H

View File

@@ -1,156 +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 "addterminaltostripcommand.h"
#include "../../qetgraphicsitem/terminalelement.h"
/**
* @brief AddTerminalToStripCommand::AddTerminalToStripCommand
* Add \p terminal to \p strip
* @param terminal : terminal to add to strip
* @param strip : terminal strip where terminal must be added
* @param parent : parent undo command
*/
AddTerminalToStripCommand::AddTerminalToStripCommand(TerminalElement *terminal, TerminalStrip *strip, QUndoCommand *parent) :
QUndoCommand(parent),
m_terminal(terminal),
m_new_strip(strip),
m_operation(Operation::add)
{
auto t_label = terminal->actualLabel();
auto ts_name = strip->name();
auto str_1 = t_label.isEmpty() ? QObject::tr("Ajouter une borne") :
QObject::tr("Ajouter la borne %1").arg(t_label);
auto str_2 = ts_name.isEmpty() ? QObject::tr("à un groupe de bornes") :
QObject::tr("au groupe de bornes %1").arg(ts_name);
setText(str_1 + " " + str_2);
}
/**
* @brief AddTerminalToStripCommand::AddTerminalToStripCommand
* Move \p terminal from \p old_strip to \p new_strip
* @param terminal : terminal to move
* @param old_strip : terminal where start the move
* @param new_strip : terminal where finish the move
* @param parent : parent undo command
*/
AddTerminalToStripCommand::AddTerminalToStripCommand(TerminalElement *terminal, TerminalStrip *old_strip,
TerminalStrip *new_strip, QUndoCommand *parent) :
QUndoCommand(parent),
m_terminal(terminal),
m_old_strip(old_strip),
m_new_strip(new_strip),
m_operation(Operation::move)
{
auto t_label = terminal->actualLabel();
auto old_ts_name = old_strip->name();
auto new_ts_name = new_strip->name();
auto str_1 = t_label.isEmpty() ? QObject::tr("Déplacer une borne") :
QObject::tr("Déplacer la borne %1").arg(t_label);
auto str_2 = old_ts_name.isEmpty() ? QObject::tr("d'un groupe de bornes") :
QObject::tr("du groupe de bornes %1").arg(old_ts_name);
auto str_3 = new_ts_name.isEmpty() ? QObject::tr("à un autre groupe de bornes") :
QObject::tr("au groupe de bornes %1").arg(new_ts_name);
setText(str_1 + " " + str_2 + " " + str_3);
}
AddTerminalToStripCommand::~AddTerminalToStripCommand()
{}
/**
* @brief AddTerminalToStripCommand::undo
* Reimplemented from QUndoCommand
*/
void AddTerminalToStripCommand::undo()
{
if (!m_terminal ||
!m_new_strip) {
return;
}
m_new_strip->removeTerminal(m_terminal);
if ( m_operation == Operation::move &&
m_old_strip) {
m_old_strip->addTerminal(m_terminal);
}
}
/**
* @brief AddTerminalToStripCommand::redo
* Reimplemented from QUndoCommand
*/
void AddTerminalToStripCommand::redo()
{
if (!m_terminal ||
!m_new_strip) {
return;
}
if (m_operation == Operation::move &&
m_old_strip) {
m_old_strip->removeTerminal(m_terminal);
}
m_new_strip->addTerminal(m_terminal);
}
/**
* @brief RemoveTerminalFromStripCommand::RemoveTerminalFromStripCommand
* @param terminal
* @param strip
* @param parent
*/
RemoveTerminalFromStripCommand::RemoveTerminalFromStripCommand(TerminalElement *terminal,
TerminalStrip *strip,
QUndoCommand *parent) :
QUndoCommand(parent),
m_terminal(terminal),
m_strip(strip)
{
auto t_label = terminal->actualLabel();
auto strip_name = strip->name();
auto str_1 = t_label.isEmpty() ? QObject::tr("Enlever une borne") :
QObject::tr("Enlever la borne %1").arg(t_label);
auto str_2 = strip_name.isEmpty() ? QObject::tr("d'un groupe de bornes") :
QObject::tr("du groupe de bornes %1").arg(strip_name);
setText(str_1 + " " + str_2);
}
void RemoveTerminalFromStripCommand::undo()
{
if (m_terminal && m_strip) {
m_strip->addTerminal(m_terminal);
}
}
void RemoveTerminalFromStripCommand::redo()
{
if (m_terminal && m_strip) {
m_strip->removeTerminal(m_terminal);
}
}

View File

@@ -1,79 +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 ADDTERMINALTOSTRIPCOMMAND_H
#define ADDTERMINALTOSTRIPCOMMAND_H
#include <QUndoCommand>
#include <QPointer>
class TerminalElement;
class TerminalStrip;
/**
* @brief The AddTerminalToStripCommand class
* Add a terminal element to a terminal strip
* Two cases are handled :
* Add free terminal to strip,
* Move terminal from strip to another strip
*/
class AddTerminalToStripCommand : public QUndoCommand
{
public:
AddTerminalToStripCommand(TerminalElement *terminal, TerminalStrip *strip, QUndoCommand *parent = nullptr);
AddTerminalToStripCommand(TerminalElement *terminal, TerminalStrip *old_strip,
TerminalStrip *new_strip, QUndoCommand *parent = nullptr);
~AddTerminalToStripCommand() override;
void undo() override;
void redo() override;
private:
enum Operation{
none,
add,
move,
};
QPointer<TerminalElement> m_terminal;
QPointer<TerminalStrip> m_old_strip;
QPointer<TerminalStrip> m_new_strip;
Operation m_operation = Operation::none;
};
/**
* @brief The RemoveTerminalFromStripCommand class
* Remove a terminal from a terminal strip.
* The removed terminal become free.
*/
class RemoveTerminalFromStripCommand : public QUndoCommand
{
public:
RemoveTerminalFromStripCommand (TerminalElement *terminal, TerminalStrip *strip, QUndoCommand *parent = nullptr);
~RemoveTerminalFromStripCommand() override {}
void undo() override;
void redo() override;
private:
QPointer<TerminalElement> m_terminal;
QPointer<TerminalStrip> m_strip;
};
#endif // ADDTERMINALTOSTRIPCOMMAND_H

View File

@@ -1,43 +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 "changeterminalstripdata.h"
ChangeTerminalStripData::ChangeTerminalStripData(TerminalStrip *strip,
const TerminalStripData &data,
QUndoCommand *parent) :
QUndoCommand(parent),
m_strip(strip),
m_new_data(data)
{
setText(QObject::tr("Modifier les proriétés d'un groupe de bornes"));
m_old_data = strip->data();
}
void ChangeTerminalStripData::undo()
{
if (m_strip) {
m_strip->setData(m_old_data);
}
}
void ChangeTerminalStripData::redo()
{
if (m_strip) {
m_strip->setData(m_new_data);
}
}

View File

@@ -1,41 +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 CHANGETERMINALSTRIPDATA_H
#define CHANGETERMINALSTRIPDATA_H
#include <QUndoCommand>
#include "../terminalstripdata.h"
#include "../terminalstrip.h"
/**
* @brief The ChangeTerminalStripData class
*/
class ChangeTerminalStripData : public QUndoCommand
{
public:
ChangeTerminalStripData(TerminalStrip *strip, const TerminalStripData &data, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
QPointer<TerminalStrip> m_strip;
TerminalStripData m_old_data, m_new_data;
};
#endif // CHANGETERMINALSTRIPDATA_H

View File

@@ -1,634 +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 "terminalstrip.h"
#include "../qetproject.h"
#include "../qetgraphicsitem/element.h"
#include "../qetgraphicsitem/terminalelement.h"
#include "../elementprovider.h"
#include "../qetxml.h"
using shared_real_terminal = QSharedPointer<RealTerminal>;
using shared_physical_terminal = QSharedPointer<PhysicalTerminal>;
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/**
* @brief The RealTerminal class
* Represent a real terminal.
* A real terminal can be a drawed terminal in a folio
* or a terminal set by user but not present
* on any folio (for example a reserved terminal).
*/
class RealTerminal
{
public :
/**
* @brief RealTerminal
* @param parent_strip : parent terminal strip
* @param terminal : terminal element (if any) in a folio
*/
RealTerminal(TerminalStrip *parent_strip, Element *terminal = nullptr) :
m_element(terminal),
m_parent_terminal_strip(parent_strip)
{}
/**
* @brief isElement
* @return true if this real terminal is linked to a terminal element
*/
bool isElement() const {
return m_element.isNull() ? false : true;
}
/**
* @brief element
* @return the element linked to this real terminal
* or nullptr if not linked to an Element.
*/
Element *element() const {
return m_element.data();
}
/**
* @brief label
* @return the label of this real terminal
*/
QString label() const {
if (!m_element.isNull()) {
return m_element->actualLabel();
} else {
return QStringLiteral("");
}
}
/**
* @brief elementUuid
* @return if this real terminal is an element
* in a folio, return the uuid of the element
* else return a null uuid.
*/
QUuid elementUuid() const {
if (!m_element.isNull()) {
return m_element->uuid();
} else {
return QUuid();
}
}
/**
* @brief uuid
* @return the uuid of this real terminal
*/
QUuid uuid() const {
return m_uuid;
}
static QString xmlTagName() {
return QStringLiteral("real_terminal");
}
/**
* @brief toXml
* @param parent_document
* @return this real terminal to xml
*/
QDomElement toXml(QDomDocument &parent_document) const
{
auto root_elmt = parent_document.createElement(this->xmlTagName());
root_elmt.setAttribute("is_draw", m_element ? "true" : "false");
root_elmt.setAttribute("uuid", m_element ? m_element->uuid().toString() :
m_uuid.toString());
return root_elmt;
}
/**
* @brief fromXml
* @param xml_element
* @return
*/
bool fromXml(QDomElement xml_element, const QVector<TerminalElement *> &terminal_vector)
{
if (xml_element.tagName() != xmlTagName()) {
return true;
}
auto is_draw = xml_element.attribute(QStringLiteral("is_draw")) == QLatin1String("true")
? true : false;
auto uuid_ = QUuid::fromString(xml_element.attribute(QStringLiteral("uuid")));
if (is_draw) {
for (auto terminal : terminal_vector) {
if (terminal->uuid() == uuid_)
{
m_element = terminal;
break;
}
}
} else {
m_uuid = uuid_;
}
return true;
}
private :
QPointer<Element> m_element;
QPointer<TerminalStrip> m_parent_terminal_strip;
QUuid m_uuid = QUuid::createUuid();
};
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/**
* @brief The PhysicalTerminal class
* Represent a physical terminal.
* A physical terminal is composed a least by one real terminal.
* When a physical terminal have more than one real terminal
* that mean the physical terminal have levels (one by real terminal).
* The index of terminals returned by the function terminals()
* is the same as the real level of the physical terminal, the index are from back to front.
*
* Example for a 3 levels terminal.
* index 0 = back (mounting plate)
* index 1 = middle
* index 2 = front (electrical cabinet door)
*
* m
* o _
* u | |
* n | | _
* t | || |
* i | || | _
* n | || || | d
* g |0||1||2| o
* | || ||_| o
* p | || | r
* l | ||_|
* a | |
* t |_|
* e
*
*/
class PhysicalTerminal
{
public:
/**
* @brief PhysicalTerminal
* @param parent_strip : Parent terminal strip
* @param terminals : A vector of real terminals
* who compose this physical terminal.
* \p terminals must have at least one terminal
*/
PhysicalTerminal(TerminalStrip *parent_strip,
QVector<shared_real_terminal> terminals) :
m_parent_terminal_strip(parent_strip),
m_real_terminal(terminals)
{}
/**
* @brief setTerminals
* Set the real terminal of this physical terminal
* the order of the terminal in \p terminals represent
* the level index.
* @param terminals
*/
void setTerminals(QVector<shared_real_terminal> terminals) {
m_real_terminal = terminals;
}
/**
* @brief levelCount
* @return the number of level of this terminal
*/
int levelCount() const {
return m_real_terminal.size();
}
/**
* @brief terminals
* @return A vector of real terminal who compose this physical terminal
*/
QVector<shared_real_terminal> terminals() const {
return m_real_terminal;
}
static QString xmlTagName() {
return QStringLiteral("physical_terminal");
}
/**
* @brief toXml
* @param parent_document
* @return this physical terminal to xml
*/
QDomElement toXml(QDomDocument &parent_document) const
{
auto root_elmt = parent_document.createElement(this->xmlTagName());
for (auto &real_t : m_real_terminal) {
root_elmt.appendChild(real_t->toXml(parent_document));
}
return root_elmt;
}
private:
QPointer<TerminalStrip> m_parent_terminal_strip;
QVector<shared_real_terminal> m_real_terminal;
};
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/**
* @brief TerminalStrip::TerminalStrip
* @param project
*/
TerminalStrip::TerminalStrip(QETProject *project) :
QObject(project),
m_project(project)
{}
/**
* @brief TerminalStrip::TerminalStrip
* @param installation
* @param location
* @param name
* @param project
*/
TerminalStrip::TerminalStrip(const QString &installation, const QString &location, const QString &name, QETProject *project) :
QObject(project),
m_project(project)
{
m_data.m_installation = installation;
m_data.m_location = location;
m_data.m_name = name;
}
void TerminalStrip::setInstallation(const QString &installation) {
m_data.m_installation = installation;
}
void TerminalStrip::setLocation(const QString &location) {
m_data.m_location = location;
}
void TerminalStrip::setName(const QString &name) {
m_data.m_name = name;
}
void TerminalStrip::setComment(const QString &comment) {
m_data.m_comment = comment;
}
void TerminalStrip::setDescription(const QString &description) {
m_data.m_description = description;
}
/**
* @brief TerminalStrip::data
* @return The internal data of this strip
*/
TerminalStripData TerminalStrip::data() const {
return m_data;
}
/**
* @brief TerminalStrip::setData
* The internal data of this strip to data.
* the uuid of the new data is set to the uuid
* of the previous data to keep the uuid
* of the terminal strip unchanged
* @param data
*/
void TerminalStrip::setData(const TerminalStripData &data)
{
auto uuid_ = m_data.m_uuid;
m_data = data;
m_data.m_uuid = uuid_;
}
/**
* @brief TerminalStrip::addTerminal
* Add terminal to this terminal strip
* @param terminal
* @return true if the terminal was successfully added.
* Return false, if terminal already exist.
* Return false, if terminal is not a terminal element.
*/
bool TerminalStrip::addTerminal(Element *terminal)
{
if (m_terminal_elements_vector.contains(terminal)) {
return false;
}
if (terminal->elementData().m_type != ElementData::Terminale) {
return false;
}
m_terminal_elements_vector.append(terminal);
//Create the real terminal
shared_real_terminal real_terminal(new RealTerminal(this, terminal));
m_real_terminals.append(real_terminal);
//Create a new single level physical terminal
shared_physical_terminal physical_terminal(
new PhysicalTerminal(this,
QVector<shared_real_terminal>{real_terminal}));
m_physical_terminals.append(physical_terminal);
static_cast<TerminalElement *>(terminal)->setParentTerminalStrip(this);
return true;
}
/**
* @brief TerminalStrip::removeTerminal
* Remove terminal from this terminal strip
* @param terminal
* @return true if terminal was successfully removed
*/
bool TerminalStrip::removeTerminal(Element *terminal)
{
if (m_terminal_elements_vector.contains(terminal))
{
m_terminal_elements_vector.removeOne(terminal);
//Get the real and physical terminal associated to @terminal
if (auto real_terminal = realTerminal(terminal))
{
if (auto physical_terminal = physicalTerminal(real_terminal))
{
if (physical_terminal->levelCount() == 1) {
m_physical_terminals.removeOne(physical_terminal);
} else {
auto v = physical_terminal->terminals();
v.removeOne(real_terminal);
physical_terminal->setTerminals(v);
}
}
m_real_terminals.removeOne(real_terminal);
static_cast<TerminalElement *>(terminal)->setParentTerminalStrip(nullptr);
return true;
}
//There is no reason to be here, but in case of....
return false;
}
return false;
}
/**
* @brief TerminalStrip::haveTerminal
* @param terminal
* @return true if \p terminal belong to this strip
*/
bool TerminalStrip::haveTerminal(Element *terminal) {
return m_terminal_elements_vector.contains(terminal);
}
/**
* @brief TerminalStrip::physicalTerminalCount
* @return the number of physical terminal.
* A physical terminal is the representation of a real electrical terminal.
* Notice that a physical terminal can have level (like in real life)
*/
int TerminalStrip::physicalTerminalCount() const {
return m_physical_terminals.size();
}
TerminalStripIndex TerminalStrip::index(int index)
{
TerminalStripIndex tsi_;
if (index < 0 ||
index >= m_physical_terminals.size()) {
return tsi_;
}
auto phy_term = m_physical_terminals.at(index);
for(auto &real_term : phy_term->terminals()) {
tsi_.m_label.append(real_term->label());
tsi_.m_uuid.append(real_term->elementUuid());
tsi_.m_is_element.append(real_term->isElement());
tsi_.m_element.append(static_cast<TerminalElement*>(real_term->element()));
}
tsi_.m_valid = true;
return tsi_;
}
/**
* @brief TerminalStrip::terminalElement
* @return A vector of all terminal element owned by this strip
*/
QVector<QPointer<Element> > TerminalStrip::terminalElement() const {
return m_terminal_elements_vector;
}
/**
* @brief TerminalStrip::toXml
* @param parent_document
* @return
*/
QDomElement TerminalStrip::toXml(QDomDocument &parent_document)
{
auto root_elmt = parent_document.createElement(this->xmlTagName());
root_elmt.appendChild(m_data.toXml(parent_document));
//Undrawed terminals
auto xml_layout = parent_document.createElement("layout");
for (auto &phy_t : m_physical_terminals) {
xml_layout.appendChild(phy_t->toXml(parent_document));
}
root_elmt.appendChild(xml_layout);
return root_elmt;
}
/**
* @brief TerminalStrip::fromXml
* @param xml_element
* @return Set up this terminal strip from the xml description \p xml_element
*/
bool TerminalStrip::fromXml(QDomElement &xml_element)
{
if (xml_element.tagName() != xmlTagName()) {
return false;
}
//Read terminal strip data
auto xml_data = xml_element.firstChildElement(m_data.xmlTagName());
if (!xml_data.isNull()) {
m_data.fromXml(xml_data);
}
//Read layout
auto xml_layout = xml_element.firstChildElement(QStringLiteral("layout"));
if (!xml_layout.isNull())
{
//Get all free elements terminal of the project
ElementProvider ep(m_project);
auto free_terminals = ep.freeTerminal();
//Read each physical terminal
for(auto &xml_physical : QETXML::findInDomElement(xml_layout, PhysicalTerminal::xmlTagName()))
{
QVector<shared_real_terminal> real_t_vector;
//Read each real terminal of the current physical terminal of the loop
for (auto &xml_real : QETXML::findInDomElement(xml_physical, RealTerminal::xmlTagName()))
{
shared_real_terminal real_t(new RealTerminal(this));
real_t->fromXml(xml_real, free_terminals);
if(real_t->isElement())
{
m_terminal_elements_vector.append(real_t->element());
static_cast<TerminalElement*>(real_t->element())->setParentTerminalStrip(this);
}
real_t_vector.append(real_t);
}
shared_physical_terminal phy_t(new PhysicalTerminal(this, real_t_vector));
m_physical_terminals.append(phy_t);
m_real_terminals.append(real_t_vector);
}
}
return true;
}
/**
* @brief TerminalStrip::realTerminal
* @param terminal
* @return the real terminal linked to \p terminal
* the returned QSharedPointer can be null.
*/
QSharedPointer<RealTerminal> TerminalStrip::realTerminal(Element *terminal)
{
shared_real_terminal rt;
for (auto &real : qAsConst(m_real_terminals)) {
if (real->element() == terminal) {
return real;
}
}
return rt;
}
/**
* @brief TerminalStrip::physicalTerminal
* @param terminal
* @return the physical terminal linked to \p terminal.
* The returned QSharedPointer can be null.
*/
QSharedPointer<PhysicalTerminal> TerminalStrip::physicalTerminal(QSharedPointer<RealTerminal> terminal)
{
shared_physical_terminal pt;
for (auto &physical : qAsConst(m_physical_terminals))
{
if (physical->terminals().contains(terminal))
{
pt = physical;
break;
}
}
return pt;
}
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
bool TerminalStripIndex::isValid() const
{
return m_valid;
}
QString TerminalStripIndex::label(int level) const
{
if (level<0 ||
level >= m_label.size()) {
return QStringLiteral("");
}
return m_label.at(level);
}
QUuid TerminalStripIndex::uuid(int level) const
{
if (level<0 ||
level >= m_uuid.size()) {
return QUuid();
}
return m_uuid.at(level);
}
bool TerminalStripIndex::isElement(int level) const
{
if (level<0 ||
level >= m_is_element.size()) {
return false;
}
return m_is_element.at(level);
}
TerminalElement *TerminalStripIndex::element(int level) const
{
if (level<0 ||
level >= m_element.size()) {
return nullptr;
}
return m_element.at(level);
}

View File

@@ -1,113 +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 TERMINALSTRIP_H
#define TERMINALSTRIP_H
#include <QObject>
#include <QPointer>
#include "terminalstripdata.h"
class Element;
class RealTerminal;
class QETProject;
class PhysicalTerminal;
class TerminalStripIndex;
class TerminalElement;
/**
* @brief The TerminalStrip class
* This class hold all the datas and configurations
* of a terminal strip (but the not the visual aspect).
* A terminal strip have some informations (name comment etc...)
* and is composed by terminals (draw in a diagram or described in the terminal strip)
*/
class TerminalStrip : public QObject
{
Q_OBJECT
public:
TerminalStrip(QETProject *project);
TerminalStrip(const QString &installation,
const QString &location,
const QString &name,
QETProject *project);
void setInstallation(const QString &installation);
QString installation() const {return m_data.m_installation;}
void setLocation(const QString &location);
QString location() const {return m_data.m_location;}
void setName(const QString &name);
QString name() const {return m_data.m_name;}
void setComment(const QString &comment);
QString comment() const {return m_data.m_comment;}
void setDescription(const QString &description);
QString description() const {return m_data.m_description;}
QUuid uuid() const {return m_data.m_uuid;}
TerminalStripData data() const;
void setData(const TerminalStripData &data);
bool addTerminal (Element *terminal);
bool removeTerminal (Element *terminal);
bool haveTerminal (Element *terminal);
int physicalTerminalCount() const;
TerminalStripIndex index(int index = 0);
QVector<QPointer<Element>> terminalElement() const;
static QString xmlTagName() {return QStringLiteral("terminal_strip");}
QDomElement toXml(QDomDocument &parent_document);
bool fromXml(QDomElement &xml_element);
private:
QSharedPointer<RealTerminal> realTerminal(Element *terminal);
QSharedPointer<PhysicalTerminal> physicalTerminal(QSharedPointer<RealTerminal> terminal);
private:
TerminalStripData m_data;
QPointer<QETProject> m_project;
QVector<QPointer<Element>> m_terminal_elements_vector;
QVector<QSharedPointer<RealTerminal>> m_real_terminals;
QVector<QSharedPointer<PhysicalTerminal>> m_physical_terminals;
};
class TerminalStripIndex
{
friend class TerminalStrip;
private :
TerminalStripIndex () {}
TerminalStripIndex (TerminalStripIndex *) {}
public:
bool isValid() const;
QString label(int level = 0) const;
QUuid uuid(int level = 0) const;
bool isElement(int level = 0) const;
TerminalElement *element(int level = 0) const;
private:
QVector<QString> m_label;
QVector<QUuid> m_uuid;
bool m_valid = false;
QVector<bool> m_is_element;
QVector<TerminalElement *> m_element;
};
#endif // TERMINALSTRIP_H

View File

@@ -1,102 +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 "terminalstripdata.h"
#include "../qetxml.h"
#include <QDebug>
TerminalStripData::TerminalStripData()
{
}
QDomElement TerminalStripData::toXml(QDomDocument &xml_document) const
{
auto root_elmt = xml_document.createElement(this->xmlTagName());
root_elmt.setAttribute(QStringLiteral("uuid"), m_uuid.toString());
auto info_elmt = xml_document.createElement("informations");
root_elmt.appendChild(info_elmt);
if (!m_installation.isEmpty()) {
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("installation"), m_installation));
}
if (!m_location.isEmpty()) {
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("location"), m_location));
}
if (!m_name.isEmpty()) {
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("name"), m_name));
}
if (!m_comment.isEmpty()) {
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("comment"), m_comment));
}
if (!m_description.isEmpty()) {
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("description"), m_description));
}
return root_elmt;
}
bool TerminalStripData::fromXml(const QDomElement &xml_element)
{
if (xml_element.tagName() != this->xmlTagName())
{
qDebug() << "TerminalStripData::fromXml : failed to load from xml " \
"due to wrong tag name. Expected " << this->xmlTagName() << " used " << xml_element.tagName();
return false;
}
m_uuid.fromString(xml_element.attribute("uuid"));
for (auto &xml_info :
QETXML::findInDomElement(xml_element.firstChildElement("informations"),
QStringLiteral("information")))
{
auto name = xml_info.attribute("name");
auto value = xml_info.text();
if (name == QStringLiteral("installation")) { m_installation = value;}
else if (name == QStringLiteral("location")) {m_location = value;}
else if (name == QStringLiteral("name")) {m_name = value;}
else if (name == QStringLiteral("comment")) {m_comment = value;}
else if (name == QStringLiteral("description")) {m_description = value;}
}
return true;
}
TerminalStripData &TerminalStripData::operator=(const TerminalStripData &other)
{
m_installation = other.m_installation;
m_location = other.m_location;
m_name = other.m_name;
m_comment = other.m_comment;
m_description = other.m_description;
m_uuid = other.m_uuid;
return *this;
}
QDomElement TerminalStripData::infoToXml(QDomDocument &xml_doc, const QString &name, const QString &value)
{
auto xml_elmt = xml_doc.createElement("information");
xml_elmt.setAttribute(QStringLiteral("name"), name);
xml_elmt.appendChild(xml_doc.createTextNode(value));
return xml_elmt;
}

View File

@@ -1,55 +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 TERMINALSTRIPDATA_H
#define TERMINALSTRIPDATA_H
#include "../properties/propertiesinterface.h"
#include <QUuid>
class TerminalStripData : public PropertiesInterface
{
friend class TerminalStrip;
friend class TerminalStripEditor;
public:
TerminalStripData();
void toSettings(QSettings &/*settings*/, const QString = QString()) const override {}
void fromSettings (const QSettings &/*settings*/, const QString = QString()) override {}
QDomElement toXml (QDomDocument &xml_document) const override;
bool fromXml (const QDomElement &xml_element) override;
static QString xmlTagName() {return QStringLiteral("terminal_strip_data");}
TerminalStripData &operator= (const TerminalStripData &other);
private :
static QDomElement infoToXml(QDomDocument &xml_doc, const QString &name, const QString &value);
QString m_installation = QStringLiteral("="),
m_location = QStringLiteral("+"),
m_name,
m_comment,
m_description;
QUuid m_uuid = QUuid::createUuid();
};
#endif // TERMINALSTRIPDATA_H

View File

@@ -1,107 +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 "terminalstripcreatordialog.h"
#include "ui_terminalstripcreatordialog.h"
#include "../terminalstrip.h"
#include "../../qetproject.h"
/**
* @brief TerminalStripCreatorDialog::TerminalStripCreatorDialog
* @param project : Project to add a new terminal strip
* @param parent : parent widget
*/
TerminalStripCreatorDialog::TerminalStripCreatorDialog(QETProject *project, QWidget *parent) :
QDialog(parent),
ui(new Ui::TerminalStripCreatorDialog),
m_project(project)
{
ui->setupUi(this);
}
/**
* @brief TerminalStripCreatorDialog::~TerminalStripCreatorDialog
*/
TerminalStripCreatorDialog::~TerminalStripCreatorDialog() {
delete ui;
}
/**
* @brief TerminalStripCreatorDialog::setInstallation
* Set the installation field string
* @param installation
*/
void TerminalStripCreatorDialog::setInstallation(const QString &installation) {
ui->m_installation_le->setText(installation);
setCursorToEmptyLine();
}
/**
* @brief TerminalStripCreatorDialog::setLocation
* Set the location field string
* @param location
*/
void TerminalStripCreatorDialog::setLocation(const QString &location) {
ui->m_location_le->setText(location);
setCursorToEmptyLine();
}
/**
* @brief TerminalStripCreatorDialog::generatedTerminalStrip
* @return A new terminal Strip according to the value set by user.
* The terminal strip is already added to the terminalStrip list of the project
* so it's ready to use.
*/
TerminalStrip *TerminalStripCreatorDialog::generatedTerminalStrip() const
{
QString installation_ = ui->m_installation_le->text();
QString location_ = ui->m_location_le->text();
QString name_ = ui->m_name_le->text();
if (installation_.isEmpty()) {
installation_ = QStringLiteral("=INST"); }
if (location_.isEmpty()) {
location_ = QStringLiteral("+LOC"); }
if (name_.isEmpty()) {
name_ = QStringLiteral("X"); }
auto strip = m_project->newTerminalStrip(installation_,
location_,
name_);
strip->setComment(ui->m_comment_le->text());
strip->setDescription(ui->m_description_te->toPlainText());
return strip;
}
/**
* @brief TerminalStripCreatorDialog::setCursorToEmptyLine
* Set the cursor to the first empty field.
* It's usefull when user create a new terminal strip
* with some value prefilled, to increase productivity.
*/
void TerminalStripCreatorDialog::setCursorToEmptyLine()
{
if (ui->m_installation_le->text().isEmpty()) {
return;
}
if (ui->m_location_le->text().isEmpty()) {
ui->m_location_le->setFocus();
return;
}
ui->m_name_le->setFocus();
}

View File

@@ -1,54 +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 TERMINALSTRIPCREATORDIALOG_H
#define TERMINALSTRIPCREATORDIALOG_H
#include <QDialog>
class TerminalStrip;
class QETProject;
namespace Ui {
class TerminalStripCreatorDialog;
}
/**
* @brief The TerminalStripCreatorDialog class
* A simple dialog for create a new terminal strip
*/
class TerminalStripCreatorDialog : public QDialog
{
Q_OBJECT
public:
explicit TerminalStripCreatorDialog(QETProject *project, QWidget *parent = nullptr);
~TerminalStripCreatorDialog() override;
void setInstallation(const QString &installation);
void setLocation(const QString &location);
TerminalStrip *generatedTerminalStrip() const;
private:
void setCursorToEmptyLine();
private:
Ui::TerminalStripCreatorDialog *ui;
QETProject *m_project = nullptr;
};
#endif // TERMINALSTRIPCREATORDIALOG_H

View File

@@ -1,146 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TerminalStripCreatorDialog</class>
<widget class="QDialog" name="TerminalStripCreatorDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>744</width>
<height>321</height>
</rect>
</property>
<property name="windowTitle">
<string>Création groupe de bornes</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Localisation :</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Nom :</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Installation :</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="m_name_le"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="m_location_le"/>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="m_installation_le"/>
</item>
<item row="7" column="0" colspan="2">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Description :</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QPlainTextEdit" name="m_description_te"/>
</item>
<item row="10" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Commentaire :</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="m_comment_le"/>
</item>
</layout>
</widget>
<tabstops>
<tabstop>m_installation_le</tabstop>
<tabstop>m_location_le</tabstop>
<tabstop>m_name_le</tabstop>
<tabstop>m_comment_le</tabstop>
<tabstop>m_description_te</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>TerminalStripCreatorDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>TerminalStripCreatorDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -1,383 +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 "terminalstripeditor.h"
#include "ui_terminalstripeditor.h"
#include "terminalstripcreatordialog.h"
#include "../../qetproject.h"
#include "../terminalstrip.h"
#include "../elementprovider.h"
#include "../qetgraphicsitem/terminalelement.h"
#include "../UndoCommand/addterminalstripcommand.h"
#include "../UndoCommand/addterminaltostripcommand.h"
#include "../UndoCommand/changeterminalstripdata.h"
#include "terminalstriptreewidget.h"
#include "../../qeticons.h"
#include <QTreeWidgetItem>
/**
* @brief TerminalStripEditor::TerminalStripEditor
* @param project : Project to manage the terminal strip
* @param parent : paent widget
*/
TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
QDialog(parent),
ui(new Ui::TerminalStripEditor),
m_project(project)
{
ui->setupUi(this);
ui->m_remove_terminal_strip_pb->setDisabled(true);
buildTree();
ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex());
setUpUndoConnections();
}
/**
* @brief TerminalStripEditor::~TerminalStripEditor
*/
TerminalStripEditor::~TerminalStripEditor() {
delete ui;
}
void TerminalStripEditor::setUpUndoConnections()
{
connect(ui->m_terminal_strip_tw, &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_terminal_strip_tw, &TerminalStripTreeWidget::terminalMovedFromStripToStrip,
[this] (QUuid terminal_uuid, QUuid old_strip_uuid, QUuid new_strip_uuid)
{
auto terminal = m_uuid_terminal_H.value(terminal_uuid);
auto old_strip = m_uuid_strip_H.value(old_strip_uuid);
auto new_strip = m_uuid_strip_H.value(new_strip_uuid);
if (!terminal || !old_strip || !new_strip) {
return;
}
auto undo = new AddTerminalToStripCommand(terminal, old_strip, new_strip);
m_project->undoStack()->push(undo);
});
connect(ui->m_terminal_strip_tw, &TerminalStripTreeWidget::terminalRemovedFromStrip,
[this] (QUuid terminal_uuid, QUuid old_strip_uuid)
{
auto terminal_ = m_uuid_terminal_H.value(terminal_uuid);
auto strip_ = m_uuid_strip_H.value(old_strip_uuid);
if (!terminal_ || !strip_) {
return;
}
auto undo = new RemoveTerminalFromStripCommand(terminal_, strip_);
m_project->undoStack()->push(undo);
});
}
/**
* @brief TerminalStripEditor::buildTree
* Build the tree widget use to explore terminal strip
*/
void TerminalStripEditor::buildTree()
{
ui->m_terminal_strip_tw->clear();
auto title = m_project->title();
if (title.isEmpty()) {
title = tr("Projet sans titre");
}
QStringList strl{title};
new QTreeWidgetItem(ui->m_terminal_strip_tw, strl, TerminalStripTreeWidget::Root);
QStringList ftstrl(tr("Bornes indépendante"));
new QTreeWidgetItem(ui->m_terminal_strip_tw, 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();
}
/**
* @brief TerminalStripEditor::addTerminalStrip
* Add a new terminal strip to the list of displayed terminal strip
* in the tree widget
* @param terminal_strip
* @return the QTreeWidgetItem who represent the terminal strip
* both if created or already exist
*/
QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_strip)
{
if (auto item = m_item_strip_H.key(terminal_strip)) {
return item;
}
auto root_item = ui->m_terminal_strip_tw->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 ; i<root_item->childCount() ; ++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 ; i<inst_qtwi->childCount() ; ++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 ; i<terminal_strip->physicalTerminalCount() ; ++i)
{
auto index = terminal_strip->index(i);
auto term_item = new QTreeWidgetItem(strip_item, QStringList(index.label()), TerminalStripTreeWidget::Terminal);
term_item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, index.uuid().toString());
term_item->setIcon(0, QET::Icons::ElementTerminal);
if (index.isElement()) {
m_uuid_terminal_H.insert(index.uuid(), index.element());
}
}
m_item_strip_H.insert(strip_item, terminal_strip);
m_uuid_strip_H.insert(terminal_strip->uuid(), terminal_strip);
return strip_item;
}
/**
* @brief TerminalStripEditor::addFreeTerminal
* Add free terminal (aka terminal which not belong to a terminal strip)
* in the tree widget
*/
void TerminalStripEditor::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_terminal_strip_tw->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);
}
}
/**
* @brief TerminalStripEditor::clearDataTab
*/
void TerminalStripEditor::clearDataTab()
{
ui->m_installation_le ->clear();
ui->m_location_le ->clear();
ui->m_name_le ->clear();
ui->m_comment_le ->clear();
ui->m_description_te ->clear();
m_current_strip = nullptr;
}
/**
* @brief TerminalStripEditor::on_m_add_terminal_strip_pb_clicked
* Action when user click on add terminal strip button
*/
void TerminalStripEditor::on_m_add_terminal_strip_pb_clicked()
{
QScopedPointer<TerminalStripCreatorDialog> dialog(new TerminalStripCreatorDialog(m_project, this));
if (auto item = ui->m_terminal_strip_tw->currentItem())
{
if (item->type() == TerminalStripTreeWidget::Strip) {
item = item->parent();
}
if (item->type() == TerminalStripTreeWidget::Location) {
dialog->setLocation(item->data(0, Qt::DisplayRole).toString());
item = item->parent();
}
if (item->type() == TerminalStripTreeWidget::Installation) {
dialog->setInstallation(item->data(0, Qt::DisplayRole).toString());
}
}
if (dialog->exec() == QDialog::Accepted)
{
auto ts = dialog->generatedTerminalStrip();
m_project->undoStack()->push(new AddTerminalStripCommand(ts, m_project));
auto item = addTerminalStrip(ts);
ui->m_terminal_strip_tw->setCurrentItem(item);
}
}
/**
* @brief TerminalStripEditor::on_m_remove_terminal_strip_pb_clicked
* Action when user click on remove terminal strip button
*/
void TerminalStripEditor::on_m_remove_terminal_strip_pb_clicked()
{
auto item = ui->m_terminal_strip_tw->currentItem();
if (auto strip = m_item_strip_H.value(item))
{
m_item_strip_H.remove(item);
m_uuid_strip_H.remove(strip->uuid());
delete item;
m_project->undoStack()->push(new RemoveTerminalStripCommand(strip, m_project));
}
on_m_reload_pb_clicked();
}
/**
* @brief TerminalStripEditor::on_m_reload_pb_clicked
*/
void TerminalStripEditor::on_m_reload_pb_clicked()
{
auto current_ = m_current_strip;
ui->m_terminal_strip_tw->clear();
m_item_strip_H.clear();
m_uuid_terminal_H.clear();
m_uuid_strip_H.clear();
qDeleteAll(m_item_strip_H.keys());
buildTree();
ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex());
//Reselect the tree widget item of the current edited strip
auto item = m_item_strip_H.key(current_);
if (item) {
ui->m_terminal_strip_tw->setCurrentItem(item);
}
}
/**
* @brief TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged
* @param current
* @param previous
*/
void TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
Q_UNUSED(previous)
if (!current) {
clearDataTab();
ui->m_remove_terminal_strip_pb->setDisabled(true);
return;
}
TerminalStrip *strip_ = nullptr;
if (current->type() == TerminalStripTreeWidget::Strip) {
strip_ = m_item_strip_H.value(current);
ui->m_remove_terminal_strip_pb->setEnabled(true);
}
else if (current->type() == TerminalStripTreeWidget::Terminal
&& current->parent()
&& current->parent()->type() == TerminalStripTreeWidget::Strip) {
strip_ = m_item_strip_H.value(current->parent());
ui->m_remove_terminal_strip_pb->setDisabled(true);
} else {
ui->m_remove_terminal_strip_pb->setDisabled(true);
}
if (strip_) {
m_current_strip = strip_;
ui->m_installation_le ->setText(strip_->installation());
ui->m_location_le ->setText(strip_->location());
ui->m_name_le ->setText(strip_->name());
ui->m_comment_le ->setText(strip_->comment());
ui->m_description_te ->setPlainText(strip_->description());
} else {
clearDataTab();
}
}
void TerminalStripEditor::on_m_apply_data_pb_clicked(QAbstractButton *button)
{
Q_UNUSED(button)
if (m_current_strip)
{
TerminalStripData data;
data.m_installation = ui->m_installation_le->text();
data.m_location = ui->m_location_le->text();
data.m_name = ui->m_name_le->text();
data.m_comment = ui->m_comment_le->text();
data.m_description = ui->m_description_te->toPlainText();
m_project->undoStack()->push(new ChangeTerminalStripData(m_current_strip, data, nullptr));
}
on_m_reload_pb_clicked();
}

View File

@@ -1,70 +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 TERMINALSTRIPEDITOR_H
#define TERMINALSTRIPEDITOR_H
#include <QDialog>
namespace Ui {
class TerminalStripEditor;
}
class QETProject;
class TerminalStrip;
class QTreeWidgetItem;
class TerminalElement;
class QAbstractButton;
/**
* @brief The TerminalStripEditor class
* Main dialog used to edit terminal strip
* of a project
*/
class TerminalStripEditor : public QDialog
{
Q_OBJECT
public:
explicit TerminalStripEditor(QETProject *project, QWidget *parent = nullptr);
~TerminalStripEditor() override;
private:
void setUpUndoConnections();
void buildTree();
QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip);
void addFreeTerminal();
void clearDataTab();
private slots:
void on_m_add_terminal_strip_pb_clicked();
void on_m_remove_terminal_strip_pb_clicked();
void on_m_reload_pb_clicked();
void on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_m_apply_data_pb_clicked(QAbstractButton *button);
private:
Ui::TerminalStripEditor *ui;
QETProject *m_project = nullptr;
QHash<QTreeWidgetItem *, TerminalStrip *> m_item_strip_H;
QHash<QUuid, QPointer<TerminalElement>> m_uuid_terminal_H;
QHash<QUuid, QPointer<TerminalStrip>> m_uuid_strip_H;
TerminalStrip *m_current_strip = nullptr;
};
#endif // TERMINALSTRIPEDITOR_H

View File

@@ -1,271 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TerminalStripEditor</class>
<widget class="QDialog" name="TerminalStripEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>951</width>
<height>491</height>
</rect>
</property>
<property name="windowTitle">
<string>Gestionnaire de borniers</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="0,1" columnstretch="0">
<item row="0" column="0">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="m_add_terminal_strip_pb">
<property name="text">
<string>Ajouter un bornier</string>
</property>
<property name="icon">
<iconset resource="../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/list-add.png</normaloff>:/ico/16x16/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_remove_terminal_strip_pb">
<property name="text">
<string>Supprimer le bornier</string>
</property>
<property name="icon">
<iconset resource="../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/list-remove.png</normaloff>:/ico/16x16/list-remove.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_reload_pb">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/view-refresh.png</normaloff>:/ico/16x16/view-refresh.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="handleWidth">
<number>4</number>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="TerminalStripTreeWidget" name="m_terminal_strip_tw">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="dragEnabled">
<bool>false</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="autoExpandDelay">
<number>500</number>
</property>
<property name="animated">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Explorateur de bornier</string>
</property>
</column>
</widget>
<widget class="QTabWidget" name="m_tab_widget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="m_layout_tab">
<attribute name="title">
<string>Disposition</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableView" name="tableView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_data_tab">
<attribute name="title">
<string>Propriétés</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Installation :</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Commentaire</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="m_name_le"/>
</item>
<item row="4" column="1">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QPlainTextEdit" name="m_description_te"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Nom :</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="m_location_le"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="m_installation_le"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Localisation :</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="m_comment_le"/>
</item>
<item row="6" column="0" colspan="2">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="m_apply_data_pb">
<property name="standardButtons">
<set>QDialogButtonBox::Apply</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TerminalStripTreeWidget</class>
<extends>QTreeWidget</extends>
<header location="global">terminalstriptreewidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>m_tab_widget</tabstop>
<tabstop>m_installation_le</tabstop>
<tabstop>m_location_le</tabstop>
<tabstop>m_name_le</tabstop>
<tabstop>m_comment_le</tabstop>
<tabstop>m_description_te</tabstop>
<tabstop>tableView</tabstop>
</tabstops>
<resources>
<include location="../../../qelectrotech.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -1,139 +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>
int TerminalStripTreeWidget::UUID_USER_ROLE = Qt::UserRole + 1;
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::fromString(dragged_item->data(0, UUID_USER_ROLE).toString()),
QUuid::fromString(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::fromString(dragged_item->data(0, UUID_USER_ROLE).toString()),
QUuid::fromString(old_parent->data(0, UUID_USER_ROLE).toString()));
}
else if (overred_item->type() == Strip) //To another strip
{
emit terminalMovedFromStripToStrip(QUuid::fromString(dragged_item->data(0, UUID_USER_ROLE).toString()),
QUuid::fromString(old_parent->data(0, UUID_USER_ROLE).toString()),
QUuid::fromString(overred_item->data(0, UUID_USER_ROLE).toString()));
}
}
}
Qt::DropActions TerminalStripTreeWidget::supportedDropActions() const {
return Qt::MoveAction;
}

View File

@@ -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 int UUID_USER_ROLE;
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

View File

@@ -20,7 +20,6 @@
#include "diagram.h" #include "diagram.h"
#include "qetgraphicsitem/ViewItem/qetgraphicstableitem.h" #include "qetgraphicsitem/ViewItem/qetgraphicstableitem.h"
#include "qetgraphicsitem/element.h" #include "qetgraphicsitem/element.h"
#include "qetgraphicsitem/terminalelement.h"
#include "qetproject.h" #include "qetproject.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
@@ -182,28 +181,3 @@ QetGraphicsTableItem *ElementProvider::tableFromUuid(const QUuid &uuid)
return nullptr; return nullptr;
} }
/**
* @brief ElementProvider::freeTerminal
* @return a vector of every terminals element who doesn't
* belong to a terminal strip.
*/
QVector<TerminalElement *> ElementProvider::freeTerminal() const
{
QVector<TerminalElement *> vector_;
for (const auto diagram : m_diagram_list) {
DiagramContent dc(diagram, false);
for (const auto element : qAsConst(dc.m_elements)) {
if (element->elementData().m_type == ElementData::Terminale)
{
auto te = static_cast<TerminalElement *>(element);
if (!te->parentTerminalStrip()) {
vector_.append(static_cast<TerminalElement *>(element));
}
}
}
}
return vector_;
}

View File

@@ -26,7 +26,6 @@ class QETProject;
class Diagram; class Diagram;
class Element; class Element;
class QetGraphicsTableItem; class QetGraphicsTableItem;
class TerminalElement;
/** /**
this class can search in the given diagram or project some kind of element this class can search in the given diagram or project some kind of element
@@ -44,7 +43,6 @@ class ElementProvider
QList <Element *> find(const int filter) const; QList <Element *> find(const int filter) const;
QVector <QetGraphicsTableItem *> table(QetGraphicsTableItem *table = nullptr, QAbstractItemModel *model = nullptr); QVector <QetGraphicsTableItem *> table(QetGraphicsTableItem *table = nullptr, QAbstractItemModel *model = nullptr);
QetGraphicsTableItem *tableFromUuid(const QUuid &uuid); QetGraphicsTableItem *tableFromUuid(const QUuid &uuid);
QVector<TerminalElement *> freeTerminal() const;
private: private:
QList <Diagram *> m_diagram_list; QList <Diagram *> m_diagram_list;

View File

@@ -42,7 +42,6 @@
#include "undocommand/rotateselectioncommand.h" #include "undocommand/rotateselectioncommand.h"
#include "undocommand/rotatetextscommand.h" #include "undocommand/rotatetextscommand.h"
#include "diagram.h" #include "diagram.h"
#include "TerminalStrip/ui/terminalstripeditor.h"
#ifdef BUILD_WITHOUT_KF5 #ifdef BUILD_WITHOUT_KF5
#else #else
@@ -437,16 +436,6 @@ void QETDiagramEditor::setUpActions()
} }
}); });
m_terminal_strip_dialog = new QAction(QET::Icons::TerminalStrip, tr("Gestionnaire de borniers (DEV)"), this);
connect(m_terminal_strip_dialog, &QAction::triggered, [this]()
{
if (auto project = this->currentProject())
{
auto str = new TerminalStripEditor(project, this);
str->show();
}
});
//Lauch the plugin of terminal generator //Lauch the plugin of terminal generator
m_project_terminalBloc = new QAction(QET::Icons::TerminalStrip, tr("Lancer le plugin de création de borniers"), this); m_project_terminalBloc = new QAction(QET::Icons::TerminalStrip, tr("Lancer le plugin de création de borniers"), this);
connect(m_project_terminalBloc, &QAction::triggered, this, &QETDiagramEditor::generateTerminalBlock); connect(m_project_terminalBloc, &QAction::triggered, this, &QETDiagramEditor::generateTerminalBlock);
@@ -820,7 +809,6 @@ void QETDiagramEditor::setUpMenu()
menu_project -> addAction(m_add_nomenclature); menu_project -> addAction(m_add_nomenclature);
menu_project -> addAction(m_csv_export); menu_project -> addAction(m_csv_export);
menu_project -> addAction(m_project_export_conductor_num); menu_project -> addAction(m_project_export_conductor_num);
menu_project -> addAction(m_terminal_strip_dialog);
menu_project -> addAction(m_project_terminalBloc); menu_project -> addAction(m_project_terminalBloc);
#ifdef QET_EXPORT_PROJECT_DB #ifdef QET_EXPORT_PROJECT_DB
menu_project -> addSeparator(); menu_project -> addSeparator();
@@ -1514,7 +1502,16 @@ void QETDiagramEditor::slot_updateActions()
m_close_file-> setEnabled(opened_project); m_close_file-> setEnabled(opened_project);
m_save_file-> setEnabled(opened_project); m_save_file-> setEnabled(opened_project);
m_save_file_as-> setEnabled(opened_project); m_save_file_as-> setEnabled(opened_project);
m_project_edit_properties-> setEnabled(opened_project);
m_project_export_conductor_num->setEnabled(opened_project);
//prj_terminalBloc -> setEnabled(opened_project);
m_rotate_texts-> setEnabled(editable_project); m_rotate_texts-> setEnabled(editable_project);
m_project_add_diagram-> setEnabled(editable_project);
m_remove_diagram_from_project-> setEnabled(editable_project);
m_clean_project-> setEnabled(editable_project);
m_add_nomenclature-> setEnabled(editable_project);
m_add_summary-> setEnabled(editable_project);
m_csv_export-> setEnabled(editable_project);
m_export_to_images-> setEnabled(opened_diagram); m_export_to_images-> setEnabled(opened_diagram);
m_print-> setEnabled(opened_diagram); m_print-> setEnabled(opened_diagram);
m_export_to_pdf-> setEnabled(opened_diagram); m_export_to_pdf-> setEnabled(opened_diagram);
@@ -1525,17 +1522,6 @@ void QETDiagramEditor::slot_updateActions()
m_row_column_actions_group. setEnabled(editable_project); m_row_column_actions_group. setEnabled(editable_project);
m_grey_background-> setEnabled(opened_diagram); m_grey_background-> setEnabled(opened_diagram);
//Project menu
m_project_edit_properties -> setEnabled(opened_project);
m_project_add_diagram -> setEnabled(editable_project);
m_remove_diagram_from_project -> setEnabled(editable_project);
m_clean_project -> setEnabled(editable_project);
m_add_summary -> setEnabled(editable_project);
m_add_nomenclature -> setEnabled(editable_project);
m_csv_export -> setEnabled(editable_project);
m_project_export_conductor_num-> setEnabled(opened_project);
m_terminal_strip_dialog -> setEnabled(editable_project);
slot_updateUndoStack(); slot_updateUndoStack();
slot_updateModeActions(); slot_updateModeActions();

View File

@@ -192,7 +192,6 @@ class QETDiagramEditor : public QETMainWindow
*m_csv_export, ///< generate nomenclature *m_csv_export, ///< generate nomenclature
*m_add_nomenclature, ///< Add nomenclature graphics item; *m_add_nomenclature, ///< Add nomenclature graphics item;
*m_add_summary, ///<Add summary graphics item *m_add_summary, ///<Add summary graphics item
*m_terminal_strip_dialog = nullptr, ///<Lauch terminal strip dialog
*m_project_terminalBloc, ///< generate terminal block *m_project_terminalBloc, ///< generate terminal block
*m_project_export_conductor_num,///<Export the wire num to csv *m_project_export_conductor_num,///<Export the wire num to csv
*m_export_project_db, ///Export to file the internal database of the current project *m_export_project_db, ///Export to file the internal database of the current project

View File

@@ -40,26 +40,3 @@ void TerminalElement::initLink(QETProject *project) {
Element::initLink(project); Element::initLink(project);
} }
/**
* @brief TerminalElement::setParentTerminalStrip
* Set \p strip as parent terminal strip.
* Be carefull, this function only set internally the parent terminal strip.
* This function don't check if there is a previous
* parent terminal strip and don't check
* if the new terminal strip have this terminal element
* in her list of terminal element.
* @param strip
*/
void TerminalElement::setParentTerminalStrip(TerminalStrip *strip) {
m_parent_terminal_strip = strip;
}
/**
* @brief TerminalElement::parentTerminalStrip
* @return The parent terminal strip of this
* terminal element or nullptr if not.
*/
TerminalStrip *TerminalElement::parentTerminalStrip() const {
return m_parent_terminal_strip.data();
}

View File

@@ -20,7 +20,6 @@
#include "element.h" #include "element.h"
#include "../TerminalStrip/terminalstrip.h"
class QETProject; class QETProject;
/** /**
@@ -34,12 +33,6 @@ class TerminalElement : public Element
QGraphicsItem * = nullptr, int * = nullptr); QGraphicsItem * = nullptr, int * = nullptr);
~TerminalElement() override; ~TerminalElement() override;
void initLink(QETProject *project) override; void initLink(QETProject *project) override;
void setParentTerminalStrip(TerminalStrip *strip);
TerminalStrip *parentTerminalStrip() const;
private:
QPointer<TerminalStrip> m_parent_terminal_strip;
}; };
#endif // TERMINALELEMENT_H #endif // TERMINALELEMENT_H

View File

@@ -31,8 +31,6 @@
#include "titleblocktemplate.h" #include "titleblocktemplate.h"
#include "ui/dialogwaiting.h" #include "ui/dialogwaiting.h"
#include "ui/importelementdialog.h" #include "ui/importelementdialog.h"
#include "TerminalStrip/terminalstrip.h"
#include "qetxml.h"
#include <QHash> #include <QHash>
#include <QStandardPaths> #include <QStandardPaths>
@@ -914,16 +912,6 @@ QDomDocument QETProject::toXml()
appended_diagram.toElement().setAttribute("order", order_num ++); appended_diagram.toElement().setAttribute("order", order_num ++);
} }
//Write terminal strip to xml
if (m_terminal_strip_vector.count())
{
auto xml_strip = xml_doc.createElement(QStringLiteral("terminal_strips"));
for (auto &strip : m_terminal_strip_vector) {
xml_strip.appendChild(strip->toXml(xml_doc));
}
project_root.appendChild(xml_strip);
}
// Write the elements collection. // Write the elements collection.
project_root.appendChild(m_elements_collection->root().cloneNode(true)); project_root.appendChild(m_elements_collection->root().cloneNode(true));
@@ -1353,26 +1341,16 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
} }
m_data_base.blockSignals(true); m_data_base.blockSignals(true);
//Load the project-wide properties //Load the project-wide properties
readProjectPropertiesXml(xml_project); readProjectPropertiesXml(xml_project);
//Load the default properties for the new diagrams //Load the default properties for the new diagrams
readDefaultPropertiesXml(xml_project); readDefaultPropertiesXml(xml_project);
//load the embedded titleblock templates //load the embedded titleblock templates
m_titleblocks_collection.fromXml(xml_project.documentElement()); m_titleblocks_collection.fromXml(xml_project.documentElement());
//Load the embedded elements collection //Load the embedded elements collection
readElementsCollectionXml(xml_project); readElementsCollectionXml(xml_project);
//Load the diagrams //Load the diagrams
readDiagramsXml(xml_project); readDiagramsXml(xml_project);
//Load the terminal strip
readTerminalStripXml(xml_project);
m_data_base.blockSignals(false); m_data_base.blockSignals(false);
m_data_base.updateDB(); m_data_base.updateDB();
@@ -1590,26 +1568,6 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project)
} }
} }
/**
* @brief QETProject::readTerminalStripXml
* Read the terminal strips of this project
* @param xml_project
*/
void QETProject::readTerminalStripXml(const QDomDocument &xml_project)
{
auto xml_elmt = xml_project.documentElement();
auto xml_strips = xml_elmt.firstChildElement(QStringLiteral("terminal_strips"));
if (!xml_strips.isNull())
{
for (auto xml_strip : QETXML::findInDomElement(xml_strips, TerminalStrip::xmlTagName()))
{
auto terminal_strip = new TerminalStrip(this);
terminal_strip->fromXml(xml_strip);
addTerminalStrip(terminal_strip);
}
}
}
/** /**
Export project properties under the \a xml_element XML element. Export project properties under the \a xml_element XML element.
*/ */
@@ -1858,64 +1816,6 @@ void QETProject::setProjectProperties(const DiagramContext &context) {
updateDiagramsFolioData(); updateDiagramsFolioData();
} }
/**
* @brief QETProject::terminalStrip
* @return a QVector who contain all terminal strip owned by this project
*/
QVector<TerminalStrip *> QETProject::terminalStrip() const {
return m_terminal_strip_vector;
}
/**
* @brief QETProject::newTerminalStrip
* @param installation : installation of the terminal strip
* @param location : location of the terminal strip
* @param name : name of the terminal strip
* @return Create a new terminal strip with this project as parent.
* You can retrieve this terminal strip at any time by calling the function
* QETProject::terminalStrip()
*/
TerminalStrip *QETProject::newTerminalStrip(QString installation, QString location, QString name)
{
auto ts = new TerminalStrip(installation,
location,
name,
this);
m_terminal_strip_vector.append(ts);
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 Cette methode sert a reperer un projet vide, c-a-d un projet identique a ce
que l'on obtient en faisant Fichier > Nouveau. que l'on obtient en faisant Fichier > Nouveau.

View File

@@ -42,8 +42,6 @@ class NumerotationContext;
class QUndoStack; class QUndoStack;
class XmlElementCollection; class XmlElementCollection;
class QTimer; class QTimer;
class TerminalStrip;
#ifdef BUILD_WITHOUT_KF5 #ifdef BUILD_WITHOUT_KF5
#else #else
class KAutoSaveFile; class KAutoSaveFile;
@@ -178,11 +176,6 @@ class QETProject : public QObject
void setProjectProperties(const DiagramContext &); void setProjectProperties(const DiagramContext &);
QUndoStack* undoStack() {return m_undo_stack;} QUndoStack* undoStack() {return m_undo_stack;}
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: public slots:
Diagram *addNewDiagram(int pos = -1); Diagram *addNewDiagram(int pos = -1);
void removeDiagram(Diagram *); void removeDiagram(Diagram *);
@@ -225,7 +218,6 @@ class QETProject : public QObject
void readElementsCollectionXml(QDomDocument &xml_project); void readElementsCollectionXml(QDomDocument &xml_project);
void readProjectPropertiesXml(QDomDocument &xml_project); void readProjectPropertiesXml(QDomDocument &xml_project);
void readDefaultPropertiesXml(QDomDocument &xml_project); void readDefaultPropertiesXml(QDomDocument &xml_project);
void readTerminalStripXml(const QDomDocument &xml_project);
void writeProjectPropertiesXml(QDomElement &); void writeProjectPropertiesXml(QDomElement &);
void writeDefaultPropertiesXml(QDomElement &); void writeDefaultPropertiesXml(QDomElement &);
@@ -289,7 +281,6 @@ class QETProject : public QObject
#endif #endif
QUuid m_uuid = QUuid::createUuid(); QUuid m_uuid = QUuid::createUuid();
projectDataBase m_data_base; projectDataBase m_data_base;
QVector<TerminalStrip *> m_terminal_strip_vector;
}; };
Q_DECLARE_METATYPE(QETProject *) Q_DECLARE_METATYPE(QETProject *)