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

Peter Kümmel syntheticpp at gmx.net
Mon Aug 30 12:30:27 CEST 2010


SVN commit 1169929 by kuemmel:

Change ownership when moving plot to a other tab.
Don't manage the parent via QObject: this change could be critical, see new macro in viewitem.cpp.
Using 'Z' on a plot in the other tab doesn't hide the moved plot an more.

CCBUG: 249253 

 M  +1 -1      arrowitem.cpp  
 M  +1 -1      boxitem.cpp  
 M  +1 -1      circleitem.cpp  
 M  +1 -1      ellipseitem.cpp  
 M  +1 -1      labelitem.cpp  
 M  +4 -4      layoutboxitem.cpp  
 M  +1 -1      legenditem.cpp  
 M  +1 -1      lineitem.cpp  
 M  +1 -1      pictureitem.cpp  
 M  +5 -5      plotitem.cpp  
 M  +1 -1      plotrenderitem.cpp  
 M  +1 -1      sharedaxisboxitem.cpp  
 M  +1 -1      svgitem.cpp  
 M  +2 -0      tabwidget.cpp  
 M  +42 -12    viewitem.cpp  
 M  +9 -1      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/arrowitem.cpp #1169928:1169929
@@ -149,7 +149,7 @@
         Q_ASSERT(!rc);
         rc = new ArrowItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         }
         QXmlStreamAttributes attrs = xml.attributes();
         QStringRef av;
--- branches/work/kst/portto4/kst/src/libkstapp/boxitem.cpp #1169928:1169929
@@ -70,7 +70,7 @@
         Q_ASSERT(!rc);
         rc = new BoxItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         }
         // Add any new specialized BoxItem Properties here.
       } else {
--- branches/work/kst/portto4/kst/src/libkstapp/circleitem.cpp #1169928:1169929
@@ -112,7 +112,7 @@
         Q_ASSERT(!rc);
         rc = new CircleItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         }
         // Add any new specialized CircleItem Properties here.
       } else {
--- branches/work/kst/portto4/kst/src/libkstapp/ellipseitem.cpp #1169928:1169929
@@ -79,7 +79,7 @@
         Q_ASSERT(!rc);
         rc = new EllipseItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         // Add any new specialized BoxItem Properties here.
         }
       } else {
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #1169928:1169929
@@ -245,7 +245,7 @@
         Q_ASSERT(!rc);
         rc = new LabelItem(view, av.toString());
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
          // Add any new specialized LabelItem Properties here.
           }
         }
--- branches/work/kst/portto4/kst/src/libkstapp/layoutboxitem.cpp #1169928:1169929
@@ -41,7 +41,7 @@
   if (item->parentItem() == this)
     return;
 
-  item->setParent(this);
+  item->setParentViewItem(this);
 //   layout()->addViewItem(item, layout()->rowCount(), 0, 1, layout()->columnCount());
   setPos(parentView()->sceneRect().topLeft());
   setViewRect(parentView()->sceneRect());
@@ -96,7 +96,7 @@
       if (!viewItem || viewItem->parentItem() || !viewItem->isVisible() || viewItem == this)
         continue;
 
-      viewItem->setParent(this);
+      viewItem->setParentViewItem(this);
     }
 
     parentView()->setLayoutBoxItem(this);
@@ -109,7 +109,7 @@
       if (!viewItem)
         continue;
 
-      viewItem->setParent(0);
+      viewItem->setParentViewItem(0);
     }
 
     parentView()->setLayoutBoxItem(0);
@@ -166,7 +166,7 @@
         Q_ASSERT(!rc);
         rc = new LayoutBoxItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         }
         // Add any specialized BoxItem Properties here.
       } else if (xml.name().toString() == "layoutitem") {
--- branches/work/kst/portto4/kst/src/libkstapp/legenditem.cpp #1169928:1169929
@@ -46,7 +46,7 @@
 
   setViewRect(0.0, 0.0, 0.0, 0.0);
   parentView()->scene()->addItem(this);
-  setParent(_plotItem->renderItem());
+  setParentViewItem(_plotItem->renderItem());
 
   QPointF origin = QPointF(_plotItem->plotRect().width() * 0.15, _plotItem->plotRect().height() * 0.15);
   setPos(origin);
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #1169928:1169929
@@ -284,7 +284,7 @@
         Q_ASSERT(!rc);
         rc = new LineItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         }
         // Add any new specialized LineItem Properties here.
       } else {
--- branches/work/kst/portto4/kst/src/libkstapp/pictureitem.cpp #1169928:1169929
@@ -107,7 +107,7 @@
         Q_ASSERT(!rc);
         rc = new PictureItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         }
         // Add any new specialized PictureItem Properties here.
       } else if (xml.name().toString() == "data") {
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #1169928:1169929
@@ -1632,7 +1632,7 @@
     setInSharedAxisBox(true);
     setAllowedGripModes(0);
     setFlags(0);
-    setParent(parent);
+    setParentViewItem(parent);
     setBrush(Qt::transparent);
 
     _sharedBox = parent;
@@ -1642,7 +1642,7 @@
     setInSharedAxisBox(false);
     setAllowedGripModes(Move | Resize | Rotate);
     setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
-    setParent(0);
+    setParentViewItem(0);
     setBrush(Qt::white);
 
     _sharedBox = 0;
@@ -2720,7 +2720,7 @@
     _topLabelDetails->setVisible(_plotMaximizedTopVisible);
     _plotMaximized = false;
     PlotItemManager::self()->removeFocusPlot(this);
-    setParent(_plotMaximizedSourceParent);
+    setParentViewItem(_plotMaximizedSourceParent);
     setPos(_plotMaximizedSourcePosition);
     setViewRect(_plotMaximizedSourceRect);
     setZValue(_plotMaximizedSourceZValue);
@@ -2744,7 +2744,7 @@
     _plotMaximizedSourceParent = parentViewItem();
     _plotMaximizedSourceParentRect = parentView()->sceneRect();
 
-    setParent(0);
+    setParentViewItem(0);
     setPos(0, 0);
     setViewRect(parentView()->sceneRect());
     setZValue(PLOT_MAXIMIZED_ZORDER);
@@ -3579,7 +3579,7 @@
         Q_ASSERT(!rc);
         rc = new PlotItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         }
         QXmlStreamAttributes attrs = xml.attributes();
         QStringRef av;
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #1169928:1169929
@@ -36,7 +36,7 @@
   : ViewItem(parentItem->parentView()), _referencePointMode(false), _highlightPointActive(false), _invertHighlight(false) {
 
   setTypeName(tr("Plot Render"));
-  setParent(parentItem);
+  setParentViewItem(parentItem);
   setHasStaticGeometry(true);
   setAllowedGripModes(0);
   setAllowedGrips(0);
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.cpp #1169928:1169929
@@ -1251,7 +1251,7 @@
         Q_ASSERT(!rc);
         rc = new SharedAxisBoxItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         }
         QXmlStreamAttributes attrs = xml.attributes();
         QStringRef av = attrs.value("sharex");
--- branches/work/kst/portto4/kst/src/libkstapp/svgitem.cpp #1169928:1169929
@@ -100,7 +100,7 @@
         Q_ASSERT(!rc);
         rc = new SvgItem(view);
         if (parent) {
-          rc->setParent(parent);
+          rc->setParentViewItem(parent);
         }
         // Add any new specialized SvgItem Properties here.
       } else if (xml.name().toString() == "data") {
--- branches/work/kst/portto4/kst/src/libkstapp/tabwidget.cpp #1169928:1169929
@@ -61,6 +61,8 @@
   const MimeDataViewItem* m = MimeDataViewItem::downcast(event->mimeData());
   if (m && m->item) {       
     View* view = tabWidget->currentView();
+    m->item->setParentView(view);
+    m->item->setParentViewItem(0);
     view->appendToLayout(CurvePlacement::Auto, m->item);
     event->acceptProposedAction();
   }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1169928:1169929
@@ -43,10 +43,21 @@
 #define DEBUG_REPARENT 0
 #define DEBUG_CHILD_GEOMETRY 0
 
+
+// Don't mix QObject and QGraphicItem ownership
+// Enabling the macro could have bad side effects, we will see.
+// TODO check for memory leaks when enabled.
+#define KST_DISBALE_QOBJECT_PARENT
+
 namespace Kst {
 
-ViewItem::ViewItem(View *parent)
-  : QObject(parent), NamedObject(),
+ViewItem::ViewItem(View *parentView) :
+#ifdef KST_DISBALE_QOBJECT_PARENT
+    QObject(),
+#else
+    QObject(parentView)
+#endif
+    NamedObject(),
     _isXTiedZoom(false),
     _isYTiedZoom(false),
     _gripMode(Move),
@@ -70,18 +81,19 @@
     _allowedGrips(TopLeftGrip | TopRightGrip | BottomRightGrip | BottomLeftGrip |
                   TopMidGrip | RightMidGrip | BottomMidGrip | LeftMidGrip),
     _parentRelativeHeight(0),
-    _parentRelativeWidth(0)
+    _parentRelativeWidth(0),
+    _parentView(parentView)
  {
   _initializeShortName();
   setZValue(DRAWING_ZORDER);
   setAcceptsHoverEvents(true);
   setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
-  connect(parent, SIGNAL(mouseModeChanged(View::MouseMode)),
+  connect(_parentView, SIGNAL(mouseModeChanged(View::MouseMode)),
           this, SLOT(viewMouseModeChanged(View::MouseMode)));
-  connect(parent, SIGNAL(viewModeChanged(View::ViewMode)),
+  connect(_parentView, SIGNAL(viewModeChanged(View::ViewMode)),
           this, SLOT(updateView()));
 
-  connect(this, SIGNAL(geometryChanged()), parent,SLOT(viewChanged()));
+  connect(this, SIGNAL(geometryChanged()), _parentView, SLOT(viewChanged()));
 
   setLayoutMargins(ApplicationSettings::self()->layoutMargins());
   setLayoutSpacing(ApplicationSettings::self()->layoutSpacing());
@@ -396,15 +408,39 @@
 }
 
 View *ViewItem::parentView() const {
+#ifdef KST_DISBALE_QOBJECT_PARENT
+  return _parentView;
+#else
   return qobject_cast<View*>(parent());
+#endif
 }
 
+void ViewItem::setParentView(View* parentView) {
+#ifdef KST_DISBALE_QOBJECT_PARENT
+  _parentView = parentView;  
+#else
+  parentView()->setParent(parent);
+#endif
+  updateRelativeSize();
+}
 
+
 ViewItem *ViewItem::parentViewItem() const {
   return qgraphicsitem_cast<ViewItem*>(parentItem());
 }
 
 
+void ViewItem::setParentViewItem(ViewItem* parent) {
+  setParentItem(parent);
+  updateRelativeSize();
+}
+
+
+void ViewItem::setParent(ViewItem* parent) {
+  setParentViewItem(parent);  
+}
+
+
 ViewItem::GripMode ViewItem::gripMode() const {
   return _gripMode;
 }
@@ -1501,12 +1537,6 @@
 }
 
 
-void ViewItem::setParent(ViewItem* parent) {
-  setParentItem(parent);
-  updateRelativeSize();
-}
-
-
 void ViewItem::updateRelativeSize() {
   if (parentViewItem()) {
     _parentRelativeHeight = (height() / parentViewItem()->height());
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #1169928:1169929
@@ -79,8 +79,11 @@
     const QString typeName() const { return _typeName; }
 
     View *parentView() const;
+    void setParentView(View *parent);
+
     ViewItem *parentViewItem() const;
-    void setParent(ViewItem *parent);
+    void setParentViewItem(ViewItem *parent);
+
     virtual void updateRelativeSize();
     
     qreal relativeHeight() const { return _parentRelativeHeight; }
@@ -314,6 +317,11 @@
 
     QPointF dragStartPosition;
 
+    View *_parentView;
+
+    // use void setParentViewItem(ViewItem *parent);
+    void setParent(ViewItem *parent);    
+
     friend class View;
     friend class Scene;
 };


More information about the Kst mailing list