diff --git a/sources/TerminalStrip/terminalstrip.cpp b/sources/TerminalStrip/terminalstrip.cpp index 2b1b86da9..7d3700a41 100644 --- a/sources/TerminalStrip/terminalstrip.cpp +++ b/sources/TerminalStrip/terminalstrip.cpp @@ -167,20 +167,13 @@ class PhysicalTerminal /************************************************************************************/ /************************************************************************************/ - - /** * @brief TerminalStrip::TerminalStrip + * @param installation + * @param location * @param name * @param project */ -TerminalStrip::TerminalStrip(const QString &name, QETProject *project) : - QObject(project), - m_project(project) -{ - m_data.m_name = name; -} - TerminalStrip::TerminalStrip(const QString &installation, const QString &location, const QString &name, QETProject *project) : QObject(project), m_project(project) @@ -202,6 +195,10 @@ void TerminalStrip::setName(const QString &name) { m_data.m_name = name; } +void TerminalStrip::setDescription(const QString &description) { + m_data.m_description = description; +} + /** * @brief TerminalStrip::addTerminal * Add terminal to this terminal strip diff --git a/sources/TerminalStrip/terminalstrip.h b/sources/TerminalStrip/terminalstrip.h index 65fc9d999..abcede0ce 100644 --- a/sources/TerminalStrip/terminalstrip.h +++ b/sources/TerminalStrip/terminalstrip.h @@ -39,8 +39,13 @@ class TerminalStrip : public QObject 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 setDescription(const QString &description); + QString description() const {return m_data.m_description;} bool addTerminal(Element *terminal); bool removeTerminal(Element *terminal); diff --git a/sources/TerminalStrip/terminalstripdata.h b/sources/TerminalStrip/terminalstripdata.h index b4324ee02..94eda3090 100644 --- a/sources/TerminalStrip/terminalstripdata.h +++ b/sources/TerminalStrip/terminalstripdata.h @@ -35,8 +35,9 @@ class TerminalStripData : public PropertiesInterface private : QString m_installation = QStringLiteral("="), - m_location = QStringLiteral("+"), - m_name; + m_location = QStringLiteral("+"), + m_name, + m_description; }; diff --git a/sources/TerminalStrip/ui/terminalstripcreatordialog.cpp b/sources/TerminalStrip/ui/terminalstripcreatordialog.cpp new file mode 100644 index 000000000..24dbe9cbd --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstripcreatordialog.cpp @@ -0,0 +1,103 @@ +/* + Copyright 2006-2021 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "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"); } + + return m_project->newTerminalStrip(installation_, + location_, + name_); +} + +/** + * @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(); +} diff --git a/sources/TerminalStrip/ui/terminalstripcreatordialog.h b/sources/TerminalStrip/ui/terminalstripcreatordialog.h new file mode 100644 index 000000000..22deb7ddf --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstripcreatordialog.h @@ -0,0 +1,54 @@ +/* + Copyright 2006-2021 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef TERMINALSTRIPCREATORDIALOG_H +#define TERMINALSTRIPCREATORDIALOG_H + +#include + +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 diff --git a/sources/TerminalStrip/ui/terminalstripcreatordialog.ui b/sources/TerminalStrip/ui/terminalstripcreatordialog.ui new file mode 100644 index 000000000..b7119de46 --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstripcreatordialog.ui @@ -0,0 +1,135 @@ + + + TerminalStripCreatorDialog + + + + 0 + 0 + 744 + 321 + + + + Création groupe de bornes + + + + + + Localisation : + + + + + + + Nom : + + + + + + + Installation : + + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Description : + + + + + + + Qt::Horizontal + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + m_installation_le + m_location_le + m_name_le + m_description_te + + + + + buttonBox + accepted() + TerminalStripCreatorDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + TerminalStripCreatorDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/TerminalStrip/ui/terminalstripeditor.cpp b/sources/TerminalStrip/ui/terminalstripeditor.cpp index a06c494b7..ba417e954 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.cpp +++ b/sources/TerminalStrip/ui/terminalstripeditor.cpp @@ -17,16 +17,128 @@ */ #include "terminalstripeditor.h" #include "ui_terminalstripeditor.h" +#include "terminalstripcreatordialog.h" +#include "../../qetproject.h" +#include "../terminalstrip.h" +#include + +/** + * @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); + buildTree(); } -TerminalStripEditor::~TerminalStripEditor() -{ +/** + * @brief TerminalStripEditor::~TerminalStripEditor + */ +TerminalStripEditor::~TerminalStripEditor() { delete ui; } + +/** + * @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, TerminalStripEditor::Root); + + const auto ts_vector = m_project->terminalStrip(); + for (const auto ts : ts_vector) { + addTerminalStrip(ts); + } +} + +/** + * @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 + */ +QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_strip) +{ + 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 ; ichildCount() ; ++i) { + auto child_inst = root_item->child(i); + if (child_inst->data(0, Qt::DisplayRole).toString() == installation_str) { + inst_qtwi = child_inst; + break; + } + } + if (!inst_qtwi) { + QStringList inst_strl{installation_str}; + inst_qtwi = new QTreeWidgetItem(root_item, inst_strl, TerminalStripEditor::Inst); + } + + //Check if location already exist + //if not create a new one + auto location_str = terminal_strip->location(); + QTreeWidgetItem *loc_qtwi = nullptr; + for (int i = 0 ; ichildCount() ; ++i) { + auto child_loc = inst_qtwi->child(i); + if (child_loc->data(0, Qt::DisplayRole).toString() == location_str) { + loc_qtwi = child_loc; + break; + } + } + if (!loc_qtwi) { + QStringList loc_strl{location_str}; + loc_qtwi = new QTreeWidgetItem(inst_qtwi, loc_strl, TerminalStripEditor::Loc); + } + + //Add the terminal strip + QStringList name{terminal_strip->name()}; + return new QTreeWidgetItem(loc_qtwi, name, TerminalStripEditor::Strip); +} + +/** + * @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 dialog(new TerminalStripCreatorDialog(m_project, this)); + + if (auto item = ui->m_terminal_strip_tw->currentItem()) + { + if (item->type() == TerminalStripEditor::Strip) { + item = item->parent(); + } + if (item->type() == TerminalStripEditor::Loc) { + dialog->setLocation(item->data(0, Qt::DisplayRole).toString()); + item = item->parent(); + } + if (item->type() == TerminalStripEditor::Inst) { + dialog->setInstallation(item->data(0, Qt::DisplayRole).toString()); + } + } + + if (dialog->exec() == QDialog::Accepted) + { + auto item = addTerminalStrip(dialog->generatedTerminalStrip()); + ui->m_terminal_strip_tw->setCurrentItem(item); + } +} diff --git a/sources/TerminalStrip/ui/terminalstripeditor.h b/sources/TerminalStrip/ui/terminalstripeditor.h index 1cac27444..99312e0ba 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.h +++ b/sources/TerminalStrip/ui/terminalstripeditor.h @@ -25,15 +25,36 @@ namespace Ui { } class QETProject; +class TerminalStrip; +class QTreeWidgetItem; +/** + * @brief The TerminalStripEditor class + * Main dialog used to edit terminal strip + * of a project + */ class TerminalStripEditor : public QDialog { Q_OBJECT + enum TreeWidgetType{ + Root, + Inst, + Loc, + Strip + }; + public: explicit TerminalStripEditor(QETProject *project, QWidget *parent = nullptr); ~TerminalStripEditor() override; + private: + void buildTree(); + QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip); + + private slots: + void on_m_add_terminal_strip_pb_clicked(); + private: Ui::TerminalStripEditor *ui; QETProject *m_project = nullptr; diff --git a/sources/TerminalStrip/ui/terminalstripeditor.ui b/sources/TerminalStrip/ui/terminalstripeditor.ui index e659bb195..9b0f2ffde 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.ui +++ b/sources/TerminalStrip/ui/terminalstripeditor.ui @@ -18,21 +18,24 @@ - + Ajouter un bornier - + Supprimer le bornier - + + + true + Explorateur de bornier diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index c485ec41c..2f555d906 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -31,6 +31,7 @@ #include "titleblocktemplate.h" #include "ui/dialogwaiting.h" #include "ui/importelementdialog.h" +#include "TerminalStrip/terminalstrip.h" #include #include @@ -1816,6 +1817,34 @@ void QETProject::setProjectProperties(const DiagramContext &context) { updateDiagramsFolioData(); } +/** + * @brief QETProject::terminalStrip + * @return a QVector who contain all terminal strip owned by this project + */ +QVector 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; +} + /** Cette methode sert a reperer un projet vide, c-a-d un projet identique a ce que l'on obtient en faisant Fichier > Nouveau. diff --git a/sources/qetproject.h b/sources/qetproject.h index a4561de4e..f7cec3e0a 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -42,6 +42,8 @@ class NumerotationContext; class QUndoStack; class XmlElementCollection; class QTimer; +class TerminalStrip; + #ifdef BUILD_WITHOUT_KF5 #else class KAutoSaveFile; @@ -176,6 +178,9 @@ class QETProject : public QObject void setProjectProperties(const DiagramContext &); QUndoStack* undoStack() {return m_undo_stack;} + QVector terminalStrip() const; + TerminalStrip * newTerminalStrip(QString installation = QString(), QString location = QString(), QString name = QString()); + public slots: Diagram *addNewDiagram(int pos = -1); void removeDiagram(Diagram *); @@ -281,6 +286,7 @@ class QETProject : public QObject #endif QUuid m_uuid = QUuid::createUuid(); projectDataBase m_data_base; + QVector m_terminal_strip_vector; }; Q_DECLARE_METATYPE(QETProject *)