Author: Armens Movsesjans
Course: Mobile Linux Development with QT
Teachers: Timo Strömmer
and Juha-Matti Liukkonen

Mobile Linux Development with QT - Generic Converter


Basic Info

converter

Name: Generic Converter

Short description: Converts different types of measures from one unit to another

Long description: Converts such internationally common (and maybe some less common) units like length, area, volume, velocity, acceleration, mass, energy, power, pressure, time and temperature. If along with conventional conversions one sometimes needs to immediately know how many teaspoons of beer there are in 5 gallons [of beer], or how many calories there are in 20 tons of TNT, or how many palms fit into a distance of 10000 light-years, then this Generic Converter is what one might want to have

Status: App is ready for production in its tested environment (Ubuntu Desktop 10.04)

License: © 2010 Armens Movsesjans. GNU General Public License, version 2 or later.

Download: GenericConverter.tar.gz version 0.1

How it works

converter When converter is started for the first time all the fields are empty. When user selects a type of conversion the drop-down-list (combo-box) it emits a signal, which is caught by a slot called populateUnits, so both unit drop-down-lists are populated with appropriate units.

Choosing between units and typing values into amount text-box emits signals which are heard by a slot called updateResult. This slot takes the value from the amount text-box, takes current indices of both unit drop-down-lists (first as source, another as target) and calls processAmount method. The method checks the index of the type of conversion, and based on that calculates the result: it mulpiplies the amount by a relevant multiplier's source index (to bring it to the base) and divides by a relevant multiplier's target index (these relevant multipliers are hardcoded as QLists of doubles and has same indices as units in the unit drop-down-lists). The result is then displayed in the result text-box.

Almost the same process happens when a value is typed into the result text-box. It emits a signal heard by a slot called updateAmount, which does same logic as updateResult: gets the value from text-box, checks units indices, calls processAmount. The only difference is that the first unit drop-down-list is now the target, and the second is the source. The result is the shown in the amount text-box.

From the menu the user can either choose an action (to empty the form or quit) or get info about this application. When quitting, the values from drop-down-lists are saved (in the destructor) so that when the application is started again it starts with same units selected.

signals

Nice thing about this app is that when text-boxes are edit the emitted signal of type textEdited causes an immediate update in the result, which results in a dynamic application, which doesn't need a push button.

A not-so-nice thing about it, is that all the content of units drop-down-lists (stored in a QList of QStringLists) as well as multiplers values stored in QLists of doubles are all hardcoded, i.e. all the data gets loaded into the memory and stays there until the program is ended, which requires more memory. But then, it also means that the app needs less processing power to perform the conversions, because all the data is already there. However, during the summer I am planning to optimize it for less memory use, so that it could be better employed on mobile devices (which after all, have presently more problems with memory rather than with processing power).