[qet] [1315] As elements, diagrams now have a "version" attribute for compatibility purposes. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 1315
Author: xavier
Date: 2011-08-29 23:50:43 +0200 (Mon, 29 Aug 2011)
Log Message:
-----------
As elements, diagrams now have a "version" attribute for compatibility purposes.
Modified Paths:
--------------
branches/0.3/sources/diagram.cpp
branches/0.3/sources/diagram.h
Modified: branches/0.3/sources/diagram.cpp
===================================================================
--- branches/0.3/sources/diagram.cpp 2011-08-26 19:06:35 UTC (rev 1314)
+++ branches/0.3/sources/diagram.cpp 2011-08-29 21:50:43 UTC (rev 1315)
@@ -46,7 +46,8 @@
draw_terminals(true),
draw_colored_conductors_(true),
project_(0),
- read_only_(false)
+ read_only_(false),
+ diagram_qet_version_(-1)
{
undo_stack = new QUndoStack();
qgi_manager = new QGIManager(this);
@@ -270,6 +271,9 @@
// racine de l'arbre XML
QDomElement racine = document.createElement("diagram");
+ // add the application version number
+ racine.setAttribute("version", QET::version);
+
// proprietes du schema
if (whole_content) {
border_and_titleblock.titleBlockToXml(racine);
@@ -408,6 +412,12 @@
// lecture des attributs de ce schema
if (consider_informations) {
+ bool conv_ok;
+ qreal version_value = root.attribute("version").toDouble(&conv_ok);
+ if (conv_ok) {
+ diagram_qet_version_ = version_value;
+ }
+
border_and_titleblock.titleBlockFromXml(root);
border_and_titleblock.borderFromXml(root);
@@ -424,6 +434,17 @@
return(true);
}
+ // Backward compatibility: prior to version 0.3, we need to compensate, at
+ // diagram-opening time, the rotation of the element for each of its
+ // textfields having the "FollowParentRotation" option disabled.
+ // After 0.3, elements textfields get userx, usery and userrotation attributes
+ // that explicitly specify their position and orientation.
+ qreal project_qet_version = declaredQElectroTechVersion(true);
+ bool handle_inputs_rotation = (
+ project_qet_version != -1 && project_qet_version < 0.3 &&
+ project_ -> state() == QETProject::ProjectParsingRunning
+ );
+
// chargement de tous les elements du fichier XML
QList<Element *> added_elements;
QHash<int, Terminal *> table_adr_id;
@@ -446,17 +467,6 @@
}
// charge les caracteristiques de l'element
- // Retrocompatibilite : avant la version 0.3, il faut gerer a l'ouverture du schema
- // la compensation de la rotation de l'element pour ses champs de texte ayant l'option
- // "FollowParentRotation" desactivee
- // A partir de la 0.3, les champs de texte des elements comportent des attributs userx,
- // usery et userrotation qui specifient explicitement leur position et orientation
- bool handle_inputs_rotation = false;
- if (project_) {
- qreal project_qet_version = project_ -> declaredQElectroTechVersion();
- handle_inputs_rotation = (project_qet_version != -1 && project_qet_version < 0.3 && project_ -> state() == QETProject::ProjectParsingRunning);
- }
-
if (nvel_elmt -> fromXml(element_xml, table_adr_id, handle_inputs_rotation)) {
// ajout de l'element au schema et a la liste des elements ajoutes
addElement(nvel_elmt);
@@ -1012,6 +1022,22 @@
}
/**
+ @param fallback_to_project When a diagram does not have a declared version,
+ this method will use the one declared by its parent project only if
+ fallback_to_project is true.
+ @return the declared QElectroTech version of this diagram
+*/
+qreal Diagram::declaredQElectroTechVersion(bool fallback_to_project) const {
+ if (diagram_qet_version_ != -1) {
+ return diagram_qet_version_;
+ }
+ if (fallback_to_project && project_) {
+ return(project_ -> declaredQElectroTechVersion());
+ }
+ return(-1);
+}
+
+/**
@return true si le schema est en lecture seule
*/
bool Diagram::isReadOnly() const {
Modified: branches/0.3/sources/diagram.h
===================================================================
--- branches/0.3/sources/diagram.h 2011-08-26 19:06:35 UTC (rev 1314)
+++ branches/0.3/sources/diagram.h 2011-08-29 21:50:43 UTC (rev 1315)
@@ -85,6 +85,7 @@
QDomDocument xml_document;
QETProject *project_;
bool read_only_;
+ qreal diagram_qet_version_;
// methodes
protected:
@@ -98,6 +99,7 @@
// fonctions relatives au projet parent
QETProject *project() const;
void setProject(QETProject *);
+ qreal declaredQElectroTechVersion(bool = true) const;
// fonctions relatives a la lecture seule
bool isReadOnly() const;