Permalink
Browse files

calendar.rb is still slightly broken.

  • Loading branch information...
1 parent 80a18a7 commit 78a5681dfe11a7032b2dc1048ea35dddb67695d3 @EugeneBrazwick committed Oct 19, 2011
View
@@ -225,9 +225,10 @@ Current state:
after building the qtbindings gem, it cannot be loaded! Some caching issue, because it. qtbindings is inconvenient. Constructors are
hacked and slow.
works after that.
-0042 Thu Sep 22 21:07:50 CEST 2011
+-0042 Thu Sep 22 21:07:50 CEST 2011
Need RStore::Item class to create auto-persistent subclasses, that allow more complicated
changes.
+ Wed Oct 19 22:11:32 CEST 2011
-0043 Sun Oct 2 17:30:45 CEST 2011
Regression: reform spectest App: ICE default IO error handler doing exit(), errno = 4
Mon Oct 3 21:05:38 CEST 2011
@@ -258,3 +259,7 @@ Sat Oct 8 19:41:00 CEST 2011 Fixed. postSetup -> model_postSetup
Either say 'x true' or 'x!'.
0047 Sat Oct 15 21:15:23 CEST 2011. qtbindings is inconvenient. Constructors are
hacked and slow. bugs are hard to trace due to 'method_missing' crap.
+0048 Wed Oct 19 22:09:40 CEST 2011. model_value2key is broken for hash models.
+If changed it breaks combo_spec. But in calendar.rb the whenActivated should
+receive second argument 'key'. This is always nil which is completely wrong!
+
@@ -350,7 +350,7 @@ def whenItemChanged &block
def setLocalModel aModel
raise 'WTF' unless aModel.model?
-# tag "#{self}::setLocalModel #{aModel}!!!!!!!!!!!!" #, caller = #{caller.join("\n")}"
+# tag "#{self}::setLocalModel #{aModel}!!!!!!!!!!!!, caller = #{caller.join("\n")}"
@localmodel = aModel
# note: Qt::ComboBox has no 'selectionModel'. Only ListView and TableView.
qm = @qtc.model = @localmodel.qtc || createQModel
@@ -392,17 +392,20 @@ def col n
nil
end
- def postSetup
- setLocalModel(@localmodel) if instance_variable_defined?(:@localmodel) && @localmodel
- super
- end
+# def postSetup
+# TOO LATE.
+# setLocalModel(@localmodel) if instance_variable_defined?(:@localmodel) && @localmodel
+# super
+# end
# override, assign to @localmodel, not to @model
- def addModel control, hash = nil, &block
- control.setup hash, &block
- @localmodel = control
+ def addModel modl, hash = nil, &block
+ #tag "addModel"
+ modl.setup hash, &block
+ @localmodel = modl
#control.parent = self no such method 'parent=' .. required ?
- added control
+ added modl
+ setLocalModel(@localmodel)
end
# the default is :id. This tells the view how to retrieve the 'key'
@@ -1,5 +1,5 @@
-# Copyright (c) 2010 Eugene Brazwick
+# Copyright (c) 2010-2011 Eugene Brazwick
module Reform
@@ -23,10 +23,11 @@ module Reform
class CalendarComboBox < ComboBox
def initialize parent, qtc
super
- struct Qt::red => tr('Red'),
- Qt::blue => tr('Blue'),
- Qt::black => tr('Black'),
- Qt::magenta => tr('Magenta')
+ struct Qt::red => tr('Red'),
+ Qt::blue => tr('Blue'),
+ Qt::black => tr('Black'),
+ Qt::magenta => tr('Magenta')
+ key_connector :self
end
end
View
@@ -148,6 +148,7 @@ def self.define_simple_setter *list
n = (name.to_s + '=').to_sym
define_method name do |value = nil|
return @qtc.send(name) if value.nil?
+# tag "#@qtc.#{n} := #{value} (simple setter)"
@qtc.send(n, value)
end
end
@@ -4,8 +4,8 @@
require 'reform/app'
-# KNOWN ISSUES: changing current date in 'date' edit does not change the calwidget
-# Also, changing locale may switch current year to 7999, even though maxdate is set to 1-1-3000
+# KNOWN ISSUES:
+# changing locale may switch current year to 7999, even though maxdate is set to 1-1-3000
# below
# Indeed, max date changes in a weird fashion, and daterange for 'date' control
# does not guarantee anything.
@@ -144,8 +144,9 @@ class Const < Qt::Object
currentIndex 2
labeltext tr('&Weekday color:')
whenActivated do |data, key|
+ #tag "whenActivated(#{data}, #{key.inspect})"
format = Qt::TextCharFormat.new
- format.foreground = Qt::Brush.new(data) # .to_color
+ format.foreground = Qt::Brush.new(Reform::Graphical::make_color(data))
calendarWidget.setWeekdayTextFormat(Qt::Monday, format);
calendarWidget.setWeekdayTextFormat(Qt::Tuesday, format);
calendarWidget.setWeekdayTextFormat(Qt::Wednesday, format);
@@ -158,7 +159,7 @@ class Const < Qt::Object
currentIndex 0
labeltext tr('Week&end color:')
whenActivated do |data, key|
- (format = Qt::TextCharFormat.new).foreground = Qt::Brush.new(key)
+ (format = Qt::TextCharFormat.new).foreground = Qt::Brush.new(Reform::Graphical::make_color(data))
calendarWidget.setWeekdayTextFormat Qt::Saturday, format
calendarWidget.setWeekdayTextFormat Qt::Sunday, format
end
@@ -168,11 +169,12 @@ class Const < Qt::Object
labeltext tr('&Header text:')
whenActivated do |data, key|
format = Qt::TextCharFormat.new
- case idx
+ case key
when 0 then format.fontWeight = Qt::Font::Bold
when 1 then format.fontItalic = true
when 2 then format.foreground = Qt::Brush.new(Qt::green)
end
+ tag "set headerTextFormat"
calendarWidget.headerTextFormat format
end
}
@@ -187,14 +189,14 @@ class Const < Qt::Object
hbox { # checkBoxLayout
checkbox {
name :firstFridayCheckbox
- connector false
text tr('&First Friday in blue')
+ whenToggled { |checked| calendarModel.model_touch }
}
spacer stretch: 1
checkbox {
name :mayFirstCheckbox
- connector false
text tr('May &1 in red')
+ whenToggled { calendarModel.model_touch }
}
} # hbox
} # vbox
@@ -203,7 +205,8 @@ class Const < Qt::Object
# tag "setting whenConnected form callback"
# FIXME: once set, this is never unset and I cannot find how the original
# example does this.
- whenConnected do |model, options|
+ whenConnected do |model, propa|
+# tag "whenConnected"
if firstFridayCheckbox.checked?
firstFriday = Qt::Date.new(calendarWidget.yearShown, calendarWidget.monthShown, 1)
firstFriday = firstFriday.addDays(1) while firstFriday.dayOfWeek != Qt::Friday
View
@@ -963,13 +963,20 @@ def model_value2key value, view # or widget
when Fixnum, Qt::Enum then value.to_i
else
idid = view.key_connector || :id
+# tag "model_value2key, idid = #{idid}"
if value.respond_to?(idid)
value.send(idid)
elsif Hash === value
# just respond_to(:[]) will not work properly as x[:dd] is illegal for arrays
value[idid]
else
- nil
+ # if Hash === @model_value
+ # tag "searching value in hash #{@model_value.inspect} and return THE key"
+ # pair = @model_value.find{|k,v| v == value }
+ # if pair then pair[0] else nil end
+ # else
+ nil
+ # end
end
end
end
@@ -1018,7 +1025,8 @@ def model_dirty!
end
# sends a propertyChanged event for each field mentioned
- def model_touch sender, *fields
+ # A propagation is started, even if there are no fields given!
+ def model_touch sender = nil, *fields
transaction(sender) do |tran|
fields.each do |field|
tran.addPropertyChange self, field, model_apply_getter(field)
@@ -58,6 +58,7 @@ def whenClicked &block
# note that clicked() is called from user interaction only (or click() calls)
# but not when setChecked is used, or toggle() or setDown().
if block
+# tag "connecting clicked()"
connect(@qtc, SIGNAL('clicked(bool)'), self) do |checked|
# this does NOT overwrite the clicked() below!
rfCallBlockBack(checked, &block)
@@ -68,8 +69,11 @@ def whenClicked &block
end
end #whenClicked
+ alias :whenChecked :whenClicked
+
def whenToggled &block
if block
+# tag "connecting toggled()"
connect(@qtc, SIGNAL('toggled(bool)'), self) { |checked| rfCallBlockBack(checked, &block) }
else
@qtc.toggled(@qtc.checked?)
@@ -9,7 +9,7 @@ module Reform
=begin rdoc
ComboBox is a relative of ListView.
-It works exactly the same. To incorparate this,we introduce AbstractListView with
+It works exactly the same. To incorparate this, we introduce AbstractListView with
the complete implementation.
The following datasources are supported:
@@ -54,6 +54,7 @@ def initialize parent, qtc
# can be overriden. Called when combobox index, value has been decided
def setCurrentIndex index
+# tag "setCurrentIndex(#{index})"
@qtc.currentIndex = index
end
@@ -66,8 +67,9 @@ def whenActivated &block
connect(@qtc, SIGNAL('activated(int)'), self) do |idx|
# tag "idx = #{idx}, data_to_transmit[idx] = #{data_at(idx).inspect}"
data = @localmodel.model_row(idx)
- #tag "data = #{data.inspect}"
- rfCallBlockBack(data, @localmodel.model_value2key(data, self), &block)
+ key = @localmodel.model_value2key(data, self)
+ #tag "data = #{data.inspect}, accomp key: #{key}"
+ rfCallBlockBack(data, key, &block)
end
else
@qtc.activated(@qtc.currentIndex)
@@ -76,5 +78,18 @@ def whenActivated &block
end # class ComboBox
- createInstantiator File.basename(__FILE__, '.rb'), Qt::ComboBox, ComboBox
+ class QComboBox < Qt::ComboBox
+ def setCurrentIndex idx
+# tag "#{self}#setCurrentIndex(#{idx})"
+ method_missing(:setCurrentIndex, idx)
+ end
+
+ def currentIndex= idx
+# tag "#{self}#setCurrentIndex(#{idx}), count=#{count}"
+ method_missing(:setCurrentIndex, idx)
+# tag "currentIndex is now #{currentIndex}"
+ end
+ end
+
+ createInstantiator File.basename(__FILE__, '.rb'), QComboBox, ComboBox
end
View
@@ -42,6 +42,29 @@ class MySender
def track_propagation; $VERBOSE; end
end
+describe 'plain combobox' do
+ before do
+ Reform::app {
+ giveIt200ms
+ combo {
+ name :combo
+ struct key1: 'avanare', key2: 'what?', v: 'illuve', w: 'atarie', nasdaq: 'olme'
+ currentIndex 3
+ }
+ }
+ end
+
+ after do
+ $qApp.exec
+ end
+
+ it "should have the third element selected" do
+ qcombo = $qApp.firstform.combo.qtc
+ qcombo.currentIndex.should == 3
+ qcombo.currentText.should == 'atarie'
+ end
+end
+
describe 'combobox with hash:' do
before do
Reform::app {

0 comments on commit 78a5681

Please sign in to comment.