Zwabel’s Weblog

November 27, 2008

++codeCompletion, and Signals/Slots in KDevelop4

Filed under: KDevelop — zwabel @ 2:27 am

It’s quite a while since my last blog now. I’m still planning to present all the essential C++ support features in KDevelop4, but my plan is to polish each feature up a bit before I actually blog about it. This also serves as a nice motivation.🙂

In the last weeks, I have mainly worked on DUChain backend stuff, especially making it more efficient. Some important coneceptual scalability problems have been solved, although I have yet quite a few tricks in line to make the actual parsing faster. Temporarily I lost my motivation a little on this boring backend stuff, but in the last days I regained it, and implemented some long planned nice features that I’m going to present to you now.🙂

Signals/Slots
Most Qt programmers love the signals and slots, since they allow getting stuff up and running really fast. But there is also some annoying things about them. For example that they are managed through simple strings, where Qt doesn’t even know about the real scope of the involved types, which leads to simple string-matching instead of comparing the real types. Also you need to write the complete function signature whenever you use a singal/slot, and me personally, I tend to do little mistakes while doing that, which can lead to really annoying little bugs, that aren’t catched by the compiler. It becomes even worse when you try to do refactoring like renaming signals, slots, or some of the involved types. Since the SIGNAL and SLOT macros translate the signatures to strings, grep is until now the only thing that can be of assistance here.

Now, KDevelop4 is coming to rescue.🙂

The first thing needed was additionally recording the signatures of signals/slots in exactly the same way Qt sees them. This way, we can theoretically do exactly the same matching Qt does. But then there’s the problem of the SIGNAL/SLOT macros. With a correctly working preprocessor, those will leave relatively useless strings to the C++ parser. I have completely blocked these macros and internally replaced them with new macros, a new token, and some new structures in the parsing infrastructure, to _not_ do the same thing the compiler does. Instead, our C++ parser now completely processes the signature, and allows building uses for all involved types, and of course for the signals/slots themselves.

Together with these uses, now KDevelop4 allows you to see all places where a signal/slot is connected, intelligently rename it, and to intelligently rename any types involved in the signature. Of course, the uses are only built if a signal/slot with the given exact signature actually exists. Together with highlighting, this already now gives you an excellent tool to detect broken connections.

Essentially, this makes signal/slot connections a real well-understood first-class citizen of the DUChain.

Since people like screenshots, here you see how the uses of a slot are shown, and can be renamed.
Renaming

Signal/Slot Completion
Now the duchain integration allows excellent tracking of already existing connections. But the annoyance of actually writing the connections remains. In KDevelop3, there already was a quite cool code-completion for signals/slots, that inserted the correct complete signature four you, and thus saved you from typing. In KDevelop4 I had this thing on my list for a long time, and now finally I’ve implemented it. However since KDevelop4 is aiming a lot higher then the earlier version, this feature of course needed to be improved as well.🙂

So here you see the new Signal/Slot completion, with complete realistic signature-matching, which helps you conveniently connecting only fitting signals/slots to each other. As you see I’ve also worked a bit on the completion-widget. The highlighting colors are much softer now. This picture doesn’t show the interesting “matching” part yet, since every signal matches the connect(..) function.
signal completion

In this picture, you see how the correct signature was inserted, and a new completion-list was opened, this time asking for the slot that he signal should be connected to. As you see, the only 2 perfectly matching slots are shown directly at the top. Since you can connect signals to slots with less arguments, the argument-less slots are shown as matches too, although with lower match-quality.
slot completion

That’s it with signals/slots for now.

Builtin Operator Completion
One more thing that has been on my list for a long time, and that I’ve finally implemented, is completion for all builtin operators in C++, not only the overloaded ones. By completion I mean mainly getting the match-quality highlighted, and getting the “Best Matches” list at top. You will be wondering how often you use some kind of builtin operator, from my experience this saves from a _lot_ of typing, since in many cases the wanted item is right at the top.

Builtin operator completion

Also I have added argument-hinting for the “return” keyword, which means you can also get best matches when returning a value from a function:
return completion

And that’s it for today. Hope you like the stuff, and as always, if you want KDevelop4 to get ready faster, consider getting your hands dirty.😉

18 Comments »

  1. KDevelop seems to become an amazing tool. It is stunning to see it take shape. Kudos to you all!

    I learned Python (I love it!) and recently started to play around with PyQt, but KDevelop really makes me want to write C++. If I wanted to take the plunge, where should I start? Is there a good introduction to C++ and Qt (or even KDE) somewhere available online which you would recommend for self-study?

    Thanks a lot!

    Comment by Pythonista ;) — November 27, 2008 @ 3:18 am

  2. Signal/Slot code completion will really be an excellent feature to have for KDE/Qt development. Looking forward to it.

    Comment by Seb Ruiz — November 27, 2008 @ 3:53 am

  3. wow! this is truly amazing and useful stuff. you may yet convert me from my cold dim vim. =)

    Comment by Aaron Seigo — November 27, 2008 @ 5:09 am

  4. I agree completely with what people have said, this is really great stuff. I’ve been happy enough with KDevelop3 until now (even for KDE4 stuff) but this is really making hard for me not to try KDevelop4 as it is today. Now, if I may point out a very minor issue, the popups seem to be too large sometimes, have you considered using a smaller font for them or maybe even using a non monospaced one?

    Comment by Sergio Pistone — November 27, 2008 @ 5:52 am

  5. Awesome, just awesome. You’re making a Visual Studio @ Windows-user totally jealous here!

    I do agree with the comment on the fonts, and the arrow images seem to be a bit too much as well (they are everywhere, but why are they there?). But aside from that, I may actually have to install Linux / KDE again, just to try the awesome features you’re coming up with lately.

    btw. Would it be possible to also use the nice selection highlight from the theme? (as seen in the listview)

    Comment by Hollander — November 27, 2008 @ 6:27 am

  6. wow – really great and useful features!

    ++david😀

    Comment by Niko — November 27, 2008 @ 8:02 am

  7. nice!!

    indeed, smaller fonts would be better. Also, the colors are really a bit too much I think, they don’t seem to fit very well together. Maybe ask the oxygen guys some tips about this?

    Comment by Tom — November 27, 2008 @ 10:27 am

  8. I agree about the colors and the fonts. The arrows reveal their usefulness only when you actually use the completion (though I’m still not sure this is needed in that place) or a screencast. The completion list actually is a tree which can reveal all the information the contextbrowser contains if you want it to (by pressing left/right arrow IIRC). So thats just weird with the screenshots, it makes more sense when using the app. They might also benefit from being a bit smaller in the completion list though.

    Comment by Andreas Pakulat — November 27, 2008 @ 10:35 am

  9. @Pythonista: Google should help you😉

    Font-size: You’ve got to consider that I have a large high-resolution screen. The font-size in the completion-list always matches the one in the editor I think, which should be fine.. just reduce that one!

    Popup size: I’m planning to reduce the expansion a bit, by showing the typedef-names instead of the full type when useful.

    Arrows: The arrows might get replaces with some lighter arrows. But anyway, that’s just trivial design stuff.. they do make sense there, because they indicate when items can be expanded.

    Colors: No need for oxygen here. It’s not a question of design, but follows a simple common rule: Green=Good. I’m thinking about weakening the blue though, so that only “matching” items are highlighted with green, and others not at all.

    Comment by zwabel — November 27, 2008 @ 11:45 am

  10. @Pythonista – here is nice book

    http://cartan.cas.suffolk.edu/oopdocbook/opensource/

    Also official documentation is very nice:

    http://doc.trolltech.com/

    And off course best C++ book I’ve read: “Thinking in C++”

    Comment by kojot — November 27, 2008 @ 12:01 pm

  11. @Aaron Seigo – I love vim to and guess what… kate and kdevelop will have vim key bindings😀

    Comment by kojot — November 27, 2008 @ 12:03 pm

  12. Really nice work. I’m curious trying out static SIGNAL/SLOT validation which is definately a killer feature!

    The only thing I’m still missing in KDevelop4 is a working class browser which shows all classes in the project. When I tried it a few weeks ago it only showed the classes of open files. I wonder wether somebody is working on that?

    Comment by Bernhard — November 27, 2008 @ 3:07 pm

  13. @Bernhard:
    The class-browser is a bit orphaned atm. For me it doesn’t have a high priority since I don’t use it, and Hamish Rodda also isn’t working on it any more. If noone is faster I will of course polish it up before the release, but don’t expect too much in the near future, since there’s many things with higher priority.

    Although your problem doesn’t sound like a class-browser problem, but rather it sounds like you don’t have full-project parsing enabled. You can find that option in Settings -> Project. However you shoudn’t enable it yet if your project is very large.

    Comment by zwabel — November 27, 2008 @ 6:51 pm

  14. @zwabel: Well, if the arrows are signifying a tree-like structure, why not use the code which already exists in the widget styles for drawing expand/contract? That is designed for the purpose, a lot lighter on the eye, and most importantly more consistent with other parts of the system🙂 Thus adding a little bit of extra nifty to existing nifty, which is never a bad thing😉

    Comment by Dan Leinir Turthra Jensen — November 27, 2008 @ 9:20 pm

  15. @dan leinir:
    The whole thing is not implemented as a tree. The items can just “become bigger”, showing additional information. So QTreeView won’t paint anything for us here. It’s only used for grouping.

    Btw. I’ve already added lighter arrows in current svn, and maybe we can even use the QStyle arrows at some point.

    Comment by zwabel — November 27, 2008 @ 9:39 pm

  16. […] ++codeCompletion, and Signals/Slots in KDevelop4 It’s quite a while since my last blog now. I’m still planning to present all the essential C++ support […] […]

    Pingback by Top Posts « WordPress.com — November 28, 2008 @ 12:34 am

  17. @zwabel: i wasn’t suggesting using an actual treeview for it, just the bit of code which draws the expand/contract images🙂 As you said, that is exactly what those arrows signify (and not all widget styles use arrows for that, so by forcing arrows here, their metaphor gets confused with other navigational aides)

    Comment by Dan Leinir Turthra Jensen — November 28, 2008 @ 12:37 pm

  18. […] blog-post I’ve already written about automatic signal/slot matching and completion(See this). The code-completion box shows you the appropriate connectable signals and slots, and also shows […]

    Pingback by Creating a Qt slot, the cool way « Zwabel’s Weblog — February 13, 2009 @ 10:54 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: