Class: Ruber::AnnotationModel

Inherits:
KTextEditor::AnnotationModel
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ruber/editor/document.rb,
lib/ruber/editor/document.rb,
lib/ruber/editor/document.rb

Defined Under Namespace

Classes: Annotation

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Enumerable

#find!

Signal Summary

Constructor Details

- (AnnotationModel) initialize(doc)

A new instance of AnnotationModel



553
554
555
556
557
558
# File 'lib/ruber/editor/document.rb', line 553

def initialize doc
  super()
  @doc = doc
  @annotations = Dictionary.alpha
  connect self, SIGNAL('annotation_changed(int)'), self, SIGNAL('lineChanged(int)')
end

Class Attribute Details

+ (Object) annotation_types (readonly)

Returns the value of attribute annotation_types



544
545
546
# File 'lib/ruber/editor/document.rb', line 544

def annotation_types
  @annotation_types
end

Class Method Details

+ (Object) register_annotation_type(type, back = nil, fore = nil)

Raises:

  • (ArgumentError)


547
548
549
550
551
# File 'lib/ruber/editor/document.rb', line 547

def self.register_annotation_type type, back = nil, fore = nil
  raise ArgumentError, "Annotation type #{type} has already been added" if 
  @annotation_types.has_key?(type)
  @annotation_types[type] = [back, fore].map{|i| i ? Qt::Variant.fromValue(i) : Qt::Variant.new}
end

Instance Method Details

- (Object) add_annotation(*args)



560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
# File 'lib/ruber/editor/document.rb', line 560

def add_annotation *args
  a = args.size == 1 ? args[0] : Annotation.new( *args )
  # TODO: see why this sometimes gives extremely weird errors
  #The begin/rescue clause is there to find out why sometimes I get a crash saying:
  # `<': comparison of Fixnum with Qt::Variant failed (ArgumentError)
  #       begin
  
  #         raise IndexError, "Invalid line: #{a.line}" unless a.line < @doc.lines
  #       rescue ArgumentError
  #         puts "a.line: #{a.line}(#{a.line.class})"
  #         puts "@doc.lines: #{@doc.lines}(#{@doc.lines.class})"
  #       end
  @annotations[a.line] = a
  emit annotations_changed
  emit annotation_changed( a.line)
end

- (Object) annotation(line) Also known as: []



589
590
591
# File 'lib/ruber/editor/document.rb', line 589

def annotation line
  @annotations[line]
end

- (Object) clear



606
607
608
609
610
# File 'lib/ruber/editor/document.rb', line 606

def clear
  @annotations.clear
  emit annotations_changed
  emit reset
end

- (Object) data(line, role)



577
578
579
580
581
582
583
584
585
586
587
# File 'lib/ruber/editor/document.rb', line 577

def data line, role
  a = @annotations[line]
  return Qt::Variant.new unless a
  case role
  when Qt::DisplayRole then Qt::Variant.new a.msg
  when Qt::ToolTipRole then Qt::Variant.new a.tool_tip
  when Qt::ForegroundRole then self.class.annotation_types[a.type][1]
  when Qt::BackgroundRole then self.class.annotation_types[a.type][0]
  else Qt::Variant.new
  end
end

- (Object) each



619
620
621
# File 'lib/ruber/editor/document.rb', line 619

def each
  @annotations.each_pair{|k, v| yield v}
end

- (Boolean) empty?

Returns:

  • (Boolean)


602
603
604
# File 'lib/ruber/editor/document.rb', line 602

def empty?
  @annotations.empty?
end

- (Boolean) has_annotation?(line)

Returns:

  • (Boolean)


594
595
596
# File 'lib/ruber/editor/document.rb', line 594

def has_annotation? line
  @annotations.has_key? line
end

- (Boolean) has_annotations?

Returns:

  • (Boolean)


598
599
600
# File 'lib/ruber/editor/document.rb', line 598

def has_annotations?
  !@annotations.empty?
end

- (Object) remove_annotation(line)



612
613
614
615
616
617
# File 'lib/ruber/editor/document.rb', line 612

def remove_annotation line
  if @annotations.delete line
    emit annotations_changed 
    emit annotation_changed( line )
  end
end

Signal Details

- annotations_changed

- annotation_changed(int arg1)