mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Conductor and conductor text item : minor change about how the text is save to xml
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3485 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -951,32 +951,66 @@ bool Conductor::hasClickedOn(QPointF press_point, QPointF point) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Charge les caracteristiques du conducteur depuis un element XML.
|
* @brief Conductor::fromXml
|
||||||
@param e Un element XML
|
* Load the conductor and her information from xml element
|
||||||
@return true si le chargement a reussi, false sinon
|
* @param e
|
||||||
*/
|
* @return true is loading success else return false
|
||||||
|
*/
|
||||||
bool Conductor::fromXml(QDomElement &e) {
|
bool Conductor::fromXml(QDomElement &e) {
|
||||||
//Get the "configuration" of conductor
|
|
||||||
properties_.fromXml(e);
|
|
||||||
readProperties();
|
|
||||||
|
|
||||||
setPos(e.attribute("x", 0).toDouble(),
|
setPos(e.attribute("x", 0).toDouble(),
|
||||||
e.attribute("y", 0).toDouble());
|
e.attribute("y", 0).toDouble());
|
||||||
|
|
||||||
//Get the pos of text item
|
bool return_ = pathFromXml(e);
|
||||||
qreal user_pos_x, user_pos_y;
|
|
||||||
if (
|
text_item -> fromXml(e);
|
||||||
QET::attributeIsAReal(e, "userx", &user_pos_x) &&
|
properties_. fromXml(e);
|
||||||
QET::attributeIsAReal(e, "usery", &user_pos_y)
|
readProperties();
|
||||||
) {
|
|
||||||
text_item -> forceMovedByUser(true);
|
return return_;
|
||||||
text_item -> setPos(user_pos_x, user_pos_y);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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 &d, QHash<Terminal *, int> &table_adr_id) const {
|
||||||
|
QDomElement e = d.createElement("conductor");
|
||||||
|
|
||||||
|
e.setAttribute("x", pos().x());
|
||||||
|
e.setAttribute("y", pos().y());
|
||||||
|
e.setAttribute("terminal1", table_adr_id.value(terminal1));
|
||||||
|
e.setAttribute("terminal2", table_adr_id.value(terminal2));
|
||||||
|
|
||||||
|
// 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 = d.createElement("segment");
|
||||||
|
current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
|
||||||
|
current_segment.setAttribute("length", QString("%1").arg(segment -> length()));
|
||||||
|
e.appendChild(current_segment);
|
||||||
}
|
}
|
||||||
if (e.hasAttribute("rotation")) {
|
|
||||||
text_item -> setRotationAngle(e.attribute("rotation").toDouble());
|
|
||||||
text_item -> forceRotateByUser(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Export the properties and text
|
||||||
|
properties_. toXml(e);
|
||||||
|
text_item -> toXml(e);
|
||||||
|
|
||||||
|
return(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Conductor::pathFromXml
|
||||||
|
* Generate the path from xml file
|
||||||
|
* @param e
|
||||||
|
* @return true if generate path success else return false
|
||||||
|
*/
|
||||||
|
bool Conductor::pathFromXml(const QDomElement &e) {
|
||||||
// parcourt les elements XML "segment" et en extrait deux listes de longueurs
|
// parcourt les elements XML "segment" et en extrait deux listes de longueurs
|
||||||
// les segments non valides sont ignores
|
// les segments non valides sont ignores
|
||||||
QList<qreal> segments_x, segments_y;
|
QList<qreal> segments_x, segments_y;
|
||||||
@@ -1047,46 +1081,6 @@ bool Conductor::fromXml(QDomElement &e) {
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
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 &d, QHash<Terminal *, int> &table_adr_id) const {
|
|
||||||
QDomElement e = d.createElement("conductor");
|
|
||||||
|
|
||||||
e.setAttribute("x", pos().x());
|
|
||||||
e.setAttribute("y", pos().y());
|
|
||||||
e.setAttribute("terminal1", table_adr_id.value(terminal1));
|
|
||||||
e.setAttribute("terminal2", table_adr_id.value(terminal2));
|
|
||||||
|
|
||||||
// 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 = d.createElement("segment");
|
|
||||||
current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
|
|
||||||
current_segment.setAttribute("length", QString("%1").arg(segment -> length()));
|
|
||||||
e.appendChild(current_segment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// exporte la "configuration" du conducteur
|
|
||||||
properties_.toXml(e);
|
|
||||||
if (text_item -> wasRotateByUser()) {
|
|
||||||
e.setAttribute("rotation", QString("%1").arg(text_item -> rotationAngle()));
|
|
||||||
}
|
|
||||||
if (text_item -> wasMovedByUser()) {
|
|
||||||
e.setAttribute("userx", QString("%1").arg(text_item -> pos().x()));
|
|
||||||
e.setAttribute("usery", QString("%1").arg(text_item -> pos().y()));
|
|
||||||
}
|
|
||||||
return(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @return les segments de ce conducteur
|
/// @return les segments de ce conducteur
|
||||||
const QList<ConductorSegment *> Conductor::segmentsList() const {
|
const QList<ConductorSegment *> Conductor::segmentsList() const {
|
||||||
if (segments == NULL) return(QList<ConductorSegment *>());
|
if (segments == NULL) return(QList<ConductorSegment *>());
|
||||||
@@ -1231,6 +1225,7 @@ void Conductor::calculateTextItemPosition() {
|
|||||||
QPointF text_item_pos = text_item -> pos();
|
QPointF text_item_pos = text_item -> pos();
|
||||||
QPainterPath near_shape = nearShape();
|
QPainterPath near_shape = nearShape();
|
||||||
if (!near_shape.contains(text_item_pos)) {
|
if (!near_shape.contains(text_item_pos)) {
|
||||||
|
qDebug() << "trop loin";
|
||||||
text_item -> setPos(movePointIntoPolygon(text_item_pos, near_shape));
|
text_item -> setPos(movePointIntoPolygon(text_item_pos, near_shape));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -92,9 +92,15 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
|||||||
bool containsPoint(const QPointF &) const;
|
bool containsPoint(const QPointF &) const;
|
||||||
QString text() const;
|
QString text() const;
|
||||||
void setText(const QString &);
|
void setText(const QString &);
|
||||||
static bool valideXml(QDomElement &);
|
|
||||||
bool fromXml(QDomElement &);
|
public:
|
||||||
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
static bool valideXml (QDomElement &);
|
||||||
|
bool fromXml (QDomElement &);
|
||||||
|
QDomElement toXml (QDomDocument &, QHash<Terminal *, int> &) const;
|
||||||
|
private:
|
||||||
|
bool pathFromXml(const QDomElement &);
|
||||||
|
|
||||||
|
public:
|
||||||
const QList<ConductorSegment *> segmentsList() const;
|
const QList<ConductorSegment *> segmentsList() const;
|
||||||
void setProperties(const ConductorProperties &);
|
void setProperties(const ConductorProperties &);
|
||||||
ConductorProperties properties() const;
|
ConductorProperties properties() const;
|
||||||
|
|||||||
@@ -60,38 +60,36 @@ Conductor *ConductorTextItem::parentConductor() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Permet de lire le texte a mettre dans le champ a partir d'un element XML.
|
* @brief ConductorTextItem::fromXml
|
||||||
Cette methode se base sur la position du champ pour assigner ou non la
|
* Read the properties stored in the xml element given in parameter
|
||||||
valeur a ce champ.
|
* @param e
|
||||||
@param e L'element XML representant le champ de texte
|
*/
|
||||||
*/
|
|
||||||
void ConductorTextItem::fromXml(const QDomElement &e) {
|
void ConductorTextItem::fromXml(const QDomElement &e) {
|
||||||
setPlainText(e.attribute("text"));
|
if (e.hasAttribute("userx")) {
|
||||||
|
setPos(e.attribute("userx").toDouble(),
|
||||||
qreal user_pos_x, user_pos_y;
|
e.attribute("usery").toDouble());
|
||||||
if (
|
moved_by_user_ = true;
|
||||||
QET::attributeIsAReal(e, "userx", &user_pos_x) &&
|
}
|
||||||
QET::attributeIsAReal(e, "usery", &user_pos_y)
|
if (e.hasAttribute("rotation")) {
|
||||||
) {
|
setRotation(e.attribute("rotation").toDouble());
|
||||||
setPos(user_pos_x, user_pos_y);
|
rotate_by_user_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
setRotationAngle(e.attribute("rotation").toDouble());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param document Le document XML a utiliser
|
* @brief ConductorTextItem::toXml
|
||||||
@return L'element XML representant ce champ de texte
|
* Export the properties of this text in the attribute of the xml element given in parameter
|
||||||
*/
|
* The properties exported are position and rotation (only if moved or rotate by user)
|
||||||
QDomElement ConductorTextItem::toXml(QDomDocument &document) const {
|
* @param xml
|
||||||
QDomElement result = document.createElement("input");
|
*/
|
||||||
result.setAttribute("userx", QString("%1").arg(pos().x()));
|
void ConductorTextItem::toXml(QDomElement &xml) const {
|
||||||
result.setAttribute("usery", QString("%1").arg(pos().y()));
|
if (moved_by_user_) {
|
||||||
result.setAttribute("text", toPlainText());
|
xml.setAttribute("userx", QString("%1").arg(pos().x()));
|
||||||
if (rotationAngle()) {
|
xml.setAttribute("usery", QString("%1").arg(pos().y()));
|
||||||
result.setAttribute("rotation", QString("%1").arg(rotationAngle()));
|
}
|
||||||
|
if (rotate_by_user_) {
|
||||||
|
xml.setAttribute("rotation", QString("%1").arg(rotation()));
|
||||||
}
|
}
|
||||||
return(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class ConductorTextItem : public DiagramTextItem {
|
|||||||
enum { Type = UserType + 1006 };
|
enum { Type = UserType + 1006 };
|
||||||
Conductor *parentConductor() const;
|
Conductor *parentConductor() const;
|
||||||
virtual void fromXml(const QDomElement &);
|
virtual void fromXml(const QDomElement &);
|
||||||
virtual QDomElement toXml(QDomDocument &) const;
|
virtual void toXml (QDomElement &xml) const;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -79,6 +79,16 @@ Diagram *DiagramTextItem::diagram() const {
|
|||||||
return(qobject_cast<Diagram *>(scene()));
|
return(qobject_cast<Diagram *>(scene()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DiagramTextItem::toXml
|
||||||
|
* This method do nothing and return an empty DomElement
|
||||||
|
* This is used to be inherited by child class
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
QDomElement DiagramTextItem::toXml(QDomDocument &) const {
|
||||||
|
return QDomElement();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return l'angle de rotation actuel de ce texte
|
@return l'angle de rotation actuel de ce texte
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class DiagramTextItem : public QGraphicsTextItem {
|
|||||||
virtual int type() const { return Type; }
|
virtual int type() const { return Type; }
|
||||||
Diagram *diagram() const;
|
Diagram *diagram() const;
|
||||||
virtual void fromXml(const QDomElement &) = 0;
|
virtual void fromXml(const QDomElement &) = 0;
|
||||||
virtual QDomElement toXml(QDomDocument &) const = 0;
|
virtual QDomElement toXml(QDomDocument &) const;
|
||||||
qreal rotationAngle() const;
|
qreal rotationAngle() const;
|
||||||
void setRotationAngle(const qreal &);
|
void setRotationAngle(const qreal &);
|
||||||
void rotateBy(const qreal &);
|
void rotateBy(const qreal &);
|
||||||
|
|||||||
Reference in New Issue
Block a user