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
ba4acf82
Commit
ba4acf82
authored
Oct 25, 2015
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decimal place support from meta data
parent
32b9124d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
59 deletions
+100
-59
PX4ParameterLoader.cc
src/AutoPilotPlugins/PX4/PX4ParameterLoader.cc
+13
-0
Fact.cc
src/FactSystem/Fact.cc
+26
-1
Fact.h
src/FactSystem/Fact.h
+18
-16
FactMetaData.cc
src/FactSystem/FactMetaData.cc
+23
-20
FactMetaData.h
src/FactSystem/FactMetaData.h
+16
-11
MissionItem.cc
src/MissionItem.cc
+4
-11
No files found.
src/AutoPilotPlugins/PX4/PX4ParameterLoader.cc
View file @
ba4acf82
...
...
@@ -299,6 +299,19 @@ void PX4ParameterLoader::loadParameterFactMetaData(void)
qCDebug
(
PX4ParameterLoaderLog
)
<<
"Unit:"
<<
text
;
metaData
->
setUnits
(
text
);
}
else
if
(
elementName
==
"decimal"
)
{
Q_ASSERT
(
metaData
);
QString
text
=
xml
.
readElementText
();
qCDebug
(
PX4ParameterLoaderLog
)
<<
"Decimal:"
<<
text
;
bool
convertOk
;
QVariant
varDecimals
=
QVariant
(
text
).
toUInt
(
&
convertOk
);
if
(
convertOk
)
{
metaData
->
setDecimalPlaces
(
varDecimals
.
toInt
());
}
else
{
qCWarning
(
PX4ParameterLoaderLog
)
<<
"Invalid decimals value, name:"
<<
metaData
->
name
()
<<
" type:"
<<
metaData
->
type
()
<<
" decimals:"
<<
text
<<
" error: invalid number"
;
}
}
else
{
qDebug
()
<<
"Unknown element in XML: "
<<
elementName
;
}
...
...
src/FactSystem/Fact.cc
View file @
ba4acf82
...
...
@@ -131,7 +131,22 @@ QVariant Fact::value(void) const
QString
Fact
::
valueString
(
void
)
const
{
return
_value
.
toString
();
QString
valueString
;
switch
(
type
())
{
case
FactMetaData
:
:
valueTypeFloat
:
qDebug
()
<<
name
()
<<
value
()
<<
decimalPlaces
();
valueString
=
QString
(
"%1"
).
arg
(
value
().
toFloat
(),
0
,
'g'
,
decimalPlaces
());
break
;
case
FactMetaData
:
:
valueTypeDouble
:
valueString
=
QString
(
"%1"
).
arg
(
value
().
toDouble
(),
0
,
'g'
,
decimalPlaces
());
break
;
default:
valueString
=
value
().
toString
();
break
;
}
return
valueString
;
}
QVariant
Fact
::
defaultValue
(
void
)
const
...
...
@@ -222,6 +237,16 @@ bool Fact::maxIsDefaultForType(void) const
}
}
int
Fact
::
decimalPlaces
(
void
)
const
{
if
(
_metaData
)
{
return
_metaData
->
decimalPlaces
();
}
else
{
qWarning
()
<<
"Meta data pointer missing"
;
return
FactMetaData
::
defaultDecimalPlaces
;
}
}
QString
Fact
::
group
(
void
)
const
{
if
(
_metaData
)
{
...
...
src/FactSystem/Fact.h
View file @
ba4acf82
...
...
@@ -46,22 +46,23 @@ public:
const
Fact
&
operator
=
(
const
Fact
&
other
);
Q_PROPERTY
(
int
componentId
READ
componentId
CONSTANT
)
Q_PROPERTY
(
QString
name
READ
name
CONSTANT
)
Q_PROPERTY
(
QVariant
value
READ
value
WRITE
setValue
NOTIFY
valueChanged
USER
true
)
Q_PROPERTY
(
QVariant
valueString
READ
valueString
NOTIFY
valueChanged
)
Q_PROPERTY
(
QString
units
READ
units
CONSTANT
)
Q_PROPERTY
(
QVariant
defaultValue
READ
defaultValue
CONSTANT
)
Q_PROPERTY
(
bool
defaultValueAvailable
READ
defaultValueAvailable
CONSTANT
)
Q_PROPERTY
(
bool
valueEqualsDefault
READ
valueEqualsDefault
NOTIFY
valueChanged
)
Q_PROPERTY
(
FactMetaData
::
ValueType_t
type
READ
type
CONSTANT
)
Q_PROPERTY
(
QString
shortDescription
READ
shortDescription
CONSTANT
)
Q_PROPERTY
(
QString
longDescription
READ
longDescription
CONSTANT
)
Q_PROPERTY
(
QVariant
min
READ
min
CONSTANT
)
Q_PROPERTY
(
bool
minIsDefaultForType
READ
minIsDefaultForType
CONSTANT
)
Q_PROPERTY
(
QVariant
max
READ
max
CONSTANT
)
Q_PROPERTY
(
bool
maxIsDefaultForType
READ
maxIsDefaultForType
CONSTANT
)
Q_PROPERTY
(
QString
group
READ
group
CONSTANT
)
Q_PROPERTY
(
int
componentId
READ
componentId
CONSTANT
)
Q_PROPERTY
(
QString
group
READ
group
CONSTANT
)
Q_PROPERTY
(
QString
name
READ
name
CONSTANT
)
Q_PROPERTY
(
QVariant
value
READ
value
WRITE
setValue
NOTIFY
valueChanged
USER
true
)
Q_PROPERTY
(
QVariant
valueString
READ
valueString
NOTIFY
valueChanged
)
Q_PROPERTY
(
QString
units
READ
units
CONSTANT
)
Q_PROPERTY
(
QVariant
defaultValue
READ
defaultValue
CONSTANT
)
Q_PROPERTY
(
bool
defaultValueAvailable
READ
defaultValueAvailable
CONSTANT
)
Q_PROPERTY
(
bool
valueEqualsDefault
READ
valueEqualsDefault
NOTIFY
valueChanged
)
Q_PROPERTY
(
FactMetaData
::
ValueType_t
type
READ
type
CONSTANT
)
Q_PROPERTY
(
QString
shortDescription
READ
shortDescription
CONSTANT
)
Q_PROPERTY
(
QString
longDescription
READ
longDescription
CONSTANT
)
Q_PROPERTY
(
QVariant
min
READ
min
CONSTANT
)
Q_PROPERTY
(
bool
minIsDefaultForType
READ
minIsDefaultForType
CONSTANT
)
Q_PROPERTY
(
QVariant
max
READ
max
CONSTANT
)
Q_PROPERTY
(
bool
maxIsDefaultForType
READ
maxIsDefaultForType
CONSTANT
)
Q_PROPERTY
(
int
decimalPlaces
READ
decimalPlaces
CONSTANT
)
/// Convert and validate value
/// @param convertOnly true: validate type conversion only, false: validate against meta data as well
...
...
@@ -86,6 +87,7 @@ public:
QVariant
max
(
void
)
const
;
bool
maxIsDefaultForType
(
void
)
const
;
QString
group
(
void
)
const
;
int
decimalPlaces
(
void
)
const
;
/// Sets and sends new value to vehicle even if value is the same
void
forceSetValue
(
const
QVariant
&
value
);
...
...
src/FactSystem/FactMetaData.cc
View file @
ba4acf82
...
...
@@ -32,30 +32,32 @@
#include <limits>
FactMetaData
::
FactMetaData
(
QObject
*
parent
)
:
QObject
(
parent
),
_group
(
"*Default Group"
),
_type
(
valueTypeInt32
),
_defaultValue
(
0
),
_defaultValueAvailable
(
false
),
_min
(
_minForType
()),
_max
(
_maxForType
()),
_minIsDefaultForType
(
true
),
_maxIsDefaultForType
(
true
)
FactMetaData
::
FactMetaData
(
QObject
*
parent
)
:
QObject
(
parent
)
,
_group
(
"*Default Group"
)
,
_type
(
valueTypeInt32
)
,
_defaultValue
(
0
)
,
_defaultValueAvailable
(
false
)
,
_min
(
_minForType
())
,
_max
(
_maxForType
())
,
_minIsDefaultForType
(
true
)
,
_maxIsDefaultForType
(
true
)
,
_decimalPlaces
(
defaultDecimalPlaces
)
{
}
FactMetaData
::
FactMetaData
(
ValueType_t
type
,
QObject
*
parent
)
:
QObject
(
parent
),
_group
(
"*Default Group"
),
_type
(
type
),
_defaultValue
(
0
),
_defaultValueAvailable
(
false
),
_min
(
_minForType
()),
_max
(
_maxForType
()),
_minIsDefaultForType
(
true
),
_maxIsDefaultForType
(
true
)
FactMetaData
::
FactMetaData
(
ValueType_t
type
,
QObject
*
parent
)
:
QObject
(
parent
)
,
_group
(
"*Default Group"
)
,
_type
(
type
)
,
_defaultValue
(
0
)
,
_defaultValueAvailable
(
false
)
,
_min
(
_minForType
())
,
_max
(
_maxForType
())
,
_minIsDefaultForType
(
true
)
,
_maxIsDefaultForType
(
true
)
,
_decimalPlaces
(
defaultDecimalPlaces
)
{
}
...
...
@@ -76,6 +78,7 @@ const FactMetaData& FactMetaData::operator=(const FactMetaData& other)
_max
=
other
.
_max
;
_minIsDefaultForType
=
other
.
_minIsDefaultForType
;
_maxIsDefaultForType
=
other
.
_maxIsDefaultForType
;
_decimalPlaces
=
other
.
_decimalPlaces
;
return
*
this
;
}
...
...
src/FactSystem/FactMetaData.h
View file @
ba4acf82
...
...
@@ -59,18 +59,19 @@ public:
const
FactMetaData
&
operator
=
(
const
FactMetaData
&
other
);
// Property accessors
QString
name
(
void
)
const
{
return
_name
;
}
QString
group
(
void
)
const
{
return
_group
;
}
ValueType_t
type
(
void
)
const
{
return
_type
;
}
QString
name
(
void
)
const
{
return
_name
;
}
QString
group
(
void
)
const
{
return
_group
;
}
ValueType_t
type
(
void
)
const
{
return
_type
;
}
QVariant
defaultValue
(
void
)
const
;
bool
defaultValueAvailable
(
void
)
const
{
return
_defaultValueAvailable
;
}
QString
shortDescription
(
void
)
const
{
return
_shortDescription
;
}
QString
longDescription
(
void
)
const
{
return
_longDescription
;}
QString
units
(
void
)
const
{
return
_units
;
}
QVariant
min
(
void
)
const
{
return
_min
;
}
QVariant
max
(
void
)
const
{
return
_max
;
}
bool
minIsDefaultForType
(
void
)
const
{
return
_minIsDefaultForType
;
}
bool
maxIsDefaultForType
(
void
)
const
{
return
_maxIsDefaultForType
;
}
bool
defaultValueAvailable
(
void
)
const
{
return
_defaultValueAvailable
;
}
QString
shortDescription
(
void
)
const
{
return
_shortDescription
;
}
QString
longDescription
(
void
)
const
{
return
_longDescription
;}
QString
units
(
void
)
const
{
return
_units
;
}
QVariant
min
(
void
)
const
{
return
_min
;
}
QVariant
max
(
void
)
const
{
return
_max
;
}
bool
minIsDefaultForType
(
void
)
const
{
return
_minIsDefaultForType
;
}
bool
maxIsDefaultForType
(
void
)
const
{
return
_maxIsDefaultForType
;
}
int
decimalPlaces
(
void
)
const
{
return
_decimalPlaces
;
}
// Property setters
void
setName
(
const
QString
&
name
)
{
_name
=
name
;
}
...
...
@@ -81,6 +82,7 @@ public:
void
setUnits
(
const
QString
&
units
)
{
_units
=
units
;
}
void
setMin
(
const
QVariant
&
max
);
void
setMax
(
const
QVariant
&
max
);
void
setDecimalPlaces
(
int
decimalPlaces
)
{
_decimalPlaces
=
decimalPlaces
;
}
/// Converts the specified value, validating against meta data
/// @param value Value to convert, can be string
...
...
@@ -90,6 +92,8 @@ public:
/// @returns false: Convert failed, errorString set
bool
convertAndValidate
(
const
QVariant
&
value
,
bool
convertOnly
,
QVariant
&
typedValue
,
QString
&
errorString
);
static
const
int
defaultDecimalPlaces
=
3
;
private:
QVariant
_minForType
(
void
)
const
;
QVariant
_maxForType
(
void
)
const
;
...
...
@@ -106,6 +110,7 @@ private:
QVariant
_max
;
bool
_minIsDefaultForType
;
bool
_maxIsDefaultForType
;
int
_decimalPlaces
;
};
#endif
src/MissionItem.cc
View file @
ba4acf82
...
...
@@ -20,15 +20,6 @@ This file is part of the QGROUNDCONTROL project
======================================================================*/
/**
* @file
* @brief MissionItem class
*
* @author Benjamin Knecht <mavteam@student.ethz.ch>
* @author Petri Tanskanen <mavteam@student.ethz.ch>
*
*/
#include <QStringList>
#include <QDebug>
...
...
@@ -115,10 +106,12 @@ MissionItem::MissionItem(QObject* parent,
FactMetaData
*
latitudeMetaData
=
new
FactMetaData
(
FactMetaData
::
valueTypeDouble
,
_latitudeFact
);
latitudeMetaData
->
setUnits
(
"deg"
);
latitudeMetaData
->
setDecimalPlaces
(
7
);
FactMetaData
*
longitudeMetaData
=
new
FactMetaData
(
FactMetaData
::
valueTypeDouble
,
_longitudeFact
);
longitudeMetaData
->
setUnits
(
"deg"
);
longitudeMetaData
->
setDecimalPlaces
(
7
);
FactMetaData
*
altitudeMetaData
=
new
FactMetaData
(
FactMetaData
::
valueTypeDouble
,
_altitudeFact
);
altitudeMetaData
->
setUnits
(
"meters"
);
...
...
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