qt 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be7294fb17e8d0cd4eeb66cc86fe6ee91940a95d5a6f3afaf9dfa44fb54445ba
4
- data.tar.gz: 20683a100daf8ca9299a2227ae2605acbde2393e2444d020625c058cbc76993c
3
+ metadata.gz: 5b47b66563f703c260222b8ac0e38f2bf27e4ee654dd3152181bb8866e93e182
4
+ data.tar.gz: 797218dab7d7ce473510b05bd500c8151503b0ebc018648c5d82a5e5abb7e8f0
5
5
  SHA512:
6
- metadata.gz: 151a6423964153f8e5f54cba0cc7c54d1ff6b4a7fbd10b003d2a19f6263831493d18ed6fbaeabf88d5791d3e3326e356ba50e0d5332e212c75341bf6ea3c2f50
7
- data.tar.gz: 9e7542fc4bc481b7c3110f4b55aa4b33dd327babbe4aaad3dc4078ce2bd404a97a90022f1e49d97bd3ae05cb805e4db8fd0aef13e368974505dc361d29edfdd9
6
+ metadata.gz: 37e94ba0242411ddd9f46d6858f397f53e2d2d62e38ba7ccba9a15fc517f86291b015d82dd359dfe0eb5ce12a011ebeb379d95a23c607c1be299883d5c24ed2a
7
+ data.tar.gz: 5fc3cc069da9615f8efb690d2888f5ec7f5c02422885e070331b4e271381405a082993c705d100c9e30b6ceb5661471701769c81e5ff6ff072024fe34c7b9c15
@@ -65,7 +65,6 @@ module Qt
65
65
  klass = Qt.const_get(normalized_qt_class, false)
66
66
  return nil unless klass.is_a?(Class)
67
67
  return nil unless klass.const_defined?(:QT_CLASS, false)
68
- return nil unless klass <= Qt::QObject
69
68
 
70
69
  klass
71
70
  rescue NameError
@@ -87,6 +86,7 @@ module Qt
87
86
 
88
87
  pointer = wrapper.handle
89
88
  return wrapper if null_pointer?(pointer)
89
+ return wrapper unless qobject_wrapper?(wrapper.class)
90
90
 
91
91
  cached = cached_wrapper_for(pointer)
92
92
  return cached if cached
@@ -157,6 +157,10 @@ module Qt
157
157
  depth
158
158
  end
159
159
 
160
+ def qobject_wrapper?(klass)
161
+ klass.is_a?(Class) && klass <= Qt::QObject
162
+ end
163
+
160
164
  def normalize_expected_qt_class(expected_qt_class)
161
165
  return nil if expected_qt_class.nil?
162
166
 
data/lib/qt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Qt
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
@@ -52,6 +52,7 @@ def map_cpp_arg_type(type_name, qt_class: nil, int_cast_types: nil)
52
52
  return { ffi: :string, cast: :qdate_from_utf8 } if type == 'QDate'
53
53
  return { ffi: :string, cast: :qtime_from_utf8 } if type == 'QTime'
54
54
  return { ffi: :string, cast: :qkeysequence_from_utf8 } if type == 'QKeySequence'
55
+ return { ffi: :int, cast: :qcursor_shape } if type == 'QCursor'
55
56
  return { ffi: :pointer, cast: :qicon_ref } if type == 'QIcon'
56
57
  return { ffi: :string, cast: :qany_string_view } if type == 'QAnyStringView'
57
58
  return { ffi: :string, cast: :qvariant_from_utf8 } if type == 'QVariant'
@@ -95,7 +96,7 @@ def map_pointer_cpp_return_type(type, ast: nil)
95
96
 
96
97
  info = { ffi_return: :pointer }
97
98
  base_type = type.sub(/\s*\*\z/, '').strip
98
- if ast && class_inherits?(ast, base_type, 'QObject')
99
+ if ast && ast_class_index(ast)[:methods_by_class].key?(base_type)
99
100
  info[:pointer_class] = base_type
100
101
  end
101
102
 
@@ -19,6 +19,8 @@ def all_ffi_functions(specs, free_function_specs:)
19
19
  end
20
20
 
21
21
  def append_constructor_ffi_function(fns, spec)
22
+ return if spec[:constructor][:mode] == :wrap_only
23
+
22
24
  ctor_args = constructor_ffi_args(spec)
23
25
  fns << { name: ctor_function_name(spec), ffi_return: :pointer, args: ctor_args }
24
26
  end
@@ -160,7 +160,7 @@ def related_value_class_candidate?(ast, qt_class, all_classes, template_classes)
160
160
  return false if abstract_class?(ast, qt_class)
161
161
  return false if class_inherits?(ast, qt_class, 'QObject')
162
162
 
163
- constructor_usable_for_codegen?(ast, qt_class)
163
+ true
164
164
  end
165
165
 
166
166
  def related_qt_type_names(ast, qt_class)
@@ -178,11 +178,12 @@ end
178
178
 
179
179
  def append_related_qt_types_from_decl(out, parsed, method_name)
180
180
  candidates = []
181
- candidates << normalized_cpp_type_name(parsed[:return_type]).to_s if parsed[:return_type]
182
- parsed[:params].each { |param| candidates << normalized_cpp_type_name(param[:type]).to_s }
183
- candidates.each do |candidate|
181
+ candidates << [related_qt_type_name(parsed[:return_type]), parsed[:return_type].to_s] if parsed[:return_type]
182
+ parsed[:params].each { |param| candidates << [related_qt_type_name(param[:type]), param[:type].to_s] }
183
+ candidates.each do |candidate, raw_type|
184
184
  next if candidate.empty? || !candidate.start_with?('Q')
185
- next unless related_type_name_matches_method?(candidate, method_name)
185
+ next unless related_type_name_matches_method?(candidate, method_name) ||
186
+ (qt_pointer_type?(raw_type) && candidate.end_with?('Item'))
186
187
 
187
188
  out << candidate
188
189
  end
@@ -195,6 +196,14 @@ def related_type_name_matches_method?(qt_type, method_name)
195
196
  method_name.to_s.downcase.include?(token)
196
197
  end
197
198
 
199
+ def qt_pointer_type?(raw_type)
200
+ raw_type.to_s.strip.end_with?('*')
201
+ end
202
+
203
+ def related_qt_type_name(raw_type)
204
+ normalized_cpp_type_name(raw_type).to_s.delete_suffix('*')
205
+ end
206
+
198
207
  def discover_target_qt_classes(ast, scope)
199
208
  all_classes = q_class_names(ast)
200
209
  template_classes = template_qt_classes(ast)
@@ -220,9 +229,24 @@ def widget_target_qt_class?(ast, qt_class)
220
229
 
221
230
  class_inherits?(ast, qt_class, 'QWidget') ||
222
231
  class_inherits?(ast, qt_class, 'QLayout') ||
232
+ widget_item_target_qt_class?(ast, qt_class) ||
223
233
  qt_class == 'QTableWidgetItem'
224
234
  end
225
235
 
236
+ def widget_item_target_qt_class?(ast, qt_class)
237
+ return false unless qt_class.end_with?('Item')
238
+ return false if class_inherits?(ast, qt_class, 'QObject')
239
+
240
+ collect_constructor_decls(ast, qt_class).any? do |decl|
241
+ parsed = parse_method_signature(decl)
242
+ next false unless parsed
243
+
244
+ parsed[:params].any? do |param|
245
+ normalized_cpp_type_name(param[:type]).to_s.match?(/\AQ\w*Widget\*\z/)
246
+ end
247
+ end
248
+ end
249
+
226
250
  def qobject_target_qt_class?(ast, qt_class)
227
251
  return false if qt_class.end_with?('Private')
228
252
  return false if qt_class == 'QApplication'
@@ -264,8 +288,10 @@ def build_base_spec_for_qt_class(ast, qt_class)
264
288
  parent_constructor_for_type(parent_type, widget_child)
265
289
  elsif string_path_cast
266
290
  string_path_constructor(string_path_cast)
267
- else
291
+ elsif ctor_decls.any? { |decl| constructor_supports_no_args?(decl) }
268
292
  { parent: false }
293
+ else
294
+ { parent: false, mode: :wrap_only }
269
295
  end
270
296
  base_spec_hash(qt_class, parent_ctor)
271
297
  end
@@ -246,6 +246,7 @@ def arg_expr(arg)
246
246
  when :qdate_from_utf8 then "qdate_from_bridge_value(#{arg[:name]})"
247
247
  when :qtime_from_utf8 then "qtime_from_bridge_value(#{arg[:name]})"
248
248
  when :qkeysequence_from_utf8 then "QKeySequence(as_qstring(#{arg[:name]}))"
249
+ when :qcursor_shape then "QCursor(static_cast<Qt::CursorShape>(#{arg[:name]}))"
249
250
  when :qicon_ref then "*static_cast<QIcon*>(#{arg[:name]})"
250
251
  when :qany_string_view then "QAnyStringView(as_qstring(#{arg[:name]}))"
251
252
  when :qvariant_from_utf8 then "qvariant_from_bridge_value(#{arg[:name]})"
@@ -385,8 +386,10 @@ def generate_cpp_bridge(specs, free_function_specs)
385
386
  end
386
387
 
387
388
  def append_cpp_spec_methods(lines, spec)
388
- generate_cpp_constructor(lines, spec)
389
- lines << ''
389
+ unless spec[:constructor][:mode] == :wrap_only
390
+ generate_cpp_constructor(lines, spec)
391
+ lines << ''
392
+ end
390
393
  spec[:methods].each do |method|
391
394
  generate_cpp_method(lines, spec, method)
392
395
  lines << ''
@@ -717,6 +720,8 @@ def setter_alias_base_name(method)
717
720
  return nil unless method[:args].length == 1
718
721
  return nil if method[:property]
719
722
 
723
+ return 'cursor' if method[:qt_name] == 'setCursor'
724
+
720
725
  property_name_from_setter(method[:qt_name] || method[:ruby_name].to_s)
721
726
  end
722
727
 
@@ -747,7 +752,10 @@ def qapplication_singleton_forwarder_names(methods, singleton_setter_aliases)
747
752
  end
748
753
 
749
754
  def append_widget_initializer(lines, spec:, widget_root:, indent:)
750
- if spec[:constructor][:mode] == :string_path
755
+ if spec[:constructor][:mode] == :wrap_only
756
+ append_wrap_only_initializer(lines, spec, indent)
757
+ return
758
+ elsif spec[:constructor][:mode] == :string_path
751
759
  append_string_path_initializer(lines, spec, indent)
752
760
  elsif spec[:constructor][:mode] == :keysequence_parent
753
761
  append_keysequence_parent_initializer(lines, spec, widget_root, indent)
@@ -761,6 +769,12 @@ def append_widget_initializer(lines, spec:, widget_root:, indent:)
761
769
  lines << "#{indent}end"
762
770
  end
763
771
 
772
+ def append_wrap_only_initializer(lines, spec, indent)
773
+ lines << "#{indent}def initialize(*)"
774
+ lines << "#{indent} raise NotImplementedError, '#{spec[:ruby_class]} cannot be directly instantiated yet'"
775
+ lines << "#{indent}end"
776
+ end
777
+
764
778
  def append_parent_widget_initializer(lines, spec, widget_root, indent)
765
779
  lines << "#{indent}def initialize(parent = nil)"
766
780
  lines << "#{indent} @handle = Native.#{spec[:prefix]}_new(parent&.handle)"
@@ -1049,6 +1063,7 @@ def collect_enum_constants_for_scope(ast, target_scope, warnings = [])
1049
1063
  next unless node['kind'] == 'EnumDecl'
1050
1064
  next unless scope == target_scope
1051
1065
 
1066
+ next_value = 0
1052
1067
  Array(node['inner']).each do |entry|
1053
1068
  next unless entry['kind'] == 'EnumConstantDecl'
1054
1069
 
@@ -1058,9 +1073,14 @@ def collect_enum_constants_for_scope(ast, target_scope, warnings = [])
1058
1073
 
1059
1074
  raw_value = ast_extract_first_value(entry)
1060
1075
  value = parse_ast_integer_value(raw_value)
1061
- next if value.nil?
1076
+ if value.nil?
1077
+ value = next_value
1078
+ else
1079
+ next_value = value
1080
+ end
1062
1081
 
1063
1082
  append_constant_with_conflict_warning(constants, name, value, warnings, target_scope.join('::'))
1083
+ next_value = value + 1
1064
1084
  end
1065
1085
  end
1066
1086
 
@@ -1075,6 +1095,9 @@ def collect_qt_namespace_enum_constants(ast, warnings = [])
1075
1095
 
1076
1096
  append_constant_with_conflict_warning(constants, alias_name, value, warnings, 'Qt::QEventAlias')
1077
1097
  end
1098
+ collect_enum_constants_for_scope(ast, ['QCursor'], warnings).each do |name, value|
1099
+ append_constant_with_conflict_warning(constants, name, value, warnings, 'Qt::QCursorAlias')
1100
+ end
1078
1101
  constants
1079
1102
  end
1080
1103
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maksim Veynberg
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubygems_version: 3.6.7
103
+ rubygems_version: 4.0.9
104
104
  specification_version: 4
105
105
  summary: Ruby bindings for Qt 6.4.2+
106
106
  test_files: []