Merge branch 'XMLPropertiesNew'

This commit is contained in:
joshua
2021-03-09 19:09:31 +01:00
88 changed files with 2777 additions and 1586 deletions

View File

@@ -31,6 +31,8 @@
#include "element.h"
#include "../QetGraphicsItemModeler/qetgraphicshandleritem.h"
#include "../qetxml.h"
#include <QMultiHash>
#include <QtDebug>
@@ -78,15 +80,9 @@ class ConductorXmlRetroCompatibility
*/
Conductor::Conductor(Terminal *p1, Terminal* p2) :
terminal1(p1),
terminal2(p2),
m_mouse_over(false),
m_text_item(nullptr),
segments(nullptr),
m_moving_segment(false),
modified_path(false),
has_to_save_profile(false),
must_highlight_(Conductor::None)
terminal2(p2)
{
setTagName("conductor");
//set Zvalue at 11 to be upper than the DiagramImageItem and element
setZValue(11);
m_previous_z_value = zValue();
@@ -111,8 +107,8 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
}
//By default, the 4 profils are nuls -> we must to use priv_calculeConductor
conductor_profiles.insert(Qt::TopLeftCorner, ConductorProfile());
conductor_profiles.insert(Qt::TopRightCorner, ConductorProfile());
conductor_profiles.insert(Qt::TopLeftCorner, ConductorProfile());
conductor_profiles.insert(Qt::TopRightCorner, ConductorProfile());
conductor_profiles.insert(Qt::BottomLeftCorner, ConductorProfile());
conductor_profiles.insert(Qt::BottomRightCorner, ConductorProfile());
@@ -225,7 +221,7 @@ void Conductor::updateConductorPath(const QPointF &p1, Qet::Orientation o1, cons
ConductorProfile &conductor_profile = conductor_profiles[currentPathType()];
Q_ASSERT_X(conductor_profile.segmentsCount(QET::Both) > 1, "Conductor::priv_modifieConductor", "pas de points a modifier");
Q_ASSERT_X(!conductor_profile.isNull(), "Conductor::priv_modifieConductor", "pas de profil utilisable");
Q_ASSERT_X(!conductor_profile.isNull(), "Conductor::priv_modifieConductor", "pas de profil utilisable");
// recupere les coordonnees fournies des bornes
QPointF new_p1 = mapFromScene(p1);
@@ -329,10 +325,10 @@ QHash<ConductorSegmentProfile *, qreal> Conductor::shareOffsetBetweenSegments(
// on remet le trop-plein dans la reserve d'offset
remaining_offset += qAbs(segments_hash[csp]) * getSign(local_offset);
//qDebug() << " trop-plein de" << qAbs(segments_hash[csp]) * getSign(local_offset) << "remaining_offset =" << remaining_offset;
//qDebug() << " trop-plein de" << qAbs(segments_hash[csp]) * getSign(local_offset) << "remaining_offset =" << remaining_offset;
segments_hash[csp] = 0.0;
} else {
//qDebug() << " offset local de" << local_offset << "accepte";
//qDebug() << " offset local de" << local_offset << "accepte";
}
}
}
@@ -364,17 +360,17 @@ void Conductor::generateConductorPath(const QPointF &p1, Qet::Orientation o1, co
// distingue le depart de l'arrivee : le trajet se fait toujours de gauche a droite (apres prolongation)
if (newp1.x() <= newp2.x()) {
depart = newp1;
arrivee = newp2;
depart0 = sp1;
arrivee0 = sp2;
depart = newp1;
arrivee = newp2;
depart0 = sp1;
arrivee0 = sp2;
ori_depart = o1;
ori_arrivee = o2;
} else {
depart = newp2;
arrivee = newp1;
depart0 = sp2;
arrivee0 = sp1;
depart = newp2;
arrivee = newp1;
depart0 = sp2;
arrivee0 = sp1;
ori_depart = o2;
ori_arrivee = o1;
}
@@ -587,36 +583,16 @@ ConductorTextItem *Conductor::textItem() const
@return true si l'element XML represente bien un Conducteur ; false sinon
*/
bool Conductor::valideXml(QDomElement &e){
// verifie le nom du tag
if (e.tagName() != "conductor") return(false);
// verifie la presence des attributs minimaux
if (!e.hasAttribute("terminal1")) return(false);
if (!e.hasAttribute("terminal2")) return(false);
// // TODO: seems to short! (see fromXML)
// if (QETXML::propertyDouble(e, "x") ||
// QETXML::propertyDouble(e, "y"))
// return false;
bool conv_ok;
// parse l'abscisse
if (e.hasAttribute("element1")) {
if (QUuid(e.attribute("element1")).isNull())
return false;
if (QUuid(e.attribute("terminal1")).isNull())
return false;
} else {
e.attribute("terminal1").toInt(&conv_ok);
if (!conv_ok) return(false);
}
// if (QETXML::propertyBool(e, "freezeLabel"))
// return false;
// parse l'ordonnee
if (e.hasAttribute("element2")) {
if (QUuid(e.attribute("element2")).isNull())
return false;
if (QUuid(e.attribute("terminal2")).isNull())
return false;
} else {
e.attribute("terminal2").toInt(&conv_ok);
if (!conv_ok) return(false);
}
return(true);
return true;
}
/**
@@ -989,16 +965,26 @@ void Conductor::pointsToSegments(const QList<QPointF>& points_list) {
@param dom_element
@return true is loading success else return false
*/
bool Conductor::fromXml(QDomElement &dom_element)
bool Conductor::fromXmlPriv(const QDomElement &dom_element)
{
setPos(dom_element.attribute("x", nullptr).toDouble(),
dom_element.attribute("y", nullptr).toDouble());
double x=0, y=0;
QETXML::propertyDouble(dom_element, "x", &x);
QETXML::propertyDouble(dom_element, "y", &y);
setPos(x, y);
bool return_ = pathFromXml(dom_element);
m_text_item -> fromXml(dom_element);
ConductorProperties pr;
pr.fromXml(dom_element);
auto prs = QETXML::findInDomElement(dom_element, ConductorProperties::xmlTagName());
ConductorProperties pr;
if (!prs.isEmpty()) {
pr.fromXml(prs.first());
} else {
// legacy
// added in 0.9 remove in later version!
pr.fromXml(dom_element);
}
//Load Sequential Values
if (dom_element.hasAttribute("sequ_1") || dom_element.hasAttribute("sequf_1") || dom_element.hasAttribute("seqt_1") || dom_element.hasAttribute("seqtf_1") || dom_element.hasAttribute("seqh_1") || dom_element.hasAttribute("sequf_1"))
@@ -1006,15 +992,15 @@ bool Conductor::fromXml(QDomElement &dom_element)
else
m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers"));
m_freeze_label = dom_element.attribute("freezeLabel") == "true"? true : false;
QETXML::propertyBool(dom_element, "freezeLabel", &m_freeze_label);
setProperties(pr);
return return_;
}
/**
@brief Conductor::toXml
// does not support legacy method
/*!
@brief Conductor::toXmlPriv
Exporte les caracteristiques du conducteur sous forme d'une element XML.
@param dom_document :
Le document XML a utiliser pour creer l'element XML
@@ -1023,70 +1009,122 @@ bool Conductor::fromXml(QDomElement &dom_element)
bornes dans le document XML et leur adresse en memoire
@return Un element XML representant le conducteur
*/
QDomElement Conductor::toXml(QDomDocument &dom_document,
QHash<Terminal *,
int> &table_adr_id) const
{
QDomElement dom_element = dom_document.createElement("conductor");
void Conductor::toXmlPriv(QDomElement& dom_element) const {
dom_element.setAttribute("x", QString::number(pos().x()));
dom_element.setAttribute("y", QString::number(pos().y()));
dom_element.setAttribute("x", QString::number(pos().x()));
dom_element.setAttribute("y", QString::number(pos().y()));
// Terminal is uniquely identified by the uuid of the terminal and the element
if (terminal1->uuid().isNull()) {
// legacy method to identify the terminal
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability
} else {
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
}
// Terminal is uniquely identified by the uuid of the terminal and the element
if (terminal1->uuid().isNull()) {
// legacy method to identify the terminal
dom_element.setAttribute("terminal1", terminal1->ID()); // for backward compability
} else {
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
}
if (terminal2->uuid().isNull()) {
// legacy method to identify the terminal
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
} else {
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
}
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
if (terminal2->uuid().isNull()) {
// legacy method to identify the terminal
dom_element.setAttribute("terminal2", terminal2->ID()); // for backward compability
} else {
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
}
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
// on n'exporte les segments du conducteur que si ceux-ci ont
// ete modifies par l'utilisateur
if (modified_path)
{
// parcours et export des segments
QDomElement current_segment;
foreach(ConductorSegment *segment, segmentsList())
{
current_segment = dom_document.createElement("segment");
current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
current_segment.setAttribute("length", QString("%1").arg(segment -> length()));
dom_element.appendChild(current_segment);
}
}
// on n'exporte les segments du conducteur que si ceux-ci ont
// ete modifies par l'utilisateur
if (modified_path)
{
// parcours et export des segments
QDomElement current_segment;
foreach(ConductorSegment *segment, segmentsList())
{
current_segment = dom_element.ownerDocument().createElement("segment");
current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
current_segment.setAttribute("length", QString("%1").arg(segment -> length()));
dom_element.appendChild(current_segment);
}
}
QDomDocument doc = dom_element.ownerDocument();
QDomElement dom_seq = m_autoNum_seq.toXml(doc);
dom_element.appendChild(dom_seq);
QDomElement dom_seq = m_autoNum_seq.toXml(dom_document);
dom_element.appendChild(dom_seq);
// Export the properties and text
m_properties. toXml(dom_element);
if(m_text_item->wasMovedByUser())
{
dom_element.setAttribute("userx", QString::number(m_text_item->pos().x()));
dom_element.setAttribute("usery", QString::number(m_text_item->pos().y()));
}
if(m_text_item->wasRotateByUser())
dom_element.setAttribute("rotation", QString::number(m_text_item->rotation()));
return(dom_element);
// Export the properties and text
dom_element.appendChild(m_properties. toXml(doc));
if(m_text_item->wasMovedByUser())
{
dom_element.setAttribute("userx", QString::number(m_text_item->pos().x()));
dom_element.setAttribute("usery", QString::number(m_text_item->pos().y()));
}
if(m_text_item->wasRotateByUser())
dom_element.setAttribute("rotation", QString::number(m_text_item->rotation()));
}
/**
@brief Conductor::pathFromXml
Generate the path (of the line) from xml file by checking the segments in the xml
file
@param e
@return true if generate path success else return false
Exporte les caracteristiques du conducteur sous forme d'une element XML.
@param d Le document XML a utiliser pour creer l'element XML
@param table_adr_id Hash stockant les correspondances entre les ids des
bornes dans le document XML et leur adresse en memoire
@return Un element XML representant le conducteur
*/
//QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int> &table_adr_id) const
//{
// QDomElement dom_element = dom_document.createElement("conductor");
// dom_element.setAttribute("x", QString::number(pos().x()));
// dom_element.setAttribute("y", QString::number(pos().y()));
// // Terminal is uniquely identified by the uuid of the terminal and the element
// if (terminal1->uuid().isNull()) {
// // legacy method to identify the terminal
// dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability
// } else {
// dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
// dom_element.setAttribute("terminal1", terminal1->uuid().toString());
// }
// if (terminal2->uuid().isNull()) {
// // legacy method to identify the terminal
// dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
// } else {
// dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
// dom_element.setAttribute("terminal2", terminal2->uuid().toString());
// }
// dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
// // on n'exporte les segments du conducteur que si ceux-ci ont
// // ete modifies par l'utilisateur
// if (modified_path)
// {
// // parcours et export des segments
// QDomElement current_segment;
// foreach(ConductorSegment *segment, segmentsList())
// {
// current_segment = dom_document.createElement("segment");
// current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
// current_segment.setAttribute("length", QString("%1").arg(segment -> length()));
// dom_element.appendChild(current_segment);
// }
// }
// QDomElement dom_seq = m_autoNum_seq.toXml(dom_document);
// dom_element.appendChild(dom_seq);
// // Export the properties and text
// m_properties.toXml(dom_document);
// if(m_text_item->wasMovedByUser())
// {
// dom_element.setAttribute("userx", QString::number(m_text_item->pos().x()));
// dom_element.setAttribute("usery", QString::number(m_text_item->pos().y()));
// }
// if(m_text_item->wasRotateByUser())
// dom_element.setAttribute("rotation", QString::number(m_text_item->rotation()));
// return(dom_element);
//}
/**
*/
bool Conductor::pathFromXml(const QDomElement &e) {
// parcourt les elements XML "segment" et en extrait deux listes de longueurs
@@ -1098,14 +1136,21 @@ bool Conductor::pathFromXml(const QDomElement &e) {
if (current_segment.isNull() || current_segment.tagName() != "segment") continue;
// le segment doit avoir une longueur
if (!current_segment.hasAttribute("length")) continue;
qreal segment_length;
if (QETXML::propertyDouble(current_segment, "length", & segment_length))
continue;
// cette longueur doit etre un reel
bool ok;
qreal segment_length = current_segment.attribute("length").toDouble(&ok);
if (!ok) continue;
bool isHorizontal = false;
QString orientation;
if (QETXML::propertyString(current_segment, "orientation", &orientation) == QETXML::PropertyFlags::Success) {
if (orientation == "horizontal")
isHorizontal = true;
} else {
qDebug() << "PathFromXML failed";
return false;
}
if (current_segment.attribute("orientation") == "horizontal") {
if (isHorizontal) {
segments_x << segment_length;
segments_y << 0.0;
} else {
@@ -1237,7 +1282,7 @@ ConductorSegment *Conductor::middleSegment()
QPointF Conductor::posForText(Qt::Orientations &flag)
{
ConductorSegment *segment = segments;
ConductorSegment *segment = segments;
bool all_segment_is_vertical = true;
bool all_segment_is_horizontal = true;
@@ -1356,7 +1401,7 @@ void Conductor::calculateTextItemPosition()
}
//Adjust the position of text if his rotation
//is 0° or 270°, to be exactly centered to the conductor
//is 0?? or 270??, to be exactly centered to the conductor
if (m_text_item -> rotation() == 0)
{
text_pos.rx() -= m_text_item -> boundingRect().width()/2;
@@ -1633,12 +1678,12 @@ void Conductor::displayedTextChanged()
new_value.setValue(new_properties);
QUndoCommand *undo = new QUndoCommand(tr("Modifier les propriétés d'un conducteur", "undo caption"));
QUndoCommand *undo = new QUndoCommand(tr("Modifier les propri??t??s d'un conducteur", "undo caption"));
new QPropertyUndoCommand(this, "properties", old_value, new_value, undo);
if (!relatedPotentialConductors().isEmpty())
{
undo->setText(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
undo->setText(tr("Modifier les propri??t??s de plusieurs conducteurs", "undo caption"));
foreach (Conductor *potential_conductor, relatedPotentialConductors())
{
@@ -1724,7 +1769,7 @@ QSet<Conductor *> Conductor::relatedPotentialConductors(const bool all_diagram,
*/
QETDiagramEditor* Conductor::diagramEditor() const
{
if (!diagram()) return nullptr;
if (!diagram()) return nullptr;
if (diagram() -> views().isEmpty()) return nullptr;
QWidget *w = const_cast<QGraphicsView *>(diagram() -> views().at(0));

View File

@@ -20,6 +20,8 @@
#include "../autoNum/assignvariables.h"
#include "../conductorproperties.h"
#include "../conductorproperties.h"
#include "../properties/propertiesinterface.h"
#include <QGraphicsPathItem>
class ConductorProfile;
@@ -39,7 +41,7 @@ typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
This class represents a conductor, i.e. a wire between two element
terminals.
*/
class Conductor : public QGraphicsObject
class Conductor : public QGraphicsObject, public PropertiesInterface
{
Q_OBJECT
@@ -100,11 +102,10 @@ class Conductor : public QGraphicsObject
public:
static bool valideXml (QDomElement &);
bool fromXml (QDomElement &);
QDomElement toXml (
QDomDocument &,
QHash<Terminal *,
int> &) const;
bool fromXmlPriv(const QDomElement &) override;
void toXmlPriv(QDomElement&dom_element) const override;
void toSettings(QSettings &, const QString & = QString()) const override {}
void fromSettings(QSettings &, const QString & = QString()) override {}
private:
bool pathFromXml(const QDomElement &);
@@ -137,7 +138,7 @@ class Conductor : public QGraphicsObject
{return m_autoNum_seq;}
void setSequenceNum(const autonum::sequentialNumbers& sn);
QList<QPointF> junctions() const;
QList<QPointF> junctions() const;
private:
void setUpConnectionForFormula(
@@ -181,28 +182,28 @@ class Conductor : public QGraphicsObject
QVector<QetGraphicsHandlerItem *> m_handler_vector;
int m_vector_index = -1;
bool m_mouse_over;
bool m_mouse_over{false};
/// Functional properties
ConductorProperties m_properties;
/// Text input for non simple, non-singleline conductors
ConductorTextItem *m_text_item;
ConductorTextItem *m_text_item{nullptr};
/// Segments composing the conductor
ConductorSegment *segments;
ConductorSegment *segments{nullptr};
/// Attributs related to mouse interaction
bool m_moving_segment;
bool m_moving_segment{false};
int moved_point;
qreal m_previous_z_value;
ConductorSegment *m_moved_segment;
QPointF before_mov_text_pos_;
/// Whether the conductor was manually modified by users
bool modified_path;
bool modified_path{false};
/// Whether the current profile should be saved as soon as possible
bool has_to_save_profile;
bool has_to_save_profile{false};
/// conductor profile: "photography" of what the conductor is supposed to look
/// like - there is one profile per kind of traject
ConductorProfilesGroup conductor_profiles;
/// Define whether and how the conductor should be highlighted
Highlight must_highlight_;
Highlight must_highlight_{Conductor::None};
bool m_valid;
bool m_freeze_label = false;

View File

@@ -21,15 +21,15 @@
#include "../diagramcommands.h"
#include "../qetgraphicsitem/conductor.h"
#include "../qetxml.h"
/**
Constructeur
@param parent_conductor Conducteur auquel ce texte est rattache
*/
ConductorTextItem::ConductorTextItem(Conductor *parent_conductor) :
DiagramTextItem(parent_conductor),
parent_conductor_(parent_conductor),
moved_by_user_(false),
rotate_by_user_(false)
parent_conductor_(parent_conductor)
{
setAcceptHoverEvents(true);
}
@@ -69,13 +69,17 @@ Conductor *ConductorTextItem::parentConductor() const
@param e
*/
void ConductorTextItem::fromXml(const QDomElement &e) {
if (e.hasAttribute("userx")) {
setPos(e.attribute("userx").toDouble(),
e.attribute("usery").toDouble());
double userx=0, usery=0;
if (QETXML::propertyDouble(e, "userx", &userx) == QETXML::PropertyFlags::Success &&
QETXML::propertyDouble(e, "usery", &usery) == QETXML::PropertyFlags::Success) {
setPos(userx, usery);
moved_by_user_ = true;
}
if (e.hasAttribute("rotation")) {
setRotation(e.attribute("rotation").toDouble());
double rotation;
if (QETXML::propertyDouble(e, "rotation", &rotation) == QETXML::PropertyFlags::Success) {
setRotation(rotation);
rotate_by_user_ = true;
}
}

View File

@@ -52,7 +52,7 @@ class ConductorTextItem : public DiagramTextItem
protected:
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
@@ -61,8 +61,8 @@ class ConductorTextItem : public DiagramTextItem
// attributes
private:
Conductor *parent_conductor_;
bool moved_by_user_;
bool rotate_by_user_;
bool moved_by_user_{false};
bool rotate_by_user_{false};
QPointF before_mov_pos_;
};
#endif

View File

@@ -86,36 +86,36 @@ DynamicElementTextItem::DynamicElementTextItem()
@param dom_doc
@return
*/
QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
QDomElement DynamicElementTextItem::toXml(QDomDocument& dom_doc) const
{
QDomElement root_element = dom_doc.createElement(xmlTagName());
QDomElement root_element = dom_doc.createElement(xmlTagName());
root_element.setAttribute("x", QString::number(pos().x()));
root_element.setAttribute("y", QString::number(pos().y()));
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
root_element.setAttribute("uuid", m_uuid.toString());
root_element.setAttribute("frame", m_frame? "true" : "false");
root_element.setAttribute("text_width", QString::number(m_text_width));
root_element.setAttribute("font", font().toString());
root_element.setAttribute("keep_visual_rotation", m_keep_visual_rotation ? "true" : "false");
root_element.setAttribute("x", QString::number(pos().x()));
root_element.setAttribute("y", QString::number(pos().y()));
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
root_element.setAttribute("uuid", m_uuid.toString());
root_element.setAttribute("frame", m_frame? "true" : "false");
root_element.setAttribute("text_width", QString::number(m_text_width));
root_element.setAttribute("font", font().toString());
root_element.setAttribute("keep_visual_rotation", m_keep_visual_rotation ? "true" : "false");
QMetaEnum me = textFromMetaEnum();
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
me = QMetaEnum::fromType<Qt::Alignment>();
if(this->alignment() &Qt::AlignRight)
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight));
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight));
else if(this->alignment() &Qt::AlignLeft)
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft));
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft));
else if(this->alignment() &Qt::AlignHCenter)
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter));
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter));
if(this->alignment() &Qt::AlignBottom)
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignBottom));
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignBottom));
else if(this->alignment() & Qt::AlignTop)
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop));
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop));
else if(this->alignment() &Qt::AlignVCenter)
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter));
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter));
QDomElement dom_text = dom_doc.createElement("text");
@@ -216,7 +216,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
setColor(QColor(dom_color.text()));
//Force the update of the displayed text
setTextFrom(m_text_from);
setTextFrom(m_text_from); // TODO: does not update because there is a retrun inside if the textfrom argument is the same as m_text_from
QGraphicsTextItem::setPos(dom_elmt.attribute("x", QString::number(0)).toDouble(),
dom_elmt.attribute("y", QString::number(0)).toDouble());
@@ -1323,12 +1323,12 @@ void DynamicElementTextItem::updateXref()
m_slave_Xref_item->setFont(QETApp::diagramTextsFont(5));
m_slave_Xref_item->installSceneEventFilter(this);
m_update_slave_Xref_connection << connect(m_master_element.data(), &Element::xChanged, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(m_master_element.data(), &Element::yChanged, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(m_master_element.data(), &Element::elementInfoChange, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(diagram()->project(), &QETProject::diagramRemoved, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(diagram()->project(), &QETProject::XRefPropertiesChanged, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(m_master_element.data(), &Element::xChanged, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(m_master_element.data(), &Element::yChanged, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(m_master_element.data(), &Element::elementInfoChange, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(diagram()->project(), &QETProject::diagramRemoved, this, &DynamicElementTextItem::updateXref);
m_update_slave_Xref_connection << connect(diagram()->project(), &QETProject::XRefPropertiesChanged, this, &DynamicElementTextItem::updateXref);
}
else
m_slave_Xref_item->setPlainText(xref_label);

View File

@@ -82,7 +82,7 @@ class DynamicElementTextItem : public DiagramTextItem
DynamicElementTextItem(const DynamicElementTextItem &);
public:
QDomElement toXml(QDomDocument &dom_doc) const override;
QDomElement toXml(QDomDocument&) const override;
void fromXml(const QDomElement &dom_elmt) override;
Element *parentElement() const;
@@ -160,7 +160,7 @@ class DynamicElementTextItem : public DiagramTextItem
QList<QMetaObject::Connection>
m_formula_connection,
m_update_slave_Xref_connection;
QColor m_user_color;
QColor m_user_color{QColor()};
bool
m_frame = false,
m_first_scene_change = true;

View File

@@ -98,7 +98,8 @@ Element::Element(
}
}
int elmt_state;
buildFromXml(location.xml(), &elmt_state);
qDebug() << "\tCollection Path: " << location.collectionPath();
buildFromXml(location.xml(), &elmt_state); // build from the collection definition
if (state) {
*state = elmt_state;
}
@@ -351,8 +352,8 @@ void Element::drawSelection(
Q_UNUSED(options);
painter -> save();
// Annulation des renderhints
painter -> setRenderHint(QPainter::Antialiasing, false);
painter -> setRenderHint(QPainter::TextAntialiasing, false);
painter -> setRenderHint(QPainter::Antialiasing, false);
painter -> setRenderHint(QPainter::TextAntialiasing, false);
painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
// Dessin du cadre de selection en gris
QPen t;
@@ -401,7 +402,7 @@ void Element::drawHighlight(
/**
@brief Element::buildFromXml
Build this element from an xml description
Build this element from an xml description (from the collection)
@param xml_def_elmt
@param state
Optional pointer which define the status of build
@@ -434,9 +435,9 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
if (conv_ok && QET::version.toDouble() < element_version)
{
std::cerr << qPrintable(
QObject::tr("Avertissement : l'élément "
" a été enregistré avec une version"
" ultérieure de QElectroTech.")
QObject::tr("Avertissement : l'??l??ment "
" a ??t?? enregistr?? avec une version"
" ult??rieure de QElectroTech.")
) << std::endl;
}
}
@@ -518,11 +519,15 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
if (qde.isNull())
continue;
if (parseElement(qde)) {
qDebug() << "\t\tElement.cpp:buildFromXml;parseElement: " << qde.tagName();
if (parseElement(qde)) { // TODO: why lines are not parsed here?
qDebug() << "\t\t\tParsing Element success";
++ parsed_elements_count;
}
else
{
qDebug() << "\t\t\tParsing Element no success";
if (state)
*state = 7;
m_state = QET::GIOK;
@@ -548,13 +553,11 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
m_state = QET::GIOK;
return(false);
}
else
{
if (state)
*state = 0;
m_state = QET::GIOK;
return(true);
}
if (state)
*state = 0;
m_state = QET::GIOK;
return(true);
}
/**
@@ -565,8 +568,8 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
*/
bool Element::parseElement(const QDomElement &dom)
{
if (dom.tagName() == "terminal") return(parseTerminal(dom));
else if (dom.tagName() == "input") return(parseInput(dom));
if (dom.tagName() == "terminal") return(parseTerminal(dom));
else if (dom.tagName() == "input") return(parseInput(dom));
else if (dom.tagName() == "dynamic_text") return(parseDynamicText(dom));
else return(true);
}
@@ -658,13 +661,11 @@ DynamicElementTextItem *Element::parseDynamicText(
*/
Terminal *Element::parseTerminal(const QDomElement &dom_element)
{
TerminalData* data = new TerminalData();
if (!data->fromXml(dom_element)) {
delete data;
if (!Terminal::valideXml(dom_element))
return nullptr;
}
Terminal *new_terminal = new Terminal(data, this);
Terminal *new_terminal = new Terminal(0, 0, Qet::Orientation::North, this); // does not matter which values are typed in here, because they get overwritten by the fromXML() function
new_terminal->fromXml(dom_element);
m_terminals << new_terminal;
//Sort from top to bottom and left to rigth
@@ -679,7 +680,7 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element)
return (a->dockConductor().y() < b->dockConductor().y());
});
return(new_terminal);
return(new_terminal); // TODO: makes no sense
}
/**
@@ -693,8 +694,8 @@ bool Element::valideXml(QDomElement &e) {
// verifie la presence des attributs minimaux
if (!e.hasAttribute("type")) return(false);
if (!e.hasAttribute("x")) return(false);
if (!e.hasAttribute("y")) return(false);
if (!e.hasAttribute("x")) return(false);
if (!e.hasAttribute("y")) return(false);
bool conv_ok;
// parse l'abscisse
@@ -721,15 +722,14 @@ bool Element::valideXml(QDomElement &e) {
*/
bool Element::fromXml(
QDomElement &e,
QHash<int,
Terminal *> &table_id_adr)
QHash<int, Terminal *> &table_id_adr)
{
m_state = QET::GILoadingFromXml;
/*
les bornes vont maintenant etre recensees pour associer leurs id a leur adresse reelle
ce recensement servira lors de la mise en place des fils
*/
QList<QDomElement> liste_terminals;
QList<QDomElement> liste_terminals; // terminals in the element in the diagram
foreach(QDomElement qde,
QET::findInDomElement(e, "terminals", "terminal")) {
if (Terminal::valideXml(qde)) liste_terminals << qde;
@@ -737,15 +737,29 @@ bool Element::fromXml(
QHash<int, Terminal *> priv_id_adr;
int terminals_non_trouvees = 0;
foreach(QGraphicsItem *qgi, childItems()) {
// The added childs from the collection now must match with the terminals from the diagram. Iterate through
// all Terminals in the collection and in the diagram to link them together
for(QGraphicsItem *qgi: childItems()) { // TODO: Where the Terminals are added as childs?
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
bool terminal_trouvee = false;
foreach(QDomElement qde, liste_terminals) {
if (p -> fromXml(qde)) {
priv_id_adr.insert(
qde.attribute(
"id").toInt(),
p);
for(QDomElement qde: liste_terminals) {
// The position in the collection element definition is the origin position (originPos).
// The position in the diagram element definition is the position where the conductor is connected (dock position)
// Therefore a simple operator overloading is not possible.
Terminal diagramTerminal(0,0, Qet::Orientation::East);
diagramTerminal.fromXml(qde);
QPointF dockPos1 = diagramTerminal.originPos(); // position here is directly the dock_elmt_ position (stored in the diagram)
QPointF dockPos2 = p->dockPos();
if (qFuzzyCompare(dockPos1.x(), dockPos2.x()) &&
qFuzzyCompare(dockPos1.y(), dockPos2.y()) &&
p->orientation() == diagramTerminal.orientation()) { // check if the part in the collection is the same as in the diagram stored
qDebug() << "Matching Terminal found.";
// store id for legacy purpose, because when opening a old project in the collection the terminal does not have an uuid. Therefore the id must be used
if (p->uuid().isNull()) {
p->setID(qde.attribute("id").toInt());
}
priv_id_adr.insert(qde.attribute("id").toInt(), p);
terminal_trouvee = true;
// We used to break here, because we did not expect
// several terminals to share the same position.
@@ -758,6 +772,7 @@ bool Element::fromXml(
if (terminals_non_trouvees > 0)
{
qDebug() << "element.cpp: Element::fromXML; Elements not found: " << terminals_non_trouvees;
m_state = QET::GIOK;
return(false);
}
@@ -775,15 +790,15 @@ bool Element::fromXml(
}
// copie des associations id / adr
foreach(int id_trouve, priv_id_adr.keys()) {
table_id_adr.insert(id_trouve,
table_id_adr.insert(id_trouve,
priv_id_adr.value(id_trouve));
}
}
//load uuid of connected elements
QList <QDomElement> uuid_list = QET::findInDomElement(e,
"links_uuids",
"link_uuid");
QList <QDomElement> uuid_list = QET::findInDomElement(e, "links_uuids", "link_uuid");
foreach (QDomElement qdo, uuid_list) tmp_uuids_link << qdo.attribute("uuid");
foreach (QDomElement qdo, uuid_list)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
tmp_uuids_link << qdo.attribute("uuid");
@@ -837,7 +852,7 @@ bool Element::fromXml(
//************************//
//***Dynamic texts item***//
//************************//
//************************// read from the diagram section
for (const QDomElement& qde : QET::findInDomElement(
e,
"dynamic_texts",
@@ -892,9 +907,7 @@ bool Element::fromXml(
\~French L'element XML representant cet element electrique
*/
QDomElement Element::toXml(
QDomDocument &document,
QHash<Terminal *,
int> &table_adr_id) const
QDomDocument &document) const
{
QDomElement element = document.createElement("element");
@@ -921,18 +934,6 @@ QDomElement Element::toXml(
element.setAttribute("z", QString::number(this->zValue()));
element.setAttribute("orientation", QString::number(orientation()));
/* get the first id to use for the bounds of this element
* recupere le premier id a utiliser pour les bornes de cet element */
int id_terminal = 0;
if (!table_adr_id.isEmpty()) {
// trouve le plus grand id
int max_id_t = -1;
foreach (int id_t, table_adr_id.values()) {
if (id_t > max_id_t) max_id_t = id_t;
}
id_terminal = max_id_t + 1;
}
// registration of device terminals
// enregistrement des bornes de l'appareil
QDomElement xml_terminals = document.createElement("terminals");
@@ -941,8 +942,10 @@ QDomElement Element::toXml(
foreach(Terminal *t, terminals()) {
// alors on enregistre la borne
QDomElement terminal = t -> toXml(document);
terminal.setAttribute("id", id_terminal); // for backward compatibility
table_adr_id.insert(t, id_terminal ++);
if (t->ID() > 0) {
// for backward compatibility
terminal.setAttribute("id", t->ID()); // for backward compatibility
}
xml_terminals.appendChild(terminal);
}
element.appendChild(xml_terminals);

View File

@@ -1,4 +1,4 @@
/*
/*
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
@@ -39,7 +39,7 @@ class ElementTextItemGroup;
/**
This is the base class for electrical elements.
*/
class Element : public QetGraphicsItem
class Element : public QetGraphicsItem // TODO: derive from propertiesInterface!
{
friend class DiagramEventAddElement;
@@ -140,14 +140,8 @@ class Element : public QetGraphicsItem
QPoint hotspot() const;
void editProperty() override;
static bool valideXml(QDomElement &);
virtual bool fromXml(
QDomElement &,
QHash<int,
Terminal *> &);
virtual QDomElement toXml(
QDomDocument &,
QHash<Terminal *,
int> &) const;
virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &);
virtual QDomElement toXml(QDomDocument &) const;
QUuid uuid() const;
int orientation() const;
@@ -188,7 +182,7 @@ class Element : public QetGraphicsItem
*/
QString linkTypeToString() const;
void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this element
void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this element
protected:
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
@@ -225,9 +219,9 @@ class Element : public QetGraphicsItem
protected:
//ATTRIBUTES related to linked element
QList <Element *> connected_elements;
QList <QUuid> tmp_uuids_link;
QUuid m_uuid;
kind m_link_type = Element::Simple;
QList <QUuid> tmp_uuids_link;
QUuid m_uuid;
kind m_link_type = Element::Simple;
//ATTRIBUTES related to informations
DiagramContext m_kind_informations;

View File

@@ -317,8 +317,8 @@ void ElementTextItemGroup::setHoldToBottomPage(bool hold)
&Element::linkedElementChanged,
[this]()
{QTimer::singleShot(200,
this,
&ElementTextItemGroup::autoPos);}
this,
&ElementTextItemGroup::autoPos);}
);
if(m_parent_element->diagram())
m_XrefChanged_timer = connect(
@@ -326,8 +326,8 @@ void ElementTextItemGroup::setHoldToBottomPage(bool hold)
&QETProject::XRefPropertiesChanged,
[this]()
{QTimer::singleShot(200,
this,
&ElementTextItemGroup::autoPos);}
this,
&ElementTextItemGroup::autoPos);}
);
}
autoPos();
@@ -438,6 +438,7 @@ QDomElement ElementTextItemGroup::toXml(QDomDocument &dom_document) const
return dom_element;
}
// TOOD: inherit from propertiesinterface
/**
@brief ElementTextItemGroup::fromXml
Import data of this group from xml
@@ -623,7 +624,7 @@ void ElementTextItemGroup::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if(diagram() && m_first_move)
diagram()->elementTextsMover().beginMovement(diagram(),
this);
this);
if(m_first_move)
{
@@ -706,7 +707,7 @@ void ElementTextItemGroup::mouseDoubleClickEvent(
*/
void ElementTextItemGroup::keyPressEvent(QKeyEvent *event)
{
if(event->modifiers() == Qt::ControlModifier)
if(event->modifiers() == Qt::ControlModifier)
{
if(event->key() == Qt::Key_Left && m_alignment != Qt::AlignLeft)
{
@@ -800,12 +801,12 @@ void ElementTextItemGroup::updateXref()
m_slave_Xref_item = new QGraphicsTextItem(xref_label, this);
m_slave_Xref_item->setFont(QETApp::diagramTextsFont(5));
m_update_slave_Xref_connection << connect(master_elmt, &Element::xChanged, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(master_elmt, &Element::yChanged, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(master_elmt, &Element::elementInfoChange, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(project, &QETProject::projectDiagramsOrderChanged, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(project, &QETProject::diagramRemoved, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(project, &QETProject::XRefPropertiesChanged, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(master_elmt, &Element::xChanged, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(master_elmt, &Element::yChanged, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(master_elmt, &Element::elementInfoChange, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(project, &QETProject::projectDiagramsOrderChanged, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(project, &QETProject::diagramRemoved, this, &ElementTextItemGroup::updateXref);
m_update_slave_Xref_connection << connect(project, &QETProject::XRefPropertiesChanged, this, &ElementTextItemGroup::updateXref);
}
else
m_slave_Xref_item->setPlainText(xref_label);

View File

@@ -32,7 +32,7 @@ class CrossRefItem;
This class represent a group of element text
Texts in the group can be aligned left / center /right
*/
class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
class ElementTextItemGroup : public QObject, public QGraphicsItemGroup // TODO: derive from PropertiesInterface
{
Q_OBJECT
@@ -112,7 +112,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
m_hold_to_bottom_of_page = false,
m_block_alignment_update = false,
m_frame = false;
QPointF m_initial_position;
QPointF m_initial_position{QPointF(0,0)};
int m_vertical_adjustment = 0;
CrossRefItem *m_Xref_item = nullptr;
Element *m_parent_element = nullptr;

View File

@@ -51,6 +51,7 @@ IndependentTextItem::~IndependentTextItem()
{
}
// TODO: inherit from PropertiesInterface
/**
Permet de lire le texte a mettre dans le champ a partir d'un element XML.
Cette methode se base sur la position du champ pour assigner ou non la

View File

@@ -40,7 +40,7 @@ class IndependentTextItem : public DiagramTextItem
int type() const override { return Type; }
void fromXml(const QDomElement &) override;
QDomElement toXml(QDomDocument &) const override;
QDomElement toXml(QDomDocument&) const override;
protected:
void focusOutEvent(QFocusEvent *event) override;

View File

@@ -25,10 +25,7 @@
@param parent : Parent Item
*/
QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent):
QGraphicsObject(parent),
is_movable_(true),
m_first_move(true),
snap_to_grid_(true)
QGraphicsObject(parent)
{}
QetGraphicsItem::~QetGraphicsItem()

View File

@@ -56,10 +56,10 @@ class QetGraphicsItem : public QGraphicsObject
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
protected:
bool is_movable_;
bool m_first_move;
bool snap_to_grid_;
QPointF m_mouse_to_origin_movement;
bool is_movable_{true};
bool m_first_move{true};
bool snap_to_grid_{true};
QPointF m_mouse_to_origin_movement{QPointF(0,0)};
QET::GraphicsItemState m_state = QET:: GIOK;
};

View File

@@ -326,7 +326,7 @@ void QetShapeItem::paint(
switch (m_shapeType)
{
case Line: painter->drawLine(QLineF(m_P1, m_P2)); break;
case Line: painter->drawLine(QLineF(m_P1, m_P2)); break;
case Rectangle: painter->drawRoundedRect(QRectF(m_P1, m_P2),
m_xRadius,
m_yRadius); break;
@@ -663,7 +663,7 @@ void QetShapeItem::insertPoint()
if(new_polygon != m_polygon)
{
//Wrap the undo for avoid to merge the undo commands when user add several points.
QUndoCommand *undo = new QUndoCommand(tr("Ajouter un point à un polygone"));
QUndoCommand *undo = new QUndoCommand(tr("Ajouter un point ?? un polygone"));
new QPropertyUndoCommand(this, "polygon", m_polygon, new_polygon, undo);
diagram()->undoStack().push(undo);
}
@@ -836,6 +836,7 @@ void QetShapeItem::handlerMouseReleaseEvent()
}
}
// TODO: inherit from Propertiesinterface!
/**
@brief QetShapeItem::fromXml
Build this item from the xml description
@@ -951,28 +952,28 @@ bool QetShapeItem::toDXF(const QString &filepath,const QPen &pen)
switch (m_shapeType)
{
case Line:
Createdxf::drawLine(filepath,
Createdxf::drawLine(filepath,
QLineF( mapToScene(m_P1),
mapToScene(m_P2)),
Createdxf::dxfColor(pen));
return true;
return true;
case Rectangle:
Createdxf::drawRectangle(filepath,
Createdxf::drawRectangle(filepath,
QRectF(mapToScene(m_P1),
mapToScene(m_P2)).normalized(),
Createdxf::dxfColor(pen));
return true;
return true;
case Ellipse:
Createdxf::drawEllipse(filepath,
Createdxf::drawEllipse(filepath,
QRectF(mapToScene(m_P1),
mapToScene(m_P2)).normalized(),
Createdxf::dxfColor(pen));
return true;
return true;
case Polygon:
Createdxf::drawPolygon(filepath,m_polygon,Createdxf::dxfColor(pen));
return true;
Createdxf::drawPolygon(filepath,m_polygon,Createdxf::dxfColor(pen));
return true;
default:
return false;
return false;
}
}
@@ -995,10 +996,10 @@ void QetShapeItem::editProperty()
QString QetShapeItem::name() const
{
switch (m_shapeType) {
case Line: return tr("une ligne");
case Line: return tr("une ligne");
case Rectangle: return tr("un rectangle");
case Ellipse: return tr("une éllipse");
case Ellipse: return tr("une ??llipse");
case Polygon: return tr("une polyligne");
default: return tr("une shape");
default: return tr("une shape");
}
}

View File

@@ -35,7 +35,7 @@ class SlaveElement : public Element
void unlinkElement(Element *elmt) override;
private:
QGraphicsTextItem *m_xref_item;
QGraphicsTextItem *m_xref_item{nullptr};
};
#endif // SLAVEELEMENT_H

View File

@@ -25,6 +25,8 @@
#include "../qetgraphicsitem/element.h"
#include "conductortextitem.h"
#include "../qetxml.h"
#include <utility>
QColor Terminal::neutralColor = QColor(Qt::blue);
@@ -41,7 +43,7 @@ const qreal Terminal::Z = 1000;
@param name of terminal
@param hiddenName
*/
void Terminal::init()
void Terminal::init(QString number, QString name, bool hiddenName)
{
//Calcul the docking point of the element
//m_pos of d is the docking point of conductor
@@ -62,7 +64,13 @@ void Terminal::init()
origin += QPointF(-3.0, -3.0);
qreal w = qAbs(dcx - dex) + 7;
qreal h = qAbs(dcy - dey) + 7;
m_br = QRectF(origin, QSizeF(w, h));
m_br = QRectF(origin, QSizeF(w, h));
// Number of terminal
number_terminal_ = std::move(number);
// Name of terminal
d->m_name = std::move(name);
name_terminal_hidden = hiddenName;
setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::LeftButton);
@@ -70,13 +78,92 @@ void Terminal::init()
setZValue(Z);
}
/*!
\brief Terminal::init
Additionaly to the init above, this method stores position and orientation into the data class
\param pf
\param o
\param number
\param name
\param hiddenName
*/
void Terminal::init(
QPointF pf,
Qet::Orientation o,
QString number,
QString name,
bool hiddenName)
{
setTagName("terminal");
// definition du pount d'amarrage pour un conducteur
d->m_pos = pf;
// definition de l'orientation de la borne (par defaut : sud)
if (o < Qet::North || o > Qet::West) d->m_orientation = Qet::South;
else d->m_orientation = o;
init(number, name, hiddenName);
}
/**
initialise une borne
@param pf position du point d'amarrage pour un conducteur
@param o orientation de la borne : Qt::Horizontal ou Qt::Vertical
@param e Element auquel cette borne appartient
*/
Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
QGraphicsObject(e),
d(new TerminalData(this)),
parent_element_ (e)
{
init(pf, o, "_", "_", false);
}
/**
initialise une borne
@param pf_x Abscisse du point d'amarrage pour un conducteur
@param pf_y Ordonnee du point d'amarrage pour un conducteur
@param o orientation de la borne : Qt::Horizontal ou Qt::Vertical
@param e Element auquel cette borne appartient
*/
Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
QGraphicsObject(e),
d(new TerminalData(this)),
parent_element_ (e)
{
init(QPointF(pf_x, pf_y), o, "_", "_", false);
}
/**
initialise une borne
@param pf position du point d'amarrage pour un conducteur
@param o orientation de la borne : Qt::Horizontal ou Qt::Vertical
@param num number of terminal (ex 3 - 4 for NO)
@param name of terminal
@param hiddenName hide or show the name
@param e Element auquel cette borne appartient
*/
Terminal::Terminal(
QPointF pf,
Qet::Orientation o,
QString num,
QString name,
bool hiddenName,
Element *e) :
QGraphicsObject (e),
d(new TerminalData(this)),
parent_element_ (e)
{
init(pf, o, std::move(num), std::move(name), hiddenName);
}
Terminal::Terminal(TerminalData* data, Element* e) :
QGraphicsObject(e),
d(data),
parent_element_(e)
{
d->setParent(this);
init();
init("_", "_", false);
}
/**
@@ -84,7 +171,7 @@ Terminal::Terminal(TerminalData* data, Element* e) :
* Destruction of the terminal, and also docked conductor
*/
Terminal::~Terminal() {
qDeleteAll(m_conductors_list);
qDeleteAll(m_conductors_list);
}
/**
@@ -110,6 +197,34 @@ Qet::Orientation Terminal::orientation() const
} else return(d->m_orientation);
}
/**
@brief Terminal::setNumber
@param number
*/
void Terminal::setNumber(QString number)
{
number_terminal_ = std::move(number);
}
/**
@brief Terminal::setName
@param name : QString
@param hiddenName : bool
*/
void Terminal::setName(QString name, bool hiddenName)
{
d->m_name = std::move(name);
name_terminal_hidden = hiddenName;
}
/**
@brief Terminal::name
@return the name of terminal.
*/
inline QString Terminal::name() const {
return(d->m_name);
}
/**
@brief Terminal::addConductor
Add a conductor to this terminal
@@ -175,8 +290,8 @@ void Terminal::paint(
painter -> save();
//annulation des renderhints
painter -> setRenderHint(QPainter::Antialiasing, false);
painter -> setRenderHint(QPainter::TextAntialiasing, false);
painter -> setRenderHint(QPainter::Antialiasing, false);
painter -> setRenderHint(QPainter::TextAntialiasing, false);
painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
// on travaille avec les coordonnees de l'element parent
@@ -310,7 +425,7 @@ void Terminal::drawHelpLine(bool draw)
QLineF Terminal::HelpLine() const
{
QPointF scene_dock = dockConductor();
QRectF rect = diagram() -> border_and_titleblock.insideBorderRect();
QRectF rect = diagram() -> border_and_titleblock.insideBorderRect();
QLineF line(scene_dock , QPointF());
@@ -388,7 +503,7 @@ Terminal* Terminal::alignedWithTerminal() const
//Available_terminals have several terminals, we get the nearest terminal
line.setP2(available_terminals.first() -> dockConductor());
qreal current_lenght = line.length();
qreal current_lenght = line.length();
Terminal *nearest_terminal = available_terminals.takeFirst();
//Search the nearest terminal to this one
@@ -457,7 +572,7 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
//setCursor(Qt::CrossCursor);
// d'un mouvement a l'autre, il faut retirer l'effet hover de la borne precedente
if (m_previous_terminal) {
if (m_previous_terminal) {
if (m_previous_terminal == this) m_hovered = true;
else m_previous_terminal -> m_hovered = false;
m_previous_terminal -> m_hovered_color = m_previous_terminal -> neutralColor;
@@ -624,6 +739,10 @@ bool Terminal::canBeLinkedTo(Terminal *other_terminal)
return true;
}
void Terminal::setID(int id) {
m_id = id;
}
/**
@brief Terminal::conductors
@return La liste des conducteurs lies a cette borne
@@ -634,22 +753,19 @@ QList<Conductor *> Terminal::conductors() const
}
/**
@brief Terminal::toXml
@brief Terminal::toXmlPriv
Methode d'export en XML
@param doc Le Document XML a utiliser pour creer l'element XML
@return un QDomElement representant cette borne
*/
QDomElement Terminal::toXml(QDomDocument &doc) const
void Terminal::toXmlPriv(QDomElement &qdo) const
{
QDomElement qdo = doc.createElement("terminal");
// for backward compatibility
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
// end for backward compatibility
// for backward compatibility
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
// end for backward compatibility
qdo.setAttribute("orientation", d->m_orientation);
return(qdo);
qdo.setAttribute("orientation", d->m_orientation);
}
/**
@@ -658,42 +774,25 @@ QDomElement Terminal::toXml(QDomDocument &doc) const
@param terminal Le QDomElement a analyser
@return true si le QDomElement passe en parametre est une borne, false sinon
*/
bool Terminal::valideXml(QDomElement &terminal)
bool Terminal::valideXml(const QDomElement &terminal)
{
// verifie le nom du tag
if (terminal.tagName() != "terminal") return(false);
// verifie la presence des attributs minimaux
if (!terminal.hasAttribute("x")) return(false);
if (!terminal.hasAttribute("y")) return(false);
if (!terminal.hasAttribute("orientation")) return(false);
// affuteuse_250h.qet contains in line 8398 terminals which do not have this
// if (QETXML::propertyString(terminal, "number"))
// return false;
// affuteuse_250h.qet contains in line 8398 terminals which do not have this
// if (QETXML::propertyBool(terminal, "nameHidden"))
// return false;
bool conv_ok;
// parse l'abscisse
terminal.attribute("x").toDouble(&conv_ok);
if (!conv_ok) return(false);
// parse l'ordonnee
terminal.attribute("y").toDouble(&conv_ok);
if (!conv_ok) return(false);
// parse l'id
terminal.attribute("id").toInt(&conv_ok);
if (!conv_ok) return(false);
// parse l'orientation
int terminal_or = terminal.attribute("orientation").toInt(&conv_ok);
if (!conv_ok) return(false);
if (terminal_or != Qet::North
&& terminal_or != Qet::South
&& terminal_or != Qet::East
&& terminal_or != Qet::West) return(false);
if (!TerminalData::valideXml(terminal))
return false;
// a ce stade, la borne est syntaxiquement correcte
return(true);
return true;
}
/**
/** RETURNS True
@brief Terminal::fromXml
Permet de savoir si un element XML represente cette borne. Attention,
l'element XML n'est pas verifie
@@ -701,13 +800,17 @@ bool Terminal::valideXml(QDomElement &terminal)
@return true si la borne "se reconnait"
(memes coordonnes, meme orientation), false sinon
*/
bool Terminal::fromXml(QDomElement &terminal)
{
return (
qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) &&
qFuzzyCompare(terminal.attribute("y").toDouble(), dock_elmt_.y()) &&
(terminal.attribute("orientation").toInt() == d->m_orientation)
);
bool Terminal::fromXmlPriv(const QDomElement &terminal) {
QETXML::propertyString(terminal, "number", &number_terminal_);
QETXML::propertyBool(terminal, "nameHidden", &name_terminal_hidden);
if(!d->fromXml(terminal))
return false;
init(number_terminal_, d->m_name, name_terminal_hidden); // initialize dock_elmt_. This must be done after Terminal data is initialized
return true;
}
/**
@@ -744,6 +847,18 @@ QUuid Terminal::uuid() const
return d->m_uuid;
}
int Terminal::ID() const {
return m_id;
}
QPointF Terminal::dockPos() {
return dock_elmt_;
}
QPointF Terminal::originPos() {
return d->m_pos;
}
/**
@brief Conductor::relatedPotentialTerminal
Return terminal at the same potential from the same

View File

@@ -21,6 +21,9 @@
#include <QtWidgets>
#include <QtXml>
#include "../qet.h"
#include "../properties/propertiesinterface.h"
class Conductor;
class Diagram;
class Element;
@@ -32,7 +35,7 @@ class TerminalData;
plug point for conductors.
This class handles all mouse events for connecting conductors
*/
class Terminal : public QGraphicsObject
class Terminal : public QGraphicsObject, public PropertiesInterface
{
Q_OBJECT
@@ -42,7 +45,11 @@ class Terminal : public QGraphicsObject
// constructors, destructor
public:
Terminal(QPointF, Qet::Orientation, Element * = nullptr);
Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
Terminal(TerminalData* data, Element *e = nullptr);
Terminal(QPointF, Qet::Orientation, QString number,
QString name, bool hiddenName, Element * = nullptr);
~Terminal() override;
private:
@@ -63,17 +70,25 @@ class Terminal : public QGraphicsObject
const QStyleOptionGraphicsItem *,
QWidget *) override;
void drawHelpLine (bool draw = true);
QLineF HelpLine () const;
QLineF HelpLine () const;
QRectF boundingRect () const override;
// methods to manage conductors attached to the terminal
Terminal* alignedWithTerminal () const;
bool addConductor (Conductor *conductor);
void removeConductor (Conductor *conductor);
int conductorsCount () const;
Diagram *diagram () const;
Element *parentElement () const;
QUuid uuid () const;
bool addConductor (Conductor *conductor);
void removeConductor (Conductor *conductor);
int conductorsCount () const;
Diagram *diagram () const;
Element *parentElement () const;
QUuid uuid () const;
int ID() const;
QPointF dockPos();
QPointF originPos();
QString number() const;
void setNumber(QString number);
void setName(QString name, bool hiddenName);
QString name() const;
QList<Conductor *> conductors() const;
Qet::Orientation orientation() const;
@@ -81,11 +96,15 @@ class Terminal : public QGraphicsObject
void updateConductor();
bool isLinkedTo(Terminal *);
bool canBeLinkedTo(Terminal *);
void setID(int id);
// methods related to XML import/export
static bool valideXml(QDomElement &);
bool fromXml (QDomElement &);
QDomElement toXml (QDomDocument &) const;
static bool valideXml(const QDomElement &);
bool fromXmlPriv (const QDomElement &) override;
void toXmlPriv(QDomElement &) const override;
void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/}
void fromSettings(QSettings &,const QString & = QString()) override{/*TODO: implement*/}
protected:
// methods related to events management
@@ -103,6 +122,7 @@ class Terminal : public QGraphicsObject
static const qreal terminalSize;
static const qreal Z;
// Various static colors used for hover effects
// The assignement is in the cpp file
/// default color
static QColor neutralColor;
/// color for legal actions
@@ -113,12 +133,12 @@ class Terminal : public QGraphicsObject
static QColor forbiddenColor;
private:
bool m_draw_help_line{false};
bool m_draw_help_line{false};
QGraphicsLineItem *m_help_line{nullptr};
QGraphicsLineItem *m_help_line_a{nullptr};
TerminalData* d;
TerminalData* d{nullptr};
/// Parent electrical element
Element *parent_element_{nullptr};
@@ -127,18 +147,29 @@ class Terminal : public QGraphicsObject
QPointF dock_elmt_;
private:
/// List of conductors attached to the terminal
QList<Conductor *> m_conductors_list;
QRectF m_br;
/// Last terminal seen through an attached conductor
Terminal *m_previous_terminal = nullptr;
/// Whether the mouse pointer is hovering the terminal
bool m_hovered = false;
/// Color used for the hover effect
QColor m_hovered_color = Terminal::neutralColor;
QList<Conductor *> m_conductors_list;
/**
Pointer to a rectangle representing the terminal bounding rect;
used to calculate the bounding rect once only;
used a pointer because boundingRect() is supposed to be const.
*/
QRectF m_br;
/// Last terminal seen through an attached conductor
Terminal *m_previous_terminal{nullptr};
/// Whether the mouse pointer is hovering the terminal
bool m_hovered{false};
/// Color used for the hover effect
QColor m_hovered_color{Terminal::neutralColor};
/// Number of Terminal
QString number_terminal_;
bool name_terminal_hidden{true};
/// legacy id used by the conductor to find the terminal. From 0.8x on the uuid is used instead.
int m_id{-1};
private:
void init();
void init(QPointF pf, Qet::Orientation o);
void init(QString number, QString name, bool hiddenName);
void init(QPointF pf, Qet::Orientation o,QString number, QString name, bool hiddenName);
};
/**
@@ -147,9 +178,19 @@ class Terminal : public QGraphicsObject
*/
inline int Terminal::conductorsCount() const
{
return(m_conductors_list.size());
return(m_conductors_list.size());
}
/**
@brief Terminal::number
@return the number of terminal.
*/
inline QString Terminal::number() const
{
return(number_terminal_);
}
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
const bool all_diagram = true);