mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
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:
@@ -685,10 +685,11 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
||||
project_ -> state() == QETProject::ProjectParsingRunning
|
||||
);
|
||||
|
||||
// chargement de tous les elements du fichier XML
|
||||
//Load all elements from the XML
|
||||
QList<Element *> added_elements;
|
||||
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;
|
||||
|
||||
// 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;
|
||||
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);
|
||||
qDebug() << qPrintable(debug_message);
|
||||
delete nvel_elmt;
|
||||
@@ -760,11 +762,16 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
||||
Terminal *p2 = table_adr_id.value(id_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);
|
||||
if (c->isValid())
|
||||
{
|
||||
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";
|
||||
}
|
||||
|
||||
@@ -59,12 +59,11 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
|
||||
setZValue(9);
|
||||
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_p2 = terminal2 -> addConductor(this);
|
||||
|
||||
// en cas d'echec de l'ajout (conducteur deja existant notamment)
|
||||
if (!ajout_p1 || !ajout_p2) return;
|
||||
//m_valid become false if the conductor can't be added to terminal (conductor already exist)
|
||||
m_valid = (!ajout_p1 || !ajout_p2) ? false : true;
|
||||
|
||||
// attributs de dessin par defaut (communs a tous les conducteurs)
|
||||
if (!pen_and_brush_initialized) {
|
||||
@@ -113,6 +112,15 @@ Conductor::~Conductor() {
|
||||
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
|
||||
trace. Cette fonction est typiquement appelee lorsqu'une seule des bornes du
|
||||
|
||||
@@ -46,6 +46,8 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
||||
Conductor(Terminal *, Terminal *);
|
||||
virtual ~Conductor();
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
Conductor(const Conductor &);
|
||||
|
||||
@@ -164,6 +166,7 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
||||
qreal segments_squares_scale_;
|
||||
/// Define whether and how the conductor should be highlighted
|
||||
Highlight must_highlight_;
|
||||
bool m_valid;
|
||||
|
||||
private:
|
||||
void segmentsToPath();
|
||||
|
||||
Reference in New Issue
Block a user