[Kde-bindings] document extension interfaces missing for KTextEditor::Document in korundum4

Stefano Crocco stefano.crocco at alice.it
Wed Aug 6 06:49:22 UTC 2008


On Tuesday 05 August 2008, Richard Dale wrote:
> On Tuesday 05 August 2008 08:40:58 Stefano Crocco wrote:
> > Maybe this is a known issue, but I decided to report about it anyway, in
> > case it wasn't. It seems that korundum4 doesn't include bindings for the
> > document extension interfaces listed here:
> > http://api.kde.org/4.x-api/kdelibs-apidocs/interfaces/ktexteditor/html/gr
> >ou p__kte__group__doc__extensions.html
> >
> > This is a sample program:
> >
> > require 'korundum4'
> > require 'ktexteditor'
> >
> > class AnnotationModel < KTextEditor::AnnotationModel
> >
> >   def data line, role
> >     Qt::Variant.new
> >   end
> >
> > end
> >
> > data = KDE::AboutData.new "kruby", "", KDE::ki18n("KRuby"), "0.0.1"
> > KDE::CmdLineArgs.init [], data
> >
> > app = KDE::Application.new
> > doc = KTextEditor::EditorChooser.editor('katepart').create_document( nil)
> > model = AnnotationModel.new
> > doc.setAnnotationModel model
> >
> > Running it, I get:
> >
> > prova.rb:18:in `method_missing': undefined method `setAnnotationModel'
> > for #<KTextEditor::Document:0xb58b2f80 objectName=""> (NoMethodError)
> > from prova.rb:18
> >
> > 
>
> The KTextEditor interfaces are incomplete in that you have to know which
> classes you can cast to other classes via qobject_cast in C++. It is
> actually implementation specific to the kate part that you can cast a
> KTextEditor::Document to a KTextEditor::AnnotationInterface. In other
> implementations you wouldn't be able to do that. To get round the problem
> in C# we added a qobject_cast method. For Ruby there is already a QtRuby
> cast_object_to() method, and that could be enhanced to use qt_metacast() so
> it would work in the KTextEditor:: classes. Maybe it should be renamed
> qobject_cast() too.
>
> -- Richard
>
> _______________________________________________
> Kde-bindings mailing list
> Kde-bindings at kde.org
> https://mail.kde.org/mailman/listinfo/kde-bindings

If I understand you correctly, I'll have to wait until cast_object_to is 
changed to use qt_metacast, right? Indeed, I tried to use it as it is, but, as 
you said, it doesn't work. The code I tested is the following:

require 'korundum4'
require 'ktexteditor'

class AnnotationModel < KTextEditor::AnnotationModel

  def data line, role
    puts "DATA"
    Qt::Variant.new
  end

end

data = KDE::AboutData.new "kruby", "", KDE::ki18n("KRuby"), "0.0.1"
KDE::CmdLineArgs.init [], data

app = KDE::Application.new
doc = KTextEditor::EditorChooser.editor('katepart').create_document( nil)
model = AnnotationModel.new

d = Qt::Internal.cast_object_to(doc, KTextEditor::AnnotationInterface)
d.setAnnotationModel model
p d.annotationModel.data 0, Qt::DisplayRole

It seems to work, until the last line, where it crashes. Also, calling

d.annotationModel.class

after 

d.setAnnotationModel model

gives KTextEditor::AnnotationModel instead of AnnotationModel.

Stefano



More information about the Kde-bindings mailing list