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 *)