ruber 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +339 -0
- data/INSTALL +137 -0
- data/LICENSE +8 -0
- data/bin/ruber +65 -0
- data/data/share/apps/ruber/core_components.yaml +31 -0
- data/data/share/apps/ruber/ruberui.rc +109 -0
- data/data/share/icons/ruber.png +0 -0
- data/data/share/pixmaps/ruby.png +0 -0
- data/icons/ruber-16.png +0 -0
- data/icons/ruber-32.png +0 -0
- data/icons/ruber-48.png +0 -0
- data/icons/ruber-8.png +0 -0
- data/lib/ruber/application/application.rb +288 -0
- data/lib/ruber/application/plugin.yaml +11 -0
- data/lib/ruber/component_manager.rb +899 -0
- data/lib/ruber/config/config.rb +82 -0
- data/lib/ruber/config/plugin.yaml +3 -0
- data/lib/ruber/document_project.rb +209 -0
- data/lib/ruber/documents/document_list.rb +416 -0
- data/lib/ruber/documents/plugin.yaml +4 -0
- data/lib/ruber/editor/document.rb +506 -0
- data/lib/ruber/editor/editor_view.rb +167 -0
- data/lib/ruber/editor/ktexteditor_wrapper.rb +202 -0
- data/lib/ruber/exception_widgets.rb +245 -0
- data/lib/ruber/external_program_plugin.rb +397 -0
- data/lib/ruber/filtered_output_widget.rb +342 -0
- data/lib/ruber/gui_states_handler.rb +231 -0
- data/lib/ruber/kde_config_option_backend.rb +167 -0
- data/lib/ruber/kde_sugar.rb +249 -0
- data/lib/ruber/main_window/choose_plugins_dlg.rb +353 -0
- data/lib/ruber/main_window/main_window.rb +524 -0
- data/lib/ruber/main_window/main_window_actions.rb +537 -0
- data/lib/ruber/main_window/main_window_internal.rb +239 -0
- data/lib/ruber/main_window/open_file_in_project_dlg.rb +212 -0
- data/lib/ruber/main_window/output_color_widget.rb +35 -0
- data/lib/ruber/main_window/plugin.yaml +58 -0
- data/lib/ruber/main_window/save_modified_files_dlg.rb +89 -0
- data/lib/ruber/main_window/status_bar.rb +156 -0
- data/lib/ruber/main_window/ui/choose_plugins_widget.rb +90 -0
- data/lib/ruber/main_window/ui/choose_plugins_widget.ui +77 -0
- data/lib/ruber/main_window/ui/main_window_settings_widget.rb +108 -0
- data/lib/ruber/main_window/ui/main_window_settings_widget.ui +89 -0
- data/lib/ruber/main_window/ui/new_project_widget.rb +119 -0
- data/lib/ruber/main_window/ui/new_project_widget.ui +178 -0
- data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +109 -0
- data/lib/ruber/main_window/ui/open_file_in_project_dlg.ui +168 -0
- data/lib/ruber/main_window/ui/output_color_widget.rb +241 -0
- data/lib/ruber/main_window/ui/output_color_widget.ui +204 -0
- data/lib/ruber/main_window/workspace.rb +442 -0
- data/lib/ruber/output_widget.rb +1093 -0
- data/lib/ruber/plugin.rb +264 -0
- data/lib/ruber/plugin_like.rb +589 -0
- data/lib/ruber/plugin_specification.rb +106 -0
- data/lib/ruber/plugin_specification_reader.rb +451 -0
- data/lib/ruber/project.rb +493 -0
- data/lib/ruber/project_backend.rb +105 -0
- data/lib/ruber/projects/plugin.yaml +11 -0
- data/lib/ruber/projects/project_files_list.rb +314 -0
- data/lib/ruber/projects/project_files_widget.rb +301 -0
- data/lib/ruber/projects/project_list.rb +314 -0
- data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +74 -0
- data/lib/ruber/projects/ui/project_files_rule_chooser_widget.ui +61 -0
- data/lib/ruber/projects/ui/project_files_widget.rb +117 -0
- data/lib/ruber/projects/ui/project_files_widget.ui +123 -0
- data/lib/ruber/qt_sugar.rb +673 -0
- data/lib/ruber/settings_container.rb +515 -0
- data/lib/ruber/settings_dialog.rb +244 -0
- data/lib/ruber/settings_dialog_manager.rb +503 -0
- data/lib/ruber/utils.rb +414 -0
- data/lib/ruber/yaml_option_backend.rb +159 -0
- data/outsider_files +15 -0
- data/plugins/autosave/autosave.rb +404 -0
- data/plugins/autosave/plugin.yaml +16 -0
- data/plugins/autosave/ui/autosave_config_widget.rb +83 -0
- data/plugins/autosave/ui/autosave_config_widget.ui +68 -0
- data/plugins/command/command.png +0 -0
- data/plugins/command/command.rb +74 -0
- data/plugins/command/plugin.yaml +11 -0
- data/plugins/find_in_files/find_in_files.rb +337 -0
- data/plugins/find_in_files/find_in_files_dlg.rb +411 -0
- data/plugins/find_in_files/find_in_files_ui.rc +11 -0
- data/plugins/find_in_files/find_in_files_widgets.rb +485 -0
- data/plugins/find_in_files/plugin.yaml +23 -0
- data/plugins/find_in_files/ui/config_widget.rb +58 -0
- data/plugins/find_in_files/ui/config_widget.ui +41 -0
- data/plugins/find_in_files/ui/find_in_files_widget.rb +260 -0
- data/plugins/find_in_files/ui/find_in_files_widget.ui +324 -0
- data/plugins/project_browser/plugin.yaml +10 -0
- data/plugins/project_browser/project_browser.rb +245 -0
- data/plugins/rake/plugin.yaml +39 -0
- data/plugins/rake/rake.png +0 -0
- data/plugins/rake/rake.rb +567 -0
- data/plugins/rake/rake_extension.rb +153 -0
- data/plugins/rake/rake_widgets.rb +615 -0
- data/plugins/rake/rakeui.rc +27 -0
- data/plugins/rake/ui/add_quick_task_widget.rb +71 -0
- data/plugins/rake/ui/add_quick_task_widget.ui +59 -0
- data/plugins/rake/ui/choose_task_widget.rb +77 -0
- data/plugins/rake/ui/choose_task_widget.ui +72 -0
- data/plugins/rake/ui/config_widget.rb +127 -0
- data/plugins/rake/ui/config_widget.ui +123 -0
- data/plugins/rake/ui/project_widget.rb +217 -0
- data/plugins/rake/ui/project_widget.ui +246 -0
- data/plugins/rspec/plugin.yaml +30 -0
- data/plugins/rspec/rspec.png +0 -0
- data/plugins/rspec/rspec.rb +945 -0
- data/plugins/rspec/rspec.svg +90 -0
- data/plugins/rspec/rspecui.rc +20 -0
- data/plugins/rspec/ruber_rspec_formatter.rb +312 -0
- data/plugins/rspec/ui/rspec_project_widget.rb +170 -0
- data/plugins/rspec/ui/rspec_project_widget.ui +193 -0
- data/plugins/ruby_development/plugin.yaml +27 -0
- data/plugins/ruby_development/ruby_development.png +0 -0
- data/plugins/ruby_development/ruby_development.rb +453 -0
- data/plugins/ruby_development/ruby_developmentui.rc +19 -0
- data/plugins/ruby_development/ui/project_widget.rb +112 -0
- data/plugins/ruby_development/ui/project_widget.ui +108 -0
- data/plugins/ruby_runner/config_widget.rb +116 -0
- data/plugins/ruby_runner/plugin.yaml +26 -0
- data/plugins/ruby_runner/project_widget.rb +62 -0
- data/plugins/ruby_runner/ruby.png +0 -0
- data/plugins/ruby_runner/ruby_interpretersui.rc +26 -0
- data/plugins/ruby_runner/ruby_runner.rb +411 -0
- data/plugins/ruby_runner/ui/config_widget.rb +92 -0
- data/plugins/ruby_runner/ui/config_widget.ui +91 -0
- data/plugins/ruby_runner/ui/project_widget.rb +60 -0
- data/plugins/ruby_runner/ui/project_widget.ui +48 -0
- data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +59 -0
- data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.ui +44 -0
- data/plugins/state/plugin.yaml +28 -0
- data/plugins/state/state.rb +520 -0
- data/plugins/state/ui/config_widget.rb +92 -0
- data/plugins/state/ui/config_widget.ui +89 -0
- data/plugins/syntax_checker/plugin.yaml +18 -0
- data/plugins/syntax_checker/syntax_checker.rb +662 -0
- data/ruber.desktop +10 -0
- data/spec/annotation_model_spec.rb +174 -0
- data/spec/common.rb +119 -0
- data/spec/component_manager_spec.rb +1259 -0
- data/spec/document_list_spec.rb +626 -0
- data/spec/document_project_spec.rb +373 -0
- data/spec/document_spec.rb +779 -0
- data/spec/editor_view_spec.rb +167 -0
- data/spec/external_program_plugin_spec.rb +676 -0
- data/spec/filtered_output_widget_spec.rb +642 -0
- data/spec/gui_states_handler_spec.rb +304 -0
- data/spec/kde_config_option_backend_spec.rb +214 -0
- data/spec/kde_sugar_spec.rb +101 -0
- data/spec/ktexteditor_wrapper_spec.rb +305 -0
- data/spec/output_widget_spec.rb +1703 -0
- data/spec/plugin_spec.rb +1393 -0
- data/spec/plugin_specification_reader_spec.rb +1765 -0
- data/spec/plugin_specification_spec.rb +401 -0
- data/spec/project_backend_spec.rb +172 -0
- data/spec/project_files_list_spec.rb +401 -0
- data/spec/project_list_spec.rb +511 -0
- data/spec/project_spec.rb +990 -0
- data/spec/qt_sugar_spec.rb +328 -0
- data/spec/settings_container_spec.rb +617 -0
- data/spec/settings_dialog_manager_spec.rb +773 -0
- data/spec/settings_dialog_spec.rb +419 -0
- data/spec/state_spec.rb +991 -0
- data/spec/utils_spec.rb +406 -0
- data/spec/workspace_spec.rb +869 -0
- data/spec/yaml_option_backend_spec.rb +246 -0
- metadata +284 -0
@@ -0,0 +1,773 @@
|
|
1
|
+
require 'spec/common'
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
require 'ruber/settings_dialog_manager'
|
6
|
+
require 'ruber/settings_dialog'
|
7
|
+
require 'ruber/settings_container'
|
8
|
+
|
9
|
+
describe 'Ruber::SettingsDialogManager' do
|
10
|
+
|
11
|
+
before do
|
12
|
+
@back = flexmock('backend'){|m| m.should_ignore_missing}
|
13
|
+
@cont = Object.new
|
14
|
+
@cont.extend Ruber::SettingsContainer
|
15
|
+
@cont.send :setup_container, @back
|
16
|
+
@options = {
|
17
|
+
OS.new({:name => :o1, :default => 'abc', :group => :G1}) => 'abc',
|
18
|
+
OS.new({:name => :o2, :default => 3, :group => :G2}) => 1
|
19
|
+
}
|
20
|
+
@options.each do |k, v|
|
21
|
+
@cont.add_option k
|
22
|
+
@cont[k.group, k.name] = v
|
23
|
+
end
|
24
|
+
@mw = Qt::Widget.new
|
25
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should inherit from Qt::Object' do
|
29
|
+
dlg = Ruber::SettingsDialog.new @cont, [], []
|
30
|
+
manager = Ruber::SettingsDialogManager.new dlg, @options.keys, []
|
31
|
+
manager.should be_a(Qt::Object)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should call the setup_option method for each option when created' do
|
35
|
+
dlg = Ruber::SettingsDialog.new @cont, [], []
|
36
|
+
$settings_dialog_manager_constructor = Set.new
|
37
|
+
class Ruber::SettingsDialogManager
|
38
|
+
alias_method :old_setup_option, :setup_option
|
39
|
+
def setup_option opt
|
40
|
+
$settings_dialog_manager_constructor << opt
|
41
|
+
end
|
42
|
+
end
|
43
|
+
manager = Ruber::SettingsDialogManager.new dlg, @options.keys, []
|
44
|
+
$settings_dialog_manager_constructor.should == Set.new(@options.keys)
|
45
|
+
class Ruber::SettingsDialogManager
|
46
|
+
alias_method :setup_option, :old_setup_option
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'Ruber::SettingsDialogManager#setup_option' do
|
53
|
+
|
54
|
+
include FlexMock::ArgumentTypes
|
55
|
+
|
56
|
+
before do
|
57
|
+
@back = flexmock('backend'){|m| m.should_ignore_missing}
|
58
|
+
@cont = Object.new
|
59
|
+
@cont.extend Ruber::SettingsContainer
|
60
|
+
@cont.send :setup_container, @back
|
61
|
+
@options = {
|
62
|
+
OS.new({:name => :o1, :default => 'abc', :group => :G1}) => 'abc',
|
63
|
+
OS.new({:name => :o2, :default => 3, :group => :G2}) => 1,
|
64
|
+
OS.new({:name => :o3, :default => nil, :group => :G1}) => /a/
|
65
|
+
}
|
66
|
+
w = Qt::Widget.new
|
67
|
+
w1 = Qt::LineEdit.new( w){|le| le.object_name = '_G1__o1'}
|
68
|
+
|
69
|
+
@widgets = [ w, Qt::SpinBox.new{|s| s.object_name = '_G2__o2'} ]
|
70
|
+
|
71
|
+
@options.each do |k, v|
|
72
|
+
@cont.add_option k
|
73
|
+
@cont[k.group, k.name] = v
|
74
|
+
end
|
75
|
+
@mw = Qt::Widget.new
|
76
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
77
|
+
@dlg = Ruber::SettingsDialog.new nil, [], []
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should call the setup_automatic_option method if one of the widgets, or one of their children has an object name made of: underscore, option group, double underscore, option name' do
|
81
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], @widgets
|
82
|
+
options = @options.invert
|
83
|
+
lineedit = @widgets[0].find_child(Qt::LineEdit)
|
84
|
+
flexmock(manager).should_receive(:setup_automatic_option).once.with(options['abc'], lineedit, @widgets[0])
|
85
|
+
flexmock(manager).should_receive(:setup_automatic_option).once.with(options[1], @widgets[1], @widgets[1])
|
86
|
+
flexmock(manager).should_receive(:setup_automatic_option).never.with(options[nil], any, any)
|
87
|
+
@options.each_key{|v| manager.send :setup_option, v}
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'Ruber::SettingsDialogManager#setup_automatic_option, if the widget has a signle signal in the "signal" property' do
|
93
|
+
|
94
|
+
before do
|
95
|
+
@mw = Qt::Widget.new
|
96
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
97
|
+
@dlg = Ruber::SettingsDialog.new nil, [], []
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should connect the object\'s signal with the SettingsDialogManager "settings_changed" slot' do
|
101
|
+
widgets = [Qt::LineEdit.new{|w| w.object_name = '_G1__o1'}]
|
102
|
+
widgets[0].set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
103
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
104
|
+
def manager.connect;end #needed because otherwise flexmock refuses to create a mock for it, saying it's undefined
|
105
|
+
flexmock(manager).should_receive(:connect).once.with(widgets[0], SIGNAL('textChanged(QString)'), manager, SLOT(:settings_changed)).once
|
106
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), widgets[0], widgets[0]
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should automatically determine the signature of the signal, if only the name is given' do
|
110
|
+
widgets = [Qt::LineEdit.new{|w| w.object_name = '_G1__o1'}]
|
111
|
+
widgets[0].set_property 'signal', Qt::Variant.new('textChanged')
|
112
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
113
|
+
def manager.connect;end #needed because otherwise flexmock refuses to create a mock for it, saying it's undefined
|
114
|
+
flexmock(manager).should_receive(:connect).once.with(widgets[0], SIGNAL('textChanged(QString)'), manager, SLOT(:settings_changed)).once
|
115
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), widgets[0], widgets[0]
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should raise ArgumentError if the signature of the signal isn\'t given and no signal matches the given name' do
|
119
|
+
widgets = [Qt::LineEdit.new{|w| w.object_name = '_G1__o1'}]
|
120
|
+
widgets[0].set_property 'signal', Qt::Variant.new('my_signal')
|
121
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
122
|
+
lambda do
|
123
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), widgets[0], widgets[0]
|
124
|
+
end.should raise_error(ArgumentError, "No signal with name 'my_signal' exist")
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should raise ArgumentError if the signature of the signal isn\'t given and more than one signal has the given name' do
|
128
|
+
widgets = [Qt::ComboBox.new{|w| w.object_name = '_G1__o1'}]
|
129
|
+
widgets[0].set_property 'signal', Qt::Variant.new('currentIndexChanged')
|
130
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
131
|
+
lambda do
|
132
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), widgets[0], widgets[0]
|
133
|
+
end.should raise_error(ArgumentError, "Ambiguous signal name, 'currentIndexChanged'")
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should associate the option with widget and its "read" property, if given' do
|
137
|
+
w = Qt::LineEdit.new do |wi|
|
138
|
+
wi.object_name = '_G1__o1'
|
139
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
140
|
+
wi.set_property 'read', Qt::Variant.new('text_from_option')
|
141
|
+
end
|
142
|
+
widgets = [w]
|
143
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
144
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, w
|
145
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'text_from_option']
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should associate the option with widget and its "store" property, if given' do
|
149
|
+
w = Qt::LineEdit.new do |wi|
|
150
|
+
wi.object_name = '_G1__o1'
|
151
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
152
|
+
wi.set_property 'store', Qt::Variant.new('text_to_option')
|
153
|
+
end
|
154
|
+
widgets = [w]
|
155
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
156
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, w
|
157
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text_to_option']
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should raise ArgumentError if the widget has the read and/or the store properties together with the access property' do
|
161
|
+
w = Qt::LineEdit.new do |wi|
|
162
|
+
wi.object_name = '_G1__o1'
|
163
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
164
|
+
wi.set_property 'store', Qt::Variant.new('text_to_option')
|
165
|
+
wi.set_property 'access', Qt::Variant.new('option')
|
166
|
+
end
|
167
|
+
|
168
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
169
|
+
lambda do
|
170
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, w
|
171
|
+
end.should raise_error(ArgumentError, 'The widget _G1__o1 has both the access property and one or both of the store and read properties')
|
172
|
+
|
173
|
+
w = Qt::LineEdit.new do |wi|
|
174
|
+
wi.object_name = '_G1__o1'
|
175
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
176
|
+
wi.set_property 'read', Qt::Variant.new('option_to_text')
|
177
|
+
wi.set_property 'access', Qt::Variant.new('option')
|
178
|
+
end
|
179
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
180
|
+
lambda do
|
181
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, w
|
182
|
+
end.should raise_error(ArgumentError, 'The widget _G1__o1 has both the access property and one or both of the store and read properties')
|
183
|
+
|
184
|
+
w = Qt::LineEdit.new do |wi|
|
185
|
+
wi.object_name = '_G1__o1'
|
186
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
187
|
+
wi.set_property 'store', Qt::Variant.new('text_to_option')
|
188
|
+
wi.set_property 'read', Qt::Variant.new('option_to_text')
|
189
|
+
wi.set_property 'access', Qt::Variant.new('option')
|
190
|
+
end
|
191
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
192
|
+
lambda do
|
193
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, w
|
194
|
+
end.should raise_error(ArgumentError, 'The widget _G1__o1 has both the access property and one or both of the store and read properties')
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should use the widget\'s "access" insteaod of the "store" property, if it exists' do
|
198
|
+
w = Qt::LineEdit.new do |wi|
|
199
|
+
wi.object_name = '_G1__o1'
|
200
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
201
|
+
wi.set_property 'access', Qt::Variant.new('option')
|
202
|
+
end
|
203
|
+
widgets = [w]
|
204
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
205
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, w
|
206
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'option']
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should derive the "read" property from the widget\'s "access" property, if it exists, by removing the ending ? or ! (if it exists) and by adding an ending =' do
|
210
|
+
w = Qt::LineEdit.new do |wi|
|
211
|
+
wi.object_name = '_G1__o1'
|
212
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
213
|
+
wi.set_property 'access', Qt::Variant.new('option')
|
214
|
+
end
|
215
|
+
widgets = [w]
|
216
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
217
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, w
|
218
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'option=']
|
219
|
+
|
220
|
+
w.set_property 'access', Qt::Variant.new('option?')
|
221
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
222
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, w
|
223
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'option=']
|
224
|
+
|
225
|
+
w.set_property 'access', Qt::Variant.new('option!')
|
226
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
227
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, w
|
228
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'option=']
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should associate the option with the widget\'s top-level widget for reading, storing or both if respectively the "read", "store" or "access" property begin with $' do
|
233
|
+
top = Qt::Widget.new
|
234
|
+
w = Qt::LineEdit.new(top) do |wi|
|
235
|
+
wi.object_name = '_G1__o1'
|
236
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
237
|
+
wi.set_property 'read', Qt::Variant.new('$text_from_option')
|
238
|
+
wi.set_property 'store', Qt::Variant.new('option_from_text')
|
239
|
+
end
|
240
|
+
widgets = [top]
|
241
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], top
|
242
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, top
|
243
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [top, 'text_from_option']
|
244
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'option_from_text']
|
245
|
+
|
246
|
+
top = Qt::Widget.new
|
247
|
+
w = Qt::LineEdit.new(top) do |wi|
|
248
|
+
wi.object_name = '_G1__o1'
|
249
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
250
|
+
wi.set_property 'read', Qt::Variant.new('text_from_option')
|
251
|
+
wi.set_property 'store', Qt::Variant.new('$option_from_text')
|
252
|
+
end
|
253
|
+
widgets = [top]
|
254
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], top
|
255
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, top
|
256
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'text_from_option']
|
257
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [top, 'option_from_text']
|
258
|
+
|
259
|
+
top = Qt::Widget.new
|
260
|
+
w = Qt::LineEdit.new(top) do |wi|
|
261
|
+
wi.object_name = '_G1__o1'
|
262
|
+
wi.set_property 'signal', Qt::Variant.new('textChanged(QString)')
|
263
|
+
wi.set_property 'access', Qt::Variant.new('$option')
|
264
|
+
end
|
265
|
+
widgets = [top]
|
266
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], top
|
267
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), w, top
|
268
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [top, 'option=']
|
269
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [top, 'option']
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'should generate the "store" property from the name of the signal, removing the changed/edited/modified words from its end, if the object has neither "store" nor the "access" property' do
|
273
|
+
w = Qt::LineEdit.new{|wi| wi.object_name = '_G1__o1'}
|
274
|
+
opt = OS.new({:name => :o1, :group => :G1, :default => 'abc'})
|
275
|
+
|
276
|
+
w.set_property 'signal', Qt::Variant.new( 'textChanged(QString)')
|
277
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
278
|
+
manager.send :setup_automatic_option, opt, w, w
|
279
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
280
|
+
|
281
|
+
w.set_property 'signal', Qt::Variant.new( 'textModified(QString)')
|
282
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
283
|
+
manager.send :setup_automatic_option, opt, w, w
|
284
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
285
|
+
|
286
|
+
w.set_property 'signal', Qt::Variant.new( 'textEdited(QString)')
|
287
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
288
|
+
manager.send :setup_automatic_option, opt, w, w
|
289
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
290
|
+
|
291
|
+
w.set_property 'signal', Qt::Variant.new( 'text_changed(QString)')
|
292
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
293
|
+
manager.send :setup_automatic_option, opt, w, w
|
294
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
295
|
+
|
296
|
+
w.set_property 'signal', Qt::Variant.new( 'text_modified(QString)')
|
297
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
298
|
+
manager.send :setup_automatic_option, opt, w, w
|
299
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
300
|
+
|
301
|
+
w.set_property 'signal', Qt::Variant.new( 'text_edited(QString)')
|
302
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
303
|
+
manager.send :setup_automatic_option, opt, w, w
|
304
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
305
|
+
|
306
|
+
w.set_property 'signal', Qt::Variant.new( 'state(QString)')
|
307
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
308
|
+
manager.send :setup_automatic_option, opt, w, w
|
309
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'state']
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'should generate the "store" property from the name of the signal, removing the changed/edited/modified words from its end, if the object has neither "store" nor the "access" property' do
|
313
|
+
w = Qt::LineEdit.new{|wi| wi.object_name = '_G1__o1'}
|
314
|
+
opt = OS.new({:name => :o1, :group => :G1, :default => 'abc'})
|
315
|
+
|
316
|
+
w.set_property 'signal', Qt::Variant.new( 'textChanged(QString)')
|
317
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
318
|
+
manager.send :setup_automatic_option, opt, w, w
|
319
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
320
|
+
|
321
|
+
w.set_property 'signal', Qt::Variant.new( 'textModified(QString)')
|
322
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
323
|
+
manager.send :setup_automatic_option, opt, w, w
|
324
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
325
|
+
|
326
|
+
w.set_property 'signal', Qt::Variant.new( 'textEdited(QString)')
|
327
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
328
|
+
manager.send :setup_automatic_option, opt, w, w
|
329
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
330
|
+
|
331
|
+
w.set_property 'signal', Qt::Variant.new( 'text_changed(QString)')
|
332
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
333
|
+
manager.send :setup_automatic_option, opt, w, w
|
334
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
335
|
+
|
336
|
+
w.set_property 'signal', Qt::Variant.new( 'text_modified(QString)')
|
337
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
338
|
+
manager.send :setup_automatic_option, opt, w, w
|
339
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
340
|
+
|
341
|
+
w.set_property 'signal', Qt::Variant.new( 'text_edited(QString)')
|
342
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
343
|
+
manager.send :setup_automatic_option, opt, w, w
|
344
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'text']
|
345
|
+
|
346
|
+
w.set_property 'signal', Qt::Variant.new( 'state(QString)')
|
347
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
348
|
+
manager.send :setup_automatic_option, opt, w, w
|
349
|
+
manager.instance_variable_get(:@associations)[w.object_name][:store].should == [w, 'state']
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'should generate the "read" property from the name of the signal, removing the changed/edited/modified words from its end and adding a final =, if the object has neither "read" nor the "access" property' do
|
353
|
+
w = Qt::LineEdit.new{|wi| wi.object_name = '_G1__o1'}
|
354
|
+
opt = OS.new({:name => :o1, :group => :G1, :default => 'abc'})
|
355
|
+
|
356
|
+
w.set_property 'signal', Qt::Variant.new( 'textChanged(QString)')
|
357
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
358
|
+
manager.send :setup_automatic_option, opt, w, w
|
359
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'text=']
|
360
|
+
|
361
|
+
w.set_property 'signal', Qt::Variant.new( 'textModified(QString)')
|
362
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
363
|
+
manager.send :setup_automatic_option, opt, w, w
|
364
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'text=']
|
365
|
+
|
366
|
+
w.set_property 'signal', Qt::Variant.new( 'textEdited(QString)')
|
367
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
368
|
+
manager.send :setup_automatic_option, opt, w, w
|
369
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'text=']
|
370
|
+
|
371
|
+
w.set_property 'signal', Qt::Variant.new( 'text_changed(QString)')
|
372
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
373
|
+
manager.send :setup_automatic_option, opt, w, w
|
374
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'text=']
|
375
|
+
|
376
|
+
w.set_property 'signal', Qt::Variant.new( 'text_modified(QString)')
|
377
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
378
|
+
manager.send :setup_automatic_option, opt, w, w
|
379
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'text=']
|
380
|
+
|
381
|
+
w.set_property 'signal', Qt::Variant.new( 'text_edited(QString)')
|
382
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
383
|
+
manager.send :setup_automatic_option, opt, w, w
|
384
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'text=']
|
385
|
+
|
386
|
+
w.set_property 'signal', Qt::Variant.new( 'state(QString)')
|
387
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
388
|
+
manager.send :setup_automatic_option, opt, w, w
|
389
|
+
manager.instance_variable_get(:@associations)[w.object_name][:read].should == [w, 'state=']
|
390
|
+
end
|
391
|
+
|
392
|
+
end
|
393
|
+
|
394
|
+
describe 'Ruber::SettingsDialogManager#setup_automatic_option, when the widget specifies more than one signal' do
|
395
|
+
|
396
|
+
before do
|
397
|
+
@mw = Qt::Widget.new
|
398
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
399
|
+
@dlg = Ruber::SettingsDialog.new nil, [], []
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'should connect each of its signals to the settings_changed slot' do
|
403
|
+
widgets = [Qt::LineEdit.new{|w| w.object_name = '_G1__o1'}]
|
404
|
+
widgets[0].set_property 'signal', Qt::Variant.new('[textChanged(QString), textEdited(QString)]')
|
405
|
+
widgets[0].set_property 'access', Qt::Variant.new('text')
|
406
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
407
|
+
def manager.connect;end #needed because otherwise flexmock refuses to create a mock for it, saying it's undefined
|
408
|
+
flexmock(manager).should_receive(:connect).once.with(widgets[0], SIGNAL('textChanged(QString)'), manager, SLOT(:settings_changed)).once
|
409
|
+
flexmock(manager).should_receive(:connect).once.with(widgets[0], SIGNAL('textEdited(QString)'), manager, SLOT(:settings_changed)).once
|
410
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), widgets[0], widgets[0]
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'should automatically determine the signatures of the signals' do
|
414
|
+
widgets = [Qt::LineEdit.new{|w| w.object_name = '_G1__o1'}]
|
415
|
+
widgets[0].set_property 'signal', Qt::Variant.new('[textChanged, textEdited]')
|
416
|
+
widgets[0].set_property 'access', Qt::Variant.new('text')
|
417
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
418
|
+
def manager.connect;end #needed because otherwise flexmock refuses to create a mock for it, saying it's undefined
|
419
|
+
flexmock(manager).should_receive(:connect).once.with(widgets[0], SIGNAL('textChanged(QString)'), manager, SLOT(:settings_changed)).once
|
420
|
+
flexmock(manager).should_receive(:connect).once.with(widgets[0], SIGNAL('textEdited(QString)'), manager, SLOT(:settings_changed)).once
|
421
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), widgets[0], widgets[0]
|
422
|
+
end
|
423
|
+
|
424
|
+
it 'should raise ArgumentError if the widget doesn\'t have the "access" property or both the "store" and the "read" properties' do
|
425
|
+
widgets = [Qt::LineEdit.new{|w| w.object_name = '_G1__o1'}]
|
426
|
+
widgets[0].set_property 'signal', Qt::Variant.new('[textChanged, textEdited]')
|
427
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], widgets
|
428
|
+
lambda do
|
429
|
+
manager.send :setup_automatic_option, OS.new({:name => :o1, :group => :G1, :default => 'abc'}), widgets[0], widgets[0]
|
430
|
+
end.should raise_error(ArgumentError, "When more signals are specified, you need to specify also the access property or both the read and store properties")
|
431
|
+
end
|
432
|
+
|
433
|
+
end
|
434
|
+
|
435
|
+
describe 'Ruber::SettingsDialogManager#setup_automatic_option, when no signal is specified' do
|
436
|
+
|
437
|
+
defaults = [
|
438
|
+
[ Qt::CheckBox , 'toggled(bool)', "checked?"],
|
439
|
+
[Qt::PushButton , 'toggled(bool)', "checked?"],
|
440
|
+
[KDE::PushButton , 'toggled(bool)', "checked?"],
|
441
|
+
[KDE::ColorButton, 'changed(QColor)', "color"],
|
442
|
+
[KDE::IconButton, 'iconChanged(QString)', "icon"],
|
443
|
+
[Qt::LineEdit , 'textChanged(QString)', "text"],
|
444
|
+
[KDE::LineEdit , 'textChanged(QString)', "text"],
|
445
|
+
[KDE::RestrictedLine, 'textChanged(QString)', "text"],
|
446
|
+
[Qt::ComboBox, 'currentIndexChanged(int)', "current_index"],
|
447
|
+
[KDE::ComboBox, 'currentIndexChanged(int)', "current_index"],
|
448
|
+
[KDE::ColorCombo, 'currentIndexChanged(int)', "color"],
|
449
|
+
[Qt::TextEdit, 'textChanged(QString)', "text"],
|
450
|
+
[KDE::TextEdit, 'textChanged(QString)', "text"],
|
451
|
+
[Qt::PlainTextEdit, 'textChanged(QString)', "text"],
|
452
|
+
[Qt::SpinBox, 'valueChanged(int)', "value"],
|
453
|
+
[KDE::IntSpinBox, 'valueChanged(int)', "value"],
|
454
|
+
[Qt::DoubleSpinBox, 'valueChanged(double)', "value"],
|
455
|
+
[KDE::IntNumInput, 'valueChanged(int)', "value"],
|
456
|
+
[KDE::DoubleNumInput, 'valueChanged(double)', "value"],
|
457
|
+
[Qt::TimeEdit, 'timeChanged(QTime)', "time"],
|
458
|
+
[Qt::DateEdit, 'dateChanged(QDate)', "date"],
|
459
|
+
[Qt::DateTimeEdit, 'dateTimeChanged(QDateTime)', "date_time"],
|
460
|
+
[Qt::Dial, 'valueChanged(int)', "value"],
|
461
|
+
[Qt::Slider, 'valueChanged(int)', "value"],
|
462
|
+
[KDE::DatePicker, 'dateChanged(QDate)', "date"],
|
463
|
+
[KDE::DateTimeWidget, 'valueChanged(QDateTime)', "date_time"],
|
464
|
+
[KDE::DateWidget, 'changed(QDate)', "date"],
|
465
|
+
[KDE::FontComboBox, 'currentFontChanged(QFont)', "current_font"],
|
466
|
+
[KDE::FontRequester, 'fontSelected(QFont)', "font"],
|
467
|
+
[KDE::UrlRequester, 'textChanged(QString)', "url"]
|
468
|
+
]
|
469
|
+
|
470
|
+
before do
|
471
|
+
@mw = Qt::Widget.new
|
472
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
473
|
+
@dlg = Ruber::SettingsDialog.new nil, [], []
|
474
|
+
end
|
475
|
+
|
476
|
+
defaults.each do |cls, *s|
|
477
|
+
desc = "should behave as if the widget had'#{s[0]}' for the \"signal\" property and '#{s[1]}' for the \"accessor\" property, if the object is of class #{cls} and neither the 'access' nor the 'read' and 'store' properties have been specified"
|
478
|
+
it desc do
|
479
|
+
extend FlexMock::ArgumentTypes
|
480
|
+
widgets = [cls.new{|w| w.object_name = '_G1__o1'}]
|
481
|
+
opt = OS.new({:name => :o1, :group => :G1, :default => 'x'})
|
482
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [opt], widgets
|
483
|
+
def manager.connect;end
|
484
|
+
flexmock(manager).should_receive(:connect).once.with(widgets[0], SIGNAL(s[0]), manager, SLOT(:settings_changed))
|
485
|
+
manager.send :setup_automatic_option, opt, widgets[0], widgets[0]
|
486
|
+
assoc = manager.instance_variable_get(:@associations)
|
487
|
+
assoc['_G1__o1'][:store][1].should == s[1]
|
488
|
+
assoc['_G1__o1'][:read][1].should == s[1].sub(/[\?!]$/, '') + '='
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
defaults.each do |cls, *s|
|
493
|
+
desc = "should behave as if the widget had'#{s[0]}' for the \"signal\" property if the object is of class #{cls} and the 'access' property has been specified"
|
494
|
+
it desc do
|
495
|
+
extend FlexMock::ArgumentTypes
|
496
|
+
w = cls.new do |w|
|
497
|
+
w.object_name = '_G1__o1'
|
498
|
+
w.set_property 'access', Qt::Variant.new('option')
|
499
|
+
end
|
500
|
+
opt = OS.new({:name => :o1, :group => :G1, :default => 'x'})
|
501
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [opt], [w]
|
502
|
+
def manager.connect;end
|
503
|
+
flexmock(manager).should_receive(:connect).once.with(w, SIGNAL(s[0]), manager, SLOT(:settings_changed))
|
504
|
+
manager.send :setup_automatic_option, opt, w, w
|
505
|
+
assoc = manager.instance_variable_get(:@associations)
|
506
|
+
assoc['_G1__o1'][:store][1].should == 'option'
|
507
|
+
assoc['_G1__o1'][:read][1].should == 'option='
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
defaults.each do |cls, *s|
|
512
|
+
desc = "should behave as if the widget had'#{s[0]}' for the \"signal\" property if the object is of class #{cls} and the 'read' and 'store' properties have been specified"
|
513
|
+
it desc do
|
514
|
+
extend FlexMock::ArgumentTypes
|
515
|
+
w = cls.new do |w|
|
516
|
+
w.object_name = '_G1__o1'
|
517
|
+
w.set_property 'read', Qt::Variant.new('option=')
|
518
|
+
w.set_property 'store', Qt::Variant.new('option')
|
519
|
+
end
|
520
|
+
opt = OS.new({:name => :o1, :group => :G1, :default => 'x'})
|
521
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [opt], [w]
|
522
|
+
def manager.connect;end
|
523
|
+
flexmock(manager).should_receive(:connect).once.with(w, SIGNAL(s[0]), manager, SLOT(:settings_changed))
|
524
|
+
manager.send :setup_automatic_option, opt, w, w
|
525
|
+
assoc = manager.instance_variable_get(:@associations)
|
526
|
+
assoc['_G1__o1'][:store][1].should == 'option'
|
527
|
+
assoc['_G1__o1'][:read][1].should == 'option='
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
it 'should raise ArgumentError if the object is of an unknown class' do
|
532
|
+
w = Qt::Frame.new{|w| w.object_name = '_G1__o1'}
|
533
|
+
manager = Ruber::SettingsDialogManager.new @dlg, [], [w]
|
534
|
+
opt = OS.new({:name => :o1, :group => :G1, :default => 'x'})
|
535
|
+
lambda do
|
536
|
+
manager.send :setup_automatic_option, opt, w, w
|
537
|
+
end.should raise_error(ArgumentError, "No default signal exists for class Qt::Frame, you need to specify one")
|
538
|
+
end
|
539
|
+
|
540
|
+
end
|
541
|
+
|
542
|
+
describe 'Ruber::SettingsDialog#convert_value' do
|
543
|
+
|
544
|
+
before do
|
545
|
+
@mw = Qt::Widget.new
|
546
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
547
|
+
@back = flexmock('backend'){|m| m.should_ignore_missing}
|
548
|
+
@cont = Object.new
|
549
|
+
@cont.extend Ruber::SettingsContainer
|
550
|
+
@cont.send :setup_container, @back
|
551
|
+
@dlg = @cont.dialog
|
552
|
+
@manager = @dlg.instance_variable_get(:@manager)
|
553
|
+
end
|
554
|
+
|
555
|
+
it 'should return the firts argument if both argument are of the same class' do
|
556
|
+
str1 = "abc"
|
557
|
+
@manager.send(:convert_value, str1, "xyz").should equal(str1)
|
558
|
+
@manager.send(:convert_value, 1, 2).should == 1
|
559
|
+
end
|
560
|
+
|
561
|
+
it 'should return the first argument if there\'s no conversion method from the class of the first to the class of the second' do
|
562
|
+
a = [1,2, 3]
|
563
|
+
@manager.send(:convert_value, a, "xyz").should equal(a)
|
564
|
+
h = {:a => 1, :b => 2}
|
565
|
+
@manager.send(:convert_value, h, []).should equal(h)
|
566
|
+
end
|
567
|
+
|
568
|
+
it 'should convert a string to a symbol and vice versa' do
|
569
|
+
@manager.send(:convert_value, :xyz, "abc").should == 'xyz'
|
570
|
+
@manager.send(:convert_value, 'xyz', :abc).should == :xyz
|
571
|
+
end
|
572
|
+
|
573
|
+
it 'should convert a string to a KDE::Url and vice versa' do
|
574
|
+
@manager.send(:convert_value, ENV['HOME'], KDE::Url.new).should == KDE::Url.from_path(ENV['HOME'])
|
575
|
+
@manager.send(:convert_value, KDE::Url.from_path(ENV['HOME']), '').should == ENV['HOME']
|
576
|
+
@manager.send(:convert_value, KDE::Url.new, '').should == ''
|
577
|
+
end
|
578
|
+
|
579
|
+
it 'should convert a string to a FixNum and vice versa' do
|
580
|
+
@manager.send(:convert_value, 1, '').should == '1'
|
581
|
+
@manager.send(:convert_value, '1', 0).should == 1
|
582
|
+
end
|
583
|
+
|
584
|
+
it 'should convert a string to a Float and vice versa' do
|
585
|
+
@manager.send(:convert_value, 1.2, '').should == 1.2.to_s
|
586
|
+
@manager.send(:convert_value, '1.2', 1.0).should == 1.2
|
587
|
+
end
|
588
|
+
|
589
|
+
it 'should not convert true to false or vice versa' do
|
590
|
+
@manager.send(:convert_value, true, false).should be_true
|
591
|
+
@manager.send(:convert_value, false, true).should be_false
|
592
|
+
end
|
593
|
+
|
594
|
+
end
|
595
|
+
|
596
|
+
describe 'Ruber::SettingsDialog#read_settings' do
|
597
|
+
|
598
|
+
before do
|
599
|
+
@mw = Qt::Widget.new
|
600
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
601
|
+
@back = flexmock('backend'){|m| m.should_ignore_missing}
|
602
|
+
@cont = Object.new
|
603
|
+
@cont.extend Ruber::SettingsContainer
|
604
|
+
@cont.send :setup_container, @back
|
605
|
+
@options = [
|
606
|
+
OS.new({:name => :o1, :default => 3, :group => :G1}),
|
607
|
+
OS.new({:name => :o2, :default => "abc", :group => :G2}),
|
608
|
+
OS.new({:name => :o3, :default => true, :group => :G1}),
|
609
|
+
]
|
610
|
+
@option_values = [-2, "xyz", false]
|
611
|
+
@options.each{|o| @cont.add_option o}
|
612
|
+
@options.zip(@option_values).each{|op, val| @cont[op.group, op.name] = val}
|
613
|
+
end
|
614
|
+
|
615
|
+
it 'should call the read methods associated to each option, passing as argument the value of the option read from the option container' do
|
616
|
+
widgets_data = [
|
617
|
+
OS.new({:caption => 'C1', :code => 'Qt::LineEdit.new{|w| w.object_name = "_G2__o2"}'}),
|
618
|
+
OS.new({:caption => 'C1', :code => 'Qt::CheckBox.new{|w| w.object_name = "_G1__o3"}'})
|
619
|
+
]
|
620
|
+
widgets_data.each{|w| @cont.add_widget w}
|
621
|
+
dlg = @cont.dialog
|
622
|
+
flexmock(dlg.find_child(Qt::LineEdit, '_G2__o2')).should_receive(:text=).once.with('xyz')
|
623
|
+
flexmock(dlg.find_child(Qt::CheckBox, '_G1__o3')).should_receive(:checked=).once.with(false)
|
624
|
+
dlg.instance_variable_get(:@manager).read_settings
|
625
|
+
end
|
626
|
+
|
627
|
+
it 'should convert the values stored in the options by passing them to the "convert_value" method before updating the widgets' do
|
628
|
+
opt = OS.new({:name => :o1, :group => :G3, :default => :abc})
|
629
|
+
@cont.add_option opt
|
630
|
+
@cont[:G2, :o2] = ENV['HOME']
|
631
|
+
@cont[:G3, :o1] = :xyz
|
632
|
+
widgets_data = [
|
633
|
+
OS.new({:caption => 'C1', :code => 'Qt::LineEdit.new{|w| w.object_name = "_G3__o1"}'}),
|
634
|
+
OS.new({:caption => 'C1', :code => 'KDE::UrlRequester.new{|w| w.object_name = "_G2__o2"}'})
|
635
|
+
]
|
636
|
+
widgets_data.each{|w| @cont.add_widget w}
|
637
|
+
dlg = @cont.dialog
|
638
|
+
flexmock(dlg.find_child(Qt::LineEdit, '_G3__o1')).should_receive(:text=).once.with('xyz')
|
639
|
+
flexmock(dlg.find_child(KDE::UrlRequester, '_G2__o2')).should_receive(:url=).once.with KDE::Url.from_path(ENV['HOME'])
|
640
|
+
manager = dlg.instance_variable_get(:@manager)
|
641
|
+
flexmock(manager).should_receive(:convert_value).once.with(ENV['HOME'], KDE::Url.new).and_return(KDE::Url.from_path(ENV['HOME']))
|
642
|
+
flexmock(manager).should_receive(:convert_value).once.with(:xyz, '').and_return('xyz')
|
643
|
+
manager.read_settings
|
644
|
+
end
|
645
|
+
|
646
|
+
end
|
647
|
+
|
648
|
+
describe 'Ruber::SettingsDialogManager#store_settings' do
|
649
|
+
|
650
|
+
before do
|
651
|
+
@mw = Qt::Widget.new
|
652
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
653
|
+
@back = flexmock('backend'){|m| m.should_ignore_missing}
|
654
|
+
@cont = Object.new
|
655
|
+
@cont.extend Ruber::SettingsContainer
|
656
|
+
@cont.send :setup_container, @back
|
657
|
+
@options = [
|
658
|
+
OS.new({:name => :o1, :default => 3, :group => :G1}),
|
659
|
+
OS.new({:name => :o2, :default => "abc", :group => :G2}),
|
660
|
+
OS.new({:name => :o3, :default => true, :group => :G1}),
|
661
|
+
]
|
662
|
+
@option_values = [-2, "xyz", false]
|
663
|
+
@options.each{|o| @cont.add_option o}
|
664
|
+
@options.zip(@option_values).each{|op, val| @cont[op.group, op.name] = val}
|
665
|
+
end
|
666
|
+
|
667
|
+
it 'store the value of each option, read using the corresponding "store" method, in the container' do
|
668
|
+
widgets_data = [
|
669
|
+
OS.new({:caption => 'C1', :code => 'Qt::LineEdit.new{|w| w.object_name = "_G2__o2"}'}),
|
670
|
+
OS.new({:caption => 'C1', :code => 'Qt::CheckBox.new{|w| w.object_name = "_G1__o3"}'})
|
671
|
+
]
|
672
|
+
widgets_data.each{|w| @cont.add_widget w}
|
673
|
+
dlg = @cont.dialog
|
674
|
+
flexmock(dlg.find_child(Qt::LineEdit, '_G2__o2')).should_receive(:text).once.and_return('hello')
|
675
|
+
flexmock(dlg.find_child(Qt::CheckBox, '_G1__o3')).should_receive(:checked?).once.and_return true
|
676
|
+
flexmock(@cont).should_receive(:[]=).once.with(:G1, :o3, true)
|
677
|
+
flexmock(@cont).should_receive(:[]=).once.with(:G2, :o2, 'hello')
|
678
|
+
dlg.instance_variable_get(:@manager).store_settings
|
679
|
+
|
680
|
+
end
|
681
|
+
|
682
|
+
it 'should convert the values stored in the options by passing them to the "convert_value" method before updating the container' do
|
683
|
+
opt = OS.new({:name => :o1, :group => :G3, :default => :abc})
|
684
|
+
@cont.add_option opt
|
685
|
+
@cont[:G2, :o2] = ''
|
686
|
+
@cont[:G3, :o1] = :abcd
|
687
|
+
widgets_data = [
|
688
|
+
OS.new({:caption => 'C1', :code => 'Qt::LineEdit.new{|w| w.object_name = "_G3__o1"}'}),
|
689
|
+
OS.new({:caption => 'C1', :code => 'KDE::UrlRequester.new{|w| w.object_name = "_G2__o2"}'})
|
690
|
+
]
|
691
|
+
widgets_data.each{|w| @cont.add_widget w}
|
692
|
+
dlg = @cont.dialog
|
693
|
+
flexmock(dlg.find_child(Qt::LineEdit, '_G3__o1')).should_receive(:text).once.and_return('xyz')
|
694
|
+
flexmock(dlg.find_child(KDE::UrlRequester, '_G2__o2')).should_receive(:url).once.and_return KDE::Url.from_path(ENV['HOME'])
|
695
|
+
manager = dlg.instance_variable_get(:@manager)
|
696
|
+
flexmock(manager).should_receive(:convert_value).once.with(KDE::Url.from_path(ENV['HOME']), '').and_return(ENV['HOME'])
|
697
|
+
flexmock(manager).should_receive(:convert_value).once.with('xyz', :abcd).and_return(:xyz)
|
698
|
+
flexmock(@cont).should_receive(:[]=).once.with(:G3, :o1, :xyz)
|
699
|
+
flexmock(@cont).should_receive(:[]=).once.with(:G2, :o2, ENV['HOME'])
|
700
|
+
manager.store_settings
|
701
|
+
end
|
702
|
+
|
703
|
+
end
|
704
|
+
|
705
|
+
describe 'Ruber::SettingsDialog#read_default_settings' do
|
706
|
+
|
707
|
+
before do
|
708
|
+
@mw = Qt::Widget.new
|
709
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
710
|
+
@back = flexmock('backend'){|m| m.should_ignore_missing}
|
711
|
+
@cont = Object.new
|
712
|
+
@cont.extend Ruber::SettingsContainer
|
713
|
+
@cont.send :setup_container, @back
|
714
|
+
@options = [
|
715
|
+
OS.new({:name => :o1, :default => 3, :group => :G1}),
|
716
|
+
OS.new({:name => :o2, :default => "abc", :group => :G2}),
|
717
|
+
OS.new({:name => :o3, :default => true, :group => :G1}),
|
718
|
+
]
|
719
|
+
@option_values = [-2, "xyz", false]
|
720
|
+
@options.each{|o| @cont.add_option o}
|
721
|
+
@options.zip(@option_values).each{|op, val| @cont[op.group, op.name] = val}
|
722
|
+
end
|
723
|
+
|
724
|
+
it 'should call the read methods associated to each option, passing as argument the default value of the option read from the option container' do
|
725
|
+
widgets_data = [
|
726
|
+
OS.new({:caption => 'C1', :code => 'Qt::LineEdit.new{|w| w.object_name = "_G2__o2"}'}),
|
727
|
+
OS.new({:caption => 'C1', :code => 'Qt::CheckBox.new{|w| w.object_name = "_G1__o3"}'})
|
728
|
+
]
|
729
|
+
widgets_data.each{|w| @cont.add_widget w}
|
730
|
+
dlg = @cont.dialog
|
731
|
+
flexmock(dlg.find_child(Qt::LineEdit, '_G2__o2')).should_receive(:text=).once.with(@options[1].default)
|
732
|
+
flexmock(dlg.find_child(Qt::CheckBox, '_G1__o3')).should_receive(:checked=).once.with(@options[2].default)
|
733
|
+
dlg.instance_variable_get(:@manager).read_default_settings
|
734
|
+
end
|
735
|
+
|
736
|
+
it 'should convert the default values of the options by passing them to the "convert_value" method before updating the widgets' do
|
737
|
+
opt = OS.new({:name => :o1, :group => :G3, :default => :abc})
|
738
|
+
@cont.add_option opt
|
739
|
+
@cont[:G2, :o2] = ENV['HOME']
|
740
|
+
@cont[:G3, :o1] = :xyz
|
741
|
+
widgets_data = [
|
742
|
+
OS.new({:caption => 'C1', :code => 'Qt::LineEdit.new{|w| w.object_name = "_G3__o1"}'}),
|
743
|
+
OS.new({:caption => 'C1', :code => 'KDE::UrlRequester.new{|w| w.object_name = "_G2__o2"}'})
|
744
|
+
]
|
745
|
+
widgets_data.each{|w| @cont.add_widget w}
|
746
|
+
dlg = @cont.dialog
|
747
|
+
flexmock(@cont).should_receive(:default).once.with(:G2, :o2).and_return('/usr')
|
748
|
+
flexmock(@cont).should_receive(:default).once.with(:G3, :o1).and_return(:abc)
|
749
|
+
flexmock(dlg.find_child(Qt::LineEdit, '_G3__o1')).should_receive(:text=).once.with('abc')
|
750
|
+
flexmock(dlg.find_child(KDE::UrlRequester, '_G2__o2')).should_receive(:url=).once.with KDE::Url.from_path('/usr')
|
751
|
+
manager = dlg.instance_variable_get(:@manager)
|
752
|
+
flexmock(manager).should_receive(:convert_value).once.with('/usr', KDE::Url.new).and_return(KDE::Url.from_path('/usr'))
|
753
|
+
flexmock(manager).should_receive(:convert_value).once.with(:abc, '').and_return('abc')
|
754
|
+
manager.read_default_settings
|
755
|
+
end
|
756
|
+
|
757
|
+
end
|
758
|
+
|
759
|
+
describe 'Ruber::SettingsDialogManager#settings_changed' do
|
760
|
+
|
761
|
+
it 'should enable the Apply button of the dialog' do
|
762
|
+
@mw = Qt::Widget.new
|
763
|
+
flexmock(Ruber).should_receive(:[]).with(:main_window).and_return(@mw).by_default
|
764
|
+
back = flexmock('backend'){|m| m.should_ignore_missing}
|
765
|
+
cont = Object.new
|
766
|
+
cont.extend Ruber::SettingsContainer
|
767
|
+
cont.send :setup_container, back
|
768
|
+
dlg = cont.dialog
|
769
|
+
flexmock(dlg).should_receive(:enable_button_apply).once.with(true)
|
770
|
+
dlg.instance_variable_get(:@manager).send :settings_changed
|
771
|
+
end
|
772
|
+
|
773
|
+
end
|