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
143 144 145 |
# File 'lib/qtext/extensions.rb', line 143 def self.invalid @@invalid ||= ModelIndex.new end |
Instance Method Details
#<=>(other) ⇒ Object
sort by row, then column TODO This is in Clevic::TableIndex now.
164 165 166 167 168 169 170 171 |
# File 'lib/qtext/extensions.rb', line 164 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.
190 191 192 193 194 195 196 197 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 |
# File 'lib/qtext/extensions.rb', line 190 def choppy( *args, &block ) return ModelIndex.invalid unless self.valid? # initialize with defaults stash = IndexCollector.new( row, column ) case args.size when 0 stash.gather( &block ) when 1 # args.first is a hash, or nil raise( TypeError, "not a hash" ) unless args.first.is_a?( Hash ) stash.gather( args.first, &block ) when 2 # args are two parameters - row, column stash.row, stash.column = args stash.gather( &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
5 6 7 |
# File 'lib/qtext/object_table_model.rb', line 5 def entity model.collection[row] end |
#inspect ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/qtext/extensions.rb', line 148 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
147 |
# File 'lib/qtext/extensions.rb', line 147 alias_method :old_inspect, :inspect |