mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 14:14:15 +02:00
Fix GitHub issue #798: element editor crash on scroll-wheel zoom
ElementView applied scale() on every wheel notch with no bound on the
resulting view transform. Held down, the scroll-wheel zoom drives the
transform scale (m11) to floating-point overflow; the transform becomes
non-invertible, mapToScene() returns NaN and the next background paint
aborts the editor ("program closes completely" as reported on Windows).
Route zoomIn/zoomOut/zoomInSlowly/zoomOutSlowly through a new
scaleClamped() helper that only applies the scale while the result stays
within [m_min_zoom, m_max_zoom] (0.1 .. 200). Behaviour within that range
is unchanged.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HdWpDp3TrPKbHnv7YUcNJj
This commit is contained in:
@@ -100,13 +100,30 @@ void ElementView::setSelectionMode()
|
||||
emit(modeChanged());
|
||||
}
|
||||
|
||||
/**
|
||||
Applique un facteur d'echelle a la vue en bornant l'echelle resultante
|
||||
entre m_min_zoom et m_max_zoom. Sans cette borne, un zoom repete (molette)
|
||||
finit par faire deborder la transformation de la vue et fait planter
|
||||
l'editeur (issue #798).
|
||||
@param factor facteur d'echelle a appliquer
|
||||
*/
|
||||
void ElementView::scaleClamped(qreal factor)
|
||||
{
|
||||
const qreal current = transform().m11();
|
||||
const qreal target = current * factor;
|
||||
if (target < m_min_zoom || target > m_max_zoom) {
|
||||
return;
|
||||
}
|
||||
scale(factor, factor);
|
||||
}
|
||||
|
||||
/**
|
||||
Agrandit le schema (+33% = inverse des -25 % de zoomMoins())
|
||||
*/
|
||||
void ElementView::zoomIn()
|
||||
{
|
||||
adjustSceneRect();
|
||||
scale(4.0/3.0, 4.0/3.0);
|
||||
scaleClamped(4.0/3.0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +132,7 @@ void ElementView::zoomIn()
|
||||
void ElementView::zoomOut()
|
||||
{
|
||||
adjustSceneRect();
|
||||
scale(0.75, 0.75);
|
||||
scaleClamped(0.75);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +140,7 @@ void ElementView::zoomOut()
|
||||
*/
|
||||
void ElementView::zoomInSlowly()
|
||||
{
|
||||
scale(1.02, 1.02);
|
||||
scaleClamped(1.02);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +148,7 @@ void ElementView::zoomInSlowly()
|
||||
*/
|
||||
void ElementView::zoomOutSlowly()
|
||||
{
|
||||
scale(0.98, 0.98);
|
||||
scaleClamped(0.98);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user