mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-03-17 23:59:58 +01:00
As elements, diagrams now have a "version" attribute for compatibility purposes.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1315 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -46,7 +46,8 @@ Diagram::Diagram(QObject *parent) :
|
|||||||
draw_terminals(true),
|
draw_terminals(true),
|
||||||
draw_colored_conductors_(true),
|
draw_colored_conductors_(true),
|
||||||
project_(0),
|
project_(0),
|
||||||
read_only_(false)
|
read_only_(false),
|
||||||
|
diagram_qet_version_(-1)
|
||||||
{
|
{
|
||||||
undo_stack = new QUndoStack();
|
undo_stack = new QUndoStack();
|
||||||
qgi_manager = new QGIManager(this);
|
qgi_manager = new QGIManager(this);
|
||||||
@@ -270,6 +271,9 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
// racine de l'arbre XML
|
// racine de l'arbre XML
|
||||||
QDomElement racine = document.createElement("diagram");
|
QDomElement racine = document.createElement("diagram");
|
||||||
|
|
||||||
|
// add the application version number
|
||||||
|
racine.setAttribute("version", QET::version);
|
||||||
|
|
||||||
// proprietes du schema
|
// proprietes du schema
|
||||||
if (whole_content) {
|
if (whole_content) {
|
||||||
border_and_titleblock.titleBlockToXml(racine);
|
border_and_titleblock.titleBlockToXml(racine);
|
||||||
@@ -408,6 +412,12 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
|
|
||||||
// lecture des attributs de ce schema
|
// lecture des attributs de ce schema
|
||||||
if (consider_informations) {
|
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.titleBlockFromXml(root);
|
||||||
border_and_titleblock.borderFromXml(root);
|
border_and_titleblock.borderFromXml(root);
|
||||||
|
|
||||||
@@ -424,6 +434,17 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
return(true);
|
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
|
// chargement de tous les elements du fichier XML
|
||||||
QList<Element *> added_elements;
|
QList<Element *> added_elements;
|
||||||
QHash<int, Terminal *> table_adr_id;
|
QHash<int, Terminal *> table_adr_id;
|
||||||
@@ -446,17 +467,6 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// charge les caracteristiques de l'element
|
// 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)) {
|
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
|
// ajout de l'element au schema et a la liste des elements ajoutes
|
||||||
addElement(nvel_elmt);
|
addElement(nvel_elmt);
|
||||||
@@ -1011,6 +1021,22 @@ void Diagram::setProject(QETProject *project) {
|
|||||||
project_ = project;
|
project_ = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@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
|
@return true si le schema est en lecture seule
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class Diagram : public QGraphicsScene {
|
|||||||
QDomDocument xml_document;
|
QDomDocument xml_document;
|
||||||
QETProject *project_;
|
QETProject *project_;
|
||||||
bool read_only_;
|
bool read_only_;
|
||||||
|
qreal diagram_qet_version_;
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
protected:
|
protected:
|
||||||
@@ -98,6 +99,7 @@ class Diagram : public QGraphicsScene {
|
|||||||
// fonctions relatives au projet parent
|
// fonctions relatives au projet parent
|
||||||
QETProject *project() const;
|
QETProject *project() const;
|
||||||
void setProject(QETProject *);
|
void setProject(QETProject *);
|
||||||
|
qreal declaredQElectroTechVersion(bool = true) const;
|
||||||
|
|
||||||
// fonctions relatives a la lecture seule
|
// fonctions relatives a la lecture seule
|
||||||
bool isReadOnly() const;
|
bool isReadOnly() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user