mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Add enum Type to terminalData class
This commit is contained in:
@@ -98,7 +98,7 @@ void PartTerminal::paint(
|
||||
// dessin de la borne en rouge
|
||||
t.setColor(isSelected() ? Terminal::neutralColor : Qt::red);
|
||||
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
|
||||
t.setColor(isSelected() ? Qt::red : Terminal::neutralColor);
|
||||
@@ -118,7 +118,7 @@ void PartTerminal::paint(
|
||||
QPainterPath PartTerminal::shape() const
|
||||
{
|
||||
QPainterPath shape;
|
||||
shape.lineTo(d -> second_point);
|
||||
shape.lineTo(d -> m_second_point);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(1);
|
||||
@@ -132,7 +132,7 @@ QPainterPath PartTerminal::shape() 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();
|
||||
|
||||
qreal adjust = (SHADOWS_HEIGHT + 1) / 2;
|
||||
@@ -174,10 +174,10 @@ void PartTerminal::updateSecondPoint()
|
||||
{
|
||||
qreal ts = 4.0; // terminal size
|
||||
switch(d -> m_orientation) {
|
||||
case Qet::North: d -> second_point = QPointF(0.0, ts); break;
|
||||
case Qet::East : d -> second_point = QPointF(-ts, 0.0); break;
|
||||
case Qet::South: d -> second_point = QPointF(0.0, -ts); break;
|
||||
case Qet::West : d -> second_point = QPointF(ts, 0.0); break;
|
||||
case Qet::North: d -> m_second_point = QPointF(0.0, ts); break;
|
||||
case Qet::East : d -> m_second_point = QPointF(-ts, 0.0); break;
|
||||
case Qet::South: d -> m_second_point = QPointF(0.0, -ts); break;
|
||||
case Qet::West : d -> m_second_point = QPointF(ts, 0.0); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "terminaldata.h"
|
||||
|
||||
#include <QGraphicsObject>
|
||||
#include <QDebug>
|
||||
|
||||
TerminalData::TerminalData():
|
||||
PropertiesInterface()
|
||||
@@ -58,8 +59,8 @@ void TerminalData::toSettings(QSettings &settings, const QString prefix) const
|
||||
*/
|
||||
void TerminalData::fromSettings(const QSettings &settings, const QString prefix)
|
||||
{
|
||||
Q_UNUSED(settings);
|
||||
Q_UNUSED(prefix);
|
||||
Q_UNUSED(settings)
|
||||
Q_UNUSED(prefix)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,20 +79,17 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
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("y", QString("%1").arg(q->scenePos().y()));
|
||||
|
||||
// Write name and number to XML
|
||||
xml_element.setAttribute("uuid", m_uuid.toString());
|
||||
xml_element.setAttribute("name", m_name);
|
||||
|
||||
// write the orientation of the terminal
|
||||
// ecrit l'orientation de la borne
|
||||
xml_element.setAttribute("orientation",
|
||||
Qet::orientationToString(m_orientation));
|
||||
|
||||
xml_element.setAttribute("type", typeToString(m_type));
|
||||
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
@@ -137,5 +135,45 @@ bool TerminalData::fromXml (const QDomElement &xml_element)
|
||||
m_orientation = Qet::orientationFromString(
|
||||
xml_element.attribute("orientation"));
|
||||
|
||||
m_type = typeFromString(xml_element.attribute("type"));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,12 @@ class QGraphicsObject;
|
||||
*/
|
||||
class TerminalData : public PropertiesInterface
|
||||
{
|
||||
enum Type {
|
||||
Generic,
|
||||
TerminalInner,
|
||||
TerminalOuter
|
||||
};
|
||||
|
||||
public:
|
||||
TerminalData();
|
||||
TerminalData(QGraphicsObject* parent);
|
||||
@@ -33,6 +39,9 @@ class TerminalData : public PropertiesInterface
|
||||
QDomElement toXml(QDomDocument &xml_element) const 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
|
||||
// of PartTerminal/Terminal and they must access this data
|
||||
public:
|
||||
@@ -46,7 +55,7 @@ class TerminalData : public PropertiesInterface
|
||||
Position of the second point of the terminal
|
||||
in scene coordinates
|
||||
*/
|
||||
QPointF second_point;
|
||||
QPointF m_second_point;
|
||||
/**
|
||||
@brief m_uuid
|
||||
Uuid of the terminal.
|
||||
@@ -80,6 +89,9 @@ class TerminalData : public PropertiesInterface
|
||||
PartTerminal and Terminal have access to it.
|
||||
*/
|
||||
QPointF m_pos;
|
||||
|
||||
TerminalData::Type m_type = TerminalData::Generic;
|
||||
|
||||
private:
|
||||
QGraphicsObject* q{nullptr};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user