Class: Clevic::Delegate

Inherits:
Qt::ItemDelegate
  • Object
show all
Includes:
FieldValuer
Defined in:
lib/clevic/delegate.rb,
lib/clevic/qt/delegate.rb,
lib/clevic/swing/delegate.rb

Overview

This has both a field and an entity, so it’s a perfect candidate for including FieldValuer, which it does.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FieldValuer

#attribute_value, #attribute_value=, #display_value, #edit_value, #edit_value=, #find_related, #raw_value, #text_value=, #tooltip, valuer, #valuer, #writer

Constructor Details

#initialize(field) ⇒ Delegate

Returns a new instance of Delegate.



10
11
12
13
# File 'lib/clevic/delegate.rb', line 10

def initialize( field )
  super()
  @field = field
end

Instance Attribute Details

#entityObject

This is the ORM entity instance for which this delegate is editing a single field. It needs to be the entire entity so we can set the edited field value on it.



18
19
20
# File 'lib/clevic/delegate.rb', line 18

def entity
  @entity
end

#fieldObject (readonly)

the Clevic::Field instance which this delegate edits.



24
25
26
# File 'lib/clevic/delegate.rb', line 24

def field
  @field
end

#parentObject

The parent widget of this delegate / this delegate’s widget



21
22
23
# File 'lib/clevic/delegate.rb', line 21

def parent
  @parent
end

Instance Method Details

#attributeObject



26
27
28
# File 'lib/clevic/delegate.rb', line 26

def attribute
  field.attribute
end

#editorEvent(event, model, style_option_view_item, model_index) ⇒ Object

This catches the event that begins the edit process.



15
16
17
18
19
# File 'lib/clevic/qt/delegate.rb', line 15

def editorEvent( event, model, style_option_view_item, model_index )
  # See qt Clevic::TableView
  parent.respond_to?( "before_edit_index=" ) && parent.before_edit_index = model_index
  super
end

#entity_classObject



30
31
32
# File 'lib/clevic/delegate.rb', line 30

def entity_class
  field.entity_class
end

#full_editObject

change the visual state of the editor to the biggest / most space-consuming it can be. This grew out of combo boxes having a drop-down that can show or hide.



42
43
# File 'lib/clevic/delegate.rb', line 42

def full_edit
end

#inspectObject



37
38
39
# File 'lib/clevic/swing/delegate.rb', line 37

def inspect
  "<#{self.class.name} native=#{native} needs_pre_selection=#{needs_pre_selection?}>"
end

#is_combo?Boolean

assume this is not a combo delegate. That will come later.

Returns:

  • (Boolean)


35
36
37
# File 'lib/clevic/delegate.rb', line 35

def is_combo?
  false
end

#minimal_editObject

change the visual state of the editor to the smallest / least space-consuming it can be. This grew out of combo boxes having a drop-down that can show or hide.



48
49
# File 'lib/clevic/delegate.rb', line 48

def minimal_edit
end

#nativeObject

Return something useful if this should use the default GUI framework mechanism for table editing. Default is false, so native framework won’t be used. For Java/Swing, this would return the a class object indicating the type of data, eg java.lang.Boolean, or java.lang.String or something from JTable.setDefaultEditor



33
34
35
# File 'lib/clevic/swing/delegate.rb', line 33

def native
  false
end

#needs_pre_selection?Boolean

workaround for broken JTable editing starts

Returns:

  • (Boolean)


24
25
26
# File 'lib/clevic/swing/delegate.rb', line 24

def needs_pre_selection?
  false
end

#show_message(msg, &block) ⇒ Object

FIXME this must actually show a message, and the Qt code must use it too



13
14
15
16
17
18
19
20
21
# File 'lib/clevic/swing/delegate.rb', line 13

def show_message( msg, &block )
  if block_given?
    @message_receivers << block
  else
    @message_receivers.each do |receiver|
      receiver.call( msg )
    end
  end
end

#updateEditorGeometry(editor, style_option_view_item, model_index) ⇒ Object

Figure out where to put the editor widget, taking into account the sizes of the headers TODO most of the subclasses are probably the same as this



7
8
9
10
11
12
# File 'lib/clevic/qt/delegate.rb', line 7

def updateEditorGeometry( editor, style_option_view_item, model_index )
  rect = style_option_view_item.rect
  rect.set_width( [editor.size_hint.width,rect.width].max )
  rect.set_height( editor.size_hint.height )
  editor.set_geometry( rect )
end