Add enum Type to terminalData class

This commit is contained in:
joshua
2021-02-06 18:35:55 +01:00
parent a00404bc9f
commit 252106178b
3 changed files with 65 additions and 15 deletions

View File

@@ -98,7 +98,7 @@ void PartTerminal::paint(
// dessin de la borne en rouge // dessin de la borne en rouge
t.setColor(isSelected() ? Terminal::neutralColor : Qt::red); t.setColor(isSelected() ? Terminal::neutralColor : Qt::red);
painter -> setPen(t); painter -> setPen(t);
painter -> drawLine(QPointF(0.0, 0.0), d -> second_point); painter -> drawLine(QPointF(0.0, 0.0), d -> m_second_point);
// dessin du point d'amarrage au conducteur en bleu // dessin du point d'amarrage au conducteur en bleu
t.setColor(isSelected() ? Qt::red : Terminal::neutralColor); t.setColor(isSelected() ? Qt::red : Terminal::neutralColor);
@@ -118,7 +118,7 @@ void PartTerminal::paint(
QPainterPath PartTerminal::shape() const QPainterPath PartTerminal::shape() const
{ {
QPainterPath shape; QPainterPath shape;
shape.lineTo(d -> second_point); shape.lineTo(d -> m_second_point);
QPainterPathStroker pps; QPainterPathStroker pps;
pps.setWidth(1); pps.setWidth(1);
@@ -132,7 +132,7 @@ QPainterPath PartTerminal::shape() const
*/ */
QRectF PartTerminal::boundingRect() const QRectF PartTerminal::boundingRect() const
{ {
QRectF br(QPointF(0, 0), d -> second_point); QRectF br(QPointF(0, 0), d -> m_second_point);
br = br.normalized(); br = br.normalized();
qreal adjust = (SHADOWS_HEIGHT + 1) / 2; qreal adjust = (SHADOWS_HEIGHT + 1) / 2;
@@ -174,10 +174,10 @@ void PartTerminal::updateSecondPoint()
{ {
qreal ts = 4.0; // terminal size qreal ts = 4.0; // terminal size
switch(d -> m_orientation) { switch(d -> m_orientation) {
case Qet::North: d -> second_point = QPointF(0.0, ts); break; case Qet::North: d -> m_second_point = QPointF(0.0, ts); break;
case Qet::East : d -> second_point = QPointF(-ts, 0.0); break; case Qet::East : d -> m_second_point = QPointF(-ts, 0.0); break;
case Qet::South: d -> second_point = QPointF(0.0, -ts); break; case Qet::South: d -> m_second_point = QPointF(0.0, -ts); break;
case Qet::West : d -> second_point = QPointF(ts, 0.0); break; case Qet::West : d -> m_second_point = QPointF(ts, 0.0); break;
} }
} }

View File

@@ -1,6 +1,7 @@
#include "terminaldata.h" #include "terminaldata.h"
#include <QGraphicsObject> #include <QGraphicsObject>
#include <QDebug>
TerminalData::TerminalData(): TerminalData::TerminalData():
PropertiesInterface() PropertiesInterface()
@@ -58,8 +59,8 @@ void TerminalData::toSettings(QSettings &settings, const QString prefix) const
*/ */
void TerminalData::fromSettings(const QSettings &settings, const QString prefix) void TerminalData::fromSettings(const QSettings &settings, const QString prefix)
{ {
Q_UNUSED(settings); Q_UNUSED(settings)
Q_UNUSED(prefix); Q_UNUSED(prefix)
} }
/** /**
@@ -78,20 +79,17 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const
{ {
QDomElement xml_element = xml_document.createElement("terminal"); QDomElement xml_element = xml_document.createElement("terminal");
// write the position of the terminal
// ecrit la position de la borne
xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x())); xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x()));
xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y())); xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y()));
// Write name and number to XML
xml_element.setAttribute("uuid", m_uuid.toString()); xml_element.setAttribute("uuid", m_uuid.toString());
xml_element.setAttribute("name", m_name); xml_element.setAttribute("name", m_name);
// write the orientation of the terminal
// ecrit l'orientation de la borne
xml_element.setAttribute("orientation", xml_element.setAttribute("orientation",
Qet::orientationToString(m_orientation)); Qet::orientationToString(m_orientation));
xml_element.setAttribute("type", typeToString(m_type));
return(xml_element); return(xml_element);
} }
@@ -137,5 +135,45 @@ bool TerminalData::fromXml (const QDomElement &xml_element)
m_orientation = Qet::orientationFromString( m_orientation = Qet::orientationFromString(
xml_element.attribute("orientation")); xml_element.attribute("orientation"));
m_type = typeFromString(xml_element.attribute("type"));
return true; return true;
} }
/**
* @brief TerminalData::typeToString
* @param type
* @return type into a QString
*/
QString TerminalData::typeToString(TerminalData::Type type)
{
switch (type) {
case Generic:
return QString("Generic");
case TerminalInner :
return QString("TerminalInner");
case TerminalOuter :
return QString("TerminalOuter");
}
}
/**
* @brief TerminalData::typeFromString
* @param string
* @return The type describe in string to TerminalData::Type.
* if string doesn't describe a type, TerminalData::Generic is returned
*/
TerminalData::Type TerminalData::typeFromString(const QString &string)
{
if (string == "Generic") {
return TerminalData::Generic;
} else if (string == "TerminalInner") {
return TerminalData::TerminalInner;
} else if (string == "TerminalOuter") {
return TerminalData::TerminalOuter;
} else {
qDebug() << "TerminalData::typeFromString, argument string is invalid"
" failsafe type 'TerminalData::Generic' is returned";
return TerminalData::Generic;
}
}

View File

@@ -18,6 +18,12 @@ class QGraphicsObject;
*/ */
class TerminalData : public PropertiesInterface class TerminalData : public PropertiesInterface
{ {
enum Type {
Generic,
TerminalInner,
TerminalOuter
};
public: public:
TerminalData(); TerminalData();
TerminalData(QGraphicsObject* parent); TerminalData(QGraphicsObject* parent);
@@ -33,6 +39,9 @@ class TerminalData : public PropertiesInterface
QDomElement toXml(QDomDocument &xml_element) const override; QDomElement toXml(QDomDocument &xml_element) const override;
bool fromXml(const QDomElement &xml_element) override; bool fromXml(const QDomElement &xml_element) override;
static QString typeToString(TerminalData::Type type);
static TerminalData::Type typeFromString(const QString &string);
// must be public, because this class is a private member // must be public, because this class is a private member
// of PartTerminal/Terminal and they must access this data // of PartTerminal/Terminal and they must access this data
public: public:
@@ -46,7 +55,7 @@ class TerminalData : public PropertiesInterface
Position of the second point of the terminal Position of the second point of the terminal
in scene coordinates in scene coordinates
*/ */
QPointF second_point; QPointF m_second_point;
/** /**
@brief m_uuid @brief m_uuid
Uuid of the terminal. Uuid of the terminal.
@@ -80,6 +89,9 @@ class TerminalData : public PropertiesInterface
PartTerminal and Terminal have access to it. PartTerminal and Terminal have access to it.
*/ */
QPointF m_pos; QPointF m_pos;
TerminalData::Type m_type = TerminalData::Generic;
private: private:
QGraphicsObject* q{nullptr}; QGraphicsObject* q{nullptr};
}; };