[Kde-bindings] KDE/kdebindings/qtruby

Caleb Tennis caleb at gentoo.org
Fri Aug 19 20:27:27 UTC 2005


SVN commit 451076 by ctennis:

Add findChild and findChildren methods to Qt::Base (perhaps this isn't the
best place to put them, but it works for now).  They attempt to mimic their
Qt::Object counterparts, which are not available in QtRuby because they are
template functions.

CCMAIL:kde-bindings at kde.org



 M  +8 -0      ChangeLog  
 M             rubylib/qtruby/lib/Qt/qtruby.rb  
 M  +47 -0     rubylib/qtruby/unittests.rb  


--- trunk/KDE/kdebindings/qtruby/ChangeLog #451075:451076
@@ -1,6 +1,14 @@
 2005-08-19  Caleb Tennis <caleb at aei-tech.com>
         * For marshalling ItemLists, prefer using ->at(index) over an iterator
 
+	* Add findChild and findChildren methods which attempt to mimic their Qt::Object
+          counterparts.  Unit tests included.  e.g.:   
+            object.findChildren(Qt::Widget) 
+            object.findChildren(Qt::Object, "ObjectName")
+            object.findChildren(Qt::Object, /SomeName*/)
+
+            findChild just returns the closest child to the parent from findChildren
+
 2005-08-19  Caleb Tennis <caleb at aei-tech.com>
 
         * Added a unittests.rb file as the start of a unit test suite for
--- trunk/KDE/kdebindings/qtruby/rubylib/qtruby/unittests.rb #451075:451076
@@ -49,4 +49,51 @@
     assert w1.children == [ w2, w3 ]
   end
 
+  def test_find_children
+    w = Qt::Widget.new(nil)
+    assert_raise(ArgumentError) { w.findChildren(nil) }
+
+    assert w.findChildren(Qt::Widget) == [ ]
+    w2 = Qt::Widget.new(w)
+
+    assert w.findChildren(Qt::Widget) == [ w2 ]
+    assert w.findChildren(Qt::Object) == [ w2 ]
+    assert w.findChildren(Qt::LineEdit) == [ ]
+    assert w.findChildren(Qt::Widget,"Bob") == [ ]
+    assert w.findChildren(Qt::Object,"Bob") == [ ]
+
+    w2.objectName = "Bob"
+
+    assert w.findChildren(Qt::Widget) == [ w2 ]
+    assert w.findChildren(Qt::Object) == [ w2 ]
+    assert w.findChildren(Qt::Widget,"Bob") == [ w2 ]
+    assert w.findChildren(Qt::Object,"Bob") == [ w2 ]
+    assert w.findChildren(Qt::LineEdit, "Bob") == [ ]
+
+    w3 = Qt::Widget.new(w)
+    w4 = Qt::LineEdit.new(w2)
+    w4.setObjectName("Bob")
+
+    assert w.findChildren(Qt::Widget) == [ w4, w2, w3 ]
+    assert w.findChildren(Qt::LineEdit) == [ w4 ]
+    assert w.findChildren(Qt::Widget,"Bob") == [ w4, w2 ]    
+    assert w.findChildren(Qt::LineEdit,"Bob") == [ w4 ]    
+  end
+
+  def test_find_child
+    w = Qt::Widget.new(nil)
+    assert_raise(ArgumentError) { w.findChild(nil) }
+
+    assert_nil w.findChild(Qt::Widget)
+    w2 = Qt::Widget.new(w)
+
+    w3 = Qt::Widget.new(w)
+    w3.objectName = "Bob"
+    w4 = Qt::LineEdit.new(w2)
+    w4.objectName = "Bob"
+
+    assert w.findChild(Qt::Widget,"Bob") == w3
+    assert w.findChild(Qt::LineEdit,"Bob") == w4
+  end
+
 end



More information about the Kde-bindings mailing list