clevic 0.13.0.b9 → 0.13.0.b10
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/lib/clevic/action_builder.rb +16 -16
- data/lib/clevic/ar_methods.rb +22 -22
- data/lib/clevic/attribute_list.rb +5 -5
- data/lib/clevic/cache_table.rb +18 -18
- data/lib/clevic/dataset_roller.rb +3 -3
- data/lib/clevic/default_view.rb +4 -4
- data/lib/clevic/delegate.rb +8 -8
- data/lib/clevic/delegates/combo_delegate.rb +22 -22
- data/lib/clevic/delegates/distinct_delegate.rb +5 -5
- data/lib/clevic/delegates/relational_delegate.rb +6 -6
- data/lib/clevic/delegates/set_delegate.rb +3 -3
- data/lib/clevic/dirty.rb +1 -1
- data/lib/clevic/emitter.rb +3 -3
- data/lib/clevic/extensions.rb +4 -4
- data/lib/clevic/field.rb +68 -68
- data/lib/clevic/field_valuer.rb +26 -26
- data/lib/clevic/filter_command.rb +6 -6
- data/lib/clevic/framework.rb +3 -3
- data/lib/clevic/generic_format.rb +2 -2
- data/lib/clevic/many_field.rb +3 -3
- data/lib/clevic/model_builder.rb +88 -84
- data/lib/clevic/model_column.rb +13 -13
- data/lib/clevic/ordered_dataset.rb +7 -7
- data/lib/clevic/qt/action_builder.rb +3 -3
- data/lib/clevic/qt/browser.rb +28 -28
- data/lib/clevic/qt/clipboard.rb +5 -5
- data/lib/clevic/qt/combo_delegate.rb +12 -12
- data/lib/clevic/qt/distinct_delegate.rb +1 -1
- data/lib/clevic/qt/extensions.rb +4 -4
- data/lib/clevic/qt/qt_combo_box.rb +7 -7
- data/lib/clevic/qt/relational_delegate.rb +5 -5
- data/lib/clevic/qt/search_dialog.rb +15 -15
- data/lib/clevic/qt/simplest_delegate.rb +2 -2
- data/lib/clevic/qt/table_model.rb +46 -46
- data/lib/clevic/qt/table_view.rb +48 -48
- data/lib/clevic/qt/text_delegate.rb +9 -9
- data/lib/clevic/rails_models_loaders.rb +3 -3
- data/lib/clevic/record.rb +8 -8
- data/lib/clevic/sampler.rb +6 -6
- data/lib/clevic/sequel_ar_adapter.rb +22 -22
- data/lib/clevic/sequel_clevic.rb +10 -10
- data/lib/clevic/sequel_meta.rb +5 -5
- data/lib/clevic/sequel_naked.rb +4 -4
- data/lib/clevic/swing/action.rb +20 -20
- data/lib/clevic/swing/action_builder.rb +2 -2
- data/lib/clevic/swing/boolean_delegate.rb +3 -3
- data/lib/clevic/swing/browser.rb +37 -37
- data/lib/clevic/swing/cell_editor.rb +13 -13
- data/lib/clevic/swing/cell_renderer.rb +7 -7
- data/lib/clevic/swing/clipboard.rb +19 -19
- data/lib/clevic/swing/combo_delegate.rb +26 -26
- data/lib/clevic/swing/confirm_dialog.rb +7 -7
- data/lib/clevic/swing/delegate.rb +4 -4
- data/lib/clevic/swing/extensions.rb +24 -24
- data/lib/clevic/swing/field.rb +1 -1
- data/lib/clevic/swing/relational_delegate.rb +2 -2
- data/lib/clevic/swing/row_header.rb +32 -32
- data/lib/clevic/swing/search_dialog.rb +31 -31
- data/lib/clevic/swing/selection_model.rb +12 -12
- data/lib/clevic/swing/swing_table_index.rb +6 -6
- data/lib/clevic/swing/table_model.rb +30 -30
- data/lib/clevic/swing/table_view.rb +54 -54
- data/lib/clevic/swing/table_view_focus.rb +4 -4
- data/lib/clevic/swing/tag_delegate.rb +14 -14
- data/lib/clevic/swing/tag_editor.rb +4 -4
- data/lib/clevic/swing/text_area_delegate.rb +6 -6
- data/lib/clevic/swing/text_delegate.rb +4 -4
- data/lib/clevic/table_index.rb +14 -14
- data/lib/clevic/table_model.rb +30 -30
- data/lib/clevic/table_searcher.rb +19 -19
- data/lib/clevic/table_view.rb +92 -92
- data/lib/clevic/table_view_paste.rb +19 -19
- data/lib/clevic/version.rb +1 -1
- data/lib/clevic/view.rb +22 -22
- data/models/accounts_models.rb +10 -10
- data/models/examples.rb +2 -2
- data/models/times_models.rb +32 -32
- data/models/values_models.rb +2 -2
- data/test/test_cache_table.rb +15 -15
- data/test/test_helper.rb +7 -7
- data/test/test_model_index_extensions.rb +6 -6
- data/test/test_table_model.rb +6 -6
- data/test/test_table_searcher.rb +25 -25
- metadata +33 -35
@@ -5,26 +5,26 @@ module Qt
|
|
5
5
|
def no_insert=( bool )
|
6
6
|
self.insert_policy = Qt::ComboBox::NoInsert if bool
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def <<( item )
|
10
10
|
text, data = item_to_editor( item )
|
11
11
|
add_item( text, data.to_variant )
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def include?( item )
|
15
15
|
text, data = item_to_editor( item )
|
16
16
|
find_data( data.to_variant ) != -1
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def selected_item=( item )
|
20
20
|
text, data = item_to_editor( item )
|
21
21
|
self.current_index = find_data( data.to_variant )
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def selected_item
|
25
25
|
delegate.editor_to_item( item_data( self.current_index ).value )
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# wrapper for the delegate method so we don't have
|
29
29
|
# to keep checking for nil values
|
30
30
|
def item_to_editor( item )
|
@@ -34,7 +34,7 @@ module Qt
|
|
34
34
|
['', nil ]
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# wrapper for the delegate method so we don't have
|
39
39
|
# to keep checking for nil values
|
40
40
|
def editor_to_item( data )
|
@@ -45,7 +45,7 @@ module Qt
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
# Adding these to Qt::Widget as the superclass
|
50
50
|
# doesn't work for some reason.
|
51
51
|
class ComboBox
|
@@ -12,11 +12,11 @@ class RelationalDelegate < ComboDelegate
|
|
12
12
|
def item_to_editor( item )
|
13
13
|
[ field.transform_attribute( item ), item.pk.to_variant ]
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def editor_to_item( data )
|
17
17
|
entity.related_class[ data ]
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
# called by Qt when it wants to give the delegate an index to edit
|
21
21
|
def setEditorData( editor_widget, model_index )
|
22
22
|
if is_combo?( editor_widget )
|
@@ -26,11 +26,11 @@ class RelationalDelegate < ComboDelegate
|
|
26
26
|
editor_widget.line_edit.andand.select_all
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# return an entity object, given a text selection
|
31
31
|
def translate_from_editor_text( editor_widget, text )
|
32
32
|
item_index = editor_widget.find_text( text )
|
33
|
-
|
33
|
+
|
34
34
|
# fetch record id from editor_widget item_data
|
35
35
|
item_data = editor_widget.item_data( item_index )
|
36
36
|
if item_data.valid?
|
@@ -39,7 +39,7 @@ class RelationalDelegate < ComboDelegate
|
|
39
39
|
field.related_class[ item_data.to_int ]
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
@@ -8,68 +8,68 @@ module Clevic
|
|
8
8
|
class SearchDialog
|
9
9
|
include AcceptReject
|
10
10
|
include QtFlags
|
11
|
-
|
11
|
+
|
12
12
|
attr_reader :match_flags, :layout
|
13
13
|
attr_accessor :result
|
14
|
-
|
14
|
+
|
15
15
|
def initialize( parent )
|
16
16
|
@layout = Ui_SearchDialog.new
|
17
17
|
@dialog = Qt::Dialog.new
|
18
18
|
@layout.setupUi( @dialog )
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def from_start?
|
22
22
|
layout.from_start.value
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def from_start=( value )
|
26
26
|
layout.from_start.value = value
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def regex?
|
30
30
|
layout.regex.value
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def whole_words?
|
34
34
|
layout.whole_words.value
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def search_combo
|
38
38
|
layout.search_combo
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def forwards?
|
42
42
|
layout.forwards.checked?
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def backwards?
|
46
46
|
layout.backwards.checked?
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
# return either :backwards or :forwards
|
50
50
|
def direction
|
51
51
|
return :forwards if forwards?
|
52
52
|
return :backwards if backwards?
|
53
53
|
raise "direction not known"
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def exec( text = '' )
|
57
57
|
search_combo.edit_text = text.to_s
|
58
58
|
search_combo.set_focus
|
59
59
|
self.result = @dialog.exec
|
60
|
-
|
60
|
+
|
61
61
|
# remember previous searches
|
62
62
|
if search_combo.find_text( search_combo.current_text ) == -1
|
63
63
|
search_combo.add_item( search_combo.current_text )
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
self
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def search_text
|
70
70
|
search_combo.current_text
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
end
|
74
74
|
|
75
75
|
end
|
@@ -18,43 +18,43 @@ including the Clevic::Record module in a Sequel::Model subclass.
|
|
18
18
|
=end
|
19
19
|
class TableModel < Qt::AbstractTableModel
|
20
20
|
include QtFlags
|
21
|
-
|
21
|
+
|
22
22
|
signals(
|
23
23
|
# index where error occurred, value, message
|
24
24
|
'data_error(QModelIndex,QVariant,QString)'
|
25
25
|
)
|
26
|
-
|
26
|
+
|
27
27
|
def emit_data_error( index, data, string )
|
28
28
|
emit data_error( index, data.to_variant, string )
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def initialize( parent = nil )
|
32
32
|
super
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
# add a new item, and set defaults from the Clevic::View
|
36
36
|
def add_new_item_start
|
37
37
|
begin_insert_rows( Qt::ModelIndex.invalid, row_count, row_count )
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def add_new_item_end
|
41
41
|
# notify listeners that the model has changed
|
42
42
|
end_insert_rows
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def remove_notify( rows, &block )
|
46
46
|
begin_remove_rows( Qt::ModelIndex.invalid, rows.first, rows.last )
|
47
47
|
# do the removal
|
48
48
|
yield
|
49
49
|
end_remove_rows
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
# save the AR model at the given index, if it's dirty
|
53
53
|
def update_vertical_header( index )
|
54
54
|
raise "preferably use data_changed here, if possible"
|
55
55
|
emit headerDataChanged( Qt::Vertical, index.row, index.row )
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def rowCount( parent = nil )
|
59
59
|
collection.size
|
60
60
|
end
|
@@ -63,34 +63,34 @@ class TableModel < Qt::AbstractTableModel
|
|
63
63
|
def row_count
|
64
64
|
collection.size
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def columnCount( parent = nil )
|
68
68
|
fields.size
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
# Not looked up or aliased properly by Qt bindings
|
72
72
|
def column_count
|
73
73
|
fields.size
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def flags( model_index )
|
77
77
|
retval = super
|
78
|
-
|
78
|
+
|
79
79
|
# sometimes this actually happens.
|
80
80
|
# TODO probably a bug in the combo editor exit code
|
81
81
|
return retval if model_index.column >= columnCount
|
82
|
-
|
82
|
+
|
83
83
|
# TODO don't return IsEditable if the model is read-only
|
84
84
|
if model_index.meta.type == :boolean
|
85
85
|
retval = item_boolean_flags
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
unless model_index.field.read_only? || read_only?
|
89
89
|
retval |= qt_item_is_editable.to_i
|
90
90
|
end
|
91
91
|
retval
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
# values for horizontal and vertical headers
|
95
95
|
def headerData( section, orientation, role )
|
96
96
|
value =
|
@@ -103,22 +103,22 @@ class TableModel < Qt::AbstractTableModel
|
|
103
103
|
# display record number. Object id is in tooltip.
|
104
104
|
section+1
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
when qt_text_alignment_role
|
108
108
|
case orientation
|
109
109
|
when Qt::Vertical
|
110
110
|
Qt::AlignRight | Qt::AlignVCenter
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
when Qt::SizeHintRole
|
114
114
|
# anything other than nil here makes the headers disappear.
|
115
115
|
nil
|
116
|
-
|
116
|
+
|
117
117
|
when qt_tooltip_role
|
118
118
|
case orientation
|
119
119
|
when Qt::Horizontal
|
120
120
|
fields[section].tooltip
|
121
|
-
|
121
|
+
|
122
122
|
when Qt::Vertical
|
123
123
|
case
|
124
124
|
when !collection[section].errors.empty?
|
@@ -131,7 +131,7 @@ class TableModel < Qt::AbstractTableModel
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
when qt_background_role
|
136
136
|
if orientation == Qt::Vertical
|
137
137
|
item = collection[section]
|
@@ -144,15 +144,15 @@ class TableModel < Qt::AbstractTableModel
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
else
|
149
149
|
#~ puts "headerData section: #{section}, role: #{const_as_string(role)}" if $options[:debug]
|
150
150
|
nil
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
return value.to_variant
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
# Provide data to UI.
|
157
157
|
def data( index, role = qt_display_role )
|
158
158
|
#~ puts "data for index: #{index.inspect}, field #{index.field.attribute.inspect} and role: #{const_as_string role}"
|
@@ -166,18 +166,18 @@ class TableModel < Qt::AbstractTableModel
|
|
166
166
|
unless index.meta.type == :boolean
|
167
167
|
value = index.display_value
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
when qt_edit_role
|
171
171
|
# see comment for qt_display_role
|
172
172
|
unless index.meta.type == :boolean
|
173
173
|
value = index.edit_value
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
when qt_checkstate_role
|
177
177
|
if index.meta.type == :boolean
|
178
178
|
index.raw_value ? qt_checked : qt_unchecked
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
when qt_text_alignment_role
|
182
182
|
case index.field.alignment
|
183
183
|
when :left; qt_alignleft
|
@@ -185,34 +185,34 @@ class TableModel < Qt::AbstractTableModel
|
|
185
185
|
when :centre; qt_aligncenter
|
186
186
|
when :justified; qt_alignjustified
|
187
187
|
end
|
188
|
-
|
188
|
+
|
189
189
|
# just here to make debug output quieter
|
190
190
|
when qt_size_hint_role;
|
191
|
-
|
191
|
+
|
192
192
|
# show field with a red background if there's an error
|
193
193
|
when qt_background_role
|
194
194
|
index.field.background_for( index.entity ) || Qt::Color.new( 'red' ) if index.has_errors?
|
195
|
-
|
195
|
+
|
196
196
|
when qt_font_role;
|
197
|
-
|
197
|
+
|
198
198
|
when qt_foreground_role
|
199
199
|
index.field.foreground_for( index.entity ) ||
|
200
200
|
if index.field.read_only? || read_only?
|
201
201
|
Qt::Color.new( 'dimgray' )
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
204
|
when qt_decoration_role;
|
205
205
|
index.field.decoration_for( index.entity )
|
206
|
-
|
206
|
+
|
207
207
|
when qt_tooltip_role
|
208
208
|
index.tooltip
|
209
|
-
|
209
|
+
|
210
210
|
else
|
211
211
|
puts "data index: #{index}, role: #{const_as_string(role)}" if $options[:debug]
|
212
212
|
nil
|
213
213
|
# return the variant
|
214
214
|
end.to_variant
|
215
|
-
|
215
|
+
|
216
216
|
rescue Exception => e
|
217
217
|
# this can generate a lot of errors from view code, so don't emit data_error every one
|
218
218
|
puts "#{entity_view.class.name}.#{index.field.id}: #{index.inspect} for role: #{const_as_string role} #{value.inspect} #{index.entity.inspect}"
|
@@ -231,23 +231,23 @@ class TableModel < Qt::AbstractTableModel
|
|
231
231
|
when qt_edit_role
|
232
232
|
# Don't allow the primary key to be changed
|
233
233
|
return false if index.attribute == entity_class.primary_key.to_sym
|
234
|
-
|
234
|
+
|
235
235
|
if ( index.column < 0 || index.column >= column_count )
|
236
236
|
raise "invalid column #{index.column}"
|
237
237
|
end
|
238
|
-
|
238
|
+
|
239
239
|
begin
|
240
240
|
case
|
241
241
|
when variant.class.name == 'Qt::Date'
|
242
242
|
index.attribute_value = Date.new( variant.year, variant.month, variant.day )
|
243
|
-
|
243
|
+
|
244
244
|
when variant.class.name == 'Qt::Time'
|
245
245
|
index.attribute_value = Time.new( variant.hour, variant.min, variant.sec )
|
246
|
-
|
246
|
+
|
247
247
|
else
|
248
248
|
index.edit_value = variant.value
|
249
249
|
end
|
250
|
-
|
250
|
+
|
251
251
|
# value conversion was successful
|
252
252
|
data_changed( index )
|
253
253
|
true
|
@@ -266,7 +266,7 @@ class TableModel < Qt::AbstractTableModel
|
|
266
266
|
else
|
267
267
|
false
|
268
268
|
end
|
269
|
-
|
269
|
+
|
270
270
|
# user-defined role
|
271
271
|
# TODO this only works with single-dotted paths
|
272
272
|
when qt_paste_role
|
@@ -283,17 +283,17 @@ class TableModel < Qt::AbstractTableModel
|
|
283
283
|
index.attribute_value = variant.value
|
284
284
|
end
|
285
285
|
true
|
286
|
-
|
286
|
+
|
287
287
|
else
|
288
288
|
puts "role: #{role.inspect}"
|
289
289
|
true
|
290
|
-
|
290
|
+
|
291
291
|
end
|
292
292
|
else
|
293
293
|
false
|
294
294
|
end
|
295
295
|
end
|
296
|
-
|
296
|
+
|
297
297
|
# A rubyish way of doing dataChanged
|
298
298
|
# - if args has one element, it's either a single ModelIndex
|
299
299
|
# or something that understands top_left and bottom_right. These
|
@@ -313,10 +313,10 @@ class TableModel < Qt::AbstractTableModel
|
|
313
313
|
# assume it's a ModelIndex
|
314
314
|
emit dataChanged( arg, arg )
|
315
315
|
end
|
316
|
-
|
316
|
+
|
317
317
|
when 2
|
318
318
|
emit dataChanged( args.first, args.last )
|
319
|
-
|
319
|
+
|
320
320
|
else
|
321
321
|
unless block.nil?
|
322
322
|
change = DataChange.new
|
@@ -326,7 +326,7 @@ class TableModel < Qt::AbstractTableModel
|
|
326
326
|
end
|
327
327
|
end
|
328
328
|
end
|
329
|
-
|
329
|
+
|
330
330
|
end
|
331
331
|
|
332
332
|
end #module
|