From 4da7f6cd13e128240547da08bcc475dfbd400bc2 Mon Sep 17 00:00:00 2001 From: joshua Date: Wed, 4 Jan 2023 22:40:18 +0100 Subject: [PATCH 1/8] TerminalStripLayoutPattern is now shared TerminalStripLayoutPattern class is now a shared pointer between all terminal strip item. QETProject have now a new class : ProjectPropertiesHandler the goal of this class is to manage every kind of properties used in the project, this class will be strongly used in future. --- qelectrotech.pro | 7 +- .../terminalstriplayoutpattern.cpp | 0 .../terminalstriplayoutpattern.h | 3 + .../terminalstriplayoutshandler.cpp | 31 +++++ .../properties/terminalstriplayoutshandler.h | 41 +++++++ .../GraphicsItem/terminalstripdrawer.cpp | 108 +++++++++++------- .../GraphicsItem/terminalstripdrawer.h | 10 +- .../GraphicsItem/terminalstripitem.cpp | 20 +++- .../GraphicsItem/terminalstripitem.h | 5 + sources/project/projectpropertieshandler.cpp | 30 +++++ sources/project/projectpropertieshandler.h | 53 +++++++++ sources/qetproject.cpp | 16 ++- sources/qetproject.h | 6 + 13 files changed, 278 insertions(+), 52 deletions(-) rename sources/TerminalStrip/GraphicsItem/{ => properties}/terminalstriplayoutpattern.cpp (100%) rename sources/TerminalStrip/GraphicsItem/{ => properties}/terminalstriplayoutpattern.h (97%) create mode 100644 sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.cpp create mode 100644 sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.h create mode 100644 sources/project/projectpropertieshandler.cpp create mode 100644 sources/project/projectpropertieshandler.h diff --git a/qelectrotech.pro b/qelectrotech.pro index d10346a88..f7a8cafba 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -126,7 +126,9 @@ INCLUDEPATH += sources/ui # sources/print # Fichiers sources -HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \ +HEADERS += $$files(sources/*.h) \ + $$files(sources/project/*.h) \ + $$files(sources/ui/*.h) \ $$files(sources/editor/*.h) \ $$files(sources/titleblock/*.h) \ $$files(sources/richtext/*.h) \ @@ -161,11 +163,13 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \ $$files(sources/TerminalStrip/ui/*.h) \ $$files(sources/TerminalStrip/UndoCommand/*.h) \ $$files(sources/TerminalStrip/GraphicsItem/*.h) \ + $$files(sources/TerminalStrip/GraphicsItem/properties/*.h) \ $$files(sources/xml/*.h) \ $$files(sources/dxf/*.h) SOURCES += $$files(sources/*.cpp) \ $$files(sources/editor/*.cpp) \ + $$files(sources/project/*.cpp) \ $$files(sources/titleblock/*.cpp) \ $$files(sources/richtext/*.cpp) \ $$files(sources/ui/*.cpp) \ @@ -200,6 +204,7 @@ SOURCES += $$files(sources/*.cpp) \ $$files(sources/TerminalStrip/ui/*.cpp) \ $$files(sources/TerminalStrip/UndoCommand/*.cpp) \ $$files(sources/TerminalStrip/GraphicsItem/*.cpp) \ + $$files(sources/TerminalStrip/GraphicsItem/properties/*.cpp) \ $$files(sources/xml/*.cpp) \ $$files(sources/dxf/*.cpp) diff --git a/sources/TerminalStrip/GraphicsItem/terminalstriplayoutpattern.cpp b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutpattern.cpp similarity index 100% rename from sources/TerminalStrip/GraphicsItem/terminalstriplayoutpattern.cpp rename to sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutpattern.cpp diff --git a/sources/TerminalStrip/GraphicsItem/terminalstriplayoutpattern.h b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutpattern.h similarity index 97% rename from sources/TerminalStrip/GraphicsItem/terminalstriplayoutpattern.h rename to sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutpattern.h index 2a6fd0f3d..5050c9eab 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstriplayoutpattern.h +++ b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutpattern.h @@ -82,6 +82,9 @@ class TerminalStripLayoutPattern int m_bridge_point_d{5}; QVector m_bridge_point_y_offset{50,70,90,110}; + QUuid m_uuid{QUuid::createUuid()}; + QString m_name; + private: void updateHeaderTextOption(); void updateTerminalsTextOption(); diff --git a/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.cpp b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.cpp new file mode 100644 index 000000000..45a3504e8 --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.cpp @@ -0,0 +1,31 @@ +/* + Copyright 2006-2023 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 "terminalstriplayoutshandler.h" + +#include + +TerminalStripLayoutsHandler::TerminalStripLayoutsHandler() +{ + m_default_layout = new TerminalStripLayoutPattern; + m_default_layout->m_name = QObject("Disposition par défaut"); +} + +QSharedPointer TerminalStripLayoutsHandler::defaultLayout() +{ + return m_default_layout; +} diff --git a/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.h b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.h new file mode 100644 index 000000000..1dcedb805 --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.h @@ -0,0 +1,41 @@ +/* + Copyright 2006-2023 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 TERMINALSTRIPLAYOUTSHANDLER_H +#define TERMINALSTRIPLAYOUTSHANDLER_H + +#include +#include + +#include "terminalstriplayoutpattern.h" + +/** + * @brief The TerminalStripLayoutsHandler class + * Manage and provide TerminalStripLayoutPattern + */ +class TerminalStripLayoutsHandler +{ + public: + TerminalStripLayoutsHandler(); + QSharedPointer defaultLayout(); + + private: + QSet> m_layout_set; + QSharedPointer m_default_layout; +}; + +#endif // TERMINALSTRIPLAYOUTSHANDLER_H diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp index 011131f61..9a608e08e 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp @@ -28,8 +28,10 @@ * @param strip * @param pattern */ -TerminalStripDrawer::TerminalStripDrawer(QPointer strip) : - m_strip(strip) +TerminalStripDrawer::TerminalStripDrawer(QPointer strip, + QSharedPointer layout) : + m_strip(strip), + m_pattern(layout) {} void TerminalStripDrawer::setStrip(TerminalStrip *strip) @@ -43,7 +45,7 @@ void TerminalStripDrawer::setStrip(TerminalStrip *strip) */ void TerminalStripDrawer::paint(QPainter *painter) { - if (m_strip) + if (m_strip && m_pattern) { //To draw text, QPainter need a Qrect. Instead of create an instance //for each text, we re-use the same instance of QRect. @@ -61,42 +63,42 @@ void TerminalStripDrawer::paint(QPainter *painter) painter->setBrush(brush_); //Draw header - painter->drawRect(m_pattern.m_header_rect); + painter->drawRect(m_pattern->m_header_rect); //Draw the header text painter->save(); - if (m_pattern.m_header_text_orientation == Qt::Horizontal) + if (m_pattern->m_header_text_orientation == Qt::Horizontal) { - text_rect.setRect(0,m_pattern.m_header_rect.y(),m_pattern.m_header_rect.width(),m_pattern.m_header_rect.height()); + text_rect.setRect(0,m_pattern->m_header_rect.y(),m_pattern->m_header_rect.width(),m_pattern->m_header_rect.height()); } else { - painter->translate(m_pattern.m_header_rect.bottomLeft()); + painter->translate(m_pattern->m_header_rect.bottomLeft()); painter->rotate(270); - text_rect.setRect(0,0,m_pattern.m_header_rect.height(),m_pattern.m_header_rect.width()); + text_rect.setRect(0,0,m_pattern->m_header_rect.height(),m_pattern->m_header_rect.width()); } const auto text_{m_strip->installation() + " " + m_strip->location() + " " + m_strip->name()}; - painter->drawText(text_rect, text_, m_pattern.headerTextOption()); + painter->drawText(text_rect, text_, m_pattern->headerTextOption()); painter->restore(); //Move painter pos to next drawing - painter->translate(m_pattern.m_header_rect.width(),0); + painter->translate(m_pattern->m_header_rect.width(),0); - int x_offset{m_pattern.m_header_rect.width()}; + int x_offset{m_pattern->m_header_rect.width()}; //Draw spacer - painter->drawRect(m_pattern.m_spacer_rect); + painter->drawRect(m_pattern->m_spacer_rect); //Move painter pos to next drawing - painter->translate(m_pattern.m_spacer_rect.width(),0); - x_offset += m_pattern.m_spacer_rect.width(); + painter->translate(m_pattern->m_spacer_rect.width(),0); + x_offset += m_pattern->m_spacer_rect.width(); //Draw terminals - const auto terminals_text_rect{m_pattern.m_terminals_text_rect}; - const auto terminals_text_orientation{m_pattern.m_terminals_text_orientation}; - const auto terminals_text_option{m_pattern.terminalsTextOption()}; + const auto terminals_text_rect{m_pattern->m_terminals_text_rect}; + const auto terminals_text_orientation{m_pattern->m_terminals_text_orientation}; + const auto terminals_text_option{m_pattern->terminalsTextOption()}; QRect terminal_rect; QHash> bridges_anchor_points; @@ -117,7 +119,7 @@ void TerminalStripDrawer::paint(QPainter *painter) break; } - terminal_rect = m_pattern.m_terminal_rect[index_]; + terminal_rect = m_pattern->m_terminal_rect[index_]; //Draw terminal rect painter->drawRect(terminal_rect); @@ -148,8 +150,8 @@ void TerminalStripDrawer::paint(QPainter *painter) if (const auto bridge_ = shared_real_terminal->bridge()) { const auto x_anchor{terminal_rect.width()/2}; - const auto y_anchor {m_pattern.m_bridge_point_y_offset[index_]}; - const auto radius_anchor{m_pattern.m_bridge_point_d/2}; + const auto y_anchor {m_pattern->m_bridge_point_y_offset[index_]}; + const auto radius_anchor{m_pattern->m_bridge_point_d/2}; painter->setBrush(Qt::SolidPattern); painter->drawEllipse(QPointF(x_anchor, y_anchor), @@ -188,45 +190,65 @@ QRectF TerminalStripDrawer::boundingRect() const return QRect{0, 0, width(), height()};; } +void TerminalStripDrawer::setLayout(QSharedPointer layout) +{ + m_pattern = layout; +} + +bool TerminalStripDrawer::haveLayout() const +{ + return !m_pattern.isNull(); +} + int TerminalStripDrawer::height() const { - auto height_{m_pattern.m_header_rect.y() + m_pattern.m_header_rect.height()}; + if (m_pattern) + { + auto height_{m_pattern->m_header_rect.y() + m_pattern->m_header_rect.height()}; - height_ = std::max(height_, m_pattern.m_spacer_rect.y() + m_pattern.m_spacer_rect.height()); + height_ = std::max(height_, m_pattern->m_spacer_rect.y() + m_pattern->m_spacer_rect.height()); - for (const auto &rect : m_pattern.m_terminal_rect) { - height_ = std::max(height_, rect.y() + rect.height()); + for (const auto &rect : m_pattern->m_terminal_rect) { + height_ = std::max(height_, rect.y() + rect.height()); + } + + return height_; } - return height_; + return 0; } int TerminalStripDrawer::width() const { - int width_{m_pattern.m_header_rect.width() + m_pattern.m_spacer_rect.width()}; - - if (m_strip) + if (m_pattern) { - //Loop over physical terminals - for (const auto &physical_t : m_strip->physicalTerminal()) + int width_{m_pattern->m_header_rect.width() + m_pattern->m_spacer_rect.width()}; + + if (m_strip) { - //Get the good offset according to how many level have the current physical terminal - const QVector> real_terminal{physical_t->realTerminals()}; - const auto real_t_count{real_terminal.size()}; - const auto offset_{4 - real_t_count}; - - //Loop over real terminals - for (auto i=0 ; iphysicalTerminal()) { - const auto index_ = offset_ + i; - if (index_ >= 4) { - break; - } + //Get the good offset according to how many level have the current physical terminal + const QVector> real_terminal{physical_t->realTerminals()}; + const auto real_t_count{real_terminal.size()}; + const auto offset_{4 - real_t_count}; - width_ += m_pattern.m_terminal_rect[index_].width(); + //Loop over real terminals + for (auto i=0 ; i= 4) { + break; + } + + width_ += m_pattern->m_terminal_rect[index_].width(); + } } } + + return width_; } - return width_; + return 0; } diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h index 22a12349a..b97e3658a 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h @@ -19,7 +19,7 @@ #define TERMINALSTRIPDRAWER_H #include -#include "terminalstriplayoutpattern.h" +#include "properties/terminalstriplayoutpattern.h" class QPainter; class TerminalStrip; @@ -27,19 +27,23 @@ class TerminalStrip; class TerminalStripDrawer { public: - TerminalStripDrawer(QPointer strip = QPointer()); + TerminalStripDrawer(QPointer strip = QPointer(), + QSharedPointer layout = QSharedPointer()); void setStrip(TerminalStrip *strip); void paint(QPainter *painter); QRectF boundingRect() const; + void setLayout(QSharedPointer layout); + bool haveLayout() const; + private: int height() const; int width() const; private: QPointer m_strip; - TerminalStripLayoutPattern m_pattern; + QSharedPointer m_pattern; }; #endif // TERMINALSTRIPDRAWER_H diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp index 6cbdcdb52..63c3f1d98 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp @@ -18,9 +18,10 @@ #include "terminalstripitem.h" #include "../diagram.h" -#include "../../qetgraphicsitem/qgraphicsitemutility.h" #include "../terminalstrip.h" #include "../ui/terminalstripeditorwindow.h" +#include "../../project/projectpropertieshandler.h" +#include "../../qetgraphicsitem/qgraphicsitemutility.h" TerminalStripItem::TerminalStripItem(QPointer strip, QGraphicsItem *parent) : QetGraphicsItem{parent}, @@ -29,6 +30,7 @@ TerminalStripItem::TerminalStripItem(QPointer strip, QGraphicsIte { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptHoverEvents(true); + setDefaultLayout(); } TerminalStripItem::TerminalStripItem(QGraphicsItem *parent) : @@ -43,6 +45,10 @@ void TerminalStripItem::setTerminalStrip(TerminalStrip *strip) m_strip = strip; m_drawer.setStrip(strip); m_pending_strip_uuid = QUuid(); + + if (!m_drawer.haveLayout()) { + setDefaultLayout(); + } } /** @@ -105,3 +111,15 @@ void TerminalStripItem::refreshPending() } } } + +void TerminalStripItem::setLayout(QSharedPointer layout) +{ + m_drawer.setLayout(layout); +} + +void TerminalStripItem::setDefaultLayout() +{ + if (m_strip && m_strip->project()) { + m_drawer.setLayout(m_strip->project()->projectPropertiesHandler().terminalStripLayoutHandler().defaultLayout()); + } +} diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripitem.h b/sources/TerminalStrip/GraphicsItem/terminalstripitem.h index dbdc13aea..d60e5ad35 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripitem.h +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.h @@ -50,6 +50,11 @@ class TerminalStripItem : public QetGraphicsItem void refreshPending(); + void setLayout(QSharedPointer layout); + + private: + void setDefaultLayout(); + private: QPointer m_strip; TerminalStripDrawer m_drawer; diff --git a/sources/project/projectpropertieshandler.cpp b/sources/project/projectpropertieshandler.cpp new file mode 100644 index 000000000..69483eaab --- /dev/null +++ b/sources/project/projectpropertieshandler.cpp @@ -0,0 +1,30 @@ +/* + Copyright 2006-2023 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 "projectpropertieshandler.h" + +#include "../qetproject.h" + +ProjectPropertiesHandler::ProjectPropertiesHandler(QETProject *project) : + m_project(project) +{ +} + +TerminalStripLayoutsHandler &ProjectPropertiesHandler::terminalStripLayoutHandler() +{ + return m_terminal_strip_layout_handler; +} diff --git a/sources/project/projectpropertieshandler.h b/sources/project/projectpropertieshandler.h new file mode 100644 index 000000000..bf0942284 --- /dev/null +++ b/sources/project/projectpropertieshandler.h @@ -0,0 +1,53 @@ +/* + Copyright 2006-2023 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 PROJECTPROPERTIESHANDLER_H +#define PROJECTPROPERTIESHANDLER_H + +#include + +#include "../TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.h" + +class QETProject; + +/** + * @brief The ProjectPropertiesHandler class + * A central class who handle, keep and provide all utilities + * to easily manage all kind of properties used in a project. + * + * This is a new class since QElectroTech 0.9 + * by consequent she is small and you can found a lot of properties (made before qet 0.9) + * everywhere in the code. + * All new properties should be managed by this class + * (of course if it make sense to be managed by this class). + * Older properties who are not managed by this class but should be, + * will be managed in future. + */ +class ProjectPropertiesHandler +{ + public: + ProjectPropertiesHandler(QETProject *project); + + TerminalStripLayoutsHandler& terminalStripLayoutHandler(); + + private: + QPointer m_project; + + TerminalStripLayoutsHandler m_terminal_strip_layout_handler; +}; + +#endif // PROJECTPROPERTIESHANDLER_H diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index e811c61a4..bdca6d7ce 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -51,12 +51,18 @@ static int BACKUP_INTERVAL = 120000; //interval in ms of backup = 2min QETProject::QETProject(QObject *parent) : QObject (parent), m_titleblocks_collection(this), - m_data_base(this, this) + m_data_base(this, this), + m_project_properties_handler{this} { setDefaultTitleBlockProperties(TitleBlockProperties::defaultProperties()); m_elements_collection = new XmlElementCollection(this); - init(); + init(); +} + +ProjectPropertiesHandler &QETProject::projectPropertiesHandler() +{ + return m_project_properties_handler; } /** @@ -68,7 +74,8 @@ QETProject::QETProject(QObject *parent) : QETProject::QETProject(const QString &path, QObject *parent) : QObject (parent), m_titleblocks_collection(this), - m_data_base(this, this) + m_data_base(this, this), + m_project_properties_handler{this} { QFile file(path); m_state = openFile(&file); @@ -89,7 +96,8 @@ QETProject::QETProject(const QString &path, QObject *parent) : QETProject::QETProject(KAutoSaveFile *backup, QObject *parent) : QObject (parent), m_titleblocks_collection(this), - m_data_base(this, this) + m_data_base(this, this), + m_project_properties_handler{this} { m_state = openFile(backup); //Failed to open from the backup, try to open the crashed diff --git a/sources/qetproject.h b/sources/qetproject.h index ca160837a..3078b5286 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -20,6 +20,7 @@ #include "ElementsCollection/elementslocation.h" #include "NameList/nameslist.h" +#include "project/projectpropertieshandler.h" #include "borderproperties.h" #include "conductorproperties.h" #include "dataBase/projectdatabase.h" @@ -27,10 +28,12 @@ #include "properties/xrefproperties.h" #include "titleblock/templatescollection.h" #include "titleblockproperties.h" + #ifdef BUILD_WITHOUT_KF5 #else # include #endif + #include class Diagram; @@ -86,6 +89,7 @@ class QETProject : public QObject // methods public: + ProjectPropertiesHandler& projectPropertiesHandler(); projectDataBase *dataBase(); QUuid uuid() const; ProjectState state() const; @@ -291,6 +295,8 @@ class QETProject : public QObject QUuid m_uuid = QUuid::createUuid(); projectDataBase m_data_base; QVector m_terminal_strip_vector; + + ProjectPropertiesHandler m_project_properties_handler; }; Q_DECLARE_METATYPE(QETProject *) From f07e4319d3ee3f7aad31d091cd946ba488bcc010 Mon Sep 17 00:00:00 2001 From: joshua Date: Thu, 5 Jan 2023 19:20:41 +0100 Subject: [PATCH 2/8] Fix ftbfs --- .../GraphicsItem/properties/terminalstriplayoutpattern.h | 3 ++- .../GraphicsItem/properties/terminalstriplayoutshandler.cpp | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutpattern.h b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutpattern.h index 5050c9eab..ac8aac7e1 100644 --- a/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutpattern.h +++ b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutpattern.h @@ -18,10 +18,11 @@ #ifndef TERMINALSTRIPLAYOUTPATTERN_H #define TERMINALSTRIPLAYOUTPATTERN_H +#include #include #include +#include #include -#include /** * @brief The TerminalStripLayoutPattern class diff --git a/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.cpp b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.cpp index 45a3504e8..148728e43 100644 --- a/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.cpp +++ b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.cpp @@ -21,8 +21,9 @@ TerminalStripLayoutsHandler::TerminalStripLayoutsHandler() { - m_default_layout = new TerminalStripLayoutPattern; - m_default_layout->m_name = QObject("Disposition par défaut"); + + m_default_layout = QSharedPointer::create(); + m_default_layout->m_name = QObject::tr("Disposition par défaut"); } QSharedPointer TerminalStripLayoutsHandler::defaultLayout() From 470e4a059bac3893c0b6a339fa0ec5968c3ce8dd Mon Sep 17 00:00:00 2001 From: joshua Date: Tue, 21 Feb 2023 21:44:28 +0100 Subject: [PATCH 3/8] Add widget to edit terminal strip item layout The widget is available in the project properties editor. WIP --- qelectrotech.pro | 5 +- .../GraphicsItem/terminalstripdrawer.cpp | 16 +- .../GraphicsItem/terminalstripdrawer.h | 1 + .../terminalstripprojectconfigpage.cpp | 49 ++ .../terminalstripprojectconfigpage.h | 46 + .../ui/terminalstriplayouteditor.cpp | 199 +++++ .../ui/terminalstriplayouteditor.h | 54 ++ .../ui/terminalstriplayouteditor.ui | 791 ++++++++++++++++++ sources/ui/projectpropertiesdialog.cpp | 13 +- sources/ui/projectpropertiesdialog.h | 3 +- 10 files changed, 1171 insertions(+), 6 deletions(-) create mode 100644 sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp create mode 100644 sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.h create mode 100644 sources/TerminalStrip/ui/terminalstriplayouteditor.cpp create mode 100644 sources/TerminalStrip/ui/terminalstriplayouteditor.h create mode 100644 sources/TerminalStrip/ui/terminalstriplayouteditor.ui diff --git a/qelectrotech.pro b/qelectrotech.pro index 887d65344..5729674e9 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -161,6 +161,7 @@ HEADERS += $$files(sources/*.h) \ $$files(sources/print/*.h) \ $$files(sources/TerminalStrip/*.h) \ $$files(sources/TerminalStrip/ui/*.h) \ + $$files(sources/TerminalStrip/ui/ConfigPage/*h) \ $$files(sources/TerminalStrip/UndoCommand/*.h) \ $$files(sources/TerminalStrip/GraphicsItem/*.h) \ $$files(sources/TerminalStrip/GraphicsItem/properties/*.h) \ @@ -202,6 +203,7 @@ SOURCES += $$files(sources/*.cpp) \ $$files(sources/print/*.cpp) \ $$files(sources/TerminalStrip/*.cpp) \ $$files(sources/TerminalStrip/ui/*.cpp) \ + $$files(sources/TerminalStrip/ui/ConfigPage/*cpp) \ $$files(sources/TerminalStrip/UndoCommand/*.cpp) \ $$files(sources/TerminalStrip/GraphicsItem/*.cpp) \ $$files(sources/TerminalStrip/GraphicsItem/properties/*.cpp) \ @@ -236,7 +238,8 @@ FORMS += $$files(sources/richtext/*.ui) \ $$files(sources/dataBase/ui/*.ui) \ $$files(sources/factory/ui/*.ui) \ $$files(sources/print/*.ui) \ - $$files(sources/TerminalStrip/ui/*.ui) + $$files(sources/TerminalStrip/ui/*.ui) \ + $$files(sources/TerminalStrip/ui/ConfigPage/*.ui) UI_SOURCES_DIR = sources/ui/ UI_HEADERS_DIR = sources/ui/ diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp index 9a608e08e..940a974ef 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp @@ -62,6 +62,14 @@ void TerminalStripDrawer::paint(QPainter *painter) painter->setPen(pen_); painter->setBrush(brush_); + if (m_debug_draw) + { + painter->save(); + painter->setPen(Qt::blue); + painter->drawRect(boundingRect()); + painter->restore(); + } + //Draw header painter->drawRect(m_pattern->m_header_rect); @@ -141,6 +149,13 @@ void TerminalStripDrawer::paint(QPainter *painter) painter->drawText(text_rect, shared_real_terminal ? shared_real_terminal->label() : QLatin1String(), terminals_text_option[index_]); + + if (m_debug_draw) + { + painter->setPen(Qt::blue); + painter->drawRect(text_rect); + } + painter->restore(); //Add bridge anchor @@ -169,7 +184,6 @@ void TerminalStripDrawer::paint(QPainter *painter) x_offset += terminal_rect.width(); } } - painter->restore(); //Draw the bridges diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h index b97e3658a..681a5b086 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h @@ -44,6 +44,7 @@ class TerminalStripDrawer private: QPointer m_strip; QSharedPointer m_pattern; + bool m_debug_draw { false }; }; #endif // TERMINALSTRIPDRAWER_H diff --git a/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp b/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp new file mode 100644 index 000000000..985a3df8f --- /dev/null +++ b/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp @@ -0,0 +1,49 @@ +/* + Copyright 2006-2023 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 "terminalstripprojectconfigpage.h" +#include "../../../qeticons.h" +#include "../terminalstriplayouteditor.h" +#include "../../../qetproject.h" + +#include + +TerminalStripProjectConfigPage::TerminalStripProjectConfigPage(QETProject *project, + QWidget *parent) : + ProjectConfigPage { project, parent } +{ + initWidgets(); +} + +QString TerminalStripProjectConfigPage::title() const { + return tr("Plan de bornes"); +} + +QIcon TerminalStripProjectConfigPage::icon() const { + return QET::Icons::TerminalStrip; +} + +void TerminalStripProjectConfigPage::initWidgets() +{ + m_layout_editor = new TerminalStripLayoutEditor{ project()->projectPropertiesHandler().terminalStripLayoutHandler().defaultLayout(), + this }; + + auto v_layout = new QVBoxLayout { this }; + v_layout->addWidget(m_layout_editor); + v_layout->addStretch(); + setLayout(v_layout); +} diff --git a/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.h b/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.h new file mode 100644 index 000000000..404dd0812 --- /dev/null +++ b/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.h @@ -0,0 +1,46 @@ +/* + Copyright 2006-2023 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 TERMINALSTRIPPROJECTCONFIGPAGE_H +#define TERMINALSTRIPPROJECTCONFIGPAGE_H + +#include "../../../ui/configpage/projectconfigpages.h" + +class TerminalStripLayoutEditor; + +class TerminalStripProjectConfigPage : public ProjectConfigPage +{ + Q_OBJECT + public: + TerminalStripProjectConfigPage(QETProject *project, QWidget *parent = nullptr); + + QString title() const override; + QIcon icon() const override; + + void applyProjectConf() override {} + + protected: + void initWidgets() override; + void initLayout() override{} + void readValuesFromProject() override {} + void adjustReadOnly() override {} + + private: + TerminalStripLayoutEditor *m_layout_editor { nullptr }; +}; + +#endif // TERMINALSTRIPPROJECTCONFIGPAGE_H diff --git a/sources/TerminalStrip/ui/terminalstriplayouteditor.cpp b/sources/TerminalStrip/ui/terminalstriplayouteditor.cpp new file mode 100644 index 000000000..b9a573006 --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstriplayouteditor.cpp @@ -0,0 +1,199 @@ +/* + Copyright 2006-2023 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 "terminalstriplayouteditor.h" +#include "ui_terminalstriplayouteditor.h" +#include "../GraphicsItem/properties/terminalstriplayoutpattern.h" + +TerminalStripLayoutEditor::TerminalStripLayoutEditor(QSharedPointer layout, + QWidget *parent) : + QWidget{ parent }, + ui{ new Ui::TerminalStripLayoutEditor }, + m_layout{ layout } +{ + ui->setupUi(this); + updateUi(); +} + +TerminalStripLayoutEditor::~TerminalStripLayoutEditor() +{ + delete ui; +} + +void TerminalStripLayoutEditor::valueEdited() +{ + if (!m_layout || m_ui_updating) { + return; + } + + //auto *data_ = m_layout.data(); + + m_layout.data()->m_header_rect.setRect(0, + ui->m_y_header_sb->value(), + ui->m_width_header_sb->value(), + ui->m_height_header_sb->value()); + + m_layout.data()->m_spacer_rect.setRect(0, + ui->m_y_spacer_sb->value(), + ui->m_width_spacer_sb->value(), + ui->m_height_spacer_sb->value()); + + m_layout.data()->m_terminal_rect[0].setRect(0, + ui->m_y_terminal_0_sb->value(), + ui->m_width_terminal_0_sb->value(), + ui->m_height_terminal_0_sb->value()); + + m_layout.data()->m_terminal_rect[1].setRect(0, + ui->m_y_terminal_1_sb->value(), + ui->m_width_terminal_1_sb->value(), + ui->m_height_terminal_1_sb->value()); + + m_layout.data()->m_terminal_rect[2].setRect(0, + ui->m_y_terminal_2_sb->value(), + ui->m_width_terminal_2_sb->value(), + ui->m_height_terminal_2_sb->value()); + + m_layout.data()->m_terminal_rect[3].setRect(0, + ui->m_y_terminal_3_sb->value(), + ui->m_width_terminal_3_sb->value(), + ui->m_height_terminal_3_sb->value()); + + m_layout.data()->m_bridge_point_y_offset[0] = ui->m_bridge_point_0_sb->value(); + m_layout.data()->m_bridge_point_y_offset[1] = ui->m_bridge_point_1_sb->value(); + m_layout.data()->m_bridge_point_y_offset[2] = ui->m_bridge_point_2_sb->value(); + m_layout.data()->m_bridge_point_y_offset[3] = ui->m_bridge_point_3_sb->value(); + + m_layout.data()->m_header_text_orientation = ui->m_header_text_orientation_cb->currentIndex() == 0 ? + Qt::Horizontal : + Qt::Vertical; + + switch (ui->m_header_text_alignment_cb->currentIndex()) { + case 0: + m_layout.data()->setHeaderTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); break; + case 1: + m_layout.data()->setHeaderTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); break; + default: + m_layout.data()->setHeaderTextAlignment(Qt::AlignRight | Qt::AlignVCenter); break; + } + + m_layout.data()->m_terminals_text_orientation[0] = ui->m_terminal_text_orientation_cb->currentIndex() == 0 ? + Qt::Horizontal : + Qt::Vertical; + + switch (ui->m_terminal_text_alignment_cb->currentIndex()) { + case 0: + m_layout.data()->setTerminalsTextAlignment( + QVector { Qt::AlignLeft | Qt::AlignVCenter, + Qt::AlignLeft | Qt::AlignVCenter, + Qt::AlignLeft | Qt::AlignVCenter, + Qt::AlignLeft | Qt::AlignVCenter }); + break; + case 1: + m_layout.data()->setTerminalsTextAlignment( + QVector { Qt::AlignHCenter | Qt::AlignVCenter, + Qt::AlignHCenter | Qt::AlignVCenter, + Qt::AlignHCenter | Qt::AlignVCenter, + Qt::AlignHCenter | Qt::AlignVCenter }); + break; + default: + m_layout.data()->setTerminalsTextAlignment( + QVector { Qt::AlignRight | Qt::AlignVCenter, + Qt::AlignRight | Qt::AlignVCenter, + Qt::AlignRight | Qt::AlignVCenter, + Qt::AlignRight | Qt::AlignVCenter }); + break; + } + + +} + +void TerminalStripLayoutEditor::updateUi() +{ + if (!m_layout) { + return; + } + + const auto data = m_layout.data(); + + m_ui_updating = true; + + ui->m_y_header_sb->setValue(data->m_header_rect.y()); + ui->m_width_header_sb->setValue(data->m_header_rect.width()); + ui->m_height_header_sb->setValue(data->m_header_rect.height()); + + ui->m_y_spacer_sb->setValue(data->m_spacer_rect.y()); + ui->m_width_spacer_sb->setValue(data->m_spacer_rect.width()); + ui->m_height_spacer_sb->setValue(data->m_spacer_rect.height()); + + const auto terminal_0 = data->m_terminal_rect[0]; + ui->m_y_terminal_0_sb->setValue(terminal_0.y()); + ui->m_height_terminal_0_sb->setValue(terminal_0.height()); + ui->m_width_terminal_0_sb->setValue(terminal_0.width()); + + const auto terminal_1 = data->m_terminal_rect[1]; + ui->m_y_terminal_1_sb->setValue(terminal_1.y()); + ui->m_height_terminal_1_sb->setValue(terminal_1.height()); + ui->m_width_terminal_1_sb->setValue(terminal_1.width()); + + const auto terminal_2 = data->m_terminal_rect[2]; + ui->m_y_terminal_2_sb->setValue(terminal_2.y()); + ui->m_height_terminal_2_sb->setValue(terminal_2.height()); + ui->m_width_terminal_2_sb->setValue(terminal_2.width()); + + const auto terminal_3 = data->m_terminal_rect[3]; + ui->m_y_terminal_3_sb->setValue(terminal_3.y()); + ui->m_height_terminal_3_sb->setValue(terminal_3.height()); + ui->m_width_terminal_3_sb->setValue(terminal_3.width()); + + const auto bridge_point = data->m_bridge_point_y_offset; + ui->m_bridge_point_0_sb->setValue(bridge_point[0]); + ui->m_bridge_point_1_sb->setValue(bridge_point[1]); + ui->m_bridge_point_2_sb->setValue(bridge_point[2]); + ui->m_bridge_point_3_sb->setValue(bridge_point[3]); + + if (data->m_header_text_orientation == Qt::Horizontal) { + ui->m_header_text_orientation_cb->setCurrentIndex(0); + } else { + ui->m_header_text_orientation_cb->setCurrentIndex(1); + } + + if (data->m_terminals_text_orientation[0] == Qt::Horizontal) { + ui->m_terminal_text_orientation_cb->setCurrentIndex(0); + } else { + ui->m_terminal_text_orientation_cb->setCurrentIndex(1); + } + + const auto header_alignment = data->headerTextAlignment(); + if (header_alignment &Qt::AlignLeft) { + ui->m_header_text_alignment_cb->setCurrentIndex(0); + } else if (header_alignment &Qt::AlignHCenter) { + ui->m_header_text_alignment_cb->setCurrentIndex(1); + } else if (header_alignment &Qt::AlignRight) { + ui->m_header_text_alignment_cb->setCurrentIndex(2); + } + + const auto terminal_alignment = data->terminalsTextAlignment().at(0); + if (terminal_alignment &Qt::AlignLeft) { + ui->m_terminal_text_alignment_cb->setCurrentIndex(0); + } else if (terminal_alignment &Qt::AlignHCenter) { + ui->m_terminal_text_alignment_cb->setCurrentIndex(1); + } else if (terminal_alignment &Qt::AlignRight) { + ui->m_terminal_text_alignment_cb->setCurrentIndex(2); + } + + m_ui_updating = false; +} diff --git a/sources/TerminalStrip/ui/terminalstriplayouteditor.h b/sources/TerminalStrip/ui/terminalstriplayouteditor.h new file mode 100644 index 000000000..2d804ebc6 --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstriplayouteditor.h @@ -0,0 +1,54 @@ +/* + Copyright 2006-2023 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 TERMINALSTRIPLAYOUTEDITOR_H +#define TERMINALSTRIPLAYOUTEDITOR_H + +#include + +class TerminalStripLayoutPattern; + +namespace Ui { + class TerminalStripLayoutEditor; +} + +/** + * @brief The TerminalStripLayoutEditor class + * Widget used to edit the layout of a terminal strip item + */ +class TerminalStripLayoutEditor : public QWidget +{ + Q_OBJECT + + public: + explicit TerminalStripLayoutEditor(QSharedPointer layout, + QWidget *parent = nullptr); + ~TerminalStripLayoutEditor(); + + private slots: + void valueEdited(); + + private: + void updateUi(); + + private: + Ui::TerminalStripLayoutEditor *ui; + QSharedPointer m_layout; + bool m_ui_updating { false } ; +}; + +#endif // TERMINALSTRIPLAYOUTEDITOR_H diff --git a/sources/TerminalStrip/ui/terminalstriplayouteditor.ui b/sources/TerminalStrip/ui/terminalstriplayouteditor.ui new file mode 100644 index 000000000..17460797b --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstriplayouteditor.ui @@ -0,0 +1,791 @@ + + + TerminalStripLayoutEditor + + + + 0 + 0 + 553 + 311 + + + + Form + + + + + + Borne niveau 2 : + + + + + + + En tête : + + + + + + + 1000 + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + Horizontal + + + + + Vertical + + + + + + + + Alignement du texte d'en tête : + + + + + + + Orientation du texte d'en tête : + + + + + + + + Gauche + + + + + Centre + + + + + Droite + + + + + + + + Orientation du texte de borne : + + + + + + + + Horizontal + + + + + Vertical + + + + + + + + Alignement du texte de borne : + + + + + + + + Gauche + + + + + Centre + + + + + Droite + + + + + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Qt::Horizontal + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Décalage vertical + + + + + + + 1000 + + + + + + + Espace : + + + + + + + Borne niveau 0 : + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Borne niveau 1 : + + + + + + + Hauteur + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Borne niveau 3 : + + + + + + + 1000 + + + + + + + Qt::Horizontal + + + + + + + Largeur + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Point de pont + + + + + + + 1000 + + + + + + + 1000 + + + + + + + + + m_y_header_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 167 + 43 + + + 276 + 155 + + + + + m_y_terminal_1_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 167 + 158 + + + 276 + 155 + + + + + m_bridge_point_0_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 492 + 127 + + + 276 + 155 + + + + + m_height_terminal_0_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 384 + 127 + + + 276 + 155 + + + + + m_width_terminal_0_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 276 + 127 + + + 276 + 155 + + + + + m_y_terminal_0_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 167 + 127 + + + 276 + 155 + + + + + m_height_spacer_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 384 + 74 + + + 276 + 155 + + + + + m_height_header_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 384 + 43 + + + 276 + 155 + + + + + m_y_spacer_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 167 + 74 + + + 276 + 155 + + + + + m_width_spacer_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 276 + 74 + + + 276 + 155 + + + + + m_width_header_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 276 + 43 + + + 276 + 155 + + + + + m_y_terminal_2_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 167 + 189 + + + 276 + 155 + + + + + m_y_terminal_3_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 167 + 220 + + + 276 + 155 + + + + + m_width_terminal_1_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 276 + 158 + + + 276 + 155 + + + + + m_width_terminal_2_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 276 + 189 + + + 276 + 155 + + + + + m_width_terminal_3_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 276 + 220 + + + 276 + 155 + + + + + m_height_terminal_1_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 384 + 158 + + + 276 + 155 + + + + + m_height_terminal_2_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 384 + 189 + + + 276 + 155 + + + + + m_height_terminal_3_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 384 + 220 + + + 276 + 155 + + + + + m_bridge_point_1_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 492 + 158 + + + 276 + 155 + + + + + m_bridge_point_3_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 492 + 220 + + + 276 + 155 + + + + + m_bridge_point_2_sb + valueChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 492 + 189 + + + 276 + 155 + + + + + m_header_text_alignment_cb + currentIndexChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 506 + 259 + + + 276 + 155 + + + + + m_header_text_orientation_cb + currentIndexChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 235 + 259 + + + 276 + 155 + + + + + m_terminal_text_alignment_cb + currentIndexChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 506 + 289 + + + 276 + 155 + + + + + m_terminal_text_orientation_cb + currentIndexChanged(int) + TerminalStripLayoutEditor + valueEdited() + + + 235 + 289 + + + 276 + 155 + + + + + + valueEdited() + + diff --git a/sources/ui/projectpropertiesdialog.cpp b/sources/ui/projectpropertiesdialog.cpp index 7b4eff861..b8ced4391 100644 --- a/sources/ui/projectpropertiesdialog.cpp +++ b/sources/ui/projectpropertiesdialog.cpp @@ -20,6 +20,7 @@ #include "../configdialog.h" #include "configpage/configpages.h" #include "configpage/projectconfigpages.h" +#include "../TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.h" #include @@ -29,14 +30,20 @@ @param project : project to edit properties @param parent : parent widget of this dialog */ -ProjectPropertiesDialog::ProjectPropertiesDialog(QETProject *project, QWidget *parent) { - NewDiagramPage *newDiagramPage = new NewDiagramPage(project,parent,this); - ProjectAutoNumConfigPage *projectAutoNumConfigPage = new ProjectAutoNumConfigPage (project); +ProjectPropertiesDialog::ProjectPropertiesDialog(QETProject *project, QWidget *parent) +{ m_properties_dialog = new ConfigDialog (parent); m_properties_dialog -> setWindowTitle(QObject::tr("Propriétés du projet", "window title")); m_properties_dialog -> addPage(new ProjectMainConfigPage(project)); + + NewDiagramPage *newDiagramPage = new NewDiagramPage(project,parent,this); m_properties_dialog -> addPage(newDiagramPage); + + ProjectAutoNumConfigPage *projectAutoNumConfigPage = new ProjectAutoNumConfigPage (project); m_properties_dialog -> addPage(projectAutoNumConfigPage); + + m_properties_dialog->addPage(new TerminalStripProjectConfigPage { project, parent }); + connect(projectAutoNumConfigPage,SIGNAL(setAutoNum(QString)),newDiagramPage,SLOT(setFolioAutonum(QString))); connect(projectAutoNumConfigPage,SIGNAL(saveCurrentTbp()),newDiagramPage,SLOT(saveCurrentTbp())); connect(projectAutoNumConfigPage,SIGNAL(loadSavedTbp()),newDiagramPage,SLOT(loadSavedTbp())); diff --git a/sources/ui/projectpropertiesdialog.h b/sources/ui/projectpropertiesdialog.h index 203521813..246175495 100644 --- a/sources/ui/projectpropertiesdialog.h +++ b/sources/ui/projectpropertiesdialog.h @@ -32,7 +32,8 @@ class ProjectPropertiesDialog : public QObject { enum Page { Main = 0, Diagram = 1, - Autonum = 2 + Autonum = 2, + TerminalStrip = 3 }; ProjectPropertiesDialog(QETProject *project, QWidget *parent = nullptr); From 45b8cb34f3e5ec6cca2efc1e362e56226dba23fc Mon Sep 17 00:00:00 2001 From: joshua Date: Fri, 10 Mar 2023 20:19:12 +0100 Subject: [PATCH 4/8] Fix minor gui wrong behavior --- sources/TerminalStrip/ui/terminalstripeditor.cpp | 1 + sources/TerminalStrip/ui/terminalstripmodel.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sources/TerminalStrip/ui/terminalstripeditor.cpp b/sources/TerminalStrip/ui/terminalstripeditor.cpp index 1f76a405c..a2ff47b99 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.cpp +++ b/sources/TerminalStrip/ui/terminalstripeditor.cpp @@ -180,6 +180,7 @@ void TerminalStripEditor::reload() if (m_model) { m_model->reload(); + spanMultiLevelTerminals(); } } diff --git a/sources/TerminalStrip/ui/terminalstripmodel.cpp b/sources/TerminalStrip/ui/terminalstripmodel.cpp index e983a1f64..c96b5bd35 100644 --- a/sources/TerminalStrip/ui/terminalstripmodel.cpp +++ b/sources/TerminalStrip/ui/terminalstripmodel.cpp @@ -186,7 +186,7 @@ QVariant TerminalStripModel::data(const QModelIndex &index, int role) const { return mrtd.led_ ? Qt::Checked : Qt::Unchecked; } - else if (role == Qt::BackgroundRole && index.column() <= CONDUCTOR_CELL ) + else if (role == Qt::BackgroundRole && index.column() < COLUMN_COUNT ) { if (m_modified_cell.contains(mrtd.element_) && m_modified_cell.value(mrtd.element_).at(index.column())) From 752fe032e72b4872e31606fb7db7cce3ee5108e4 Mon Sep 17 00:00:00 2001 From: joshua Date: Sun, 19 Mar 2023 19:19:53 +0100 Subject: [PATCH 5/8] Draw strong line for better sepration between terminal --- .../GraphicsItem/terminalstripdrawer.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp index 940a974ef..731c5160c 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp @@ -130,6 +130,23 @@ void TerminalStripDrawer::paint(QPainter *painter) terminal_rect = m_pattern->m_terminal_rect[index_]; //Draw terminal rect painter->drawRect(terminal_rect); + //Draw a stronger line if the current terminal have level + //and the current level is the first + if (real_t_count > 1 && i == 0) + { + painter->save(); + pen_ = painter->pen(); + pen_.setWidth(4); + pen_.setCapStyle(Qt::FlatCap); + painter->setPen(pen_); + const auto p1 { terminal_rect.topLeft() }; + //We can't use terminal_rect.bottomLeft for p2 because + //the returned value deviate from the true value + //(see Qt documentation about QRect) + const QPoint p2 { p1.x(), p1.y() + terminal_rect.height() }; + painter->drawLine(p1, p2); + painter->restore(); + } //Draw text painter->save(); From 48f9ef763202abe0a07330bf0249d2383ebea1c8 Mon Sep 17 00:00:00 2001 From: joshua Date: Mon, 15 May 2023 22:22:12 +0200 Subject: [PATCH 6/8] Add AbstractTerminalStrip class to be used by TerminalStripDrawer class --- .../GraphicsItem/terminalstripdrawer.cpp | 22 +-- .../GraphicsItem/terminalstripdrawer.h | 78 +++++++--- .../GraphicsItem/terminalstripitem.h | 4 +- .../GraphicsItem/trueterminalstrip.cpp | 133 ++++++++++++++++++ .../GraphicsItem/trueterminalstrip.h | 78 ++++++++++ 5 files changed, 286 insertions(+), 29 deletions(-) create mode 100644 sources/TerminalStrip/GraphicsItem/trueterminalstrip.cpp create mode 100644 sources/TerminalStrip/GraphicsItem/trueterminalstrip.h diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp index 731c5160c..8448cecfa 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp @@ -22,6 +22,9 @@ #include "../realterminal.h" #include "../terminalstrip.h" #include "../terminalstripbridge.h" +#include "trueterminalstrip.h" + +namespace TerminalStripDrawer { /** * @brief TerminalStripDrawer::TerminalStripDrawer @@ -30,13 +33,13 @@ */ TerminalStripDrawer::TerminalStripDrawer(QPointer strip, QSharedPointer layout) : - m_strip(strip), + m_strip{new TrueTerminalStrip{strip.data()}}, m_pattern(layout) {} void TerminalStripDrawer::setStrip(TerminalStrip *strip) { - m_strip = strip; + m_strip.reset(new TrueTerminalStrip{strip}); } /** @@ -115,8 +118,8 @@ void TerminalStripDrawer::paint(QPainter *painter) for (const auto &physical_t : m_strip->physicalTerminal()) { //Get the good offset according to how many level have the current physical terminal - const QVector> real_terminal{physical_t->realTerminals()}; - const auto real_t_count{real_terminal.size()}; + const QVector> real_terminal_vector{physical_t->realTerminals()}; + const auto real_t_count{real_terminal_vector.size()}; const auto offset_{4 - real_t_count}; //Loop over real terminals @@ -162,7 +165,7 @@ void TerminalStripDrawer::paint(QPainter *painter) text_rect.setRect(0, 0, rect_.height(), rect_.width()); } - const auto shared_real_terminal{real_terminal[i]}; + const auto shared_real_terminal{real_terminal_vector[i]}; painter->drawText(text_rect, shared_real_terminal ? shared_real_terminal->label() : QLatin1String(), terminals_text_option[index_]); @@ -179,7 +182,8 @@ void TerminalStripDrawer::paint(QPainter *painter) if (shared_real_terminal->isBridged()) { painter->save(); - if (const auto bridge_ = shared_real_terminal->bridge()) + if (QScopedPointer bridge_ { + shared_real_terminal->bridge() }) { const auto x_anchor{terminal_rect.width()/2}; const auto y_anchor {m_pattern->m_bridge_point_y_offset[index_]}; @@ -261,8 +265,8 @@ int TerminalStripDrawer::width() const for (const auto &physical_t : m_strip->physicalTerminal()) { //Get the good offset according to how many level have the current physical terminal - const QVector> real_terminal{physical_t->realTerminals()}; - const auto real_t_count{real_terminal.size()}; + const QVector> real_terminal_vector{physical_t->realTerminals()}; + const auto real_t_count{real_terminal_vector.size()}; const auto offset_{4 - real_t_count}; //Loop over real terminals @@ -283,3 +287,5 @@ int TerminalStripDrawer::width() const return 0; } + +} //End namespace TerminalStripDrawer diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h index 681a5b086..d32f434e8 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h @@ -1,5 +1,5 @@ /* - Copyright 2006-2022 The QElectroTech Team + Copyright 2006-2023 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify @@ -19,32 +19,74 @@ #define TERMINALSTRIPDRAWER_H #include + #include "properties/terminalstriplayoutpattern.h" class QPainter; class TerminalStrip; -class TerminalStripDrawer +namespace TerminalStripDrawer { - public: - TerminalStripDrawer(QPointer strip = QPointer(), - QSharedPointer layout = QSharedPointer()); + class AbstractBridgeInterface + { + public: + AbstractBridgeInterface() {} + virtual ~AbstractBridgeInterface() {} + virtual QUuid uuid() const = 0; + }; - void setStrip(TerminalStrip *strip); - void paint(QPainter *painter); - QRectF boundingRect() const; + class AbstractRealTerminalInterface + { + public: + AbstractRealTerminalInterface() {} + virtual ~AbstractRealTerminalInterface() {} + virtual QString label() const = 0; + virtual bool isBridged() const = 0; + virtual AbstractBridgeInterface* bridge() const = 0; + }; - void setLayout(QSharedPointer layout); - bool haveLayout() const; + class AbstractPhysicalTerminalInterface + { + public: + AbstractPhysicalTerminalInterface() {} + virtual ~AbstractPhysicalTerminalInterface() {} + virtual QVector> realTerminals() const = 0; + }; - private: - int height() const; - int width() const; + class AbstractTerminalStripInterface + { + public: + AbstractTerminalStripInterface() {} + virtual ~AbstractTerminalStripInterface() {} + virtual QString installation() const = 0; + virtual QString location() const = 0; + virtual QString name() const = 0; + virtual QVector> physicalTerminal() const = 0; + virtual bool operator()() = 0; + }; - private: - QPointer m_strip; - QSharedPointer m_pattern; - bool m_debug_draw { false }; -}; + class TerminalStripDrawer + { + public: + TerminalStripDrawer(QPointer strip = QPointer(), + QSharedPointer layout = QSharedPointer()); + + void setStrip(TerminalStrip *strip); + void paint(QPainter *painter); + QRectF boundingRect() const; + + void setLayout(QSharedPointer layout); + bool haveLayout() const; + + private: + int height() const; + int width() const; + + private: + QScopedPointer m_strip; + QSharedPointer m_pattern; + bool m_debug_draw { false }; + }; +} #endif // TERMINALSTRIPDRAWER_H diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripitem.h b/sources/TerminalStrip/GraphicsItem/terminalstripitem.h index d60e5ad35..b26a6dd8b 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripitem.h +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.h @@ -47,9 +47,7 @@ class TerminalStripItem : public QetGraphicsItem QString name() const override; void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; - void refreshPending(); - void setLayout(QSharedPointer layout); private: @@ -57,7 +55,7 @@ class TerminalStripItem : public QetGraphicsItem private: QPointer m_strip; - TerminalStripDrawer m_drawer; + TerminalStripDrawer::TerminalStripDrawer m_drawer; QUuid m_pending_strip_uuid; }; diff --git a/sources/TerminalStrip/GraphicsItem/trueterminalstrip.cpp b/sources/TerminalStrip/GraphicsItem/trueterminalstrip.cpp new file mode 100644 index 000000000..612f01425 --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/trueterminalstrip.cpp @@ -0,0 +1,133 @@ +/* + Copyright 2006-2023 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 "trueterminalstrip.h" +#include "../physicalterminal.h" +#include "../realterminal.h" +#include "../terminalstrip.h" +#include "../terminalstripbridge.h" + +#include "terminalstripdrawer.h" + +namespace TerminalStripDrawer +{ + TrueTerminalStrip::TrueTerminalStrip(TerminalStrip *strip) : + m_strip { strip } + {} + + + QString TrueTerminalStrip::installation() const + { + if (m_strip) { + return m_strip->installation(); + } else { + return QString(); + } + } + + QString TrueTerminalStrip::location() const + { + if (m_strip) { + return m_strip->location(); + } else { + return QString(); + } + } + + QString TrueTerminalStrip::name() const + { + if (m_strip) { + return m_strip->name(); + } else { + return QString(); + } + } + + QVector> TrueTerminalStrip::physicalTerminal() const + { + QVector> vector_; + if (m_strip) { + for (const auto &phy : m_strip->physicalTerminal()) { + vector_.append(QSharedPointer{ new TruePhysicalTerminal(phy) }); + } + } + + return vector_; + } + + bool TrueTerminalStrip::operator()() + { + return m_strip; + } + + TruePhysicalTerminal::TruePhysicalTerminal(QSharedPointer physical) : + m_physical { physical } + {} + + QVector> TruePhysicalTerminal::realTerminals() const + { + QVector> vector_; + if (m_physical) { + for (const auto &real_ : m_physical->realTerminals()) { + vector_.append(QSharedPointer { new TrueRealTerminal{ real_ }}); + } + } + + return vector_; + } + + TrueRealTerminal::TrueRealTerminal(QSharedPointer real) : + m_real { real } + {} + + QString TrueRealTerminal::label() const + { + if (m_real) { + return m_real->label(); + } else { + return QString(); + } + } + + bool TrueRealTerminal::isBridged() const + { + if (m_real) { + return m_real->isBridged(); + } else { + return false; + } + } + + //Return a raw pointer, the pointer is not managed by this class + AbstractBridgeInterface* TrueRealTerminal::bridge() const + { + return new TrueBridge(m_real->bridge()); + } + + TrueBridge::TrueBridge(QSharedPointer bridge) : + m_bridge { bridge } + {} + + QUuid TrueBridge::uuid() const + { + if (m_bridge) { + return m_bridge->uuid(); + } else { + return QUuid(); + } + } +} diff --git a/sources/TerminalStrip/GraphicsItem/trueterminalstrip.h b/sources/TerminalStrip/GraphicsItem/trueterminalstrip.h new file mode 100644 index 000000000..9853304f7 --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/trueterminalstrip.h @@ -0,0 +1,78 @@ +/* + Copyright 2006-2023 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 TRUETERMINALSTRIP_H +#define TRUETERMINALSTRIP_H + +#include "terminalstripdrawer.h" + +class TerminalStrip; +class PhysicalTerminal; +class RealTerminal; +class TerminalStripBridge; + +namespace TerminalStripDrawer +{ + class TrueTerminalStrip : public AbstractTerminalStripInterface + { + public: + TrueTerminalStrip(TerminalStrip *strip); + + QString installation() const override; + QString location() const override; + QString name() const override; + QVector> physicalTerminal() const override; + bool operator()() override; + + private: + QPointer m_strip; + }; + + class TruePhysicalTerminal : public AbstractPhysicalTerminalInterface + { + public: + TruePhysicalTerminal(QSharedPointer physical); + QVector> realTerminals() const override; + + private: + QSharedPointer m_physical; + }; + + class TrueRealTerminal : public AbstractRealTerminalInterface + { + public: + TrueRealTerminal(QSharedPointer real); + QString label() const override; + bool isBridged() const override; + AbstractBridgeInterface* bridge() const override; + + private: + QSharedPointer m_real; + }; + + class TrueBridge : public AbstractBridgeInterface + { + public: + TrueBridge(QSharedPointer bridge); + QUuid uuid() const override; + + private: + QSharedPointer m_bridge; + }; +} + +#endif // TRUETERMINALSTRIP_H From 8ca1e0487efb2904f44d2eb7caa6456f0c87d4d2 Mon Sep 17 00:00:00 2001 From: joshua Date: Wed, 28 Jun 2023 21:56:03 +0200 Subject: [PATCH 7/8] Add demo terminal strip class Not available for user now. --- .../GraphicsItem/demoterminalstrip.cpp | 142 ++++++++++++++++++ .../GraphicsItem/demoterminalstrip.h | 50 ++++++ .../GraphicsItem/terminalstripdrawer.cpp | 12 +- .../GraphicsItem/terminalstripdrawer.h | 7 +- .../GraphicsItem/terminalstripitem.cpp | 20 ++- .../GraphicsItem/trueterminalstrip.cpp | 10 +- .../GraphicsItem/trueterminalstrip.h | 3 +- 7 files changed, 220 insertions(+), 24 deletions(-) create mode 100644 sources/TerminalStrip/GraphicsItem/demoterminalstrip.cpp create mode 100644 sources/TerminalStrip/GraphicsItem/demoterminalstrip.h diff --git a/sources/TerminalStrip/GraphicsItem/demoterminalstrip.cpp b/sources/TerminalStrip/GraphicsItem/demoterminalstrip.cpp new file mode 100644 index 000000000..958e8bf7e --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/demoterminalstrip.cpp @@ -0,0 +1,142 @@ +/* + Copyright 2006-2023 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 "demoterminalstrip.h" + +namespace TerminalStripDrawer +{ + +/*========= DemoBridge =========*/ + class DemoBridge : public AbstractBridgeInterface + { + public: + DemoBridge(const QUuid &uuid) : + m_uuid { uuid } {} + + QUuid uuid() const override { + return m_uuid; + } + + private: + const QUuid m_uuid; + }; + + class DemoRealTerminal : public AbstractRealTerminalInterface + { + public: + DemoRealTerminal(const QString &label, const QUuid &bridge) : + m_label { label }, + m_bridge { bridge } + {} + + QString label() const override { + return m_label; + } + + bool isBridged() const override { + return true; + } + + DemoBridge *bridge() const override { + return new DemoBridge { m_bridge }; + } + + private: + QString m_label; + QUuid m_bridge; + }; + + class DemoPhysicalTerminal : public AbstractPhysicalTerminalInterface + { + public: + DemoPhysicalTerminal(QVector> real_terminals) : + m_real_terminals { real_terminals} + {} + + QVector> realTerminals() const override { + return m_real_terminals; + } + + private: + QVector> m_real_terminals; + }; + + + +/*========= DemoTerminalStrip =========*/ + + /** + * @brief DemoTerminalStrip::DemoTerminalStrip + */ + DemoTerminalStrip::DemoTerminalStrip() + { + build(); + } + + QVector > DemoTerminalStrip::physicalTerminal() const + { + return m_physical_terminal; + } + + void DemoTerminalStrip::build() + { + QUuid lvl_1 = QUuid::createUuid(); + QUuid lvl_2 = QUuid::createUuid(); + QUuid lvl_3 = QUuid::createUuid(); + + QVector > real_terminals_vector; + + real_terminals_vector << QSharedPointer { + new DemoRealTerminal( QStringLiteral("24vdc"), + lvl_1)}; + real_terminals_vector << QSharedPointer { + new DemoRealTerminal( QStringLiteral("0vdc"), + lvl_2)}; + real_terminals_vector << QSharedPointer { + new DemoRealTerminal( QStringLiteral("signal"), + lvl_3)}; + m_physical_terminal << QSharedPointer { + new DemoPhysicalTerminal {real_terminals_vector}}; + + real_terminals_vector.clear(); + real_terminals_vector << QSharedPointer { + new DemoRealTerminal( QStringLiteral("24vdc"), + lvl_1)}; + real_terminals_vector << QSharedPointer { + new DemoRealTerminal( QStringLiteral("0vdc"), + lvl_2)}; + real_terminals_vector << QSharedPointer { + new DemoRealTerminal( QStringLiteral("signal"), + lvl_3)}; + m_physical_terminal << QSharedPointer { + new DemoPhysicalTerminal {real_terminals_vector}}; + + real_terminals_vector.clear(); + real_terminals_vector << QSharedPointer { + new DemoRealTerminal( QStringLiteral("24vdc"), + lvl_1)}; + real_terminals_vector << QSharedPointer { + new DemoRealTerminal( QStringLiteral("0vdc"), + lvl_2)}; + real_terminals_vector << QSharedPointer { + new DemoRealTerminal( QStringLiteral("signal"), + lvl_3)}; + m_physical_terminal << QSharedPointer { + new DemoPhysicalTerminal {real_terminals_vector}}; + } + +} diff --git a/sources/TerminalStrip/GraphicsItem/demoterminalstrip.h b/sources/TerminalStrip/GraphicsItem/demoterminalstrip.h new file mode 100644 index 000000000..ea8bd069d --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/demoterminalstrip.h @@ -0,0 +1,50 @@ +/* + Copyright 2006-2023 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 DEMOTERMINALSTRIP_H +#define DEMOTERMINALSTRIP_H + +#include "terminalstripdrawer.h" + +namespace TerminalStripDrawer { + +class DemoTerminalStrip : public AbstractTerminalStripInterface +{ + public: + DemoTerminalStrip(); + + QString installation() const override { + return QStringLiteral("=INST"); + } + QString location() const override { + return QStringLiteral("+LOC" ); + } + QString name() const override { + return QStringLiteral("X1"); + } + QVector> physicalTerminal() const override; + + private: + void build(); + + private: + QVector> m_physical_terminal; +}; + +} //End namespace TerminalStripDrawer + +#endif // DEMOTERMINALSTRIP_H diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp index 8448cecfa..ace229a36 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp @@ -1,5 +1,5 @@ /* - Copyright 2006-2022 The QElectroTech Team + Copyright 2006-2023 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify @@ -31,15 +31,15 @@ namespace TerminalStripDrawer { * @param strip * @param pattern */ -TerminalStripDrawer::TerminalStripDrawer(QPointer strip, +TerminalStripDrawer::TerminalStripDrawer(QSharedPointer strip, QSharedPointer layout) : - m_strip{new TrueTerminalStrip{strip.data()}}, - m_pattern(layout) + m_strip { strip }, + m_pattern { layout } {} -void TerminalStripDrawer::setStrip(TerminalStrip *strip) +void TerminalStripDrawer::setStrip(QSharedPointer strip) { - m_strip.reset(new TrueTerminalStrip{strip}); + m_strip = strip; } /** diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h index d32f434e8..fbb00cefe 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h @@ -62,16 +62,15 @@ namespace TerminalStripDrawer virtual QString location() const = 0; virtual QString name() const = 0; virtual QVector> physicalTerminal() const = 0; - virtual bool operator()() = 0; }; class TerminalStripDrawer { public: - TerminalStripDrawer(QPointer strip = QPointer(), + TerminalStripDrawer(QSharedPointer strip = QSharedPointer { nullptr }, QSharedPointer layout = QSharedPointer()); - void setStrip(TerminalStrip *strip); + void setStrip(QSharedPointer strip); void paint(QPainter *painter); QRectF boundingRect() const; @@ -83,7 +82,7 @@ namespace TerminalStripDrawer int width() const; private: - QScopedPointer m_strip; + QSharedPointer m_strip; QSharedPointer m_pattern; bool m_debug_draw { false }; }; diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp index c6e2c344b..77f28adee 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp @@ -17,16 +17,21 @@ */ #include "terminalstripitem.h" + #include "../diagram.h" -#include "../terminalstrip.h" -#include "../ui/terminalstripeditorwindow.h" #include "../../project/projectpropertieshandler.h" #include "../../qetgraphicsitem/qgraphicsitemutility.h" +#include "../terminalstrip.h" +#include "../ui/terminalstripeditorwindow.h" +#include "trueterminalstrip.h" -TerminalStripItem::TerminalStripItem(QPointer strip, QGraphicsItem *parent) : - QetGraphicsItem{parent}, - m_strip{strip}, - m_drawer{strip} +TerminalStripItem::TerminalStripItem(QPointer strip, + QGraphicsItem *parent) : + QetGraphicsItem { parent }, + m_strip { strip }, + m_drawer { QSharedPointer { + new TerminalStripDrawer::TrueTerminalStrip { strip }} + } { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptHoverEvents(true); @@ -43,7 +48,8 @@ TerminalStripItem::TerminalStripItem(QGraphicsItem *parent) : void TerminalStripItem::setTerminalStrip(TerminalStrip *strip) { m_strip = strip; - m_drawer.setStrip(strip); + m_drawer.setStrip(QSharedPointer { + new TerminalStripDrawer::TrueTerminalStrip { strip }}); m_pending_strip_uuid = QUuid(); if (!m_drawer.haveLayout()) { diff --git a/sources/TerminalStrip/GraphicsItem/trueterminalstrip.cpp b/sources/TerminalStrip/GraphicsItem/trueterminalstrip.cpp index 612f01425..15273e4c1 100644 --- a/sources/TerminalStrip/GraphicsItem/trueterminalstrip.cpp +++ b/sources/TerminalStrip/GraphicsItem/trueterminalstrip.cpp @@ -25,6 +25,11 @@ namespace TerminalStripDrawer { + /** + * @brief TrueTerminalStrip::TrueTerminalStrip + * Constructor, this class don't take ownership of @a strip + * @param strip + */ TrueTerminalStrip::TrueTerminalStrip(TerminalStrip *strip) : m_strip { strip } {} @@ -69,11 +74,6 @@ namespace TerminalStripDrawer return vector_; } - bool TrueTerminalStrip::operator()() - { - return m_strip; - } - TruePhysicalTerminal::TruePhysicalTerminal(QSharedPointer physical) : m_physical { physical } {} diff --git a/sources/TerminalStrip/GraphicsItem/trueterminalstrip.h b/sources/TerminalStrip/GraphicsItem/trueterminalstrip.h index 9853304f7..10b3775fa 100644 --- a/sources/TerminalStrip/GraphicsItem/trueterminalstrip.h +++ b/sources/TerminalStrip/GraphicsItem/trueterminalstrip.h @@ -35,8 +35,7 @@ namespace TerminalStripDrawer QString installation() const override; QString location() const override; QString name() const override; - QVector> physicalTerminal() const override; - bool operator()() override; + QVector> physicalTerminal() const override; private: QPointer m_strip; From 12b7c7c47ca7ba10354b891e03fbccec2de8512d Mon Sep 17 00:00:00 2001 From: joshua Date: Mon, 18 Sep 2023 22:28:30 +0200 Subject: [PATCH 8/8] Terminal strip layout editor : add preview of terminal strip layout --- .../GraphicsItem/terminalstripdrawer.cpp | 6 - .../terminalstripprojectconfigpage.cpp | 1 - .../ui/terminalstriplayouteditor.cpp | 32 +- .../ui/terminalstriplayouteditor.h | 40 ++- .../ui/terminalstriplayouteditor.ui | 296 +++++++++--------- 5 files changed, 216 insertions(+), 159 deletions(-) diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp index ace229a36..0850fb82f 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.cpp @@ -18,12 +18,6 @@ #include "terminalstripdrawer.h" #include -#include "../physicalterminal.h" -#include "../realterminal.h" -#include "../terminalstrip.h" -#include "../terminalstripbridge.h" -#include "trueterminalstrip.h" - namespace TerminalStripDrawer { /** diff --git a/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp b/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp index 985a3df8f..3709cbadf 100644 --- a/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp +++ b/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp @@ -44,6 +44,5 @@ void TerminalStripProjectConfigPage::initWidgets() auto v_layout = new QVBoxLayout { this }; v_layout->addWidget(m_layout_editor); - v_layout->addStretch(); setLayout(v_layout); } diff --git a/sources/TerminalStrip/ui/terminalstriplayouteditor.cpp b/sources/TerminalStrip/ui/terminalstriplayouteditor.cpp index b9a573006..bb7c313dd 100644 --- a/sources/TerminalStrip/ui/terminalstriplayouteditor.cpp +++ b/sources/TerminalStrip/ui/terminalstriplayouteditor.cpp @@ -23,15 +23,29 @@ TerminalStripLayoutEditor::TerminalStripLayoutEditor(QSharedPointersetupUi(this); + ui->m_graphics_view->setScene(new QGraphicsScene{ this }); + ui->m_graphics_view->scene()->addItem(&m_preview_strip_item); updateUi(); } TerminalStripLayoutEditor::~TerminalStripLayoutEditor() { - delete ui; + delete ui; +} + +void TerminalStripLayoutEditor::resizeEvent(QResizeEvent *event) +{ + QWidget::resizeEvent(event); + updatePreview(); +} + +void TerminalStripLayoutEditor::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); + updatePreview(); } void TerminalStripLayoutEditor::valueEdited() @@ -118,7 +132,8 @@ void TerminalStripLayoutEditor::valueEdited() break; } - + updateUi(); + m_preview_strip_item.update(); } void TerminalStripLayoutEditor::updateUi() @@ -193,7 +208,14 @@ void TerminalStripLayoutEditor::updateUi() ui->m_terminal_text_alignment_cb->setCurrentIndex(1); } else if (terminal_alignment &Qt::AlignRight) { ui->m_terminal_text_alignment_cb->setCurrentIndex(2); - } + } - m_ui_updating = false; + m_ui_updating = false; + updatePreview(); +} + +void TerminalStripLayoutEditor::updatePreview() +{ + ui->m_graphics_view->fitInView(m_preview_strip_item.boundingRect().adjusted(-5,-5,5,5), + Qt::KeepAspectRatio); } diff --git a/sources/TerminalStrip/ui/terminalstriplayouteditor.h b/sources/TerminalStrip/ui/terminalstriplayouteditor.h index 2d804ebc6..2761c3964 100644 --- a/sources/TerminalStrip/ui/terminalstriplayouteditor.h +++ b/sources/TerminalStrip/ui/terminalstriplayouteditor.h @@ -18,14 +18,44 @@ #ifndef TERMINALSTRIPLAYOUTEDITOR_H #define TERMINALSTRIPLAYOUTEDITOR_H +#include #include +#include "../GraphicsItem/demoterminalstrip.h" +#include "../GraphicsItem/terminalstripdrawer.h" + class TerminalStripLayoutPattern; namespace Ui { class TerminalStripLayoutEditor; } +class PreviewStripItem : public QGraphicsItem +{ + public: + PreviewStripItem (QSharedPointer layout) : + m_drawer {QSharedPointer{new TerminalStripDrawer::DemoTerminalStrip}, + layout} + {} + + QRectF boundingRect() const override { + return m_drawer.boundingRect(); + } + + protected: + void paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) override + { + Q_UNUSED (option); Q_UNUSED (widget); + m_drawer.paint(painter); + } + + private: + TerminalStripDrawer::TerminalStripDrawer m_drawer; + +}; + /** * @brief The TerminalStripLayoutEditor class * Widget used to edit the layout of a terminal strip item @@ -39,16 +69,22 @@ class TerminalStripLayoutEditor : public QWidget QWidget *parent = nullptr); ~TerminalStripLayoutEditor(); + protected: + void resizeEvent(QResizeEvent *event) override; + void showEvent(QShowEvent *event) override; + private slots: void valueEdited(); - private: - void updateUi(); + private: + void updateUi(); + void updatePreview(); private: Ui::TerminalStripLayoutEditor *ui; QSharedPointer m_layout; bool m_ui_updating { false } ; + PreviewStripItem m_preview_strip_item {m_layout}; }; #endif // TERMINALSTRIPLAYOUTEDITOR_H diff --git a/sources/TerminalStrip/ui/terminalstriplayouteditor.ui b/sources/TerminalStrip/ui/terminalstriplayouteditor.ui index 17460797b..186d9bb95 100644 --- a/sources/TerminalStrip/ui/terminalstriplayouteditor.ui +++ b/sources/TerminalStrip/ui/terminalstriplayouteditor.ui @@ -7,17 +7,55 @@ 0 0 553 - 311 + 387 Form - - + + QLayout::SetMaximumSize + + + - Borne niveau 2 : + Espace : + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Borne niveau 1 : + + + + + + + 1000 @@ -28,8 +66,78 @@ - - + + + + 1000 + + + + + + + Borne niveau 0 : + + + + + + + Hauteur + + + + + + + Point de pont + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + Largeur + + + + + 1000 @@ -147,41 +255,6 @@ - - - - 1000 - - - - - - - 1000 - - - - - - - Qt::Horizontal - - - - - - - 1000 - - - - - - - 1000 - - - @@ -189,34 +262,27 @@ - - + + 1000 - - - - Espace : - - - - - - - Borne niveau 0 : - - - - - + + 1000 + + + + Borne niveau 2 : + + + @@ -224,8 +290,8 @@ - - + + 1000 @@ -238,29 +304,15 @@ - - - - Borne niveau 1 : - - - - - - - Hauteur - - - - - + + 1000 - - + + 1000 @@ -273,6 +325,20 @@ + + + + 1000 + + + + + + + 1000 + + + @@ -280,43 +346,15 @@ - - + + 1000 - - - - Qt::Horizontal - - - - - - - Largeur - - - - - - - 1000 - - - - - - - 1000 - - - - - + + 1000 @@ -329,40 +367,8 @@ - - - - 1000 - - - - - - - 1000 - - - - - - - Point de pont - - - - - - - 1000 - - - - - - - 1000 - - + +