Class: Qt::ModelIndex
- Defined in:
- lib/qtext/extensions.rb,
lib/qtext/object_table_model.rb
Class Method Summary collapse
-
.invalid ⇒ Object
Because using Qt::ModelIndex.new the whole time is wasteful.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
sort by row, then column TODO This is in Clevic::TableIndex now.
-
#choppy(*args, &block) ⇒ Object
CHange and cOP(P)Y - make a new index based on this one, modify the new index with values from the parameters, the args hash or the block.
- #entity ⇒ Object
- #inspect ⇒ Object
- #old_inspect ⇒ Object
Class Method Details
.invalid ⇒ Object
Because using Qt::ModelIndex.new the whole time is wasteful
151 152 153 |
# File 'lib/qtext/extensions.rb', line 151 def self.invalid @@invalid ||= ModelIndex.new end |
Instance Method Details
#<=>(other) ⇒ Object
sort by row, then column TODO This is in Clevic::TableIndex now.
172 173 174 175 176 177 178 179 |
# File 'lib/qtext/extensions.rb', line 172 def <=>( other ) row_comp = self.row <=> other.row if row_comp == 0 self.column <=> other.column else row_comp end end |
#choppy(*args, &block) ⇒ Object
CHange and cOP(P)Y - make a new index based on this one, modify the new index with values from the parameters, the args hash or the block. The block will instance_eval with no args, or pass self if there’s one arg. You can also pass two parameters, interpreted as row, columns. Examples:
new_index = index.choppy { row 10; column 13 }
new_index = index.choppy { row 10; column 13 }
new_index = index.choppy( 1,3 )
new_index = index.choppy { |i| i.row += 1 }
new_index = index.choppy :row => 16
same_index = index.choppy
If the column value is not a Numeric, a method called field_column will be called on the model with column value. field_column should return the column index.
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 223 224 225 226 227 228 |
# File 'lib/qtext/extensions.rb', line 198 def choppy( *args, &block ) return ModelIndex.invalid unless self.valid? # initialize with defaults stash = IndexCollector.new( row, column ) case args.size when 0,1 # args.first is a hash, or nil stash.collect( args.first, &block ) when 2 # args are two parameters - row, column stash.row, stash.column = args stash.collect( &block ) else raise TypeError.new( "incorrect args #{args.inspect}" ) end # convert a column name to a column index unless stash.column.is_a?( Numeric ) stash.column = model.field_column( stash.column ) end # return an invalid index if it's out of bounds, # or the choppy'd index if it's OK. if stash.row >= model.row_count || stash.column >= model.column_count ModelIndex.invalid else model.create_index( stash.row.to_i, stash.column.to_i ) end end |
#entity ⇒ Object
6 7 8 |
# File 'lib/qtext/object_table_model.rb', line 6 def entity model.collection[row] end |
#inspect ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/qtext/extensions.rb', line 156 def inspect # need the self here otherwise Qt bindings get confused. if self.valid? #<Qt::ModelIndex:0xb6004e8c> # fetch address from superclass inspect super =~ /ModelIndex:(.*)>/ # format nicely #~ "#<Qt::ModelIndex:#{$1} xy=(#{row},#{column}) gui_value=#{gui_value}>" "#<Qt::ModelIndex:#{$1} xy=(#{row},#{column})>" else "#<Qt::ModelIndex invalid>" end end |
#old_inspect ⇒ Object
155 |
# File 'lib/qtext/extensions.rb', line 155 alias_method :old_inspect, :inspect |