Class: QObject
- Inherits:
-
Gtk::HBox
show all
- Includes:
- ManqodCommon
- Defined in:
- lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb
Overview
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])
Constant Summary
ManqodCommon::CRITICAL, ManqodCommon::DEBUG, ManqodCommon::ERROR, ManqodCommon::INFO, ManqodCommon::NORMAL, ManqodCommon::WARNING
Constants included
from Eprint
Eprint::DOMAIN, Eprint::LEVEL
Instance Attribute Summary collapse
Instance Method Summary
collapse
#add_where, #admin, #admin_cache, #admin_qrow, #admin_rows, #backtrace_to_debug, #cache, #changed_ids_of_base, #client, #client_fields, #client_image_of_id, #client_qrow, #client_query, #client_rows, #eeval, #escape_string, #getBinding, #guess_base, #guess_table, #image_of_id, #lzero, #manqod_db, #measure, #myexec, #nick, #nick_id, #number_format, #qrow, #query, #reconnect_manqod_db, #rows, #run_events, #send_message, #sendmail, #set_manqod_db_uri, #set_nick
Methods included from Eprint
#ecode, #edebug, #eerror, #einfo, #enormal, #eprint, #ewarn, #gtk_set_edebug, #set_edebug, #tell_exception
Constructor Details
#initialize(q, link_or_fields = nil) ⇒ QObject
q - the QueryBuilder link_or_fields - link: an object from the RelationBuilder - fields: the fields from the table ‘qobjects`
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 12
def initialize(q,link_or_fields=nil)
whsv=false
begin
whsv=Gtk::SourceView::BUILD_VERSION
rescue => err
einfo("no Gtk::SourceView, falling back")
end
super() pack_start(Gtk::ScrolledWindow.new.set_policy(Gtk::PolicyType::AUTOMATIC,Gtk::PolicyType::NEVER).set_shadow_type(Gtk::ShadowType::NONE).add(@widget=whsv ? Gtk::SourceView.new : Gtk::TextView.new))
@rel_reverted=false
@q=q
@custom="false"
case link_or_fields.class.name
when "Hash" then
@my_id=link_or_fields["id"]
@obj_type=link_or_fields["obj_type"]
@obj_id=link_or_fields["obj_id"]
@field=link_or_fields["field"]
@custom=link_or_fields["custom"]
@rel_reverted=!@field.nil? && @field.include?("reverted")
set_link_from_data
when "RField" then
@link=link_or_fields
@my_id=nil
@obj_type="f"
@field=link.field_name
@obj_id=link.table.table_id
store
when "RTable" then
@link=link_or_fields
@my_id=nil
@obj_type="b"
@obj_id=link.table_id
store
when "Relation" then
@link=link_or_fields
@my_id=nil
@obj_type="r"
@obj_id=link.relation_id.to_i
store
else edebug("unknown link: #{@link}(#{link_or_fields.class.name})","relation-builder",WARNING)
end
if whsv
@widget.buffer.set_language(Gtk::SourceLanguageManager.new.get_language("sql"))
@widget.set_auto_indent(true).
set_highlight_current_line(true).
set_indent_on_tab(true).
set_indent_on_tab(true).
set_indent_width(4)
end
@widget.set_editable(is_custom?)
@widget.modify_base(Gtk::StateType::NORMAL,Gdk::Color.parse("yellow")) if is_custom?
@widget.signal_connect("focus-out-event"){|me,ev|
@field=text
store
@q.update(@q)
false
}
@q.qobjects.push(self)
case @obj_type
when "b" then @q.from.pack_start(self,false,false)
when "f" then
@q.select.pack_start(self,false,false)
pack_start(rmbutton=Gtk::Button.new.set_image(Gtk::Image.new(Gtk::Stock::CANCEL,Gtk::IconSize::MENU)).set_relief(Gtk::ReliefStyle::NONE),false)
rmbutton.signal_connect("clicked"){|me| self.delete}
when "r" then
@q.from.pack_start(self,false,false)
pack_start(rotbutton=Gtk::ToggleButton.new.set_image(Gtk::Image.new(Gtk::Stock::REFRESH,Gtk::IconSize::MENU)).set_relief(Gtk::ReliefStyle::NONE),false)
pack_start(rmbutton=Gtk::Button.new,false)
rmbutton.set_image(Gtk::Image.new(Gtk::Stock::CANCEL,Gtk::IconSize::MENU)).set_relief(Gtk::ReliefStyle::NONE).signal_connect("clicked"){|me| self.delete}
rotbutton.set_active(@rel_reverted)
rotbutton.signal_connect("toggled"){|me|
@rel_reverted=me.active?
store
@q.update(@q)
}
end
show_all
case @link.class.name
when "RField","Relation" then @link.set_active(true)
end
end
|
Instance Attribute Details
#link ⇒ Object
Returns the value of attribute link.
96
97
98
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 96
def link
@link
end
|
#obj_id ⇒ Object
Returns the value of attribute obj_id.
96
97
98
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 96
def obj_id
@obj_id
end
|
#obj_type ⇒ Object
Returns the value of attribute obj_type.
96
97
98
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 96
def obj_type
@obj_type
end
|
Instance Method Details
#center_on_link ⇒ Object
264
265
266
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 264
def center_on_link
link.center_on_me unless link.nil?
end
|
#delete ⇒ Object
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 221
def delete
query("delete from `qobjects` where id='#{@my_id}'") if @my_id
@q.qobjects.delete(self)
self.destroy
if is_custom?
@q.update(@q)
else
case @link.class.name
when "RField" then @link.set_active(false)
when "Relation" then @link.set_active(false)
end
end
end
|
#find_base_dir(rel, been_there = nil) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 103
def find_base_dir(rel,been_there=nil)
if been_there.nil?
been_there=Array.new
end
been_there.push(rel.relation_id)
ret=nil
ret=rel.rfield1 if rel.rfield1.table.table_id.to_i == @q.base_object.obj_id.to_i
ret=rel.rfield2 if rel.rfield2.table.table_id.to_i == @q.base_object.obj_id.to_i
unless ret
@q.rb.relations.each_pair{|rel_id,r|
unless been_there.include?(r.relation_id)
if r.rfield1.table.table_id == rel.rfield1.table.table_id or r.rfield2.table.table_id == rel.rfield1.table.table_id
if other_dir=find_base_dir(r,been_there)
ret=rel.rfield1
end
end
if r.rfield1.table.table_id == rel.rfield2.table.table_id or r.rfield2.table.table_id == rel.rfield2.table.table_id
if other_dir=find_base_dir(r,been_there)
ret=rel.rfield2
end
end
break if ret
end
}
end
ret
end
|
#gen_text ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 131
def gen_text
ret=""
if is_custom?
ret=@field || ""
else
begin
case @obj_type
when "f" then ret="`#{@link.table.table}`.`#{@link.field_name}`#{"," unless last_field?}"
when "r" then
dir=find_base_dir(@link)
dir=@link.other_field(dir) if @rel_reverted edebug("field to base: #{dir}","relation-builder",INFO)
if dir
other_field=@link.other_field(dir)
edebug("field to base other_field: #{other_field}","relation-builder",INFO)
if @link.rel_name == ""
ret="left join `#{other_field.table.table}` on `#{other_field.table.table}`.`#{other_field.field_name}` = `#{dir.table.table}`.`#{dir.field_name}`"
else
ret="left join `#{other_field.table.table}` as #{@link.rel_name} on `#{@link.rel_name}`.`#{other_field.field_name}` = `#{dir.table.table}`.`#{dir.field_name}`"
end
unless @link.rel_custom == ""
ret="#{ret} and #{@link.rel_custom}"
end
else
ret="can't reach base"
end
when "b" then
ret="`#{@link.table}`"
else ret="unknown object type"
end
rescue =>err
edebug("#{err}, #{backtrace_to_debug(err)}\n","relation-builder","warning")
ret="unavailable object"
end
end
ret
end
|
#inspect ⇒ Object
256
257
258
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 256
def inspect
"QObject of #{@link}(#{@obj_type} id:#{@my_id})"
end
|
#is_custom? ⇒ Boolean
98
99
100
101
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 98
def is_custom?
return false if @custom.nil?
@custom == "true"
end
|
#last_field? ⇒ Boolean
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 237
def last_field?
last_field=nil
@q.qobjects.reverse_each{|qobject|
if qobject.obj_type == "f"
last_field = qobject
break
end
}
last_field == self
end
|
#set_link(new_link) ⇒ Object
187
188
189
190
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 187
def set_link(new_link)
@link=new_link
self
end
|
#set_link_from_data ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 169
def set_link_from_data
unless is_custom?
@link=case @obj_type
when "b" then @q.rb.table_by_id(@obj_id)
when "f" then if table=@q.rb.table_by_id(@obj_id) then table.fields[@field]; end
when "r" then @q.rb.relations[@obj_id]
else
edebug("unknown type: #{@obj_type}","relation-builder",WARNING)
nil
end
end
update
end
|
#set_obj_id(new_obj_id) ⇒ Object
191
192
193
194
195
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 191
def set_obj_id(new_obj_id)
@obj_id=new_obj_id
set_link_from_data
store
end
|
#set_text(new_text) ⇒ Object
248
249
250
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 248
def set_text(new_text)
@widget.buffer.set_text(new_text)
end
|
#store ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 197
def store
edebug("storing(#{@my_id})","relation-builder")
if is_custom?
isql="`obj_id`='#{@obj_id}', `obj_type`='#{@obj_type}', `field`='#{escape_string(@field)}', `custom`='#{@custom}', `query_id`='#{@q.query_id}'"
else
isql=nil
case @link.class.name
when "RField" then isql="`obj_id`='#{@obj_id}', `field`='#{@link.field_name}', `obj_type`='#{@obj_type}', `query_id`='#{@q.query_id}'"
when "RTable" then isql="`obj_id`='#{@obj_id}', `obj_type`='#{@obj_type}', `query_id`='#{@q.query_id}'"
when "Relation" then isql="`obj_id`='#{@obj_id}', `obj_type`='#{@obj_type}', `query_id`='#{@q.query_id}', `field`='#{"reverted" if @rel_reverted}'"
else edebug("don't store: #{link.class.name}","relation-builder",INFO)
end
end
if isql
if @my_id
sql="update `qobjects` set #{isql} where `id`='#{@my_id}'"
else
sql="insert into `qobjects` set #{isql}"
end
query(sql)
@my_id=qrow("select id from `qobjects` order by id desc limit 1")["id"] unless @my_id
end
end
|
#text ⇒ Object
252
253
254
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 252
def text
@widget.buffer.text
end
|
#to_s ⇒ Object
260
261
262
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 260
def to_s
inspect
end
|
#update ⇒ Object
184
185
186
|
# File 'lib/FormHolder/Form/InputHolder/QBuilder/QObject.rb', line 184
def update
@widget.buffer.set_text(gen_text)
end
|