Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
656841a6
Commit
656841a6
authored
Aug 12, 2013
by
tstellanova
Browse files
Better data model update debouncing
parent
9af23ff7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/ui/QGCParamWidget.cc
View file @
656841a6
...
...
@@ -51,7 +51,8 @@ This file is part of the QGROUNDCONTROL project
*/
QGCParamWidget
::
QGCParamWidget
(
UASInterface
*
uas
,
QWidget
*
parent
)
:
QGCUASParamManager
(
uas
,
parent
),
componentItems
(
new
QMap
<
int
,
QTreeWidgetItem
*>
())
componentItems
(
new
QMap
<
int
,
QTreeWidgetItem
*>
()),
updatingParamNameLock
(
""
)
{
layoutWidget
();
...
...
@@ -202,20 +203,17 @@ void QGCParamWidget::addComponentItem(int compId, QString compName)
void
QGCParamWidget
::
handlePendingParamUpdate
(
int
compId
,
const
QString
&
paramName
,
QVariant
value
,
bool
isPending
)
{
qDebug
()
<<
"handlePendingParamUpdate:"
<<
paramName
<<
"with updat
edLineItem_weak:"
<<
updatedLineItem_wea
k
;
qDebug
()
<<
"handlePendingParamUpdate:"
<<
paramName
<<
"with updat
ingParamNameLock:"
<<
updatingParamNameLoc
k
;
if
(
updat
edLineItem_weak
)
{
QString
key
=
updatedLineItem_weak
->
data
(
0
,
Qt
::
DisplayRole
).
toString
()
;
if
(
paramName
==
key
)
{
//debounce echo from data model
return
;
}
if
(
updat
ingParamNameLock
==
paramName
)
{
qDebug
()
<<
"ignoring bounce from "
<<
paramName
;
return
;
}
else
{
updatingParamNameLock
=
paramName
;
}
QTreeWidgetItem
*
paramItem
=
updateParameterDisplay
(
compId
,
paramName
,
value
);
if
(
updatedLineItem_weak
==
NULL
)
{
updatedLineItem_weak
=
paramItem
;
}
if
(
isPending
)
{
paramItem
->
setBackground
(
0
,
QBrush
(
QColor
(
QGC
::
colorOrange
)));
paramItem
->
setBackground
(
1
,
QBrush
(
QColor
(
QGC
::
colorOrange
)));
...
...
@@ -225,17 +223,20 @@ void QGCParamWidget::handlePendingParamUpdate(int compId, const QString& paramNa
paramItem
->
setBackground
(
1
,
Qt
::
NoBrush
);
}
updatingParamNameLock
.
clear
();
}
void
QGCParamWidget
::
handleParameterUpdate
(
int
componentId
,
const
QString
&
paramName
,
QVariant
value
)
{
updatingParamNameLock
=
paramName
;
updateParameterDisplay
(
componentId
,
paramName
,
value
);
updatingParamNameLock
.
clear
();
}
void
QGCParamWidget
::
handleParameterListUpToDate
()
{
//turn off updates while we refresh the entire list
tree
->
setUpdatesEnabled
(
false
);
...
...
@@ -340,7 +341,6 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
parameterItem
->
setData
(
1
,
Qt
::
DisplayRole
,
value
);
}
parameterItem
->
setFlags
(
parameterItem
->
flags
()
|
Qt
::
ItemIsEditable
);
updatedLineItem_weak
=
parameterItem
;
//keep a temporary ref to the item that's being updated
//TODO insert alphabetically
parentItem
->
addChild
(
parameterItem
);
...
...
@@ -362,8 +362,6 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
}
}
updatedLineItem_weak
=
parameterItem
;
//keep a temporary ref to the item that's being updated
//update the parameterItem's data
if
(
value
.
type
()
==
QVariant
::
Char
)
{
parameterItem
->
setData
(
1
,
Qt
::
DisplayRole
,
value
.
toUInt
());
...
...
@@ -381,7 +379,6 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
parameterItem
->
setTextColor
(
0
,
QGC
::
colorDarkWhite
);
parameterItem
->
setTextColor
(
1
,
QGC
::
colorDarkWhite
);
updatedLineItem_weak
=
NULL
;
}
return
parameterItem
;
...
...
@@ -391,12 +388,19 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
void
QGCParamWidget
::
parameterItemChanged
(
QTreeWidgetItem
*
paramItem
,
int
column
)
{
if
(
paramItem
&&
column
>
0
)
{
if
(
!
paramItem
->
isSelected
()
||
(
paramItem
==
updatedLineItem_weak
))
{
//ignore updates reflected back from the data model, to avoid infinite loop
QString
key
=
paramItem
->
data
(
0
,
Qt
::
DisplayRole
).
toString
();
qDebug
()
<<
"parameterItemChanged:"
<<
key
<<
"with updatingParamNameLock:"
<<
updatingParamNameLock
;
if
(
key
==
updatingParamNameLock
)
{
qDebug
()
<<
"ignoring parameterItemChanged"
<<
key
;
return
;
}
else
{
updatingParamNameLock
=
key
;
}
QTreeWidgetItem
*
parent
=
paramItem
->
parent
();
while
(
parent
->
parent
()
!=
NULL
)
{
...
...
@@ -404,10 +408,9 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* paramItem, int column
}
// Parent is now top-level component
int
componentId
=
componentItems
->
key
(
parent
);
QString
key
=
paramItem
->
data
(
0
,
Qt
::
DisplayRole
).
toString
();
QVariant
value
=
paramItem
->
data
(
1
,
Qt
::
DisplayRole
);
bool
pending
=
paramDataModel
->
updatePendingParamWithValue
(
componentId
,
key
,
value
);
// If the value will result in an update
...
...
@@ -430,6 +433,7 @@ void QGCParamWidget::parameterItemChanged(QTreeWidgetItem* paramItem, int column
paramItem
->
setBackground
(
1
,
Qt
::
NoBrush
);
}
updatingParamNameLock
.
clear
();
}
}
...
...
src/ui/QGCParamWidget.h
View file @
656841a6
...
...
@@ -100,8 +100,7 @@ protected:
QLabel
*
statusLabel
;
///< User-facing parameter status label
QMap
<
int
,
QTreeWidgetItem
*>*
componentItems
;
///< The tree of component items, stored by component ID
QMap
<
int
,
QMap
<
QString
,
QTreeWidgetItem
*>*
>
paramGroups
;
///< Parameter groups to organize component items
QTreeWidgetItem
*
updatedLineItem_weak
;
///< weak ref to user-edited line
// QTreeWidgetItem* updatedPendingItem_weak;///< weak ref to pending-modified line
QString
updatingParamNameLock
;
///< Name of param currently being updated-- used for reducing echo on param change
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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