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
2979407a
Unverified
Commit
2979407a
authored
May 13, 2020
by
Don Gagne
Committed by
GitHub
May 13, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8752 from DonLakeFlyer/CustomValidator
FactMetaData: Add custom validator support
parents
ebf188a0
f961cd66
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
FactMetaData.cc
src/FactSystem/FactMetaData.cc
+7
-0
FactMetaData.h
src/FactSystem/FactMetaData.h
+9
-0
No files found.
src/FactSystem/FactMetaData.cc
View file @
2979407a
...
...
@@ -424,6 +424,13 @@ bool FactMetaData::convertAndValidateCooked(const QVariant& cookedValue, bool co
errorString
.
clear
();
if
(
!
convertOnly
&&
_customCookedValidator
)
{
errorString
=
_customCookedValidator
(
cookedValue
);
if
(
!
errorString
.
isEmpty
())
{
return
false
;
}
}
switch
(
type
())
{
case
FactMetaData
:
:
valueTypeInt8
:
case
FactMetaData
:
:
valueTypeInt16
:
...
...
src/FactSystem/FactMetaData.h
View file @
2979407a
...
...
@@ -43,6 +43,10 @@ public:
typedef
QVariant
(
*
Translator
)(
const
QVariant
&
from
);
// Custom function to validate a cooked value.
// @return Error string for failed validation explanation to user. Empty string indicates no error.
typedef
QString
(
*
CustomCookedValidator
)(
const
QVariant
&
cookedValue
);
FactMetaData
(
QObject
*
parent
=
nullptr
);
FactMetaData
(
ValueType_t
type
,
QObject
*
parent
=
nullptr
);
FactMetaData
(
ValueType_t
type
,
const
QString
name
,
QObject
*
parent
=
nullptr
);
...
...
@@ -179,6 +183,10 @@ public:
/// @returns false: Convertion failed
bool
clampValue
(
const
QVariant
&
cookedValue
,
QVariant
&
typedValue
);
/// Sets a custom cooked validator function for this metadata. The custom validator will be called
/// prior to the standard validator when convertAndValidateCooked is called.
void
setCustomCookedValidator
(
CustomCookedValidator
customValidator
)
{
_customCookedValidator
=
customValidator
;
}
static
const
int
kDefaultDecimalPlaces
=
3
;
///< Default value for decimal places if not specified/known
static
const
int
kUnknownDecimalPlaces
=
-
1
;
///< Number of decimal places to specify is not known
...
...
@@ -285,6 +293,7 @@ private:
bool
_readOnly
;
bool
_writeOnly
;
bool
_volatile
;
CustomCookedValidator
_customCookedValidator
=
nullptr
;
// Exact conversion constants
static
const
struct
UnitConsts_s
{
...
...
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