mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 22:00:35 +01:00
Gestion du chargement des fichiers enregistres dans une version < 0.3.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1085 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -488,7 +488,18 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// charge les caracteristiques de l'element
|
// charge les caracteristiques de l'element
|
||||||
if (nvel_elmt -> fromXml(element_xml, table_adr_id)) {
|
// 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
|
// ajout de l'element au schema et a la liste des elements ajoutes
|
||||||
addElement(nvel_elmt);
|
addElement(nvel_elmt);
|
||||||
added_elements << nvel_elmt;
|
added_elements << nvel_elmt;
|
||||||
|
|||||||
@@ -319,8 +319,7 @@ class RotateElementsCommand : public QUndoCommand {
|
|||||||
virtual void redo();
|
virtual void redo();
|
||||||
qreal appliedRotationAngle() const;
|
qreal appliedRotationAngle() const;
|
||||||
void setAppliedRotationAngle(const qreal &);
|
void setAppliedRotationAngle(const qreal &);
|
||||||
private:
|
static void rotateElement(Element *, QET::Orientation);
|
||||||
void rotateElement(Element *, QET::Orientation);
|
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ bool Element::valideXml(QDomElement &e) {
|
|||||||
@return true si l'import a reussi, false sinon
|
@return true si l'import a reussi, false sinon
|
||||||
|
|
||||||
*/
|
*/
|
||||||
bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr) {
|
bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool handle_inputs_rotation) {
|
||||||
/*
|
/*
|
||||||
les bornes vont maintenant etre recensees pour associer leurs id a leur adresse reelle
|
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
|
ce recensement servira lors de la mise en place des fils
|
||||||
@@ -453,14 +453,19 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// position, selection et orientation
|
// position, selection
|
||||||
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
|
|
||||||
|
// orientation
|
||||||
bool conv_ok;
|
bool conv_ok;
|
||||||
int read_ori = e.attribute("orientation").toInt(&conv_ok);
|
int read_ori = e.attribute("orientation").toInt(&conv_ok);
|
||||||
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = ori.defaultOrientation();
|
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = ori.defaultOrientation();
|
||||||
|
if (handle_inputs_rotation) {
|
||||||
|
RotateElementsCommand::rotateElement(this, (QET::Orientation)read_ori);
|
||||||
|
} else {
|
||||||
setOrientation((QET::Orientation)read_ori);
|
setOrientation((QET::Orientation)read_ori);
|
||||||
|
}
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class Element : public QObject, public QGraphicsItem {
|
|||||||
|
|
||||||
// methodes relatives aux fichiers XML
|
// methodes relatives aux fichiers XML
|
||||||
static bool valideXml(QDomElement &);
|
static bool valideXml(QDomElement &);
|
||||||
virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &);
|
virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &, bool = false);
|
||||||
virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
||||||
|
|
||||||
// methodes d'acces aux possibilites d'orientation
|
// methodes d'acces aux possibilites d'orientation
|
||||||
|
|||||||
@@ -25,9 +25,9 @@
|
|||||||
*/
|
*/
|
||||||
namespace QET {
|
namespace QET {
|
||||||
/// version de QElectroTech (utilisee pour estampiller les projets et elements)
|
/// version de QElectroTech (utilisee pour estampiller les projets et elements)
|
||||||
const QString version = "0.22";
|
const QString version = "0.3";
|
||||||
/// version affichee de QElectroTech
|
/// version affichee de QElectroTech
|
||||||
const QString displayedVersion = "0.22";
|
const QString displayedVersion = "0.3";
|
||||||
QString license();
|
QString license();
|
||||||
/// Orientation (utilise pour les bornes mais aussi pour les elements)
|
/// Orientation (utilise pour les bornes mais aussi pour les elements)
|
||||||
enum Orientation {North, East, South, West};
|
enum Orientation {North, East, South, West};
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ QString QETProject::integration_category_name = "import";
|
|||||||
*/
|
*/
|
||||||
QETProject::QETProject(int diagrams, QObject *parent) :
|
QETProject::QETProject(int diagrams, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
|
project_qet_version_(-1),
|
||||||
read_only_(false)
|
read_only_(false)
|
||||||
{
|
{
|
||||||
// 0 a n schema(s) vide(s)
|
// 0 a n schema(s) vide(s)
|
||||||
@@ -61,6 +62,7 @@ QETProject::QETProject(int diagrams, QObject *parent) :
|
|||||||
*/
|
*/
|
||||||
QETProject::QETProject(const QString &path, QObject *parent) :
|
QETProject::QETProject(const QString &path, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
|
project_qet_version_(-1),
|
||||||
read_only_(false)
|
read_only_(false)
|
||||||
{
|
{
|
||||||
// ouvre le fichier
|
// ouvre le fichier
|
||||||
@@ -94,6 +96,7 @@ QETProject::QETProject(const QString &path, QObject *parent) :
|
|||||||
*/
|
*/
|
||||||
QETProject::QETProject(const QDomElement &xml_element, QObject *parent) :
|
QETProject::QETProject(const QDomElement &xml_element, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
|
project_qet_version_(-1),
|
||||||
read_only_(false)
|
read_only_(false)
|
||||||
{
|
{
|
||||||
// copie le contenu XML
|
// copie le contenu XML
|
||||||
@@ -239,6 +242,15 @@ QString QETProject::title() const {
|
|||||||
return(project_title_);
|
return(project_title_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return la version de QElectroTech declaree dans le fichier projet lorsque
|
||||||
|
celui-ci a ete ouvert ; si ce projet n'a jamais ete enregistre / ouvert
|
||||||
|
depuis un fichier, cette methode retourne -1.
|
||||||
|
*/
|
||||||
|
qreal QETProject::declaredQElectroTechVersion() {
|
||||||
|
return(project_qet_version_);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param title le nouveau titre du projet
|
@param title le nouveau titre du projet
|
||||||
*/
|
*/
|
||||||
@@ -689,14 +701,15 @@ ElementsCategory *QETProject::rootCategory() const {
|
|||||||
*/
|
*/
|
||||||
void QETProject::readProjectXml() {
|
void QETProject::readProjectXml() {
|
||||||
QDomElement root_elmt = document_root_.documentElement();
|
QDomElement root_elmt = document_root_.documentElement();
|
||||||
|
state_ = ProjectParsingRunning;
|
||||||
|
|
||||||
// la racine du document XML est sensee etre un element "project"
|
// la racine du document XML est sensee etre un element "project"
|
||||||
if (root_elmt.tagName() == "project") {
|
if (root_elmt.tagName() == "project") {
|
||||||
// mode d'ouverture normal
|
// mode d'ouverture normal
|
||||||
if (root_elmt.hasAttribute("version")) {
|
if (root_elmt.hasAttribute("version")) {
|
||||||
bool conv_ok;
|
bool conv_ok;
|
||||||
qreal diagram_version = root_elmt.attribute("version").toDouble(&conv_ok);
|
project_qet_version_ = root_elmt.attribute("version").toDouble(&conv_ok);
|
||||||
if (conv_ok && QET::version.toDouble() < diagram_version) {
|
if (conv_ok && QET::version.toDouble() < project_qet_version_) {
|
||||||
QET::MessageBox::warning(
|
QET::MessageBox::warning(
|
||||||
0,
|
0,
|
||||||
tr("Avertissement", "message box title"),
|
tr("Avertissement", "message box title"),
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ class QETProject : public QObject {
|
|||||||
Ok = 0, /// Le projet n'est pas en erreur
|
Ok = 0, /// Le projet n'est pas en erreur
|
||||||
FileOpenFailed = 1, /// l'ouverture d'un fichier a echoue
|
FileOpenFailed = 1, /// l'ouverture d'un fichier a echoue
|
||||||
XmlParsingFailed = 2, /// l'analyse XML a echoue
|
XmlParsingFailed = 2, /// l'analyse XML a echoue
|
||||||
ProjectParsingFailed = 3 /// la lecture en tant que projet a echoue
|
ProjectParsingRunning = 3, /// la lecture du projet est en cours
|
||||||
|
ProjectParsingFailed = 4 /// la lecture en tant que projet a echoue
|
||||||
};
|
};
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
@@ -76,6 +77,7 @@ class QETProject : public QObject {
|
|||||||
QString currentDir() const;
|
QString currentDir() const;
|
||||||
QString pathNameTitle() const;
|
QString pathNameTitle() const;
|
||||||
QString title() const;
|
QString title() const;
|
||||||
|
qreal declaredQElectroTechVersion();
|
||||||
void setTitle(const QString &);
|
void setTitle(const QString &);
|
||||||
BorderProperties defaultBorderProperties() const;
|
BorderProperties defaultBorderProperties() const;
|
||||||
void setDefaultBorderProperties(const BorderProperties &);
|
void setDefaultBorderProperties(const BorderProperties &);
|
||||||
@@ -142,6 +144,8 @@ class QETProject : public QObject {
|
|||||||
XmlElementsCollection *collection_;
|
XmlElementsCollection *collection_;
|
||||||
/// Titre du projet
|
/// Titre du projet
|
||||||
QString project_title_;
|
QString project_title_;
|
||||||
|
/// Version de QElectroTech declaree dans le document XML lors de son ouverture
|
||||||
|
qreal project_qet_version_;
|
||||||
/// booleen indiquant si le projet est en ReadOnly ou non
|
/// booleen indiquant si le projet est en ReadOnly ou non
|
||||||
bool read_only_;
|
bool read_only_;
|
||||||
/// Chemin du fichier pour lequel ce projet est considere comme etant en lecture seule
|
/// Chemin du fichier pour lequel ce projet est considere comme etant en lecture seule
|
||||||
|
|||||||
Reference in New Issue
Block a user