Class: DataStreamListModel

Inherits:
Qt::AbstractListModel
  • Object
show all
Defined in:
lib/roby/log/gui/data_displays.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(streams) ⇒ DataStreamListModel

Returns a new instance of DataStreamListModel.



10
11
12
13
# File 'lib/roby/log/gui/data_displays.rb', line 10

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

Instance Attribute Details

#streamsObject (readonly)

Returns the value of attribute streams.



9
10
11
# File 'lib/roby/log/gui/data_displays.rb', line 9

def streams
  @streams
end

Instance Method Details

#add_new(stream = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/roby/log/gui/data_displays.rb', line 54

def add_new(stream = nil)
  if stream
 emit beginInsertRows(Qt::ModelIndex.new, streams.size, streams.size)
 streams << stream
 emit endInsertRows()
  else
 insertRow(streams.size, Qt::ModelIndex.new)
  end
end

#data(index, role) ⇒ Object



25
26
27
28
29
# File 'lib/roby/log/gui/data_displays.rb', line 25

def data(index, role)
    return Qt::Variant.new unless role == Qt::DisplayRole && index.valid? && index.row < streams.size
    s = streams[index.row]
    return Qt::Variant.new(s.name + " [#{s.type}]")
end

#edit_at(index) ⇒ Object



31
32
33
34
35
# File 'lib/roby/log/gui/data_displays.rb', line 31

def edit_at(index)
    return unless index.valid? && index.row < streams.size
  edit(streams[index.row])
  emit dataChanged(index, index)
end

#flags(index) ⇒ Object



21
22
23
# File 'lib/roby/log/gui/data_displays.rb', line 21

def flags(index)
  Qt::ItemIsSelectable | Qt::ItemIsEnabled
end

#insertRow(row, parent) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/roby/log/gui/data_displays.rb', line 37

def insertRow(row, parent)
    emit beginInsertRows(parent, row, row)
  if stream = edit(nil)
 @streams.insert row, stream
 return true
  end
ensure
  emit endInsertRows()
end

#removeRow(row, parent) ⇒ Object



47
48
49
50
51
52
# File 'lib/roby/log/gui/data_displays.rb', line 47

def removeRow(row, parent)
    emit beginRemoveRows(parent, row, row)
    @streams.delete_at row
    emit endRemoveRows()
    true
end

#rowCount(parent) ⇒ Object



15
16
17
18
19
# File 'lib/roby/log/gui/data_displays.rb', line 15

def rowCount(parent)
  if parent.valid? then 0
  else streams.size
  end
end