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
f1116bd9
Commit
f1116bd9
authored
Feb 11, 2017
by
Volker Krause
Browse files
Move numeric timeline chart to new Aggregator API
parent
6b49f296
Changes
4
Hide whitespace changes
Inline
Side-by-side
analyzer/analytics/analyticsview.cpp
View file @
f1116bd9
...
...
@@ -80,6 +80,7 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
auto
chartModeGroup
=
new
QActionGroup
(
this
);
chartModeGroup
->
addAction
(
ui
->
actionSingularChart
);
chartModeGroup
->
addAction
(
ui
->
actionTimelineChart
);
connect
(
chartModeGroup
,
&
QActionGroup
::
triggered
,
this
,
&
AnalyticsView
::
updateChart
);
auto
chartMode
=
new
QMenu
(
tr
(
"&Char mode"
),
this
);
chartMode
->
addAction
(
ui
->
actionSingularChart
);
...
...
@@ -111,6 +112,8 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
AnalyticsView
::~
AnalyticsView
()
{
disconnect
(
ui
->
chartView
->
chart
(),
&
QObject
::
destroyed
,
this
,
&
AnalyticsView
::
updateChart
);
QSettings
settings
;
settings
.
beginGroup
(
QStringLiteral
(
"Analytics"
));
settings
.
setValue
(
QStringLiteral
(
"TimeAggregationMode"
),
m_timeAggregationModel
->
aggregationMode
());
...
...
@@ -166,8 +169,32 @@ void AnalyticsView::chartSelected()
ui
->
actionTimelineChart
->
setChecked
(
chartMode
&
Aggregator
::
Timeline
);
}
m_chart
->
setModel
(
aggr
->
timeAggregationModel
());
// ui->chartView->setChart(aggr->timelineChart());
updateChart
();
}
void
AnalyticsView
::
updateChart
()
{
auto
aggr
=
ui
->
chartType
->
currentData
().
value
<
Aggregator
*>
();
if
(
!
aggr
)
return
;
if
(
ui
->
chartView
->
chart
())
disconnect
(
ui
->
chartView
->
chart
(),
&
QObject
::
destroyed
,
this
,
&
AnalyticsView
::
updateChart
);
// TODO
if
(
ui
->
actionTimelineChart
->
isChecked
())
{
if
(
aggr
->
timelineChart
())
{
ui
->
chartView
->
setChart
(
aggr
->
timelineChart
());
}
else
{
ui
->
chartView
->
setChart
(
m_chart
->
chart
());
m_chart
->
setModel
(
aggr
->
timeAggregationModel
());
}
}
else
if
(
ui
->
actionSingularChart
->
isChecked
())
{
ui
->
chartView
->
setChart
(
aggr
->
singlularChart
());
}
if
(
ui
->
chartView
->
chart
())
connect
(
ui
->
chartView
->
chart
(),
&
QObject
::
destroyed
,
this
,
&
AnalyticsView
::
updateChart
);
}
Aggregator
*
AnalyticsView
::
createAggregator
(
const
Aggregation
&
aggr
)
const
...
...
analyzer/analytics/analyticsview.h
View file @
f1116bd9
...
...
@@ -57,6 +57,7 @@ signals:
private:
void
chartSelected
();
void
updateChart
();
Aggregator
*
createAggregator
(
const
Aggregation
&
aggr
)
const
;
...
...
analyzer/analytics/numericaggregator.cpp
View file @
f1116bd9
...
...
@@ -18,8 +18,19 @@
#include
"numericaggregator.h"
#include
<model/numericaggregationmodel.h>
#include
<model/timeaggregationmodel.h>
#include
<QtCharts/QBarCategoryAxis>
#include
<QtCharts/QBoxPlotSeries>
#include
<QtCharts/QChart>
#include
<QtCharts/QHBoxPlotModelMapper>
#include
<QtCharts/QValueAxis>
#include
<QApplication>
#include
<QDateTime>
using
namespace
UserFeedback
::
Analyzer
;
using
namespace
QtCharts
;
NumericAggregator
::
NumericAggregator
()
=
default
;
NumericAggregator
::~
NumericAggregator
()
=
default
;
...
...
@@ -45,11 +56,42 @@ QAbstractItemModel* NumericAggregator::timeAggregationModel()
m_model
->
setSourceModel
(
sourceModel
());
const
auto
e
=
aggregation
().
elements
().
at
(
0
);
m_model
->
setAggregationValue
(
e
.
schemaEntry
().
name
()
+
QLatin1Char
(
'.'
)
+
e
.
schemaEntryElement
().
name
());
QObject
::
connect
(
m_model
.
get
(),
&
QAbstractItemModel
::
modelReset
,
[
this
]()
{
m_timelineChart
.
reset
();
});
}
return
m_model
.
get
();
}
QtCharts
::
QChart
*
NumericAggregator
::
timelineChart
()
{
return
nullptr
;
if
(
m_timelineChart
)
return
m_timelineChart
.
get
();
m_timelineChart
.
reset
(
new
QChart
);
m_timelineChart
->
setTheme
(
qApp
->
palette
().
color
(
QPalette
::
Window
).
lightnessF
()
<
0.25
?
QChart
::
ChartThemeDark
:
QChart
::
ChartThemeLight
);
auto
xAxis
=
new
QBarCategoryAxis
(
m_timelineChart
.
get
());
auto
yAxis
=
new
QValueAxis
(
m_timelineChart
.
get
());
m_timelineChart
->
addAxis
(
xAxis
,
Qt
::
AlignBottom
);
m_timelineChart
->
addAxis
(
yAxis
,
Qt
::
AlignLeft
);
auto
series
=
new
QBoxPlotSeries
(
m_timelineChart
.
get
());
series
->
setName
(
displayName
());
auto
mapper
=
new
QHBoxPlotModelMapper
(
series
);
mapper
->
setModel
(
timeAggregationModel
());
mapper
->
setFirstColumn
(
1
);
mapper
->
setFirstBoxSetRow
(
0
);
mapper
->
setLastBoxSetRow
(
timeAggregationModel
()
->
rowCount
());
mapper
->
setSeries
(
series
);
m_timelineChart
->
addSeries
(
series
);
series
->
attachAxis
(
xAxis
);
series
->
attachAxis
(
yAxis
);
QStringList
l
;
for
(
int
i
=
0
;
i
<
m_model
->
rowCount
();
++
i
)
{
l
.
push_back
(
timeAggregationModel
()
->
index
(
i
,
0
).
data
(
TimeAggregationModel
::
DateTimeRole
).
toDateTime
().
toString
(
QStringLiteral
(
"yyyy-MM-dd"
)));
}
xAxis
->
setCategories
(
l
);
return
m_timelineChart
.
get
();
}
analyzer/analytics/numericaggregator.h
View file @
f1116bd9
...
...
@@ -40,6 +40,7 @@ public:
private:
std
::
unique_ptr
<
NumericAggregationModel
>
m_model
;
std
::
unique_ptr
<
QtCharts
::
QChart
>
m_timelineChart
;
};
}}
...
...
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