mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Add demo terminal strip class
Not available for user now.
This commit is contained in:
142
sources/TerminalStrip/GraphicsItem/demoterminalstrip.cpp
Normal file
142
sources/TerminalStrip/GraphicsItem/demoterminalstrip.cpp
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#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<QSharedPointer<AbstractRealTerminalInterface>> real_terminals) :
|
||||
m_real_terminals { real_terminals}
|
||||
{}
|
||||
|
||||
QVector<QSharedPointer<AbstractRealTerminalInterface>> realTerminals() const override {
|
||||
return m_real_terminals;
|
||||
}
|
||||
|
||||
private:
|
||||
QVector<QSharedPointer<AbstractRealTerminalInterface>> m_real_terminals;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*========= DemoTerminalStrip =========*/
|
||||
|
||||
/**
|
||||
* @brief DemoTerminalStrip::DemoTerminalStrip
|
||||
*/
|
||||
DemoTerminalStrip::DemoTerminalStrip()
|
||||
{
|
||||
build();
|
||||
}
|
||||
|
||||
QVector<QSharedPointer<AbstractPhysicalTerminalInterface> > 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 <QSharedPointer<AbstractRealTerminalInterface>> real_terminals_vector;
|
||||
|
||||
real_terminals_vector << QSharedPointer<AbstractRealTerminalInterface> {
|
||||
new DemoRealTerminal( QStringLiteral("24vdc"),
|
||||
lvl_1)};
|
||||
real_terminals_vector << QSharedPointer<AbstractRealTerminalInterface> {
|
||||
new DemoRealTerminal( QStringLiteral("0vdc"),
|
||||
lvl_2)};
|
||||
real_terminals_vector << QSharedPointer<AbstractRealTerminalInterface> {
|
||||
new DemoRealTerminal( QStringLiteral("signal"),
|
||||
lvl_3)};
|
||||
m_physical_terminal << QSharedPointer<AbstractPhysicalTerminalInterface> {
|
||||
new DemoPhysicalTerminal {real_terminals_vector}};
|
||||
|
||||
real_terminals_vector.clear();
|
||||
real_terminals_vector << QSharedPointer<AbstractRealTerminalInterface> {
|
||||
new DemoRealTerminal( QStringLiteral("24vdc"),
|
||||
lvl_1)};
|
||||
real_terminals_vector << QSharedPointer<AbstractRealTerminalInterface> {
|
||||
new DemoRealTerminal( QStringLiteral("0vdc"),
|
||||
lvl_2)};
|
||||
real_terminals_vector << QSharedPointer<AbstractRealTerminalInterface> {
|
||||
new DemoRealTerminal( QStringLiteral("signal"),
|
||||
lvl_3)};
|
||||
m_physical_terminal << QSharedPointer<AbstractPhysicalTerminalInterface> {
|
||||
new DemoPhysicalTerminal {real_terminals_vector}};
|
||||
|
||||
real_terminals_vector.clear();
|
||||
real_terminals_vector << QSharedPointer<AbstractRealTerminalInterface> {
|
||||
new DemoRealTerminal( QStringLiteral("24vdc"),
|
||||
lvl_1)};
|
||||
real_terminals_vector << QSharedPointer<AbstractRealTerminalInterface> {
|
||||
new DemoRealTerminal( QStringLiteral("0vdc"),
|
||||
lvl_2)};
|
||||
real_terminals_vector << QSharedPointer<AbstractRealTerminalInterface> {
|
||||
new DemoRealTerminal( QStringLiteral("signal"),
|
||||
lvl_3)};
|
||||
m_physical_terminal << QSharedPointer<AbstractPhysicalTerminalInterface> {
|
||||
new DemoPhysicalTerminal {real_terminals_vector}};
|
||||
}
|
||||
|
||||
}
|
||||
50
sources/TerminalStrip/GraphicsItem/demoterminalstrip.h
Normal file
50
sources/TerminalStrip/GraphicsItem/demoterminalstrip.h
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#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<QSharedPointer<AbstractPhysicalTerminalInterface>> physicalTerminal() const override;
|
||||
|
||||
private:
|
||||
void build();
|
||||
|
||||
private:
|
||||
QVector<QSharedPointer<AbstractPhysicalTerminalInterface>> m_physical_terminal;
|
||||
};
|
||||
|
||||
} //End namespace TerminalStripDrawer
|
||||
|
||||
#endif // DEMOTERMINALSTRIP_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
|
||||
@@ -31,15 +31,15 @@ namespace TerminalStripDrawer {
|
||||
* @param strip
|
||||
* @param pattern
|
||||
*/
|
||||
TerminalStripDrawer::TerminalStripDrawer(QPointer<TerminalStrip> strip,
|
||||
TerminalStripDrawer::TerminalStripDrawer(QSharedPointer<AbstractTerminalStripInterface> strip,
|
||||
QSharedPointer<TerminalStripLayoutPattern> 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<AbstractTerminalStripInterface> strip)
|
||||
{
|
||||
m_strip.reset(new TrueTerminalStrip{strip});
|
||||
m_strip = strip;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -62,16 +62,15 @@ namespace TerminalStripDrawer
|
||||
virtual QString location() const = 0;
|
||||
virtual QString name() const = 0;
|
||||
virtual QVector<QSharedPointer<AbstractPhysicalTerminalInterface>> physicalTerminal() const = 0;
|
||||
virtual bool operator()() = 0;
|
||||
};
|
||||
|
||||
class TerminalStripDrawer
|
||||
{
|
||||
public:
|
||||
TerminalStripDrawer(QPointer<TerminalStrip> strip = QPointer<TerminalStrip>(),
|
||||
TerminalStripDrawer(QSharedPointer<AbstractTerminalStripInterface> strip = QSharedPointer<AbstractTerminalStripInterface> { nullptr },
|
||||
QSharedPointer<TerminalStripLayoutPattern> layout = QSharedPointer<TerminalStripLayoutPattern>());
|
||||
|
||||
void setStrip(TerminalStrip *strip);
|
||||
void setStrip(QSharedPointer<AbstractTerminalStripInterface> strip);
|
||||
void paint(QPainter *painter);
|
||||
QRectF boundingRect() const;
|
||||
|
||||
@@ -83,7 +82,7 @@ namespace TerminalStripDrawer
|
||||
int width() const;
|
||||
|
||||
private:
|
||||
QScopedPointer <AbstractTerminalStripInterface> m_strip;
|
||||
QSharedPointer <AbstractTerminalStripInterface> m_strip;
|
||||
QSharedPointer<TerminalStripLayoutPattern> m_pattern;
|
||||
bool m_debug_draw { false };
|
||||
};
|
||||
|
||||
@@ -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<TerminalStrip> strip, QGraphicsItem *parent) :
|
||||
QetGraphicsItem{parent},
|
||||
m_strip{strip},
|
||||
m_drawer{strip}
|
||||
TerminalStripItem::TerminalStripItem(QPointer<TerminalStrip> strip,
|
||||
QGraphicsItem *parent) :
|
||||
QetGraphicsItem { parent },
|
||||
m_strip { strip },
|
||||
m_drawer { QSharedPointer<TerminalStripDrawer::TrueTerminalStrip> {
|
||||
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<TerminalStripDrawer::TrueTerminalStrip> {
|
||||
new TerminalStripDrawer::TrueTerminalStrip { strip }});
|
||||
m_pending_strip_uuid = QUuid();
|
||||
|
||||
if (!m_drawer.haveLayout()) {
|
||||
|
||||
@@ -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<PhysicalTerminal> physical) :
|
||||
m_physical { physical }
|
||||
{}
|
||||
|
||||
@@ -36,7 +36,6 @@ namespace TerminalStripDrawer
|
||||
QString location() const override;
|
||||
QString name() const override;
|
||||
QVector<QSharedPointer<AbstractPhysicalTerminalInterface>> physicalTerminal() const override;
|
||||
bool operator()() override;
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_strip;
|
||||
|
||||
Reference in New Issue
Block a user