[Kst] branches/work/kst/1.6/kst/src

Andrew Walker arwalker at sumusltd.com
Sat Nov 24 03:04:29 CET 2007


SVN commit 740749 by arwalker:

add ability to delete objects from within javaScript

 M  +0 -1      extensions/js/README  
 M  +41 -0     extensions/js/bind_viewobject.cpp  
 M  +11 -4     extensions/js/bind_viewobject.h  
 M  +30 -1     libkstapp/kstviewobject.cpp  
 M  +1 -0      libkstapp/kstviewobject.h  


--- branches/work/kst/1.6/kst/src/extensions/js/README #740748:740749
@@ -90,5 +90,4 @@
 
 1.2.0 issues:
 - Curves are stale in concept - split them?
-- "delete" support - in order drop references?
 - Make .position and .size directly manipulated?
--- branches/work/kst/1.6/kst/src/extensions/js/bind_viewobject.cpp #740748:740749
@@ -77,6 +77,7 @@
   { "lowerToBottom", &KstBindViewObject::lowerToBottom },
   { "raise", &KstBindViewObject::raise },
   { "lower", &KstBindViewObject::lower },
+  { "remove", &KstBindViewObject::remove },
   { 0L, 0L }
 };
 
@@ -638,6 +639,46 @@
 }
 
 
+KJS::Value KstBindViewObject::remove(KJS::ExecState *exec, const KJS::List& args) {
+  if (args.size() != 0) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires no arguments.");
+    exec->setException(eobj);
+    return KJS::Null();
+  }
+
+  {
+    KstViewObjectPtr d = makeViewObject(_d);
+    KstTopLevelViewPtr tlvTest =  kst_cast<KstTopLevelView>(_d);
+
+    if (tlvTest) {
+      KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError, "Unable to delete the view.");
+      exec->setException(eobj);
+      return KJS::Null();
+    }
+
+    KstViewObjectPtr vo;
+
+    if (d) {
+      KstReadLocker rl(d);
+
+      vo = d->topLevelParent();
+      d->remove();
+    }
+
+    if (vo) {
+      KstTopLevelViewPtr tlv =  kst_cast<KstTopLevelView>(vo);
+      if (tlv) {
+        tlv->paint(KstPainter::P_PAINT);
+      }
+    }
+  }
+
+  delete this;
+
+  return KJS::Undefined();
+}
+
+
 KJS::Value KstBindViewObject::findChild(KJS::ExecState *exec, const KJS::List& args) {
   if (args.size() != 1) {
     KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly one argument.");
--- branches/work/kst/1.6/kst/src/extensions/js/bind_viewobject.h #740748:740749
@@ -80,33 +80,40 @@
     KJS::Value convertTo(KJS::ExecState *exec, const KJS::List& args);
 
     /* @method raiseToTop
-       @returns ViewObject
+       @returns
        @arg
        @description Raises the object to the top of the z-order.
     */
     KJS::Value raiseToTop(KJS::ExecState *exec, const KJS::List& args);
 
     /* @method lowerToBottom
-       @returns ViewObject
+       @returns
        @arg
        @description Lowers the object to the bottom of the z-order.
     */
     KJS::Value lowerToBottom(KJS::ExecState *exec, const KJS::List& args);
 
     /* @method raise
-       @returns ViewObject
+       @returns
        @arg
        @description Raises the object one place in the z-order.
     */
     KJS::Value raise(KJS::ExecState *exec, const KJS::List& args);
 
     /* @method lower
-       @returns ViewObject
+       @returns
        @arg
        @description Lowers the object one place in the z-order.
     */
     KJS::Value lower(KJS::ExecState *exec, const KJS::List& args);
 
+    /* @method remove
+       @returns
+       @arg
+       @description Deletes the object.
+    */
+    KJS::Value remove(KJS::ExecState *exec, const KJS::List& args);
+
     /* @property Point position
        @description The location of the object relative to its parent.
     */
--- branches/work/kst/1.6/kst/src/libkstapp/kstviewobject.cpp #740748:740749
@@ -640,7 +640,7 @@
       KST::alignment.setPosition((*i)->geometry(), plotRegion);
     }
   }
-  
+
   plotRegion = x;
 }
 
@@ -1460,6 +1460,35 @@
 }
 
 
+void KstViewObject::remove() {
+  KstApp::inst()->document()->setModified();
+  KstViewObjectPtr vop(this);
+  KstViewObjectPtr tlp = topLevelParent();
+
+  if (tlp) {
+    KstTopLevelViewPtr tlv = kst_cast<KstTopLevelView>(tlp);
+
+    if (tlv && vop == tlv->pressTarget()) {
+      tlv->clearPressTarget();
+    }
+
+    if (this->_parent) {
+      this->_parent->invalidateClipRegion();
+    }
+
+    tlp->removeChild(this, true);
+    tlp = 0L;
+  }
+
+  while (!_children.isEmpty()) {
+    removeChild(_children.first());
+  }
+
+  vop = 0L; // basically "delete this;"
+  QTimer::singleShot(0, KstApp::inst(), SLOT(updateDialogs()));
+}
+
+
 void KstViewObject::moveTo(int id) {
   QString windowName = _moveToMap[id];
 
--- branches/work/kst/1.6/kst/src/libkstapp/kstviewobject.h #740748:740749
@@ -276,6 +276,7 @@
     virtual void lowerToBottom();
     virtual void raise();
     virtual void lower();
+    virtual void remove();
 
   protected slots:
     virtual void parentResized();


More information about the Kst mailing list