Class: SubjectTableModel
- Defined in:
- lib/tmis/interface/models/subject_table_model.rb
Overview
~~~~~~~~~~~~~~~~~~~~~~~~~~
Instance Method Summary collapse
- #columnCount(parent) ⇒ Object
- #data(index, role = Qt::DisplayRole) ⇒ Object
- #flags(index) ⇒ Object
- #headerData(section, orientation, role = Qt::DisplayRole) ⇒ Object
-
#initialize(subjects, parent) ⇒ SubjectTableModel
constructor
A new instance of SubjectTableModel.
- #insert_new ⇒ Object
- #refresh ⇒ Object
- #remove_current ⇒ Object
- #rowCount(parent) ⇒ Object
- #setData(index, variant, role = Qt::EditRole) ⇒ Object
Constructor Details
#initialize(subjects, parent) ⇒ SubjectTableModel
Returns a new instance of SubjectTableModel.
7 8 9 10 11 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 7 def initialize(subjects, parent) super() @subjects = subjects @view = parent end |
Instance Method Details
#columnCount(parent) ⇒ Object
22 23 24 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 22 def columnCount(parent) 1 end |
#data(index, role = Qt::DisplayRole) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 26 def data(index, role = Qt::DisplayRole) invalid = Qt::Variant.new return invalid unless role == Qt::DisplayRole or role == Qt::EditRole subject = @subjects[index.row] return invalid if subject.nil? v = case index.column when 0 subject.title else raise "invalid column #{index.column}" end || '' Qt::Variant.new(v) end |
#flags(index) ⇒ Object
52 53 54 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 52 def flags(index) Qt::ItemIsEditable | super(index) end |
#headerData(section, orientation, role = Qt::DisplayRole) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 40 def headerData(section, orientation, role = Qt::DisplayRole) invalid = Qt::Variant.new return invalid unless role == Qt::DisplayRole v = case orientation when Qt::Horizontal %w(Название)[section] else '' end Qt::Variant.new(v) end |
#insert_new ⇒ Object
73 74 75 76 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 73 def insert_new @subjects.prepend(Subject.new) emit layoutChanged() end |
#refresh ⇒ Object
13 14 15 16 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 13 def refresh @subjects = Subject.all emit layoutChanged() end |
#remove_current ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 78 def remove_current if @view.currentIndex.valid? subject = @subjects[@view.currentIndex.row] unless subject.stub subject.try(:destroy) @subjects.delete_at(@view.currentIndex.row) emit layoutChanged() @view.currentIndex = createIndex(-1, -1) end end end |
#rowCount(parent) ⇒ Object
18 19 20 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 18 def rowCount(parent) @subjects.size end |
#setData(index, variant, role = Qt::EditRole) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/tmis/interface/models/subject_table_model.rb', line 56 def setData(index, variant, role = Qt::EditRole) if index.valid? and role == Qt::EditRole subject = @subjects[index.row] case index.column when 0 subject.title = variant.toString.force_encoding('UTF-8') else raise "invalid column #{index.column}" end subject.save emit dataChanged(index, index) true else false end end |