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
a40c8870
Commit
a40c8870
authored
Oct 20, 2013
by
John Tapsell
Browse files
QGCXYPlot: Seperate the number of points shown and number of points store
parent
6c59f5f4
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/ui/designer/QGCXYPlot.cc
View file @
a40c8870
...
...
@@ -15,14 +15,17 @@ class XYPlotCurve : public QwtPlotItem
{
public:
XYPlotCurve
()
{
m_maxPoints
=
15
;
m_maxStorePoints
=
10000
;
m_maxShowPoints
=
15
;
setItemAttribute
(
QwtPlotItem
::
AutoScale
);
minMaxSet
=
false
;
m_color
=
Qt
::
white
;
}
void
setMaxDataPoints
(
int
max
)
{
m_maxPoints
=
max
;
}
int
maxPoints
()
const
{
return
m_maxPoints
;
}
void
setMaxDataStorePoints
(
int
max
)
{
m_maxStorePoints
=
max
;
itemChanged
();
}
void
setMaxDataShowPoints
(
int
max
)
{
m_maxShowPoints
=
max
;
itemChanged
();
}
int
maxDataStorePoints
()
const
{
return
m_maxStorePoints
;
}
int
maxDataShowPoints
()
const
{
return
m_maxShowPoints
;
}
void
appendData
(
const
QPointF
&
data
)
{
if
(
!
minMaxSet
)
{
...
...
@@ -36,9 +39,8 @@ public:
ymax
=
qMax
(
ymax
,
data
.
y
());
}
m_data
.
append
(
data
);
while
(
m_data
.
size
()
>
m_maxPoints
)
while
(
m_data
.
size
()
>
m_max
Store
Points
)
m_data
.
removeFirst
();
itemChanged
();
}
...
...
@@ -84,18 +86,18 @@ protected:
{
Q_UNUSED
(
canvasRect
);
QPointF
lastPoint
;
int
i
=
0
;
if
(
m_data
.
isEmpty
())
return
;
int
dataSize
=
m_data
.
size
();
foreach
(
const
QPointF
&
point
,
m_data
)
{
int
start
=
qMax
(
0
,
m_data
.
size
()
-
m_maxShowPoints
);
int
count
=
qMin
(
m_data
.
size
()
-
start
,
m_maxShowPoints
);
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
const
QPointF
&
point
=
m_data
.
at
(
i
+
start
);
QPointF
paintCoord
=
QPointF
(
xMap
.
xTransform
(
point
.
x
()),
yMap
.
xTransform
(
point
.
y
()));
m_color
.
setAlpha
((
i
+
m_maxPoints
-
dataSize
)
*
255
/
m_maxPoints
);
m_color
.
setAlpha
((
m_max
Show
Points
-
count
+
i
)
*
255
/
m_max
Show
Points
);
p
->
setPen
(
m_color
);
if
(
i
++
)
if
(
i
!=
0
)
p
->
drawLine
(
lastPoint
,
paintCoord
);
if
(
i
==
dataSize
)
{
if
(
i
==
count
-
1
)
{
//Draw marker for first point
const
int
marker_radius
=
2
;
QRectF
marker
=
QRectF
(
paintCoord
.
x
()
-
marker_radius
,
paintCoord
.
y
()
-
marker_radius
,
marker_radius
*
2
+
1
,
marker_radius
*
2
+
1
);
...
...
@@ -107,7 +109,8 @@ protected:
private:
QList
<
QPointF
>
m_data
;
int
m_maxPoints
;
int
m_maxStorePoints
;
int
m_maxShowPoints
;
mutable
QColor
m_color
;
double
xmin
;
...
...
@@ -123,7 +126,6 @@ QGCXYPlot::QGCXYPlot(QWidget *parent) :
ui
(
new
Ui
::
QGCXYPlot
),
plot
(
0
),
xycurve
(
0
),
maxElementsToDraw
(
5
),
x
(
0
),
x_timestamp_us
(
0
),
x_valid
(
false
),
...
...
@@ -167,7 +169,8 @@ QGCXYPlot::QGCXYPlot(QWidget *parent) :
connect
(
ui
->
minY
,
SIGNAL
(
valueChanged
(
double
)),
this
,
SLOT
(
updateMinMaxSettings
()));
connect
(
ui
->
maxY
,
SIGNAL
(
valueChanged
(
double
)),
this
,
SLOT
(
updateMinMaxSettings
()));
connect
(
ui
->
automaticAxisRange
,
SIGNAL
(
toggled
(
bool
)),
this
,
SLOT
(
updateMinMaxSettings
()));
connect
(
ui
->
maxDataSpinBox
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
updateMinMaxSettings
()));
connect
(
ui
->
maxDataShowSpinBox
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
updateMinMaxSettings
()));
connect
(
ui
->
maxDataStoreSpinBox
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
updateMinMaxSettings
()));
setEditMode
(
false
);
}
...
...
@@ -191,7 +194,8 @@ void QGCXYPlot::setEditMode(bool editMode)
ui
->
editFinishButton
->
setVisible
(
editMode
);
ui
->
editLine1
->
setVisible
(
editMode
);
ui
->
editLine2
->
setVisible
(
editMode
);
ui
->
lblMaxData
->
setVisible
(
editMode
);
ui
->
lblMaxDataStore
->
setVisible
(
editMode
);
ui
->
lblMaxDataShow
->
setVisible
(
editMode
);
ui
->
lblMaxX
->
setVisible
(
editMode
);
ui
->
lblMaxY
->
setVisible
(
editMode
);
ui
->
lblMinX
->
setVisible
(
editMode
);
...
...
@@ -200,7 +204,8 @@ void QGCXYPlot::setEditMode(bool editMode)
ui
->
maxY
->
setVisible
(
editMode
);
ui
->
minX
->
setVisible
(
editMode
);
ui
->
minY
->
setVisible
(
editMode
);
ui
->
maxDataSpinBox
->
setVisible
(
editMode
);
ui
->
maxDataShowSpinBox
->
setVisible
(
editMode
);
ui
->
maxDataStoreSpinBox
->
setVisible
(
editMode
);
ui
->
automaticAxisRange
->
setVisible
(
editMode
);
if
(
!
editMode
)
{
...
...
@@ -221,7 +226,8 @@ void QGCXYPlot::writeSettings(QSettings& settings)
settings
.
setValue
(
"QGC_XYPLOT_MAXX"
,
ui
->
maxX
->
value
());
settings
.
setValue
(
"QGC_XYPLOT_MINY"
,
ui
->
minY
->
value
());
settings
.
setValue
(
"QGC_XYPLOT_MAXY"
,
ui
->
maxY
->
value
());
settings
.
setValue
(
"QGC_XYPLOT_MAXDATA"
,
ui
->
maxDataSpinBox
->
value
());
settings
.
setValue
(
"QGC_XYPLOT_MAXDATA_STORE"
,
ui
->
maxDataStoreSpinBox
->
value
());
settings
.
setValue
(
"QGC_XYPLOT_MAXDATA_SHOW"
,
ui
->
maxDataShowSpinBox
->
value
());
settings
.
setValue
(
"QGC_XYPLOT_AUTO"
,
ui
->
automaticAxisRange
->
isChecked
());
settings
.
sync
();
...
...
@@ -235,7 +241,8 @@ void QGCXYPlot::readSettings(const QString& pre,const QVariantMap& settings)
ui
->
maxX
->
setValue
(
settings
.
value
(
pre
+
"QGC_XYPLOT_MAXX"
,
0
).
toDouble
());
ui
->
minY
->
setValue
(
settings
.
value
(
pre
+
"QGC_XYPLOT_MINY"
,
0
).
toDouble
());
ui
->
maxY
->
setValue
(
settings
.
value
(
pre
+
"QGC_XYPLOT_MAXY"
,
0
).
toDouble
());
ui
->
maxDataSpinBox
->
setValue
(
settings
.
value
(
pre
+
"QGC_XYPLOT_MAXDATA"
,
15
).
toInt
());
ui
->
maxDataStoreSpinBox
->
setValue
(
settings
.
value
(
pre
+
"QGC_XYPLOT_MAXDATA_STORE"
,
10000
).
toInt
());
ui
->
maxDataShowSpinBox
->
setValue
(
settings
.
value
(
pre
+
"QGC_XYPLOT_MAXDATA_SHOW"
,
15
).
toInt
());
plot
->
setAxisTitle
(
QwtPlot
::
xBottom
,
ui
->
editXParam
->
currentText
());
plot
->
setAxisTitle
(
QwtPlot
::
yLeft
,
ui
->
editYParam
->
currentText
());
updateMinMaxSettings
();
...
...
@@ -250,7 +257,8 @@ void QGCXYPlot::readSettings(const QSettings& settings)
ui
->
maxX
->
setValue
(
settings
.
value
(
"QGC_XYPLOT_MAXX"
,
0
).
toDouble
());
ui
->
minY
->
setValue
(
settings
.
value
(
"QGC_XYPLOT_MINY"
,
0
).
toDouble
());
ui
->
maxY
->
setValue
(
settings
.
value
(
"QGC_XYPLOT_MAXY"
,
0
).
toDouble
());
ui
->
maxDataSpinBox
->
setValue
(
settings
.
value
(
"QGC_XYPLOT_MAXDATA"
,
15
).
toInt
());
ui
->
maxDataStoreSpinBox
->
setValue
(
settings
.
value
(
"QGC_XYPLOT_MAXDATA_STORE"
,
10000
).
toInt
());
ui
->
maxDataShowSpinBox
->
setValue
(
settings
.
value
(
"QGC_XYPLOT_MAXDATA_SHOW"
,
15
).
toInt
());
plot
->
setAxisTitle
(
QwtPlot
::
xBottom
,
ui
->
editXParam
->
currentText
());
plot
->
setAxisTitle
(
QwtPlot
::
yLeft
,
ui
->
editYParam
->
currentText
());
updateMinMaxSettings
();
...
...
@@ -316,5 +324,13 @@ void QGCXYPlot::updateMinMaxSettings()
}
else
{
xycurve
->
setMinMax
(
ui
->
minX
->
value
(),
ui
->
maxX
->
value
(),
ui
->
minY
->
value
(),
ui
->
maxY
->
value
());
}
xycurve
->
setMaxDataPoints
(
ui
->
maxDataSpinBox
->
value
());
xycurve
->
setMaxDataStorePoints
(
ui
->
maxDataStoreSpinBox
->
value
());
xycurve
->
setMaxDataShowPoints
(
ui
->
maxDataShowSpinBox
->
value
());
}
void
QGCXYPlot
::
on_maxDataShowSpinBox_valueChanged
(
int
value
)
{
ui
->
maxDataStoreSpinBox
->
setMinimum
(
value
);
if
(
ui
->
maxDataStoreSpinBox
->
value
()
<
value
)
ui
->
maxDataStoreSpinBox
->
setValue
(
value
);
}
src/ui/designer/QGCXYPlot.h
View file @
a40c8870
...
...
@@ -31,13 +31,14 @@ public slots:
void
styleChanged
(
MainWindow
::
QGC_MAINWINDOW_STYLE
style
);
void
updateMinMaxSettings
();
private
slots
:
void
on_maxDataShowSpinBox_valueChanged
(
int
value
);
private:
Ui
::
QGCXYPlot
*
ui
;
QwtPlot
*
plot
;
XYPlotCurve
*
xycurve
;
int
maxElementsToDraw
;
double
x
;
/**< Last unused value for the x-coordinate */
quint64
x_timestamp_us
;
/**< Timestamp that we last recieved a value for x */
bool
x_valid
;
/**< Whether we have recieved an x value but so far no corresponding y value */
...
...
src/ui/designer/QGCXYPlot.ui
View file @
a40c8870
...
...
@@ -7,7 +7,7 @@
<x>
0
</x>
<y>
0
</y>
<width>
771
</width>
<height>
626
</height>
<height>
365
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
...
...
@@ -145,17 +145,17 @@
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout_3"
>
<item>
<widget
class=
"QLabel"
name=
"lblMaxData"
>
<widget
class=
"QLabel"
name=
"lblMaxData
Show
"
>
<property
name=
"text"
>
<string>
Number of data points to
&
show:
</string>
</property>
<property
name=
"buddy"
>
<cstring>
maxDataSpinBox
</cstring>
<cstring>
maxDataS
howS
pinBox
</cstring>
</property>
</widget>
</item>
<item>
<widget
class=
"QSpinBox"
name=
"maxDataSpinBox"
>
<widget
class=
"QSpinBox"
name=
"maxDataS
howS
pinBox"
>
<property
name=
"minimum"
>
<number>
2
</number>
</property>
...
...
@@ -167,6 +167,29 @@
</property>
</widget>
</item>
<item>
<widget
class=
"QLabel"
name=
"lblMaxDataStore"
>
<property
name=
"text"
>
<string>
To s
&
tore:
</string>
</property>
<property
name=
"buddy"
>
<cstring>
maxDataStoreSpinBox
</cstring>
</property>
</widget>
</item>
<item>
<widget
class=
"QSpinBox"
name=
"maxDataStoreSpinBox"
>
<property
name=
"minimum"
>
<number>
10
</number>
</property>
<property
name=
"maximum"
>
<number>
999999999
</number>
</property>
<property
name=
"value"
>
<number>
15
</number>
</property>
</widget>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"automaticAxisRange"
>
<property
name=
"text"
>
...
...
@@ -348,7 +371,9 @@
<tabstops>
<tabstop>
editXParam
</tabstop>
<tabstop>
editYParam
</tabstop>
<tabstop>
maxDataSpinBox
</tabstop>
<tabstop>
maxDataShowSpinBox
</tabstop>
<tabstop>
maxDataStoreSpinBox
</tabstop>
<tabstop>
automaticAxisRange
</tabstop>
<tabstop>
minX
</tabstop>
<tabstop>
maxX
</tabstop>
<tabstop>
minY
</tabstop>
...
...
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