[Kst] branches/work/kst/portto4/kst/src/libkstapp

Peter Kümmel syntheticpp at gmx.net
Sat Jun 1 14:24:08 UTC 2013


SVN commit 1356716 by kuemmel:

fix "runtime error: division by zero"

 M  +12 -10    viewitem.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1356715:1356716
@@ -1934,21 +1934,23 @@
 void ViewItem::updateRelativeSize(bool force_data) {
   if (parentViewItem()) {
     QPointF P;
-    _parentRelativeHeight = (height() / parentViewItem()->height());
-    _parentRelativeWidth = (width() / parentViewItem()->width());
+    int parentHeight = parentViewItem()->height() == 0 ? 1 : parentViewItem()->height();
+    int parentWidth  = parentViewItem()->width() == 0 ? 1 : parentViewItem()->height();
+    _parentRelativeHeight = (height() / parentHeight);
+    _parentRelativeWidth = (width() / parentWidth);
 
     P =  mapToParent(rect().center()) - parentViewItem()->rect().topLeft();
-    _parentRelativeCenter =  QPointF(P.x() / parentViewItem()->width(),
-                                     P.y() / parentViewItem()->height());
+    _parentRelativeCenter =  QPointF(P.x() / parentWidth,
+                                     P.y() / parentHeight);
     P =  mapToParent(rect().topLeft()) - parentViewItem()->rect().topLeft();
-    _parentRelativePosition =  QPointF(P.x() / parentViewItem()->width(),
-                                       P.y() / parentViewItem()->height());
+    _parentRelativePosition =  QPointF(P.x() / parentWidth,
+                                       P.y() / parentHeight);
     P =  mapToParent(rect().bottomLeft()) - parentViewItem()->rect().topLeft();
-    _parentRelativeLeft = QPointF(P.x() / parentViewItem()->width(),
-                                      P.y() / parentViewItem()->height());
+    _parentRelativeLeft = QPointF(P.x() / parentWidth,
+                                      P.y() / parentHeight);
     P =  mapToParent(rect().bottomRight()) - parentViewItem()->rect().topLeft();
-    _parentRelativeRight =  QPointF(P.x() / parentViewItem()->width(),
-                                    P.y() / parentViewItem()->height());
+    _parentRelativeRight =  QPointF(P.x() / parentWidth,
+                                    P.y() / parentHeight);
     updateDataRelativeRect(force_data);
    } else if (view()) {
     QPointF P;


More information about the Kst mailing list