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
Telemetry
KUserFeedback
Commits
26a7edd7
Commit
26a7edd7
authored
Feb 18, 2017
by
Volker Krause
Browse files
Make both individual and accumulated values available for categories
The singular chart now also shows correct values.
parent
7213eb6a
Changes
5
Hide whitespace changes
Inline
Side-by-side
analyzer/analytics/categoryaggregator.cpp
View file @
26a7edd7
...
...
@@ -19,6 +19,8 @@
#include
<model/categoryaggregationmodel.h>
#include
<model/extrarowsproxymodel.h>
#include
<model/rolemappingproxymodel.h>
#include
<model/timeaggregationmodel.h>
#include
<QtCharts/QAreaSeries>
#include
<QtCharts/QChart>
...
...
@@ -79,11 +81,14 @@ QtCharts::QChart* CategoryAggregator::timelineChart()
m_timelineChart
->
addAxis
(
yAxis
,
Qt
::
AlignLeft
);
QLineSeries
*
prevSeries
=
nullptr
;
auto
model
=
new
RoleMappingProxyModel
(
m_timelineChart
.
get
());
model
->
setSourceModel
(
timeAggregationModel
());
model
->
addRoleMapping
(
Qt
::
DisplayRole
,
TimeAggregationModel
::
AccumulatedDisplayRole
);
for
(
int
i
=
1
;
i
<
timeAggregationModel
()
->
columnCount
();
++
i
)
{
auto
series
=
new
QLineSeries
;
auto
mapper
=
new
QVXYModelMapper
(
series
);
mapper
->
setModel
(
timeAggregationM
odel
()
);
mapper
->
setModel
(
m
odel
);
mapper
->
setXColumn
(
0
);
mapper
->
setYColumn
(
i
);
mapper
->
setFirstRow
(
0
);
...
...
analyzer/model/categoryaggregationmodel.cpp
View file @
26a7edd7
...
...
@@ -78,12 +78,14 @@ QVariant CategoryAggregationModel::data(const QModelIndex& index, int role) cons
}
const
auto
idx
=
index
.
row
()
*
m_categories
.
size
()
+
index
.
column
()
-
1
;
if
(
role
==
Qt
::
DisplayRole
)
{
return
m_data
[
idx
];
}
else
if
(
role
==
TimeAggregationModel
::
DataDisplayRole
)
{
if
(
index
.
column
()
==
1
)
switch
(
role
)
{
case
TimeAggregationModel
::
AccumulatedDisplayRole
:
return
m_data
[
idx
];
return
m_data
[
idx
]
-
m_data
[
idx
-
1
];
case
Qt
::
DisplayRole
:
case
TimeAggregationModel
::
DataDisplayRole
:
if
(
index
.
column
()
==
1
)
return
m_data
[
idx
];
return
m_data
[
idx
]
-
m_data
[
idx
-
1
];
}
return
{};
...
...
analyzer/model/timeaggregationmodel.cpp
View file @
26a7edd7
...
...
@@ -136,7 +136,7 @@ QVariant TimeAggregationModel::data(const QModelIndex& index, int role) const
if
(
!
index
.
isValid
())
return
{};
if
(
role
==
Qt
::
DisplayRole
||
role
==
DataDisplayRole
)
{
if
(
role
==
Qt
::
DisplayRole
||
role
==
DataDisplayRole
||
role
==
AccumulatedDisplayRole
)
{
const
auto
d
=
m_data
.
at
(
index
.
row
());
switch
(
index
.
column
())
{
case
0
:
return
d
.
time
.
toMSecsSinceEpoch
();
// this is required by QtCharts...
...
...
analyzer/model/timeaggregationmodel.h
View file @
26a7edd7
...
...
@@ -43,6 +43,7 @@ public:
MaximumValueRole
,
TimeDisplayRole
,
DataDisplayRole
,
AccumulatedDisplayRole
,
SamplesRole
,
AllSamplesRole
};
...
...
tests/auto/categoryaggregationmodeltest.cpp
View file @
26a7edd7
...
...
@@ -103,12 +103,14 @@ private slots:
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-11-27"
));
QCOMPARE
(
model
.
index
(
0
,
1
).
data
(
Qt
::
DisplayRole
).
toInt
(),
0
);
QCOMPARE
(
model
.
index
(
0
,
2
).
data
(
Qt
::
DisplayRole
).
toInt
(),
1
);
QCOMPARE
(
model
.
index
(
0
,
3
).
data
(
Qt
::
DisplayRole
).
toInt
(),
3
);
// values are cumulative
QCOMPARE
(
model
.
index
(
0
,
3
).
data
(
Qt
::
DisplayRole
).
toInt
(),
2
);
QCOMPARE
(
model
.
index
(
0
,
3
).
data
(
TimeAggregationModel
::
AccumulatedDisplayRole
).
toInt
(),
3
);
QCOMPARE
(
model
.
index
(
1
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-11-28"
));
QCOMPARE
(
model
.
index
(
1
,
1
).
data
(
Qt
::
DisplayRole
).
toInt
(),
1
);
QCOMPARE
(
model
.
index
(
1
,
2
).
data
(
Qt
::
DisplayRole
).
toInt
(),
1
);
QCOMPARE
(
model
.
index
(
0
,
3
).
data
(
Qt
::
DisplayRole
).
toInt
(),
3
);
QCOMPARE
(
model
.
index
(
1
,
2
).
data
(
Qt
::
DisplayRole
).
toInt
(),
0
);
QCOMPARE
(
model
.
index
(
0
,
3
).
data
(
Qt
::
DisplayRole
).
toInt
(),
2
);
QCOMPARE
(
model
.
index
(
0
,
3
).
data
(
TimeAggregationModel
::
AccumulatedDisplayRole
).
toInt
(),
3
);
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
MaximumValueRole
).
toInt
(),
3
);
}
...
...
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