Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
a317d9c5
Commit
a317d9c5
authored
Apr 27, 2020
by
Remek Zajac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce weight unit and separate distance from altitude
parent
72c97a09
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
269 additions
and
5 deletions
+269
-5
FactMetaData.cc
src/FactSystem/FactMetaData.cc
+143
-4
FactMetaData.h
src/FactSystem/FactMetaData.h
+32
-1
QGroundControlQmlGlobal.h
src/QmlControls/QGroundControlQmlGlobal.h
+16
-0
UnitsSettings.cc
src/Settings/UnitsSettings.cc
+62
-0
UnitsSettings.h
src/Settings/UnitsSettings.h
+16
-0
No files found.
src/FactSystem/FactMetaData.cc
View file @
a317d9c5
This diff is collapsed.
Click to expand it.
src/FactSystem/FactMetaData.h
View file @
a317d9c5
...
...
@@ -69,6 +69,24 @@ public:
/// Returns the string for distance units which has configued by user
static
QString
appSettingsDistanceUnitsString
(
void
);
/// Converts from meters to the user specified altitude unit
static
QVariant
metersToAppSettingsAltitudeUnits
(
const
QVariant
&
meters
);
/// Converts from user specified altitude unit to meters
static
QVariant
appSettingsAltitudeUnitsToMeters
(
const
QVariant
&
distance
);
/// Returns the string for altitude units which has configued by user
static
QString
appSettingsAltitudeUnitsString
(
void
);
/// Converts from grams to the user specified weight unit
static
QVariant
gramsToAppSettingsWeightUnits
(
const
QVariant
&
meters
);
/// Converts from user specified weight unit to grams
static
QVariant
appSettingsWeightUnitsToGrams
(
const
QVariant
&
distance
);
/// Returns the string for weight units which has configued by user
static
QString
appSettingsWeightUnitsString
(
void
);
/// Converts from meters to the user specified distance unit
static
QVariant
squareMetersToAppSettingsAreaUnits
(
const
QVariant
&
squareMeters
);
...
...
@@ -209,12 +227,21 @@ private:
static
QVariant
_inchesToCentimeters
(
const
QVariant
&
inches
);
static
QVariant
_celsiusToFarenheit
(
const
QVariant
&
celsius
);
static
QVariant
_farenheitToCelsius
(
const
QVariant
&
farenheit
);
static
QVariant
_kilogramsToGrams
(
const
QVariant
&
kg
);
static
QVariant
_ouncesToGrams
(
const
QVariant
&
oz
);
static
QVariant
_poundsToGrams
(
const
QVariant
&
lbs
);
static
QVariant
_gramsToKilograms
(
const
QVariant
&
g
);
static
QVariant
_gramsToOunces
(
const
QVariant
&
g
);
static
QVariant
_gramsToPunds
(
const
QVariant
&
g
);
enum
UnitTypes
{
UnitDistance
=
0
,
UnitAltitude
,
UnitArea
,
UnitSpeed
,
UnitTemperature
UnitTemperature
,
UnitWeight
};
struct
AppSettingsTranslation_s
{
...
...
@@ -227,7 +254,9 @@ private:
};
static
const
AppSettingsTranslation_s
*
_findAppSettingsDistanceUnitsTranslation
(
const
QString
&
rawUnits
);
static
const
AppSettingsTranslation_s
*
_findAppSettingsAltitudeUnitsTranslation
(
const
QString
&
rawUnits
);
static
const
AppSettingsTranslation_s
*
_findAppSettingsAreaUnitsTranslation
(
const
QString
&
rawUnits
);
static
const
AppSettingsTranslation_s
*
_findAppSettingsWeightUnitsTranslation
(
const
QString
&
rawUnits
);
static
void
_loadJsonDefines
(
const
QJsonObject
&
jsonDefinesObject
,
QMap
<
QString
,
QString
>&
defineMap
);
...
...
@@ -267,6 +296,8 @@ private:
static
const
qreal
milesToMeters
;
static
const
qreal
feetToMeters
;
static
const
qreal
inchesToCentimeters
;
static
const
qreal
ouncesToGrams
;
static
const
qreal
poundsToGrams
;
}
constants
;
struct
BuiltInTranslation_s
{
...
...
src/QmlControls/QGroundControlQmlGlobal.h
View file @
a317d9c5
...
...
@@ -145,6 +145,22 @@ public:
QString
appSettingsDistanceUnitsString
(
void
)
const
{
return
FactMetaData
::
appSettingsDistanceUnitsString
();
}
/// Converts from meters to the user specified distance unit
Q_INVOKABLE
QVariant
metersToAppSettingsAltitudeUnits
(
const
QVariant
&
meters
)
const
{
return
FactMetaData
::
metersToAppSettingsAltitudeUnits
(
meters
);
}
/// Converts from user specified distance unit to meters
Q_INVOKABLE
QVariant
appSettingsAltitudeUnitsToMeters
(
const
QVariant
&
distance
)
const
{
return
FactMetaData
::
appSettingsAltitudeUnitsToMeters
(
distance
);
}
QString
appSettingsAltitudeUnitsString
(
void
)
const
{
return
FactMetaData
::
appSettingsAltitudeUnitsString
();
}
/// Converts from grams to the user specified weight unit
Q_INVOKABLE
QVariant
gramsToAppSettingsWeightUnits
(
const
QVariant
&
meters
)
const
{
return
FactMetaData
::
gramsToAppSettingsWeightUnits
(
meters
);
}
/// Converts from user specified weight unit to grams
Q_INVOKABLE
QVariant
appSettingsWeightUnitsToGrams
(
const
QVariant
&
distance
)
const
{
return
FactMetaData
::
appSettingsWeightUnitsToGrams
(
distance
);
}
QString
appSettingsWeightUnitsString
(
void
)
const
{
return
FactMetaData
::
appSettingsWeightUnitsString
();
}
/// Converts from square meters to the user specified area unit
Q_INVOKABLE
QVariant
squareMetersToAppSettingsAreaUnits
(
const
QVariant
&
meters
)
const
{
return
FactMetaData
::
squareMetersToAppSettingsAreaUnits
(
meters
);
}
...
...
src/Settings/UnitsSettings.cc
View file @
a317d9c5
...
...
@@ -47,6 +47,35 @@ DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, distanceUnits)
return
_distanceUnitsFact
;
}
DECLARE_SETTINGSFACT_NO_FUNC
(
UnitsSettings
,
altitudeUnits
)
{
if
(
!
_altitudeUnitsFact
)
{
// Distance/Area/Speed units settings can't be loaded from json since it creates an infinite loop of meta data loading.
QStringList
enumStrings
;
QVariantList
enumValues
;
enumStrings
<<
"Feet"
<<
"Meters"
;
enumValues
<<
QVariant
::
fromValue
(
static_cast
<
uint32_t
>
(
DistanceUnitsFeet
))
<<
QVariant
::
fromValue
(
static_cast
<
uint32_t
>
(
DistanceUnitsMeters
));
FactMetaData
*
metaData
=
new
FactMetaData
(
FactMetaData
::
valueTypeUint32
,
this
);
metaData
->
setName
(
altitudeUnitsName
);
metaData
->
setShortDescription
(
"Altitude units"
);
metaData
->
setEnumInfo
(
enumStrings
,
enumValues
);
AltitudeUnits
defaultAltitudeUnit
=
AltitudeUnitsMeters
;
switch
(
QLocale
::
system
().
measurementSystem
())
{
case
QLocale
:
:
MetricSystem
:
{
defaultAltitudeUnit
=
AltitudeUnitsMeters
;
}
break
;
case
QLocale
:
:
ImperialUSSystem
:
case
QLocale
:
:
ImperialUKSystem
:
defaultAltitudeUnit
=
AltitudeUnitsFeet
;
break
;
}
metaData
->
setRawDefaultValue
(
defaultAltitudeUnit
);
metaData
->
setQGCRebootRequired
(
true
);
_altitudeUnitsFact
=
new
SettingsFact
(
_settingsGroup
,
metaData
,
this
);
}
return
_altitudeUnitsFact
;
}
DECLARE_SETTINGSFACT_NO_FUNC
(
UnitsSettings
,
areaUnits
)
{
if
(
!
_areaUnitsFact
)
{
...
...
@@ -147,3 +176,36 @@ DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, temperatureUnits)
}
return
_temperatureUnitsFact
;
}
DECLARE_SETTINGSFACT_NO_FUNC
(
UnitsSettings
,
weightUnits
)
{
if
(
!
_weightUnitsFact
)
{
// Units settings can't be loaded from json since it creates an infinite loop of meta data loading.
QStringList
enumStrings
;
QVariantList
enumValues
;
enumStrings
<<
"Grams"
<<
"Kilograms"
<<
"Ounces"
<<
"Pounds"
;
enumValues
<<
QVariant
::
fromValue
(
static_cast
<
uint32_t
>
(
WeightUnitsGrams
))
<<
QVariant
::
fromValue
(
static_cast
<
uint32_t
>
(
WeightUnitsKg
))
<<
QVariant
::
fromValue
(
static_cast
<
uint32_t
>
(
WeightUnitsOz
))
<<
QVariant
::
fromValue
(
static_cast
<
uint32_t
>
(
WeightUnitsLbs
));
FactMetaData
*
metaData
=
new
FactMetaData
(
FactMetaData
::
valueTypeUint32
,
this
);
metaData
->
setName
(
weightUnitsName
);
metaData
->
setShortDescription
(
tr
(
"Weight units"
));
metaData
->
setEnumInfo
(
enumStrings
,
enumValues
);
WeightUnits
defaultWeightUnit
=
WeightUnitsGrams
;
switch
(
QLocale
::
system
().
measurementSystem
())
{
case
QLocale
:
:
MetricSystem
:
case
QLocale
:
:
ImperialUKSystem
:
{
defaultWeightUnit
=
WeightUnitsGrams
;
}
break
;
case
QLocale
:
:
ImperialUSSystem
:
defaultWeightUnit
=
WeightUnitsOz
;
break
;
}
metaData
->
setRawDefaultValue
(
defaultWeightUnit
);
metaData
->
setQGCRebootRequired
(
true
);
_weightUnitsFact
=
new
SettingsFact
(
_settingsGroup
,
metaData
,
this
);
}
return
_weightUnitsFact
;
}
src/Settings/UnitsSettings.h
View file @
a317d9c5
...
...
@@ -24,6 +24,11 @@ public:
DistanceUnitsMeters
};
enum
AltitudeUnits
{
AltitudeUnitsFeet
=
0
,
AltitudeUnitsMeters
};
enum
AreaUnits
{
AreaUnitsSquareFeet
=
0
,
AreaUnitsSquareMeters
,
...
...
@@ -46,17 +51,28 @@ public:
TemperatureUnitsFarenheit
,
};
enum
WeightUnits
{
WeightUnitsGrams
=
0
,
WeightUnitsKg
,
WeightUnitsOz
,
WeightUnitsLbs
};
Q_ENUM
(
DistanceUnits
)
Q_ENUM
(
AreaUnits
)
Q_ENUM
(
AltitudeUnits
)
Q_ENUM
(
SpeedUnits
)
Q_ENUM
(
TemperatureUnits
)
Q_ENUM
(
WeightUnits
)
DEFINE_SETTING_NAME_GROUP
()
DEFINE_SETTINGFACT
(
distanceUnits
)
DEFINE_SETTINGFACT
(
altitudeUnits
)
DEFINE_SETTINGFACT
(
areaUnits
)
DEFINE_SETTINGFACT
(
speedUnits
)
DEFINE_SETTINGFACT
(
temperatureUnits
)
DEFINE_SETTINGFACT
(
weightUnits
)
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment