Unit handling & upcoming advanced filtering

Issue #474 resolved
wthaemelt created an issue

Up to now, there are only a few rare situations to input a value with a unit into in QMS (e.g. elevation or proximity of waypoints). Therefore, units where not translated to local spelling. This will change with the upcoming advanced filtering. Here, the user has to formulate search queries in the local language used in QMS. While this is not a problem for languages written in Latin-1, it will be a problem for the Russian/Cyrillic version. To avoid conflicts with wrongly written units in search queries I propose to extend the list of units in IUnit.cpp by the Cyrillic equivalents for length, speed, time, … (I can provide such a list). These extended units can then be recognized in extended search queries and unit conflicts (Russian text with Latin-1 unit required but Russian unit given) won’t happen. There is no need to use Russian units elsewhere in QMS (thus, as currently, no translation of units).

Comments (6)

  1. wthaemelt reporter

    Here are necessary changes to handle Russian units. Please be aware, that UTF-8 formatting is now compulsory!

    Last lines of IUnit.cpp:

    QMap<QString, qreal> IUnit::timeToMKSMap={
        {"s", 1},
        {"min", 60},
        {"h", 3600},
        {"с", 1},
        {"мин", 60},
        {"ч", 3600},
    };
    
    QMap<QString, qreal> IUnit::distanceToMKSMap={
        {"m", 1},
        {"km", 1000},
        {"mi", 1/CUnitImperial::milePerMeter},
        {"ft", 1/CUnitImperial::footPerMeter},
        {"м", 1},
        {"км", 1000},
    };
    
    QMap<QString, qreal> IUnit::speedToMKSMap={
        {"m/s", 1},
        {"m/min", 1/60},
        {"m/h", 1/3600},
        {"km/s", 1000},
        {"km/min", 1000/60},
        {"km/h", 1000/3600},
        {"mi/s", 1/CUnitImperial::milePerMeter},
        {"mi/min", 1/(CUnitImperial::milePerMeter*60)},
        {"mi/h", 1/(CUnitImperial::milePerMeter*3600)},
        {"ft/s", 1/CUnitImperial::footPerMeter},
        {"ft/min", 1/(CUnitImperial::footPerMeter*60)},
        {"ft/h", 1/(CUnitImperial::footPerMeter*3600)},
        {"м/с", 1},
        {"м/мин", 1/60},
        {"м/ч", 1/3600},
        {"км/с", 1000},
        {"км/мин", 1000/60},
        {"км/ч", 1000/3600},    
    };
    
    QMap<QString, qreal> IUnit::areaToMKSMap={
        {"m²", 1},
        {"km²", 1000*1000},
        {"mi²", 1/(CUnitImperial::milePerMeter*CUnitImperial::milePerMeter)},
        {"ft²", 1/(CUnitImperial::footPerMeter*CUnitImperial::footPerMeter)},
        {"м²", 1},
        {"км²", 1000*1000},
    };
    

    Changes to CSearch.cpp:

    - const static QString capUnit = "(m|km|mi|ft|mi|m\\/h|km\\/h|mi\\/h|ft\\/h|mi\\/h|h|min|s)?";
    + const static QString capUnit = "(m|km|mi|ft|mi|m\\/h|km\\/h|mi\\/h|ft\\/h|mi\\/h|h|min|s|м|км|м\\/ч|км\\/ч|ч|мин|с)?";
    


    CSearchExplanationDialog.cpp:

    I'm not sure if the line

    explanation += IUnit::getUnits().join(", "); 
    

    will show the additional Russian units, too.

    Are there more places to change?

  2. Log in to comment