Bug fix : Qet crash when load a conductor without two terminal (because the allocation of a new conductor fail)

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3974 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-05-18 22:19:14 +00:00
parent e73bad2bd6
commit 4142f9c6a2
3 changed files with 29 additions and 11 deletions

View File

@@ -685,10 +685,11 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
project_ -> state() == QETProject::ProjectParsingRunning project_ -> state() == QETProject::ProjectParsingRunning
); );
// chargement de tous les elements du fichier XML //Load all elements from the XML
QList<Element *> added_elements; QList<Element *> added_elements;
QHash<int, Terminal *> table_adr_id; QHash<int, Terminal *> table_adr_id;
foreach (QDomElement element_xml, QET::findInDomElement(root, "elements", "element")) { foreach (QDomElement element_xml, QET::findInDomElement(root, "elements", "element"))
{
if (!Element::valideXml(element_xml)) continue; if (!Element::valideXml(element_xml)) continue;
// cree un element dont le type correspond a l'id type // cree un element dont le type correspond a l'id type
@@ -698,7 +699,8 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
int state = 0; int state = 0;
Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, 0, &state); Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, 0, &state);
if (state) { if (state)
{
QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(state); QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(state);
qDebug() << qPrintable(debug_message); qDebug() << qPrintable(debug_message);
delete nvel_elmt; delete nvel_elmt;
@@ -760,10 +762,15 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
Terminal *p2 = table_adr_id.value(id_p2); Terminal *p2 = table_adr_id.value(id_p2);
if (p1 != p2) if (p1 != p2)
{ {
Conductor *c = new Conductor(table_adr_id.value(id_p1), table_adr_id.value(id_p2)); Conductor *c = new Conductor(p1, p2);
addItem(c); if (c->isValid())
c -> fromXml(f); {
added_conductors << c; addItem(c);
c -> fromXml(f);
added_conductors << c;
}
else
delete c;
} }
} }
else qDebug() << "Diagram::fromXml() : Le chargement du conducteur" << id_p1 << id_p2 << "a echoue"; else qDebug() << "Diagram::fromXml() : Le chargement du conducteur" << id_p1 << id_p2 << "a echoue";

View File

@@ -59,12 +59,11 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
setZValue(9); setZValue(9);
previous_z_value = zValue(); previous_z_value = zValue();
// ajout du conducteur a la liste de conducteurs de chacune des deux bornes //Add this conductor to the list of conductor of each of the two terminal
bool ajout_p1 = terminal1 -> addConductor(this); bool ajout_p1 = terminal1 -> addConductor(this);
bool ajout_p2 = terminal2 -> addConductor(this); bool ajout_p2 = terminal2 -> addConductor(this);
//m_valid become false if the conductor can't be added to terminal (conductor already exist)
// en cas d'echec de l'ajout (conducteur deja existant notamment) m_valid = (!ajout_p1 || !ajout_p2) ? false : true;
if (!ajout_p1 || !ajout_p2) return;
// attributs de dessin par defaut (communs a tous les conducteurs) // attributs de dessin par defaut (communs a tous les conducteurs)
if (!pen_and_brush_initialized) { if (!pen_and_brush_initialized) {
@@ -113,6 +112,15 @@ Conductor::~Conductor() {
deleteSegments(); deleteSegments();
} }
/**
* @brief Conductor::isValid
* @return true if conductor is valid else false;
* A non valid conductor, is a conductor without two terminal
*/
bool Conductor::isValid() const {
return m_valid;
}
/** /**
Met a jour la representation graphique du conducteur en recalculant son Met a jour la representation graphique du conducteur en recalculant son
trace. Cette fonction est typiquement appelee lorsqu'une seule des bornes du trace. Cette fonction est typiquement appelee lorsqu'une seule des bornes du

View File

@@ -45,6 +45,8 @@ class Conductor : public QObject, public QGraphicsPathItem {
public: public:
Conductor(Terminal *, Terminal *); Conductor(Terminal *, Terminal *);
virtual ~Conductor(); virtual ~Conductor();
bool isValid() const;
private: private:
Conductor(const Conductor &); Conductor(const Conductor &);
@@ -164,6 +166,7 @@ class Conductor : public QObject, public QGraphicsPathItem {
qreal segments_squares_scale_; qreal segments_squares_scale_;
/// Define whether and how the conductor should be highlighted /// Define whether and how the conductor should be highlighted
Highlight must_highlight_; Highlight must_highlight_;
bool m_valid;
private: private:
void segmentsToPath(); void segmentsToPath();