Module: Qt::Internal
- Defined in:
- lib/Qt/qtruby4.rb,
lib/Qt/qtruby4.rb,
ext/ruby/qtruby/src/lib/Qt/qtruby4.rb,
ext/ruby/qtruby/src/lib/Qt/qtruby4.rb
Defined Under Namespace
Classes: ModuleIndex
Constant Summary collapse
- AccessPrivate =
From the enum MethodFlags in qt-copy/src/tools/moc/generator.cpp
0x00
- AccessProtected =
0x01
- AccessPublic =
0x02
- MethodMethod =
0x00
- MethodSignal =
0x04
- MethodSlot =
0x08
- MethodCompatibility =
0x10
- MethodCloned =
0x20
- MethodScriptable =
0x40
- @@classes =
{}
- @@cpp_names =
{}
- @@idclass =
[]
- @@normalize_procs =
[]
Class Method Summary collapse
- .add_normalize_proc(func) ⇒ Object
- .checkarg(argtype, typename) ⇒ Object
- .classes ⇒ Object
-
.connect(src, signal, target, block) ⇒ Object
Handles calls of the form: connect(myobj, SIGNAL(‘mysig(int)’), mytarget) {|arg(s)| …} connect(myobj, SIGNAL(‘mysig(int)’)) {|arg(s)| …} connect(myobj, SIGNAL(:mysig), mytarget) { …} connect(myobj, SIGNAL(:mysig)) { …}.
- .cpp_names ⇒ Object
- .create_qenum(num, enum_type) ⇒ Object
- .debug_level ⇒ Object
- .do_method_missing(package, method, klass, this, *args) ⇒ Object
- .find_class(classname) ⇒ Object
- .get_qboolean(b) ⇒ Object
- .get_qenum_type(e) ⇒ Object
- .get_qinteger(num) ⇒ Object
- .getAllParents(class_id, res) ⇒ Object
- .getMetaObject(klass, qobject) ⇒ Object
- .idclass ⇒ Object
- .init_all_classes ⇒ Object
- .init_class(c) ⇒ Object
- .makeMetaData(classname, classinfos, dbus, signals, slots) ⇒ Object
-
.method_connect(src, signal, target, method) ⇒ Object
Handles calls of the form: connect(:mysig, mytarget, :mymethod)) connect(SIGNAL(‘mysignal(int)’), mytarget, :mymethod)).
- .normalize_classname(classname) ⇒ Object
-
.run_initializer_block(instance, block) ⇒ Object
run that now.
- .set_qboolean(b, val) ⇒ Object
- .set_qinteger(num, val) ⇒ Object
-
.signal_connect(src, signal, block) ⇒ Object
Handles calls of the form: connect(SIGNAL(:mysig)) { …} connect(SIGNAL(‘mysig(int)’)) {|arg(s)| …}.
-
.single_shot_timer_connect(interval, target, block) ⇒ Object
Handles calls of the form: Qt::Timer.singleShot(500, myobj) { …}.
-
.string_table_handler(data, pack_str) ⇒ Object
Keeps a hash of strings against their corresponding offsets within the qt_meta_stringdata sequence of null terminated strings.
-
.try_initialize(instance, *args) ⇒ Object
Runs the initializer as far as allocating the Qt C++ instance.
Class Method Details
.add_normalize_proc(func) ⇒ Object
2496 2497 2498 |
# File 'lib/Qt/qtruby4.rb', line 2496 def self.add_normalize_proc(func) @@normalize_procs << func end |
.checkarg(argtype, typename) ⇒ Object
2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 |
# File 'lib/Qt/qtruby4.rb', line 2535 def Internal.checkarg(argtype, typename) puts " #{typename} (#{argtype})" if debug_level >= DebugLevel::High const_point = typename =~ /^const\s+/ ? -1 : 0 if argtype == 'i' if typename =~ /^int&?$|^signed int&?$|^signed$|^qint32&?$/ return 6 + const_point elsif typename =~ /^quint32&?$/ return 4 + const_point elsif typename =~ /^(?:short|ushort|unsigned short int|unsigned short|uchar||unsigned char|uint|long|ulong|unsigned long int|unsigned|float|double|WId|HBITMAP__\*|HDC__\*|HFONT__\*|HICON__\*|HINSTANCE__\*|HPALETTE__\*|HRGN__\*|HWND__\*|Q_PID|^quint16&?$|^qint16&?$)$/ return 4 + const_point elsif typename =~ /^(quint|qint|qulong|qlong|qreal)/ return 4 + const_point else t = typename.sub(/^const\s+/, '') t.sub!(/[&*]$/, '') if isEnum(t) return 2 end end elsif argtype == 'n' if typename =~ /^double$|^qreal$/ return 6 + const_point elsif typename =~ /^float$/ return 4 + const_point elsif typename =~ /^int&?$/ return 2 + const_point elsif typename =~ /^(?:short|ushort|uint|long|ulong|signed|unsigned|float|double)$/ return 2 + const_point else t = typename.sub(/^const\s+/, '') t.sub!(/[&*]$/, '') if isEnum(t) return 2 + const_point end end elsif argtype == 'B' if typename =~ /^(?:bool)[*&]?$/ return 2 + const_point end elsif argtype == 's' if typename =~ /^(const )?((QChar)[*&]?)$/ return 6 + const_point elsif typename =~ /^(?:(u(nsigned )?)?char\*)$/ return 4 + const_point elsif typename =~ /^(?:const (u(nsigned )?)?char\*)$/ return 2 + const_point elsif typename =~ /^(?:(?:const )?(QString)[*&]?)$/ return 8 + const_point end elsif argtype == 'a' # FIXME: shouldn't be hardcoded. Installed handlers should tell what ruby type they expect. if typename =~ /^(?: const\ QCOORD\*| (?:const\ )? (?: QStringList[\*&]?| QValueList<int>[\*&]?| QRgb\*| char\*\* ) )$/x return 2 + const_point end elsif argtype == 'u' # Give nil matched against string types a higher score than anything else if typename =~ /^(?:u?char\*|const u?char\*|(?:const )?((Q(C?)String))[*&]?)$/ return 4 + const_point # Numerics will give a runtime conversion error, so they fail the match elsif typename =~ /^(?:short|ushort|uint|long|ulong|signed|unsigned|int)$/ return -99 else return 2 + const_point end elsif argtype == 'U' if typename =~ /QStringList/ return 4 + const_point else return 2 + const_point end else t = typename.sub(/^const\s+/, '') t.sub!(/(::)?Ptr$/, '') t.sub!(/[&*]$/, '') if argtype == t return 4 + const_point elsif classIsa(argtype, t) return 2 + const_point elsif isEnum(argtype) and (t =~ /int|qint32|uint|quint32|long|ulong/ or isEnum(t)) return 2 + const_point end end return -99 end |
.classes ⇒ Object
2484 2485 2486 |
# File 'lib/Qt/qtruby4.rb', line 2484 def self.classes return @@classes end |
.connect(src, signal, target, block) ⇒ Object
Handles calls of the form: connect(myobj, SIGNAL(‘mysig(int)’), mytarget) {|arg(s)| …} connect(myobj, SIGNAL(‘mysig(int)’)) {|arg(s)| …} connect(myobj, SIGNAL(:mysig), mytarget) { …} connect(myobj, SIGNAL(:mysig)) { …}
2926 2927 2928 2929 2930 2931 2932 2933 |
# File 'lib/Qt/qtruby4.rb', line 2926 def Internal.connect(src, signal, target, block) args = (signal =~ /\((.*)\)/) ? $1 : "" signature = Qt::MetaObject.normalizedSignature("invoke(%s)" % args).to_s return Qt::Object.connect( src, signal, Qt::BlockInvocation.new(target, block.to_proc, signature), SLOT(signature) ) end |
.cpp_names ⇒ Object
2488 2489 2490 |
# File 'lib/Qt/qtruby4.rb', line 2488 def self.cpp_names return @@cpp_names end |
.create_qenum(num, enum_type) ⇒ Object
2796 2797 2798 |
# File 'lib/Qt/qtruby4.rb', line 2796 def Internal.create_qenum(num, enum_type) return Qt::Enum.new(num, enum_type) end |
.debug_level ⇒ Object
2531 2532 2533 |
# File 'lib/Qt/qtruby4.rb', line 2531 def Internal.debug_level Qt.debug_level end |
.do_method_missing(package, method, klass, this, *args) ⇒ Object
2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 |
# File 'lib/Qt/qtruby4.rb', line 2658 def Internal.do_method_missing(package, method, klass, this, *args) if klass.class == Module classname = klass.name else classname = @@cpp_names[klass.name] if classname.nil? if klass != Object and klass != Qt return do_method_missing(package, method, klass.superclass, this, *args) else return nil end end end if method == "new" method = classname.dup method.gsub!(/^.*::/,"") end method = "operator" + method.sub("@","") if method !~ /[a-zA-Z]+/ # Change foobar= to setFoobar() method = 'set' + method[0,1].upcase + method[1,method.length].sub("=", "") if method =~ /.*[^-+%\/|=]=$/ && method != 'operator=' methods = [] methods << method.dup args.each do |arg| if arg.nil? # For each nil arg encountered, triple the number of munged method # templates, in order to cover all possible types that can match nil temp = [] methods.collect! do |meth| temp << meth + '?' temp << meth + '#' meth << '$' end methods.concat(temp) elsif isObject(arg) methods.collect! { |meth| meth << '#' } elsif arg.kind_of? Array or arg.kind_of? Hash methods.collect! { |meth| meth << '?' } else methods.collect! { |meth| meth << '$' } end end methodIds = [] methods.collect { |meth| methodIds.concat( findMethod(classname, meth) ) } if method =~ /._./ && methodIds.length == 0 # If the method name contains underscores, convert to camel case # form and try again method.gsub!(/(.)_(.)/) {$1 + $2.upcase} return do_method_missing(package, method, klass, this, *args) end if debug_level >= DebugLevel::High puts "classname == #{classname}" puts ":: method == #{method}" puts "-> methodIds == #{methodIds.inspect}" puts "candidate list:" prototypes = dumpCandidates(methodIds).split("\n") line_len = (prototypes.collect { |p| p.length }).max prototypes.zip(methodIds) { |prototype,id| puts "#{prototype.ljust line_len} (smoke: #{id.smoke} index: #{id.index})" } end chosen = nil if methodIds.length > 0 best_match = -1 methodIds.each do |id| puts "matching => smoke: #{id.smoke} index: #{id.index}" if debug_level >= DebugLevel::High current_match = (isConstMethod(id) ? 1 : 0) (0...args.length).each do |i| current_match += checkarg(get_value_type(args[i]), get_arg_type_name(id, i)) end # Note that if current_match > best_match, then chosen must be nil if current_match > best_match best_match = current_match chosen = id # Multiple matches are an error; the equality test below _cannot_ be commented out. # If ambiguous matches occur the problem must be fixed be adjusting the relative # ranking of the arg types involved in checkarg(). elsif current_match == best_match puts "multiple methods matching, this is an error" if debug_level >= DebugLevel::Minimal chosen = nil end puts "match => #{id.index} score: #{current_match}" if debug_level >= DebugLevel::High end puts "Resolved to id: #{chosen.index}" if !chosen.nil? && debug_level >= DebugLevel::High end if debug_level >= DebugLevel::Minimal && chosen.nil? && method !~ /^operator/ id = find_pclassid(normalize_classname(klass.name)) hash = findAllMethods(id) constructor_names = nil if method == classname puts "No matching constructor found, possibles:\n" constructor_names = hash.keys.grep(/^#{classname}/) else puts "Possible prototypes:" constructor_names = hash.keys end method_ids = hash.values_at(*constructor_names).flatten puts dumpCandidates(method_ids) else puts "setCurrentMethod(smokeList index: #{chosen.smoke}, meth index: #{chosen.index})" if debug_level >= DebugLevel::High end setCurrentMethod(chosen) if chosen return nil end |
.find_class(classname) ⇒ Object
2630 2631 2632 |
# File 'lib/Qt/qtruby4.rb', line 2630 def Internal.find_class(classname) @@classes[classname] end |
.get_qboolean(b) ⇒ Object
2804 2805 2806 |
# File 'lib/Qt/qtruby4.rb', line 2804 def Internal.get_qboolean(b) return b.value end |
.get_qenum_type(e) ⇒ Object
2800 2801 2802 |
# File 'lib/Qt/qtruby4.rb', line 2800 def Internal.get_qenum_type(e) return e.type end |
.get_qinteger(num) ⇒ Object
2788 2789 2790 |
# File 'lib/Qt/qtruby4.rb', line 2788 def Internal.get_qinteger(num) return num.value end |
.getAllParents(class_id, res) ⇒ Object
2812 2813 2814 2815 2816 2817 2818 |
# File 'lib/Qt/qtruby4.rb', line 2812 def Internal.getAllParents(class_id, res) getIsa(class_id).each do |s| c = findClass(s) res << c getAllParents(c, res) end end |
.getMetaObject(klass, qobject) ⇒ Object
2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 |
# File 'lib/Qt/qtruby4.rb', line 2893 def Internal.getMetaObject(klass, qobject) if klass.nil? klass = qobject.class end parentMeta = nil if @@cpp_names[klass.superclass.name].nil? parentMeta = getMetaObject(klass.superclass, qobject) end = Meta[klass.name] if .nil? = Qt::MetaInfo.new(klass) end if ..nil? or .changed stringdata, data = makeMetaData( qobject.class.name, .classinfos, .dbus, .signals, .slots ) . = (qobject, parentMeta, stringdata, data) .changed = false end . end |
.idclass ⇒ Object
2492 2493 2494 |
# File 'lib/Qt/qtruby4.rb', line 2492 def self.idclass return @@idclass end |
.init_all_classes ⇒ Object
2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 |
# File 'lib/Qt/qtruby4.rb', line 2773 def Internal.init_all_classes() Qt::Internal::getClassList().each do |c| if c == "Qt" # Don't change Qt to Qt::t, just leave as is @@cpp_names["Qt"] = c elsif c != "QInternal" && !c.empty? Qt::Internal::init_class(c) end end @@classes['Qt::Integer'] = Qt::Integer @@classes['Qt::Boolean'] = Qt::Boolean @@classes['Qt::Enum'] = Qt::Enum end |
.init_class(c) ⇒ Object
2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 |
# File 'lib/Qt/qtruby4.rb', line 2517 def Internal.init_class(c) if c == "WebCore" || c == "std" || c == "QGlobalSpace" return end classname = Qt::Internal::normalize_classname(c) classId = Qt::Internal.findClass(c) insert_pclassid(classname, classId) @@idclass[classId.index] = classname @@cpp_names[classname] = c klass = isQObject(c) ? create_qobject_class(classname, Qt) \ : create_qt_class(classname, Qt) @@classes[classname] = klass unless klass.nil? end |
.makeMetaData(classname, classinfos, dbus, signals, slots) ⇒ Object
2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 |
# File 'lib/Qt/qtruby4.rb', line 2840 def Internal.makeMetaData(classname, classinfos, dbus, signals, slots) # Each entry in 'stringdata' corresponds to a string in the # qt_meta_stringdata_<classname> structure. # 'pack_string' is used to convert 'stringdata' into the # binary sequence of null terminated strings for the metaObject stringdata = [] pack_string = "" string_table = string_table_handler(stringdata, pack_string) # This is used to create the array of uints that make up the # qt_meta_data_<classname> structure in the metaObject data = [1, # revision string_table.call(classname), # classname classinfos.length, classinfos.length > 0 ? 10 : 0, # classinfo signals.length + slots.length, 10 + (2*classinfos.length), # methods 0, 0, # properties 0, 0] # enums/sets classinfos.each do |entry| data.push string_table.call(entry[0]) # key data.push string_table.call(entry[1]) # value end signals.each do |entry| data.push string_table.call(entry.full_name) # signature data.push string_table.call(entry.full_name.delete("^,")) # parameters data.push string_table.call(entry.reply_type) # type, "" means void data.push string_table.call("") # tag if dbus data.push MethodScriptable | MethodSignal | AccessPublic else data.push entry.access # flags, always protected for now end end slots.each do |entry| data.push string_table.call(entry.full_name) # signature data.push string_table.call(entry.full_name.delete("^,")) # parameters data.push string_table.call(entry.reply_type) # type, "" means void data.push string_table.call("") # tag if dbus data.push MethodScriptable | MethodSlot | AccessPublic # flags, always public for now else data.push entry.access # flags, always public for now end end data.push 0 # eod return [stringdata.pack(pack_string), data] end |
.method_connect(src, signal, target, method) ⇒ Object
Handles calls of the form: connect(:mysig, mytarget, :mymethod)) connect(SIGNAL(‘mysignal(int)’), mytarget, :mymethod))
2950 2951 2952 2953 2954 2955 2956 2957 2958 |
# File 'lib/Qt/qtruby4.rb', line 2950 def Internal.method_connect(src, signal, target, method) signal = SIGNAL(signal) if signal.is_a?Symbol args = (signal =~ /\((.*)\)/) ? $1 : "" signature = Qt::MetaObject.normalizedSignature("invoke(%s)" % args).to_s return Qt::Object.connect( src, signal, Qt::MethodInvocation.new(target, method, signature), SLOT(signature) ) end |
.normalize_classname(classname) ⇒ Object
2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 |
# File 'lib/Qt/qtruby4.rb', line 2500 def Internal.normalize_classname(classname) @@normalize_procs.each do |func| ret = func.call(classname) if !ret.nil? return ret end end if classname =~ /^Q3/ ruby_classname = classname.sub(/^Q3(?=[A-Z])/,'Qt3::') elsif classname =~ /^Q/ ruby_classname = classname.sub(/^Q(?=[A-Z])/,'Qt::') else ruby_classname = classname end ruby_classname end |
.run_initializer_block(instance, block) ⇒ Object
run that now. Either run the context of the new instance if no args were passed to the block. Or otherwise, run the block in the context of the arg.
2648 2649 2650 2651 2652 2653 2654 2655 2656 |
# File 'lib/Qt/qtruby4.rb', line 2648 def Internal.run_initializer_block(instance, block) if block.arity == -1 || block.arity == 0 instance.instance_eval(&block) elsif block.arity == 1 block.call(instance) else raise ArgumentError, "Wrong number of arguments to block(#{block.arity} for 1)" end end |
.set_qboolean(b, val) ⇒ Object
2808 2809 2810 |
# File 'lib/Qt/qtruby4.rb', line 2808 def Internal.set_qboolean(b, val) return b.value = val end |
.set_qinteger(num, val) ⇒ Object
2792 2793 2794 |
# File 'lib/Qt/qtruby4.rb', line 2792 def Internal.set_qinteger(num, val) return num.value = val end |
.signal_connect(src, signal, block) ⇒ Object
Handles calls of the form: connect(SIGNAL(:mysig)) { …} connect(SIGNAL(‘mysig(int)’)) {|arg(s)| …}
2938 2939 2940 2941 2942 2943 2944 2945 |
# File 'lib/Qt/qtruby4.rb', line 2938 def Internal.signal_connect(src, signal, block) args = (signal =~ /\((.*)\)/) ? $1 : "" signature = Qt::MetaObject.normalizedSignature("invoke(%s)" % args).to_s return Qt::Object.connect( src, signal, Qt::SignalBlockInvocation.new(src, block.to_proc, signature), SLOT(signature) ) end |
.single_shot_timer_connect(interval, target, block) ⇒ Object
Handles calls of the form: Qt::Timer.singleShot(500, myobj) { …}
2962 2963 2964 2965 2966 |
# File 'lib/Qt/qtruby4.rb', line 2962 def Internal.single_shot_timer_connect(interval, target, block) return Qt::Timer.singleShot( interval, Qt::BlockInvocation.new(target, block, "invoke()"), SLOT("invoke()") ) end |
.string_table_handler(data, pack_str) ⇒ Object
Keeps a hash of strings against their corresponding offsets within the qt_meta_stringdata sequence of null terminated strings. Returns a proc to get an offset given a string. That proc also adds new strings to the ‘data’ array, and updates the corresponding ‘pack_str’ Array#pack template.
2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 |
# File 'lib/Qt/qtruby4.rb', line 2825 def Internal.string_table_handler(data, pack_str) hsh = {} offset = 0 return lambda do |str| if !hsh.has_key? str hsh[str] = offset data << str pack_str << "a*x" offset += str.length + 1 end return hsh[str] end end |
.try_initialize(instance, *args) ⇒ Object
Runs the initializer as far as allocating the Qt C++ instance. Then use a throw to jump back to here with the C++ instance wrapped in a new ruby variable of type T_DATA
2637 2638 2639 2640 2641 2642 |
# File 'lib/Qt/qtruby4.rb', line 2637 def Internal.try_initialize(instance, *args) initializer = instance.method(:initialize) catch :newqt do initializer.call(*args) end end |