mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-06-11 13:43:13 +02:00
d949e6eb8c
Three bugs were causing a crash (SIGSEGV in QRegion::begin) when a power NC slave element was placed on a folio, even before linking it to a master element. 1. m_drawing (QPicture) was never reset between updateLabel() calls. QPicture accumulates paint commands — calling qp.begin() on an existing QPicture appends to it rather than replacing its content. After several updates (load, move, hover...) the picture became corrupted and crashed on play(). Fix: reset m_drawing = QPicture() at the start of updateLabel(). 2. m_drawed_contacts was only initialized to 0 in drawAsContacts(), but not in drawAsCross(). When drawing in Cross mode, fillCrossRef() called drawContact() with an uninitialized m_drawed_contacts value, producing a garbage offset. The NC contact symbol uses drawPolyline() with a sub-pixel Y coordinate (offset+2.5); with a random offset Qt generated an invalid QRegion and crashed. This explains why NC contacts crashed but NO contacts did not: the NO symbol only uses drawLine() which is more tolerant of bad coords. Fix: add m_drawed_contacts = 0 at the start of drawAsCross(). 3. setUpCrossBoundingRect() used QRectF() (null rect) as the reference rect for painter.boundingRect(), which can return invalid dimensions. Additionally, height was accumulated incorrectly: united() + setHeight() doubled the height at each iteration, causing an exponentially growing bounding rect with multiple contacts. Fix: use QRectF(0, 0, 500, 20) as reference rect and accumulate height and width independently.