Thursday 25 May 2017

TrafficControl: Recap of the QML Station Handling

The python script TrackStationConnector reads a KML file containing a station.

A KML file contains station information as a placemark.


The script TrackStationConnector extracts track information and converts it to a proper input format.


TrafficControl has a function that is analysing the input file, and if it finds a station with coordinates, it will call a function that creates the QML station

The QML item iscreated by calling a JavaScript in the QML part

This code is probably redundant, I will try to remove it later.

Finally, the JavaScript in a separate file creates the QML item.


Wednesday 17 May 2017

TrafficControl: Refactoring the Train::move() Function (3)

The refactoring task is done now, according to the state model I described before.

Most of the refactoring was done in the tcTrain method. I found some redundant code, that I've been able to remove.

I also found a bug: The variable nextTrack, that records the ID of the next track the train should select was never reset. Later, when the train arrived at a station, the value of that parameter made the program need to search for suitable tracks twice, instead of once. The end result was the same, so the bug wasn't visible.

The next step in the implementation will be to add tracks to the QML map.

Wednesday 10 May 2017

QML: Sandbox

In order to learn QML and interactions between QML and C/Qt, I created a simple sandbox that I've published on my GitHub account.

Anyone is free to download and play around with the software (under GPL conditions). However, I strongly recommend you to learn QML step-by-step and build a QML application from scratch.

The QML is created from C++:

The QML file has some static items that are defined from the beginning. Those items has some attributes that defines their appearance. Also, new items can be created dynamically.

  • A blue rectangle in the top left corner. Inside that rectangle, there is a text. When clicking in the rectangle, two things will happen:
    • Another QML item will change color from green to blue. 
    • A text will appear to the left, rotate 360 degrees and fade away. That text is created from a JavaScript that creates the item in the file sprite.qml
    • A blue rectangle in the top left corner. Inside that rectangle, there is a text. When clicking in the 
  • A blue text field below the blue rectangle, that turns green when the rectangle above is clicked
  • A blue text field that turns golden when a function in C++ is launched.
  • One of the rotating text fields to the right is re-coloured to red from C++ 
  • The faded blue square is created from a string.

The process of creating this program has taught me how to create QML objects and how to interact with C++ in a sandbox.