class DomModel
Public Class Methods
new(document, parent)
click to toggle source
Calls superclass method
# File examples/itemviews/simpledommodel/dommodel.rb, line 30 def initialize(document, parent) super(parent) @domDocument = document @rootItem = DomItem.new(@domDocument, 0) end
Public Instance Methods
columnCount(parent = Qt::ModelIndex.new)
click to toggle source
# File examples/itemviews/simpledommodel/dommodel.rb, line 36 def columnCount(parent = Qt::ModelIndex.new) return 3 end
data(index, role)
click to toggle source
# File examples/itemviews/simpledommodel/dommodel.rb, line 40 def data(index, role) if !index.valid? return Qt::Variant.new end if role != Qt::DisplayRole return Qt::Variant.new end item = index.internalPointer node = item.node attributes = [] attributeMap = node.attributes case index.column when 0 return Qt::Variant.new(node.nodeName) when 1 for i in 0...attributeMap.length attribute = attributeMap.item(i) attributes << attribute.nodeName() + '="' + attribute.nodeValue() + '"' end return Qt::Variant.new(attributes.join(" ")) when 2 if node.nodeValue.nil? return Qt::Variant.new else return Qt::Variant.new(node.nodeValue().split("\n").join(" ")) end else return Qt::Variant.new end end
flags(index)
click to toggle source
# File examples/itemviews/simpledommodel/dommodel.rb, line 75 def flags(index) if !index.valid? return Qt::ItemIsEnabled end return Qt::ItemIsEnabled | Qt::ItemIsSelectable end
headerData(section, orientation, role = Qt::DisplayRole)
click to toggle source
# File examples/itemviews/simpledommodel/dommodel.rb, line 83 def headerData(section, orientation, role = Qt::DisplayRole) if orientation == Qt::Horizontal && role == Qt::DisplayRole case section when 0 return Qt::Variant.new(tr("Name")) when 1 return Qt::Variant.new(tr("Attributes")) when 2 return Qt::Variant.new(tr("Value")) else return Qt::Variant.new end end return Qt::Variant.new end
index(row, column, parent = Qt::ModelIndex.new)
click to toggle source
# File examples/itemviews/simpledommodel/dommodel.rb, line 100 def index(row, column, parent = Qt::ModelIndex.new) if !parent.valid? parentItem = @rootItem else parentItem = parent.internalPointer() end childItem = parentItem.child(row) if ! childItem.nil? return createIndex(row, column, childItem) else return Qt::ModelIndex.new end end
parent(child)
click to toggle source
# File examples/itemviews/simpledommodel/dommodel.rb, line 115 def parent(child) if !child.valid? return Qt::ModelIndex.new end childItem = child.internalPointer() parentItem = childItem.parent() if parentItem.nil? || parentItem == @rootItem return Qt::ModelIndex.new end return createIndex(parentItem.row(), 0, parentItem) end
rowCount(parent = Qt::ModelIndex.new)
click to toggle source
# File examples/itemviews/simpledommodel/dommodel.rb, line 130 def rowCount(parent = Qt::ModelIndex.new) if !parent.valid? parentItem = @rootItem else parentItem = parent.internalPointer end return parentItem.node().childNodes().length end