diff --git a/qelectrotech.pro b/qelectrotech.pro index b9ec6ecba..2524bef3e 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) \ @@ -159,13 +161,16 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.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) \ $$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) \ @@ -198,8 +203,10 @@ 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) \ $$files(sources/xml/*.cpp) \ $$files(sources/dxf/*.cpp) @@ -231,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/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/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..ac8aac7e1 100644 --- a/sources/TerminalStrip/GraphicsItem/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 @@ -82,6 +83,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..148728e43 --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/properties/terminalstriplayoutshandler.cpp @@ -0,0 +1,32 @@ +/* + 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 = QSharedPointer::create(); + m_default_layout->m_name = QObject::tr("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..0850fb82f 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 @@ -18,23 +18,22 @@ #include "terminalstripdrawer.h" #include -#include "../physicalterminal.h" -#include "../realterminal.h" -#include "../terminalstrip.h" -#include "../terminalstripbridge.h" +namespace TerminalStripDrawer { /** * @brief TerminalStripDrawer::TerminalStripDrawer * @param strip * @param pattern */ -TerminalStripDrawer::TerminalStripDrawer(QPointer strip) : - m_strip(strip) +TerminalStripDrawer::TerminalStripDrawer(QSharedPointer strip, + QSharedPointer layout) : + m_strip { strip }, + m_pattern { layout } {} -void TerminalStripDrawer::setStrip(TerminalStrip *strip) +void TerminalStripDrawer::setStrip(QSharedPointer strip) { - m_strip = strip; + m_strip = strip; } /** @@ -43,7 +42,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. @@ -60,43 +59,51 @@ 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); + 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; @@ -105,8 +112,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 @@ -117,9 +124,26 @@ 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); + //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(); @@ -135,21 +159,29 @@ 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_]); + + if (m_debug_draw) + { + painter->setPen(Qt::blue); + painter->drawRect(text_rect); + } + painter->restore(); //Add bridge anchor 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_]}; - 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), @@ -167,7 +199,6 @@ void TerminalStripDrawer::paint(QPainter *painter) x_offset += terminal_rect.width(); } } - painter->restore(); //Draw the bridges @@ -188,45 +219,67 @@ 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_vector{physical_t->realTerminals()}; + const auto real_t_count{real_terminal_vector.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; } + +} //End namespace TerminalStripDrawer diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h b/sources/TerminalStrip/GraphicsItem/terminalstripdrawer.h index 22a12349a..fbb00cefe 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,27 +19,73 @@ #define TERMINALSTRIPDRAWER_H #include -#include "terminalstriplayoutpattern.h" + +#include "properties/terminalstriplayoutpattern.h" class QPainter; class TerminalStrip; -class TerminalStripDrawer +namespace TerminalStripDrawer { - public: - TerminalStripDrawer(QPointer strip = QPointer()); + 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; + }; - private: - int height() const; - int width() const; + class AbstractPhysicalTerminalInterface + { + public: + AbstractPhysicalTerminalInterface() {} + virtual ~AbstractPhysicalTerminalInterface() {} + virtual QVector> realTerminals() const = 0; + }; - private: - QPointer m_strip; - TerminalStripLayoutPattern m_pattern; -}; + 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; + }; + + class TerminalStripDrawer + { + public: + TerminalStripDrawer(QSharedPointer strip = QSharedPointer { nullptr }, + QSharedPointer layout = QSharedPointer()); + + void setStrip(QSharedPointer strip); + void paint(QPainter *painter); + QRectF boundingRect() const; + + void setLayout(QSharedPointer layout); + bool haveLayout() const; + + private: + int height() const; + int width() const; + + private: + QSharedPointer m_strip; + QSharedPointer m_pattern; + bool m_debug_draw { false }; + }; +} #endif // TERMINALSTRIPDRAWER_H diff --git a/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp index bbdca8b2c..77f28adee 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.cpp @@ -17,18 +17,25 @@ */ #include "terminalstripitem.h" + #include "../diagram.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); + setDefaultLayout(); } TerminalStripItem::TerminalStripItem(QGraphicsItem *parent) : @@ -41,8 +48,13 @@ 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()) { + setDefaultLayout(); + } } /** @@ -106,3 +118,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..b26a6dd8b 100644 --- a/sources/TerminalStrip/GraphicsItem/terminalstripitem.h +++ b/sources/TerminalStrip/GraphicsItem/terminalstripitem.h @@ -47,12 +47,15 @@ class TerminalStripItem : public QetGraphicsItem QString name() const override; void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; - void refreshPending(); + void setLayout(QSharedPointer layout); + + private: + void setDefaultLayout(); 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..15273e4c1 --- /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 +{ + /** + * @brief TrueTerminalStrip::TrueTerminalStrip + * Constructor, this class don't take ownership of @a strip + * @param strip + */ + 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_; + } + + 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..10b3775fa --- /dev/null +++ b/sources/TerminalStrip/GraphicsItem/trueterminalstrip.h @@ -0,0 +1,77 @@ +/* + 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; + + 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 diff --git a/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp b/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp new file mode 100644 index 000000000..3709cbadf --- /dev/null +++ b/sources/TerminalStrip/ui/ConfigPage/terminalstripprojectconfigpage.cpp @@ -0,0 +1,48 @@ +/* + 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); + 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/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/terminalstriplayouteditor.cpp b/sources/TerminalStrip/ui/terminalstriplayouteditor.cpp new file mode 100644 index 000000000..bb7c313dd --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstriplayouteditor.cpp @@ -0,0 +1,221 @@ +/* + 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); + ui->m_graphics_view->setScene(new QGraphicsScene{ this }); + ui->m_graphics_view->scene()->addItem(&m_preview_strip_item); + updateUi(); +} + +TerminalStripLayoutEditor::~TerminalStripLayoutEditor() +{ + delete ui; +} + +void TerminalStripLayoutEditor::resizeEvent(QResizeEvent *event) +{ + QWidget::resizeEvent(event); + updatePreview(); +} + +void TerminalStripLayoutEditor::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); + updatePreview(); +} + +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; + } + + updateUi(); + m_preview_strip_item.update(); +} + +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; + 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 new file mode 100644 index 000000000..2761c3964 --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstriplayouteditor.h @@ -0,0 +1,90 @@ +/* + 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 +#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 + */ +class TerminalStripLayoutEditor : public QWidget +{ + Q_OBJECT + + public: + explicit TerminalStripLayoutEditor(QSharedPointer layout, + QWidget *parent = nullptr); + ~TerminalStripLayoutEditor(); + + protected: + void resizeEvent(QResizeEvent *event) override; + void showEvent(QShowEvent *event) override; + + private slots: + void valueEdited(); + + 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 new file mode 100644 index 000000000..186d9bb95 --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstriplayouteditor.ui @@ -0,0 +1,797 @@ + + + TerminalStripLayoutEditor + + + + 0 + 0 + 553 + 387 + + + + Form + + + + QLayout::SetMaximumSize + + + + + Espace : + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Borne niveau 1 : + + + + + + + 1000 + + + + + + + En tête : + + + + + + + 1000 + + + + + + + Borne niveau 0 : + + + + + + + Hauteur + + + + + + + Point de pont + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + Largeur + + + + + + + 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 + + + + + + + + + + + Décalage vertical + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Borne niveau 2 : + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + 1000 + + + + + + + Borne niveau 3 : + + + + + + + 1000 + + + + + + + 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/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())) 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 25b219739..7c0a948b9 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -52,12 +52,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; } /** @@ -69,7 +75,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); @@ -90,7 +97,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 687bdf6af..a89c12a3c 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 *) 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);