qtext 0.6.0 → 0.6.2
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.
- data/History.txt +3 -0
- data/Manifest.txt +1 -0
- data/lib/qtext/action_builder.rb +14 -3
- data/lib/qtext/extensions.rb +52 -0
- data/lib/qtext/hash_collector.rb +120 -0
- data/lib/qtext/object_table_model.rb +41 -2
- data/lib/qtext/version.rb +1 -1
- data/test/test_hash_collector.rb +180 -0
- data/test/test_model_index_extensions.rb +111 -0
- data/test/test_object_table.rb +24 -9
- metadata +7 -4
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/lib/qtext/action_builder.rb
CHANGED
@@ -89,9 +89,13 @@ module ActionBuilder
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
def group_names
|
93
|
+
@group_names ||= []
|
94
|
+
end
|
95
|
+
|
92
96
|
# Create a new separator and add a new separator.
|
93
97
|
def separator
|
94
|
-
Qt::Action.
|
98
|
+
Qt::Action.new( parent ) do |action|
|
95
99
|
action.separator = true
|
96
100
|
add_action action
|
97
101
|
collect_actions << action
|
@@ -103,15 +107,22 @@ module ActionBuilder
|
|
103
107
|
# A method called "#{group_name}_actions" will be added to self, which will return the
|
104
108
|
# set of Qt::Action instances created in the block.
|
105
109
|
def list( group_name, &block )
|
110
|
+
@group_name = group_name
|
111
|
+
group_names << group_name
|
106
112
|
unless respond_to?( "#{group_name.to_s}_actions" )
|
107
113
|
self.class.send( :define_method, "#{group_name.to_s}_actions" ) do
|
108
114
|
eval "@#{group_name.to_s}_actions"
|
109
115
|
end
|
110
116
|
end
|
111
|
-
self.collect_actions
|
117
|
+
self.collect_actions = []
|
118
|
+
|
112
119
|
yield( self )
|
113
120
|
# copy actions to the right instance variable
|
114
121
|
eval "@#{group_name.to_s}_actions = collect_actions"
|
122
|
+
|
123
|
+
# reset these, just for cleanliness
|
124
|
+
@group_name = nil
|
125
|
+
self.collect_actions = []
|
115
126
|
end
|
116
127
|
|
117
128
|
# Create a new Qt::Action and
|
@@ -130,7 +141,7 @@ module ActionBuilder
|
|
130
141
|
raise "you can't specify both :method and a block"
|
131
142
|
end
|
132
143
|
|
133
|
-
Qt::Action.
|
144
|
+
Qt::Action.new( parent ) do |action|
|
134
145
|
action.object_name = name.to_s
|
135
146
|
action.text = text
|
136
147
|
options.each do |k,v|
|
data/lib/qtext/extensions.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'Qt4'
|
4
4
|
require 'qtext/flags.rb'
|
5
5
|
require 'bigdecimal'
|
6
|
+
require 'qtext/hash_collector.rb'
|
6
7
|
|
7
8
|
# Because Qt::Variant.new( obj ) is a PITA to type
|
8
9
|
class Object
|
@@ -35,6 +36,18 @@ class BigDecimal
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
39
|
+
# Collect row and column values in various ways
|
40
|
+
class IndexCollector < HashCollector
|
41
|
+
dsl_accessor :row, :column
|
42
|
+
|
43
|
+
def initialize( row, column )
|
44
|
+
super()
|
45
|
+
# MUST use writers here, not instance variables
|
46
|
+
self.row = row
|
47
|
+
self.column = column
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
38
51
|
# convenience methods
|
39
52
|
module Qt
|
40
53
|
|
@@ -132,6 +145,45 @@ module Qt
|
|
132
145
|
end
|
133
146
|
end
|
134
147
|
|
148
|
+
# CHange and cOP(P)Y - make a new index based on this one,
|
149
|
+
# modify the new index with values from the parameters, the
|
150
|
+
# args hash or the block.
|
151
|
+
# The block will instance_eval with no args, or pass self
|
152
|
+
# if there's one arg. You can also pass two parameters, interpreted
|
153
|
+
# as row, columns.
|
154
|
+
# Examples:
|
155
|
+
# new_index = index.choppy { row 10; column 13 }
|
156
|
+
# new_index = index.choppy { row 10; column 13 }
|
157
|
+
# new_index = index.choppy( 1,3 )
|
158
|
+
# new_index = index.choppy { |i| i.row += 1 }
|
159
|
+
# new_index = index.choppy :row => 16
|
160
|
+
# same_index = index.choppy
|
161
|
+
def choppy( *args, &block )
|
162
|
+
return ModelIndex.invalid unless self.valid?
|
163
|
+
|
164
|
+
# initialize with defaults
|
165
|
+
stash = IndexCollector.new( row, column )
|
166
|
+
|
167
|
+
case args.size
|
168
|
+
when 0,1
|
169
|
+
# args.first is a hash, or nil
|
170
|
+
stash.collect( args.first, &block )
|
171
|
+
when 2
|
172
|
+
# args are two parameters - row, column
|
173
|
+
stash.row, stash.column = args
|
174
|
+
stash.collect( &block )
|
175
|
+
else
|
176
|
+
raise TypeError.new( "incorrect args #{args.inspect}" )
|
177
|
+
end
|
178
|
+
|
179
|
+
# return an invalid index if it's out of bounds,
|
180
|
+
# or the choppy'd index if it's OK.
|
181
|
+
if stash.row >= model.row_count || stash.column >= model.column_count
|
182
|
+
ModelIndex.invalid
|
183
|
+
else
|
184
|
+
model.create_index( stash.row.to_i, stash.column.to_i )
|
185
|
+
end
|
186
|
+
end
|
135
187
|
end
|
136
188
|
|
137
189
|
# Make keystrokes events easier to work with. For <tt>Qt::Key_Whatever</tt>
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# A DSL class that allows options to be collected for a field
|
2
|
+
# definition using a block and/or a hash.
|
3
|
+
# hash = { :colour => :red, :hue => 15 }
|
4
|
+
# collector = HashCollector.new( hash ) do |hc|
|
5
|
+
# hc.saturation = 17
|
6
|
+
# hc.opacity = 0.43
|
7
|
+
# hc.grooviness = 100
|
8
|
+
# end
|
9
|
+
# or like this (without the block parameter)
|
10
|
+
# collector = HashCollector.new( hash ) do
|
11
|
+
# saturation 17
|
12
|
+
# opacity 0.43
|
13
|
+
# grooviness = 100
|
14
|
+
# end
|
15
|
+
# either way, a call to collector.to_hash will result in
|
16
|
+
# { :hue=>15, :saturation=>17, :opacity=>0.43, :grooviness=>100, :colour=>:red }
|
17
|
+
# and the following accessors will be added
|
18
|
+
# collector.hue
|
19
|
+
# collector.hue( some_value )
|
20
|
+
# collector.hue = some_value
|
21
|
+
# for hue, saturation, opacity, grooviness and colour.
|
22
|
+
class HashCollector
|
23
|
+
# remove unused methods that might clash with user accessors
|
24
|
+
keep_methods = %w( __send__ __id__ self send class inspect instance_eval instance_variables )
|
25
|
+
instance_methods.each do |method|
|
26
|
+
undef_method( method ) unless keep_methods.include?( method )
|
27
|
+
end
|
28
|
+
|
29
|
+
# Collect values from the hash and the block, using the collect method.
|
30
|
+
def initialize( hash = {}, &block )
|
31
|
+
@hash = hash || {}
|
32
|
+
gather( &block )
|
33
|
+
end
|
34
|
+
|
35
|
+
# evaluate the block and collect options from args. Even if it's nil.
|
36
|
+
def collect( args = {}, &block )
|
37
|
+
@hash.merge!( args || {} )
|
38
|
+
unless block.nil?
|
39
|
+
if block.arity == -1
|
40
|
+
instance_eval &block
|
41
|
+
else
|
42
|
+
yield self
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# return a hash of the collected elements
|
48
|
+
def to_hash
|
49
|
+
@hash
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
# Modified from Jim Freeze's article.
|
55
|
+
# For each symbol, add accessors to allow:
|
56
|
+
# instance.symbol as reader
|
57
|
+
# instance.symbol( value ) as writer
|
58
|
+
# instance.symbol = value as writer
|
59
|
+
def self.dsl_accessor( *symbols )
|
60
|
+
@stripper ||= /^([^\= ]+)\s*\=?\s*$/
|
61
|
+
symbols.each do |sym|
|
62
|
+
stripped = @stripper.match( sym.to_s )[1]
|
63
|
+
line, st = __LINE__, <<-EOF
|
64
|
+
def #{stripped}(*val)
|
65
|
+
if val.empty?
|
66
|
+
@hash[:#{stripped}]
|
67
|
+
else
|
68
|
+
@hash[:#{stripped}] = val.size == 1 ? val[0] : val
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def #{stripped}=(*val)
|
73
|
+
@hash[:#{stripped}] = val.size == 1 ? val[0] : val
|
74
|
+
end
|
75
|
+
EOF
|
76
|
+
class_eval st, __FILE__, line + 1
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Do not allow accessors to be added dynamically. In other words,
|
81
|
+
# a subclass like this
|
82
|
+
# class IndexCollector < HashCollector
|
83
|
+
# dsl_static
|
84
|
+
# dsl_accessor :row, :column
|
85
|
+
# end
|
86
|
+
# will fail if used like this
|
87
|
+
# collector = IndexCollector.new( :row => 4, :column => 6 ) do
|
88
|
+
# other 'oops'
|
89
|
+
# end
|
90
|
+
# because :other isn't added by dsl_accessor.
|
91
|
+
def self.dsl_static
|
92
|
+
@dynamic = false
|
93
|
+
end
|
94
|
+
|
95
|
+
# Allow accessors to be added dynamically, the default.
|
96
|
+
def self.dsl_dynamic
|
97
|
+
@dynamic = true
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.dynamic?
|
101
|
+
# don't optimise this to @dynamic ||= true, because it will reset
|
102
|
+
# an @dynamic of false to true
|
103
|
+
@dynamic = true if @dynamic.nil?
|
104
|
+
@dynamic
|
105
|
+
end
|
106
|
+
|
107
|
+
# Originally from Jim Freeze's article. Add the accessor methods if
|
108
|
+
# they don't already exist, and if dsl_dynamic is in effect, which is
|
109
|
+
# the default. If dsl_static is in effect, the normal method_missing
|
110
|
+
# behaviour will be invoked.
|
111
|
+
def method_missing(sym, *args)
|
112
|
+
if self.class.dynamic?
|
113
|
+
self.class.dsl_accessor sym
|
114
|
+
send( sym, *args )
|
115
|
+
else
|
116
|
+
super
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -1,6 +1,31 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'qtext/flags.rb'
|
3
3
|
|
4
|
+
module Qt
|
5
|
+
class ModelIndex
|
6
|
+
def entity
|
7
|
+
model.collection[row]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ZeroSize
|
13
|
+
def size; 0; end
|
14
|
+
end
|
15
|
+
|
16
|
+
module TreeViewable
|
17
|
+
attr_accessor :parent
|
18
|
+
|
19
|
+
def children=( ary )
|
20
|
+
ary.each{|x| x.parent = self}
|
21
|
+
@children = ary
|
22
|
+
end
|
23
|
+
|
24
|
+
def children
|
25
|
+
@children ||= ZeroSize.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
4
29
|
=begin rdoc
|
5
30
|
A header for ObjectTableModel.
|
6
31
|
=end
|
@@ -55,6 +80,7 @@ class ObjectTableModel < Qt::AbstractTableModel
|
|
55
80
|
# - :collection is an alias for :data
|
56
81
|
def initialize( args = {} )
|
57
82
|
super( args[:parent] )
|
83
|
+
@parent = args[:parent]
|
58
84
|
@collection = args[:data] || args[:collection] || []
|
59
85
|
set_headers( args[:headers] )
|
60
86
|
end
|
@@ -62,7 +88,7 @@ class ObjectTableModel < Qt::AbstractTableModel
|
|
62
88
|
# implementation of Qt:AbstractItemModel method
|
63
89
|
def rowCount( parent_model_index = Qt::ModelIndex.invalid )
|
64
90
|
if parent_model_index.valid?
|
65
|
-
|
91
|
+
parent_model_index.entity.children.size
|
66
92
|
else
|
67
93
|
collection.size
|
68
94
|
end
|
@@ -70,12 +96,25 @@ class ObjectTableModel < Qt::AbstractTableModel
|
|
70
96
|
|
71
97
|
def columnCount( parent_model_index = Qt::ModelIndex.invalid )
|
72
98
|
if parent_model_index.valid?
|
73
|
-
0
|
99
|
+
parent_model_index.entity.children.size == 0 ? 0 : headers.size
|
74
100
|
else
|
75
101
|
headers.size
|
76
102
|
end
|
77
103
|
end
|
78
104
|
|
105
|
+
# TODO what exactly is this for again? Something to do with
|
106
|
+
# QWidget.parent() and Qt::AbstractTableModel.parent(...)
|
107
|
+
def parent( *args )
|
108
|
+
if args.size == 0
|
109
|
+
retval = super()
|
110
|
+
retval || @parent
|
111
|
+
else
|
112
|
+
if model_index.valid?
|
113
|
+
collection.index( model_index.entity.parent )
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
79
118
|
# implementation of Qt:AbstractItemModel method
|
80
119
|
def headerData( section, orientation, role )
|
81
120
|
value =
|
data/lib/qtext/version.rb
CHANGED
@@ -0,0 +1,180 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class OtherThing < HashCollector
|
4
|
+
dsl_static
|
5
|
+
dsl_accessor :thing, :other
|
6
|
+
end
|
7
|
+
|
8
|
+
class BuildOn < HashCollector
|
9
|
+
dsl_accessor :ook
|
10
|
+
end
|
11
|
+
|
12
|
+
class TestHashCollector < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
@hash = { :colour => :red, :hue => 15 }
|
15
|
+
@collected_hash = { :saturation => 17, :opacity => 0.43, :grooviness => 100 }
|
16
|
+
@full_hash = @hash.merge( @collected_hash )
|
17
|
+
@collector = HashCollector.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'static hash collector' do
|
24
|
+
setup do
|
25
|
+
@collector = OtherThing.new
|
26
|
+
end
|
27
|
+
|
28
|
+
should "throw NoMethodError on collection" do
|
29
|
+
assert_raise( NoMethodError ) do
|
30
|
+
@collector.collect { thing 2; blah 3 }
|
31
|
+
end
|
32
|
+
assert_raise( NoMethodError ) do
|
33
|
+
@collector.collect {|c| c.blah = 3 }
|
34
|
+
end
|
35
|
+
assert_raise( NoMethodError ) { @collector.blah }
|
36
|
+
assert_raise( NoMethodError ) { @collector.blah = 5 }
|
37
|
+
end
|
38
|
+
|
39
|
+
should "understand defined attributes" do
|
40
|
+
assert_nothing_raised do
|
41
|
+
@collector.collect do
|
42
|
+
thing 1
|
43
|
+
other 2
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_nothing_raised { @collector.thing = 2 }
|
48
|
+
assert_nothing_raised { @collector.other = 4 }
|
49
|
+
end
|
50
|
+
|
51
|
+
should "be dynamic" do
|
52
|
+
assert BuildOn.dynamic?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def assert_collected( collector )
|
57
|
+
assert_equal 17, collector.saturation
|
58
|
+
assert_equal 0.43, collector.opacity
|
59
|
+
assert_equal 100, collector.grooviness
|
60
|
+
end
|
61
|
+
|
62
|
+
def assert_hashed( collector )
|
63
|
+
assert_equal :red, collector.colour
|
64
|
+
assert_equal 15, collector.hue
|
65
|
+
end
|
66
|
+
|
67
|
+
should "collect from a hash" do
|
68
|
+
@collector.collect( @hash )
|
69
|
+
assert_equal @hash, @collector.to_hash
|
70
|
+
end
|
71
|
+
|
72
|
+
should 'not fail on a nil hash' do
|
73
|
+
@collector.collect nil
|
74
|
+
assert_equal 0, @collector.to_hash.size
|
75
|
+
end
|
76
|
+
|
77
|
+
should 'collect from a block, with dsl setters' do
|
78
|
+
@collector.collect do
|
79
|
+
saturation 17
|
80
|
+
opacity 0.43
|
81
|
+
grooviness 100
|
82
|
+
end
|
83
|
+
assert_collected( @collector )
|
84
|
+
assert_equal @collected_hash, @collector.to_hash
|
85
|
+
end
|
86
|
+
|
87
|
+
should 'collect from a block, with = setters' do
|
88
|
+
@collector.collect do |hc|
|
89
|
+
hc.saturation = 17
|
90
|
+
hc.opacity = 0.43
|
91
|
+
hc.grooviness = 100
|
92
|
+
end
|
93
|
+
assert_collected( @collector )
|
94
|
+
assert_equal @collected_hash, @collector.to_hash
|
95
|
+
end
|
96
|
+
|
97
|
+
should 'collect from a hash and block, with dsl setters' do
|
98
|
+
@collector.collect( @hash ) do
|
99
|
+
saturation 17
|
100
|
+
opacity 0.43
|
101
|
+
grooviness 100
|
102
|
+
end
|
103
|
+
assert_collected( @collector )
|
104
|
+
assert_hashed( @collector )
|
105
|
+
assert_equal @full_hash, @collector.to_hash
|
106
|
+
end
|
107
|
+
|
108
|
+
should 'collect from a hash and block with = setters' do
|
109
|
+
@collector.collect( @hash ) do |hc|
|
110
|
+
hc.saturation = 17
|
111
|
+
hc.opacity = 0.43
|
112
|
+
hc.grooviness = 100
|
113
|
+
end
|
114
|
+
assert_collected( @collector )
|
115
|
+
assert_hashed( @collector )
|
116
|
+
assert_equal @full_hash, @collector.to_hash
|
117
|
+
end
|
118
|
+
|
119
|
+
should 'not fail construction with a nil hash' do
|
120
|
+
collector = HashCollector.new nil
|
121
|
+
assert_equal 0, @collector.to_hash.size
|
122
|
+
end
|
123
|
+
|
124
|
+
should 'construct from a hash and block, with dsl setters' do
|
125
|
+
collector = HashCollector.new( @hash ) do
|
126
|
+
saturation 17
|
127
|
+
opacity 0.43
|
128
|
+
grooviness 100
|
129
|
+
end
|
130
|
+
assert_collected( collector )
|
131
|
+
assert_hashed( collector )
|
132
|
+
assert_equal @full_hash, collector.to_hash
|
133
|
+
end
|
134
|
+
|
135
|
+
should 'construct from a hash and bslock with = setters' do
|
136
|
+
collector = HashCollector.new( @hash ) do |hc|
|
137
|
+
hc.saturation = 17
|
138
|
+
hc.opacity = 0.43
|
139
|
+
hc.grooviness = 100
|
140
|
+
end
|
141
|
+
assert_collected( collector )
|
142
|
+
assert_hashed( collector )
|
143
|
+
assert_equal @full_hash, collector.to_hash
|
144
|
+
end
|
145
|
+
|
146
|
+
should 'not conflict with Object methods' do
|
147
|
+
hc = HashCollector.new do
|
148
|
+
display 'something'
|
149
|
+
sample "This is a long string designed to test the code to the very limits of possibility."
|
150
|
+
end
|
151
|
+
|
152
|
+
assert_equal 'something', hc.display
|
153
|
+
assert_equal "This is a long string designed to test the code to the very limits of possibility.", hc.sample
|
154
|
+
end
|
155
|
+
|
156
|
+
should 'work when called with &block instead of a do ... end' do
|
157
|
+
options = gather_block do
|
158
|
+
display 'activity'
|
159
|
+
order 'lower(activity)'
|
160
|
+
sample 'Troubleshooting'
|
161
|
+
conditions 'active = true'
|
162
|
+
end
|
163
|
+
assert_equal 'activity', options[:display]
|
164
|
+
end
|
165
|
+
|
166
|
+
should 'work when called with options and &block instead of a do ... end' do
|
167
|
+
options = gather_block :blah => 'ook' do
|
168
|
+
display 'activity'
|
169
|
+
order 'lower(activity)'
|
170
|
+
sample 'Troubleshooting'
|
171
|
+
conditions 'active = true'
|
172
|
+
end
|
173
|
+
assert_equal 'activity', options[:display]
|
174
|
+
assert_equal 'ook', options[:blah]
|
175
|
+
end
|
176
|
+
|
177
|
+
def gather_block( options = {}, &block )
|
178
|
+
HashCollector.new( options, &block ).to_hash
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TestModelIndex < Test::Unit::TestCase
|
4
|
+
def self.startup
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.shutdown
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@model = Qt::StandardItemModel.new( 4, 4 )
|
12
|
+
( 0...@model.row_count ).each do |i|
|
13
|
+
( 0...@model.column_count ).each do |j|
|
14
|
+
@model.set_item( i, j, Qt::StandardItem.new( "location: (#{i},#{j})" ) )
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@zero_index = @model.create_index(0,0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
end
|
22
|
+
|
23
|
+
should "be valid" do
|
24
|
+
assert @zero_index.valid?
|
25
|
+
end
|
26
|
+
|
27
|
+
should_eventually "be invalid" do
|
28
|
+
mi = @model.create_index( @model.row_count+1, @model.column_count+1 )
|
29
|
+
assert !mi.valid?
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'be an invalid copy of an invalid index' do
|
33
|
+
choppy = Qt::ModelIndex.invalid.choppy
|
34
|
+
assert !choppy.valid?
|
35
|
+
end
|
36
|
+
|
37
|
+
should "be a valid exact copy" do
|
38
|
+
choppy = @zero_index.choppy
|
39
|
+
assert choppy.valid?
|
40
|
+
end
|
41
|
+
|
42
|
+
should 'be an invalid copy' do
|
43
|
+
choppy = @zero_index.choppy( :row => @model.row_count )
|
44
|
+
assert !choppy.valid?, "choppy: #{choppy.inspect}"
|
45
|
+
|
46
|
+
choppy = @zero_index.choppy( :column => @model.column_count )
|
47
|
+
assert !choppy.valid?
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'be a copy with a changed row and column, from hash' do
|
51
|
+
choppy = @zero_index.choppy( :row => 1, :column => 2)
|
52
|
+
assert_equal 1, choppy.row, choppy.inspect
|
53
|
+
assert choppy.valid?, choppy.inspect
|
54
|
+
assert_equal 2, choppy.column, choppy.inspect
|
55
|
+
end
|
56
|
+
|
57
|
+
should 'be a choppy with incremented row and column, from block' do
|
58
|
+
choppy = @zero_index.choppy do |i|
|
59
|
+
i.row += 1
|
60
|
+
i.column += 2
|
61
|
+
end
|
62
|
+
assert choppy.valid?
|
63
|
+
assert_equal 1, choppy.row
|
64
|
+
assert_equal 2, choppy.column
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'be a copy with changed row and column, from parameters' do
|
68
|
+
choppy = @zero_index.choppy(3,0)
|
69
|
+
assert choppy.valid?
|
70
|
+
assert_equal 3, choppy.row
|
71
|
+
assert_equal 0, choppy.column
|
72
|
+
end
|
73
|
+
|
74
|
+
should 'raise an exception because parameters are wrong' do
|
75
|
+
assert_raise TypeError do
|
76
|
+
@zero_index.choppy( 3 )
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
should 'be a copy with decremented row and column, from block' do
|
81
|
+
two_index = @model.create_index(2,2)
|
82
|
+
|
83
|
+
choppy = two_index.choppy do |i|
|
84
|
+
i.row -= 1
|
85
|
+
i.column -= 2
|
86
|
+
end
|
87
|
+
assert choppy.valid?
|
88
|
+
assert_equal 1, choppy.row
|
89
|
+
assert_equal 0, choppy.column
|
90
|
+
end
|
91
|
+
|
92
|
+
should 'be a copy with changed row and column, from block' do
|
93
|
+
choppy = @zero_index.choppy do |i|
|
94
|
+
i.row = 3
|
95
|
+
i.column = 2
|
96
|
+
end
|
97
|
+
assert choppy.valid?
|
98
|
+
assert_equal 3, choppy.row
|
99
|
+
assert_equal 2, choppy.column
|
100
|
+
end
|
101
|
+
|
102
|
+
should 'be a copy with changed row and column, from instance_eval' do
|
103
|
+
choppy = @zero_index.choppy do
|
104
|
+
row 3
|
105
|
+
column 2
|
106
|
+
end
|
107
|
+
assert choppy.valid?
|
108
|
+
assert_equal 3, choppy.row
|
109
|
+
assert_equal 2, choppy.column
|
110
|
+
end
|
111
|
+
end
|
data/test/test_object_table.rb
CHANGED
@@ -4,6 +4,7 @@ require 'Qt4'
|
|
4
4
|
|
5
5
|
class TestObjectTableModel < Test::Unit::TestCase
|
6
6
|
Thing = Struct.new( :name, :value, :location, :price, :ignored )
|
7
|
+
Thing.include TreeViewable
|
7
8
|
|
8
9
|
def self.startup
|
9
10
|
$app ||= Qt::Application.new( [] )
|
@@ -16,12 +17,18 @@ class TestObjectTableModel < Test::Unit::TestCase
|
|
16
17
|
Thing.new( "Bed", 'large', 'bedroom' ),
|
17
18
|
Thing.new( "Approximation", 'useful', 'maths', 'none', 'all' )
|
18
19
|
]
|
20
|
+
@data[3].children = @data
|
19
21
|
@model = ObjectTableModel.new( :data => @data, :headers => [ :name, :value, :location, Header.new( :attribute => :price, :alignment => Qt::AlignRight ) ] )
|
20
22
|
@main_window = Qt::MainWindow.new
|
21
|
-
@view = Qt::TableView.new( @main_window ) { |tv| tv.model = @model }
|
23
|
+
#~ @view = Qt::TableView.new( @main_window ) { |tv| tv.model = @model }
|
24
|
+
@view = Qt::TreeView.new( @main_window ) { |tv| tv.model = @model }
|
22
25
|
@main_window.central_widget = @view
|
23
26
|
end
|
24
27
|
|
28
|
+
should 'have children for data[3]' do
|
29
|
+
assert_equal 4, @data[3].children.size
|
30
|
+
end
|
31
|
+
|
25
32
|
should 'have a 4 x 4 size' do
|
26
33
|
assert_equal 4, @model.rowCount
|
27
34
|
assert_equal 4, @model.row_count
|
@@ -55,14 +62,6 @@ class TestObjectTableModel < Test::Unit::TestCase
|
|
55
62
|
assert_equal Qt::AlignRight.to_i, @model.data( @model.create_index(0,3), Qt::TextAlignmentRole ).to_i & Qt::AlignRight.to_i
|
56
63
|
end
|
57
64
|
|
58
|
-
should_eventually 'display the window' do
|
59
|
-
#~ should 'display the window' do
|
60
|
-
@main_window.window_title = 'Test ObjectTableModel'
|
61
|
-
@main_window.move( 150, 0 )
|
62
|
-
@main_window.show
|
63
|
-
$app.exec
|
64
|
-
end
|
65
|
-
|
66
65
|
should 'have a nil parent' do
|
67
66
|
assert_nil @model.parent
|
68
67
|
end
|
@@ -71,4 +70,20 @@ class TestObjectTableModel < Test::Unit::TestCase
|
|
71
70
|
model = ObjectTableModel.new( :parent => @model, :data => @data, :headers => [ :name, :value, :location, Header.new( :attribute => :price, :alignment => Qt::AlignRight ) ] )
|
72
71
|
assert_equal @model, model.parent
|
73
72
|
end
|
73
|
+
|
74
|
+
context 'tree view' do
|
75
|
+
should 'have children' do
|
76
|
+
model_index = @model.create_index(3,0)
|
77
|
+
assert_equal 4, @model.row_count( model_index )
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def dont_test_show_window
|
82
|
+
#~ def test_show_window
|
83
|
+
@main_window.window_title = 'Test ObjectTableModel'
|
84
|
+
@main_window.move( 150, 0 )
|
85
|
+
@main_window.show
|
86
|
+
$app.exec
|
87
|
+
end
|
88
|
+
|
74
89
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qtext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FIXME full name
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-29 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.
|
23
|
+
version: 1.8.0
|
24
24
|
version:
|
25
25
|
description: description of gem
|
26
26
|
email:
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/qtext/action_builder.rb
|
48
48
|
- lib/qtext/extensions.rb
|
49
49
|
- lib/qtext/flags.rb
|
50
|
+
- lib/qtext/hash_collector.rb
|
50
51
|
- lib/qtext/object_table_model.rb
|
51
52
|
- lib/qtext/version.rb
|
52
53
|
- script/console
|
@@ -82,11 +83,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
requirements: []
|
83
84
|
|
84
85
|
rubyforge_project: qtext
|
85
|
-
rubygems_version: 1.
|
86
|
+
rubygems_version: 1.3.1
|
86
87
|
signing_key:
|
87
88
|
specification_version: 2
|
88
89
|
summary: description of gem
|
89
90
|
test_files:
|
91
|
+
- test/test_model_index_extensions.rb
|
90
92
|
- test/test_object_table.rb
|
93
|
+
- test/test_hash_collector.rb
|
91
94
|
- test/test_widget.rb
|
92
95
|
- test/test_helper.rb
|