mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +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
|
||||
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
|
||||
addElement(nvel_elmt);
|
||||
added_elements << nvel_elmt;
|
||||
|
||||
@@ -319,8 +319,7 @@ class RotateElementsCommand : public QUndoCommand {
|
||||
virtual void redo();
|
||||
qreal appliedRotationAngle() const;
|
||||
void setAppliedRotationAngle(const qreal &);
|
||||
private:
|
||||
void rotateElement(Element *, QET::Orientation);
|
||||
static void rotateElement(Element *, QET::Orientation);
|
||||
|
||||
// attributs
|
||||
private:
|
||||
|
||||
@@ -403,7 +403,7 @@ bool Element::valideXml(QDomElement &e) {
|
||||
@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
|
||||
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());
|
||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||
|
||||
// orientation
|
||||
bool conv_ok;
|
||||
int read_ori = e.attribute("orientation").toInt(&conv_ok);
|
||||
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = ori.defaultOrientation();
|
||||
setOrientation((QET::Orientation)read_ori);
|
||||
|
||||
if (handle_inputs_rotation) {
|
||||
RotateElementsCommand::rotateElement(this, (QET::Orientation)read_ori);
|
||||
} else {
|
||||
setOrientation((QET::Orientation)read_ori);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ class Element : public QObject, public QGraphicsItem {
|
||||
|
||||
// methodes relatives aux fichiers XML
|
||||
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;
|
||||
|
||||
// methodes d'acces aux possibilites d'orientation
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
*/
|
||||
namespace QET {
|
||||
/// version de QElectroTech (utilisee pour estampiller les projets et elements)
|
||||
const QString version = "0.22";
|
||||
const QString version = "0.3";
|
||||
/// version affichee de QElectroTech
|
||||
const QString displayedVersion = "0.22";
|
||||
const QString displayedVersion = "0.3";
|
||||
QString license();
|
||||
/// Orientation (utilise pour les bornes mais aussi pour les elements)
|
||||
enum Orientation {North, East, South, West};
|
||||
|
||||
@@ -36,6 +36,7 @@ QString QETProject::integration_category_name = "import";
|
||||
*/
|
||||
QETProject::QETProject(int diagrams, QObject *parent) :
|
||||
QObject(parent),
|
||||
project_qet_version_(-1),
|
||||
read_only_(false)
|
||||
{
|
||||
// 0 a n schema(s) vide(s)
|
||||
@@ -61,6 +62,7 @@ QETProject::QETProject(int diagrams, QObject *parent) :
|
||||
*/
|
||||
QETProject::QETProject(const QString &path, QObject *parent) :
|
||||
QObject(parent),
|
||||
project_qet_version_(-1),
|
||||
read_only_(false)
|
||||
{
|
||||
// ouvre le fichier
|
||||
@@ -94,6 +96,7 @@ QETProject::QETProject(const QString &path, QObject *parent) :
|
||||
*/
|
||||
QETProject::QETProject(const QDomElement &xml_element, QObject *parent) :
|
||||
QObject(parent),
|
||||
project_qet_version_(-1),
|
||||
read_only_(false)
|
||||
{
|
||||
// copie le contenu XML
|
||||
@@ -239,6 +242,15 @@ QString QETProject::title() const {
|
||||
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
|
||||
*/
|
||||
@@ -689,14 +701,15 @@ ElementsCategory *QETProject::rootCategory() const {
|
||||
*/
|
||||
void QETProject::readProjectXml() {
|
||||
QDomElement root_elmt = document_root_.documentElement();
|
||||
state_ = ProjectParsingRunning;
|
||||
|
||||
// la racine du document XML est sensee etre un element "project"
|
||||
if (root_elmt.tagName() == "project") {
|
||||
// mode d'ouverture normal
|
||||
if (root_elmt.hasAttribute("version")) {
|
||||
bool conv_ok;
|
||||
qreal diagram_version = root_elmt.attribute("version").toDouble(&conv_ok);
|
||||
if (conv_ok && QET::version.toDouble() < diagram_version) {
|
||||
project_qet_version_ = root_elmt.attribute("version").toDouble(&conv_ok);
|
||||
if (conv_ok && QET::version.toDouble() < project_qet_version_) {
|
||||
QET::MessageBox::warning(
|
||||
0,
|
||||
tr("Avertissement", "message box title"),
|
||||
|
||||
@@ -60,10 +60,11 @@ class QETProject : public QObject {
|
||||
Represente l'etat du projet
|
||||
*/
|
||||
enum ProjectState {
|
||||
Ok = 0, /// Le projet n'est pas en erreur
|
||||
FileOpenFailed = 1, /// l'ouverture d'un fichier a echoue
|
||||
XmlParsingFailed = 2, /// l'analyse XML a echoue
|
||||
ProjectParsingFailed = 3 /// la lecture en tant que projet a echoue
|
||||
Ok = 0, /// Le projet n'est pas en erreur
|
||||
FileOpenFailed = 1, /// l'ouverture d'un fichier a echoue
|
||||
XmlParsingFailed = 2, /// l'analyse XML a echoue
|
||||
ProjectParsingRunning = 3, /// la lecture du projet est en cours
|
||||
ProjectParsingFailed = 4 /// la lecture en tant que projet a echoue
|
||||
};
|
||||
|
||||
// methodes
|
||||
@@ -76,6 +77,7 @@ class QETProject : public QObject {
|
||||
QString currentDir() const;
|
||||
QString pathNameTitle() const;
|
||||
QString title() const;
|
||||
qreal declaredQElectroTechVersion();
|
||||
void setTitle(const QString &);
|
||||
BorderProperties defaultBorderProperties() const;
|
||||
void setDefaultBorderProperties(const BorderProperties &);
|
||||
@@ -142,6 +144,8 @@ class QETProject : public QObject {
|
||||
XmlElementsCollection *collection_;
|
||||
/// Titre du projet
|
||||
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
|
||||
bool read_only_;
|
||||
/// Chemin du fichier pour lequel ce projet est considere comme etant en lecture seule
|
||||
|
||||
Reference in New Issue
Block a user