Class: MyRendererModel
- Inherits:
-
Gtk::TreeModelFilter
- Object
- Gtk::TreeModelFilter
- MyRendererModel
show all
- Includes:
- ManqodCommon
- Defined in:
- lib/FormHolder/Form/InputHolder/Common/Model.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])
Defined Under Namespace
Classes: Filterer
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_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
Returns a new instance of MyRendererModel.
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
96
97
98
99
100
101
102
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
130
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
168
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 45
def initialize(pc)
@idx=Hash.new
@pc=pc
@typed=""
td=item["type_def"]
ta=Hash.new
@desc=Hash.new
@filterer=Filterer.new(self)
@column_order=Array.new
if multiselector?
ta[:multiselector]=:multiselector
column_order.push(:multiselector)
end
td.split("]").each{|t|
if first=t.index("[")
parts=t[first+1 .. t.length].split(":")
hkey=parts[0]
hval=parts[1]||""
hdesc=parts[2]||""
ta[hkey]=hval
@desc[hkey]=hdesc
column_order.push(hkey)
edebug("header keys: |#{hkey}|=>|#{ta[hkey]}|(#{@desc[hkey]})","form-combo")
end
}
if ta.empty?
@type_def={'cdisplay'=>"text"}
column_order.push('cdisplay')
else
@type_def=ta
end
@header_types=Array.new.push(String) @renderers=Hash.new
i=1
column_order.each{|key|
case type_def[key]
when :multiselector
if pc.class.name == "MyRendererList::List"
renderer=Gtk::CellRendererToggle.new.set_activatable(true)
column=Gtk::TreeViewColumn.new("",renderer, {:active => i})
pc.append_column(column)
renderer.signal_connect("toggled",i,self){|me,path,col,fmodel|
iter=fmodel.convert_iter_to_child_iter(fmodel.get_iter(path))
iter[col]=!iter[col]
}
.push(TrueClass)
renderers[key]=renderer
pc.parentM.set_multiselector(self)
else
ewarn("multiselector attribute can only be interpreted on a List Form item")
end
when "text"
renderer=Gtk::CellRendererText.new
case pc.class.name
when "MyRendererCombo","MyRendererConstCombo", "FieldCombo"
pc.pack_start(renderer,true)
pc.add_attribute(renderer,:text,i)
when "MyRendererList::List"
column=Gtk::TreeViewColumn.new(@desc[key]||"",renderer, {:text => i})
pc.append_column(column)
else
edebug("unknown parent widget for this model!","form-combo","error")
end
.push(String)
renderers[key]=renderer
when "pixbuf"
renderer=Gtk::CellRendererPixbuf.new
case pc.class.name
when "MyRendererCombo"
pc.pack_start(renderer,true)
pc.add_attribute(renderer,:pixbuf,i)
when "MyRendererList"
column=Gtk::TreeViewColumn.new(,renderer, {:pixbuf => i})
pc.append_column(column)
end
.push(Gdk::Pixbuf)
renderers[key]=renderer
when "toggle"
renderer=Gtk::CellRendererToggle.new
case pc.class.name
when "MyRendererCombo","MyRendererConstCombo", "FieldCombo"
pc.pack_start(renderer,true)
pc.add_attribute(renderer,:active,i)
when "MyRendererList::List"
column=Gtk::TreeViewColumn.new(key,renderer, {:active => i})
pc.append_column(column)
else
edebug("unknown parent widget for this model!","form-combo","error")
end
.push(TrueClass)
renderers[key]=renderer
when "hidden"
.push(String)
renderer=nil
else
renderer=nil
end
i=i+1 if renderer
}
@tree_key=pc.gtk_attribute("tree_key")
@tree=!@tree_key.nil?
.push(TrueClass) @column_of_visible=.size-1
@mymodel=if @tree then Gtk::TreeStore.new(*) else Gtk::ListStore.new(*) end
super(mymodel)
set_visible_column(@column_of_visible)
pc.set_model(self)
pc.set_row_separator_func{|model, iter|
iter[0]=='separator' or iter[1]=='---'
}
end
|
Instance Attribute Details
#column_order ⇒ Object
Returns the value of attribute column_order.
174
175
176
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 174
def column_order
@column_order
end
|
#filterer ⇒ Object
Returns the value of attribute filterer.
176
177
178
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 176
def filterer
@filterer
end
|
Returns the value of attribute header_types.
172
173
174
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 172
def
@header_types
end
|
#mymodel ⇒ Object
Returns the value of attribute mymodel.
170
171
172
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 170
def mymodel
@mymodel
end
|
#pc ⇒ Object
Returns the value of attribute pc.
169
170
171
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 169
def pc
@pc
end
|
#renderers ⇒ Object
Returns the value of attribute renderers.
175
176
177
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 175
def renderers
@renderers
end
|
#type_def ⇒ Object
Returns the value of attribute type_def.
173
174
175
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 173
def type_def
@type_def
end
|
#typed ⇒ Object
Returns the value of attribute typed.
171
172
173
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 171
def typed
@typed
end
|
Instance Method Details
#add_iter(row) ⇒ Object
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 224
def add_iter(row)
iter=if @tree then mymodel.append(if row[@tree_key].to_i == -1 then nil else find_iter_by_id(row[@tree_key])end) else mymodel.append end
iter[0]=row['id'] if row.has_key?("id")
iter[0]=row['cdata'] if row.has_key?("cdata")
@idx[row['id']]=iter.clone if row.has_key?("id")
i=0
column_order.each{|key|
if type_def.has_key?(key) i=i+1
case type_def[key]
when "text","hidden"
iter[i]=row[key].to_s
if row.has_key?(key) and !row[key].nil?
@max_col_widths[key]=row[key].to_s.length unless @max_col_widths.has_key?(key)
@max_col_widths[key]=row[key].to_s.length unless @max_col_widths[key] > row[key].to_s.length
end
when "pixbuf"
if row[key].class.name == "String"
if row[key].length > 3
a=Array.new
row[key].each_byte{|v|a.push(v)}
begin
if pixdata=Gdk::Pixdata.deserialize(a) then iter[i]=pixdata.to_pixbuf(true);end
rescue Gdk::PixbufError => err
end
else
iter[i]=client_image_of_id(row[key],"gtk-menu")
end
end
when 'toggle'
iter[i]=row[key] == 'true'
end
end
}
iter[@column_of_visible]=true
end
|
#admin ⇒ Object
327
328
329
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 327
def admin
parentM.admin
end
|
#cell_value(col, iter_id = pc.text) ⇒ Object
286
287
288
289
290
291
292
293
294
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 286
def cell_value(col,iter_id=pc.text)
fiter=nil
ret=nil
each {|model, path, iter| fiter=iter if iter[0].to_s==iter_id.to_s }
if fiter and c=column_order.index(col)
ret=fiter[c+1]
end
ret
end
|
#default ⇒ Object
333
334
335
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 333
def default
item["default"]
end
|
#find_iter_by_id(iter_id) ⇒ Object
296
297
298
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 296
def find_iter_by_id(iter_id)
@idx[iter_id]
end
|
311
312
313
314
315
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 311
def
c=0
@desc.each_value{|h| c+=1 if h.length>0}
c!=0
end
|
#item ⇒ Object
178
179
180
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 178
def item
pc.item
end
|
#multiselector? ⇒ Boolean
307
308
309
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 307
def multiselector?
pc.class.name == "MyRendererList::List" && pc.pc.pc.multiselector?
end
|
#my ⇒ Object
330
331
332
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 330
def my
parentM.my
end
|
#parentM ⇒ Object
321
322
323
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 321
def parentM
pc.parentM
end
|
#parentselected ⇒ Object
324
325
326
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 324
def parentselected
pc.parentselected
end
|
#refilter ⇒ Object
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 262
def refilter
mymodel.each{|model,path,iter|
if typed.nil? || typed == "" || iter[0] == 'separator' || iter[0] == '-1' then
iter[@column_of_visible]=true
else
j=0
model.n_columns.downto(1){|i|
if iter[i-1].class.name=="String"
j+=1 if iter[i-1].upcase.index(typed.upcase)
end
}
if j>0
i=iter.clone
while i=i.parent
i[@column_of_visible]=true
end
iter[@column_of_visible]=true
else
iter[@column_of_visible]=false
end
end
}
end
|
#to_s ⇒ Object
317
318
319
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 317
def to_s
"model of #{pc}"
end
|
#toggled_ids ⇒ Object
300
301
302
303
304
305
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 300
def toggled_ids
ti=Array.new
each {|model, path, iter| ti.push(iter[0]) if iter[1] == true} if multiselector?
ti
end
|
#update ⇒ Object
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/FormHolder/Form/InputHolder/Common/Model.rb', line 182
def update
pc.set_model(nil)
mymodel.clear
@idx.clear
if item["querysql"].length == 0 && sqlid=pc.gtk_attribute("query")
if sql=parentM.admin.qrow("select `sql` from `queries` where `id` = '#{sqlid}'")["sql"]
item["querysql"]=sql
end
end
if item['wantnew']
iter=if @tree then mymodel.append(nil) else mymodel.append end
iter[0]='-1';iter[@column_of_visible]=true
iter=if @tree then mymodel.append(nil) else mymodel.append end
iter[0]='separator';iter[@column_of_visible]=true
end
@max_col_widths=Hash.new
if item['field']
client_fields(item['querysql']){|field|
row=Hash.new
row['name']=field["name"]
row['id']=row["name"]
row['type']="#{field['type']}(#{field['length']}"+if field.has_key?("decimals") then "/#{field['decimals']}" else "" end + ")"
add_iter(row)
}
else
begin
if item['admin']
parentM.admin.rows(eeval("\"#{item['querysql']}\"")).each{|row| add_iter(row);}
else
parentM.rows(eeval("\"#{item['querysql']}\"")).each{|row| add_iter(row);}
end
rescue => err
retry if tell_exception("query error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
end
end if item['querysql'].length>5
@max_col_widths.each_pair{|key,col_width| renderers[key].set_width_chars(col_width) if renderers.has_key?(key)}
pc.set_model(self)
end
|