edbee

Edbee screenshot

Last week I released edbee to Github.
Edbee in the essence is an editor QWidget designed for use with Qt.

edbee logo

Edbee screenshot

Some history

I've started with this editor component in the summer of 2012 as an in house product.
Edbee has been created because I needed a source-code editor for my Qt Application. I'm developing a very specialistic developers tool, which requires some advanced editor handling. Unfortunately my attempts with diverse standard products failed.

QTextEdit didn't fit my needs, because it was to complex at some points (The richtext part) and way to limited at other parts (replacing the document backend).
I've given it a try but it really didn't do what I needed it to do.

Scintilla was a much better attempt, except it gave me problems with editor-synchronisation. The cause for this was a sort of incompatibility Iv'e got with the messaging system that Scintilla uses and the connection-system of Qt. I probably could have solved this (and I've did solved part of it), but it required me to make considerable changes in the Scintilla source code. I really didn't like the idea of maintaining a fork of Scintilla. (Btw. Scintilla is a very nice editor-component used by several products like Scite and Notepad++)

This lead me to think I could write an editor myself, so it would fit my needs. This shouldn't be that hard, just move the cursor and draw some letters (so I thought). Well I was very wrong :)
I really like Sublime Text, it really has really some awesome features, so while writing this editor I just implement one of my favorite features: multi-caret support.
Well this last decision really made the development a much harder, especially the undo part.

When the editor was at a certain level I needed support for syntax highlighting, I've first tried to implement a system like the one that Scintilla uses, because of the simplicity of implementing it. But after realizing that I needed to write a lexer for every language I really freaked out and decided to stick with the Textmate/Sublime grammar files.

But using textmate grammer-files required the inclusion of scopes to identify items in the text. So I build in supporting classes for scopes. To recognize these scopes I needed to run the regular expressions used in the grammar files.
Running these regexps in Qt with QRegExp doesn't work. Really it doesn't I tried it..!! I've included Oniguruma for this (The regexp engine of Textmate, Sublime and Ruby)

Now I was able to identify the scopes in the editor. When I had the scopes It was more then logical to use the theme files of Textmate because these were scope-based.

Why Opensource it?

Well I don't see any real big market for it. To be honestly I don't think the quality of the editor at this moment is at the required level for a commercial product. Also I hope to improve the quality of this product by open sourcing it. Though I'm a bit afraid for the criticism I might get on the written code, I hope that critics and remarks will improve my Qt coding knowledge and the overall quality of the editor component.
Also I really would like to see multi-caret support in many more products!

The Editor App

I've written an editor application for this text-component. The initial purpose was to create a simple application that could be used for playing with the component in a simple setting. The first version was a simple form of irresponsible code to quickly play with the thing. It still has a lot of dirty hacks in it.

The plan I have with this editor is to expand it to a full cross platform scriptable editor-environment.

I've build some binaries and placed the at https://bintray.com/gamecreature/edbee/edbee-app. Be warned though, I still need to figure out all dependencies of these executables (especially the windows version) and need a better way to distribute the editor.

There's still a lot of work todo..
If anybody is interested in helping please drop me an email ( rick, blommersit, nl )* or a tweet!@gamecreature :)
* Replace the comma/spaces with the correct two symbols

Visuals Blog

It's been seven years ago my first beautiful daughter was born.
When your having children, you automatically get more time doing creative stuff. Drawing coloring, cutting and pasting (not the computer way), crafting all kinds of stuff.

While I'm being creative with my kids, I picked up an old hobby of mine, drawing cartoons.
I'm not extremely talented but sometimes I draw something that looks nice enough, that doesn't deserve to go into the recycle-old-paper box.
I would like to share these drawing on this blog..

In this article I would like to share my first more-then-a-sketch project that I made from a random-sketch for my oldest daughter two years ago.

While drawing with the kids I draw the sketch below.

Boy in a box

I scanned it in and made a line-drawing of it in Illustrator:
This was one of my first line-drawings in illustrator. I can tell you using the pen takes quite some time to get used to.

boy-box-line-sketch

To make the image a bit more vivid, I improved the line thickness of the drawing.

boy-box-fatlines

After this I've colored it in Illustrator. I really don't like the way Illustrator handles coloring and painting. The free-form mode that used to be in Flash is much more natural. (though less accurate)

boy-box-coloured

To get nice shades and a cleaner way of coloring, I fled to Photoshop. Drawing in Photoshop is more natural to me. Well here's the result of the 'shading' step in Photoshop.
boy-box-bitmap-shadows

When this step was done, I've mailed the picture to canvasenco.nl, a dutch company that delivers photo's on canvas.

An this is the result as it is today on my daughters bedroom.

boybox

She was pretty happy with it, and it still has a place in her bedroom, so I guess she still likes it :)

Ruby on Rails Json Serialization – To Infinity and beyond!

Wel the title says it all :)

There's a subtile, but very important difference between Ruby on Rails 3 and 4 with json serialization.

Rails 3

(1..10).as_json => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Rails 4

(1..10).as_json => "1..10"

I had a piece of Ruby code that modeled the business rules of the application like this:

 
{
  brackets: [
    { income: 0..19_645,               perc: 37 },
    { income: 19_646..55_991,          perc: 42 },
    { income: 55_992..Float::INFINITY, perc: 52 }
  ]
}

Try serializing this to the browser with to_json in Rails 3 and prepare for a long wait ;)

The workaround I used to this was creating an initalizer "/config/initializer/range_to_json_monkey_patch.rb"

#
# This initializer requires some explanation
# 
# In the ruby version installed (Rails 3.2.13)  the json encoding method works like this:
#   ActiveSupport::JSON::encode(1..10)  => [1,2,3,4,5,6,7,8,9,10]
#
# Doing this with a large range  is not nice!!
#
# Ruby on rails 4.0.0.1 works like this:
#   ActiveSupport::JSON::encode(1..10)  => "1..10"
#
# This initializer modifies the Range#as_json method so it works like rails 4
# this method first checks if this adjustment is required
#
if (1..4).as_json.kind_of?(Array)

  class Range
    def as_json( options=nil )
      self.to_s
    end
  end

end

Now the json-serialization of Ranges will behave like the one in Rails 4.

Crash when deleting QGraphicsProxyWidget

Currently I'm working on a track-based event editor. I'm building this editor with a QGraphicsScene. I use multiple QGraphicsViews for showing tracks and midi-events. Wave files etc...

To rename a track I was trying to show a QLineEdit directly above the track-name and commit the result when editing was completed.

Adding it to the scene like this:

QLineEdit* lineEdit = new QLineEdit("My Text");
// a few connected signals for listening to editingFinished and enterPressed
QGraphicsProxyWidget* proxyWidget = graphicsScene->addWidget( lineEdit )

While I was trying to delete a simple QGraphicsProxyWidget from my QGraphicsScene
it resulted in a crash. (Deleting proxyWidget also delete's it's QLineEdit child)

delete proxyWidget;

The stack-trace shows something about focus function withing Qt.
I tried several things like deleteLater. Calling clearFocus myself.
It all did not work..

The solution that worked for me is the following:

void editingFinishedHandler()
{
  scene()->removeItem( proxyWidget );
  proxyWidget->deleteLater();
}


(My previous solution, that's inferior to the one above: )

[code language="cpp"]
void editingFinishedHandler()
{
  proxyWidget->setWidget(0);  // < inferior solution, please see solution above
  proxyWidget->deleteLater();      
  lineEdit->deleteLater();    
}

QThread deleteLater not called on application Quit

Threading in Qt is not very hard (so it seems).
But there's no definitive way to use use QThread. Look at the different articles and opinions.

My opinion is to be pragmatic and consider the context and situation of your problem, and just use what's best for it. :)

In this article I would like to describe a problem I had with threading. I've got a gui application that uses several threads. It's an application with multiple tabs, and every tab has got several (always running) threads. These threads are event-queue threads and are waiting on messages (jobs) they need to process.

My application uses memory-leak detection so when an object doesn't get deleted I get an horrible message at the end.

I've made the threads self-destroy when you call quit:

  connect( thread, SIGNAL(finished()), thread, SLOT(deleteLater()) );

When you close the application directly via (Alt-F4 windows, or Cmd-Q on Mac) I destroy the different tabs an stop the threads.

I process this in the signal QApplication::aboutToQuit:

  thread->quit();
  thread->wait()

Calling quit ends the eventQueue of the thread and emits a finished() signal to the event queue..

But now there's a problem. I'm in the aboutToQuit signal. And it seems that the finished signal is placed on the event queue.

But the eventQueue isn't processed any more. The application exits the exec loop:

  qApp->exec();

When my application know exits I've got a problem the QThread is not deleted.

The finished() signal is placed on the qApp event queue, but isn't processed.

I've solved it by processing the eventQueue after my exec call.

int result =  qApp->exec();
int counter = 0;

while( qapp->eventDispatcher()->processEvents( QEventLoop::ExcludeUserInputEvents ) && counter < 25  ) 
{         
  ++counter;
}

I've created a loop to allow pending events to be processed. To be sure it will quit I've added a counter, but in my situation the loop is processed 2 times:

  • The first time: finished() is processed, and deleteLater() is posted to the eventQueue
  • The second time the deleteLater() is processed and the my QThread is deleted

Now I've finally got rid of that annoying memory leak message :)

** The non-deletion of QThread is not a real big issue, but the situation I describe here also applies to other slots I've connected to the finished() signal of the thread. These slot's aren't called without the method described above.