Oct 12 2011

MainWindow vs. Editor

Category: Lego,Mindstorms,RICcreator,SoftwareSpiller @ 21:24

RICcreator is a MDI application which is implemented by using tabs. Because tabs are used, only one document is viewed at a time.

Up to this point it was implemented using QTabWidget which provides tabs and a area on each tab to place widgets in. Using this, a editor (ricfile_widget) was created on each tab which each owned a ricfile.

When a user clicked on an action in the menus or toolbars, this action had to be routed to the editor currently shown. Since there are about 10-15 commands which deals with the ricfile, 10-15 wrapper functions had to exist in the MainWindow with 10-15 actual implantations in the editor. There were mainly two types of actions, open/save/export actions and actions which added a specific object.

The open/save/export actions are useful no matter which editor you are currently using, while the “add polygon” action is pretty useless when using an editor for modifying RIC fonts. (Not implemented) The goal was therefore to keep the implementations for open/save/export in MainWindow while removing all the other actions from MainWindow and keeping them strictly in ricfile_widget.


Instead of having the QTabWidget manage the editor for us, we make MainWindow keep track of it instead. Secondly we change the ownership of ricfiles to the MainWindow. To do this we make a class which keep track of a ricfile which contains the information needed. The class (openRicfile) contains the following information:

  • The ricfile
  •  The file source, was this created in the program, loaded from the HDD or downloaded from the NXT?
  • The ricfile editor which is used to edit this file.
  • The name of the file
  • The file edit state, has the file been changed since it was loaded?

Since MainWindow now owns the ricfile and the required information about it to save/export the file, the actions can now be directly implemented here.

To make it possible to create different editors, we create an interface between the MainWindow and editor. As open/save/export is now done by MainWindow and that every other command was editor specific the interface must not contain any of these. To still be able to have editor specific commands in MainWindow we allow the editor to create a Toolbar which the MainWindow will shown.

In return we add a requiriment to the editor, it must be able to change the active ricfile. The interface (ricfileEditor) have the following properties:

  • Change the ricfile to be edited by specifying a openRicfile.
  • Request a toolbar to be shown
  • Signal which tells MainWindow when openRicfile as been edited.


Instead of using a QTabWidget, a QTabBar is used instead. QTabBar only shows the tabs, it does not create a space to hold widgets. However we get slightly more control over the tabs appearance. But now that an editor can change file, we only need one for each type and therefore not a separate space.

In openRicfile we therefore only save the editor type for each file. So openRicfile instead keeps an list of implemented editors. When we request a editor, it will return the editor specified by the openRicfile. (Editors will only be created on request to preserve resources.) But since there is only one editor, we will need to store information about how the file was viewed in the editor, as this is lost when changing file. I still need to implement this, but it will just be an extra field in openRicfile containing the required information.

All the “Add [object]” actions have been implemented as a Toolbar in ricfile_widget, so MainWindow is now completely free of them, it just changes the shown toolbar whenever a new editor is to be shown.


MainWindow and ricfile_widget is now much cleaner implemented as it doesn’t contain functions which is half implemented in MainWindow and half implemented in ricfile_widget.

Secondly it is now possible add new editors quite easily and there is an way of adding actions to be shown in the MainWindow.

A side effect is that memory use has dropped greatly. ricfile_widget used about 600KB of RAM, so after opening 10 files you had doubled the memory use of the program. Now it only increases with a few KB for each file. (This is an empty file however, haven’t quite tested it with large files, but it shouldn’t be too much nevertheless.)

Another side effect is that since QTabBar is now used, it is possible to specify the text color of each tab individually. So a file which have been edited and not saved yet is highlighted by changing the color to red and adding an asterisk to the end:


RICcreator rev. 133 – win32

Leave a Reply