
Chapter 4. Implementation 64
The internal structure of the scene menu is similar to the structure of the visualization menu,
except that no QHash containers were used, as the scenes contain usually less than 30 elements.
Only the handling of the background image was optimized in order to prevent lags between scene
changes. All scenes are saved in a memory based database as shown in figure 4.25.
name1: scene1
name2: scene2
nameN: sceneN
QHash<name, sceneStruct>
sceneStruct
string background_path
float background_scale
QList<elementStruct> list
elementStruct
int pos_x
int pos_y
string type
string name
Scene list
Figure 4.25.: The structure of the scene database.
The scene database is a single QHash list with scene names as keys and scene structures as values.
A scene structure is composed of a path to the background image, the scaling factor and a list of
element structures that contain the x-y-position within the background image, their device type
and their name. Whenever a scene is selected in the scene selection box, the corresponding scene
structure is loaded into the QGraphicsScene and rendered by a QGraphicsView class. The scene
menu is connected via two signals to the device manager class: a device state change notification
and a database change notification. Both signals will only cause single elements to be redrawn
in the current scene, which make scenes faster than the visualization menu, as the number of
displayed elements is smaller. The number of database accesses is low, as the accesses occur
primarily scene changes and the scenes usually only have a small number of elements. In order to
maintain the memory-based database, it is saved in a XML file when shutting down the node and
loaded when starting the node. The following code illustrates the scene database for the example
shown in listing B.2 on page 77. An example database is shown in appendix B on page 77.
Comentarios a estos manuales