// The effective value will be restricted by ApplicationWindow.allowedOrientations
allowedOrientations: Orientation.All
+ property int showingindex: 0
SilicaFlickable {
id: statsView
}
model: statsmodel
- delegate: Rectangle {
+ delegate: Item {
+ id: delegateItem
width: graphsView.itemWidth
height: graphsView.height
- color: "transparent"
SectionHeader {
id: sectionHeaderItem
anchors.top: sectionHeaderItem.bottom
height: (isPortrait ? (statsPage.height / 2.0) - Theme.paddingLarge : statsPage.height - Theme.paddingLarge - headerItem.height) - sectionHeaderItem.height
anchors.left: parent.left
- model: values
+ bardata: barvalues
+ //linedata: barvalues
labelsx: labels
//labelsy: ["0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"]
unitsy: units
primary: Theme.primaryColor
secondary: Theme.highlightColor
- highlight: Theme.highlightColor
+ highlight: Theme.secondaryColor
miny: minval
maxy: maxval
stepy: step
gap: 0.1
fontsize: Theme.fontSizeExtraSmall
- /*
- PropertyAnimation on animate {
- id: animx
- duration: 2000
- easing.type: Easing.InOutExpo
- from: 0.0
- to: 1.0
- }
- */
- }
-
- }
- }
+ animate: (graphsView.currentItem === delegateItem) ? 1.0 : 0.0
- /*
- Column {
- id: graphsColumn
- spacing: Theme.paddingLarge
- width: isPortrait ? parent.width : parent.width * 0.5
- y: (isPortrait ? (statsPage.height / 2.0) : statsColumn.y)
- anchors.left: isPortrait ? statsColumn.left : statsColumn.right
- anchors.leftMargin: Theme.horizontalPageMargin
-
-
- Graph {
- id: graph
- width: parent.width - 2 * Theme.horizontalPageMargin
- height: isPortrait ? (statsPage.height / 2.0) - Theme.paddingLarge : statsPage.height - Theme.paddingLarge - headerItem.height
- model: currentStatus.getGraphData()
- labelsx: ["M", "T", "W", "Th", "F", "S", "Su", "A", "B", "C"]
- //labelsy: ["0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"]
- unitsy: "%"
- primary: Theme.primaryColor
- secondary: Theme.highlightColor
- highlight: Theme.highlightColor
- miny: 0.0
- maxy: 1.0
- stepy: 0.1
- gap: 0.1
- fontsize: Theme.fontSizeExtraSmall
- PropertyAnimation on animate {
- duration: 2000
- easing.type: Easing.InOutExpo
- from: 0.0
- to: 1.0
+ Behavior on animate {
+ NumberAnimation {
+ easing.type: Easing.OutExpo
+ duration: 2000
+ }
+ }
}
}
}
- */
}
}
, highlight(QColor("#0000ff"))
, axisThickness(0.02)
, bars(7)
+ , points(7)
, gap(0.1)
- , minmodel(0.0f)
- , maxmodel(1.0f)
, miny(0.0f)
, maxy(1.0f)
, stepy(0.1f)
, fontsize(24.0)
, animate(1.0)
{
- model.clear();
+ bardata.clear();
+ linedata.clear();
labelsx.clear();
labelsy.clear();
}
float axiswidth;
int count;
int barfullwidth;
+ int pointfullwidth;
+ int labelfullwidth;
float labelygap;
float labelxgap;
- int labels;
+ int labelsycount;
+ int labelsxcount;
float labelheight;
+ float steps;
QRectF size = contentsBoundingRect();
- bars = model.length();
+ bars = bardata.length();
+ points = linedata.length();
+ labelsxcount = labelsx.length();
+
+ steps = labelsx.length();
+ if (steps == 0) {
+ steps = bars;
+ }
+
labelygap = size.height() * 0.1l;
labelxgap = size.width() * 0.11;
axiswidth = qMin(size.width() * axisThickness, size.height() * axisThickness);
barfullwidth = ((size.width() - labelxgap - axiswidth) / bars);
barwidth = barfullwidth * (1.0 - gap);
- labels = labelsy.length() > 0 ? labelsy.length() : 1 + (maxy - miny) / stepy;
- labelheight = (size.height() - labelygap - axiswidth) / (labels - 0.5);
+ pointfullwidth = ((size.width() - labelxgap - axiswidth) / points);
+ labelsycount = labelsy.length() > 0 ? labelsy.length() : 1 + (maxy - miny) / stepy;
+ labelheight = (size.height() - labelygap - axiswidth) / (labelsycount - 0.5);
+ labelfullwidth = ((size.width() - labelxgap - axiswidth) / labelsxcount);
QBrush axiscolour(primary);
QBrush barcolour(secondary);
+ QBrush linecolour(highlight);
painter->setBrush(axiscolour);
painter->setPen(Qt::NoPen);
painter->setRenderHint(QPainter::Antialiasing);
painter->setOpacity(1.0);
- const QPointF points[6] = {
+ const QPointF axis[6] = {
QPointF(labelxgap, (labelheight / 2.0)),
QPointF(labelxgap, size.height() - labelygap),
QPointF(size.width(), size.height() - labelygap),
QPointF(labelxgap + axiswidth, size.height() - labelygap - axiswidth),
QPointF(labelxgap + axiswidth, (labelheight / 2.0))
};
- painter->drawPolygon(points, 6);
+ painter->drawPolygon(axis, 6);
if (bars > 0) {
painter->setBrush(barcolour);
count = 0;
- for (QList<float>::const_iterator iter = model.constBegin(); (count < bars) && (iter != model.constEnd()); iter++) {
+ for (QList<float>::const_iterator iter = bardata.constBegin(); (count < bars) && (iter != bardata.constEnd()); iter++) {
float barheight = ((*iter) - miny) / (maxy - miny);
barheight = qBound(0.0f, barheight, 1.0f) * (size.height() - labelygap - axiswidth - (labelheight / 2.0));
barheight *= animate;
}
}
+ if (points > 0) {
+ QPen pen = QPen(linecolour, 8.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
+ painter->setPen(pen);
+ painter->setBrush(Qt::NoBrush);
+
+ QPointF point[points];
+ count = 0;
+ for (QList<float>::const_iterator iter = linedata.constBegin(); (count < points) && (iter != linedata.constEnd()); iter++) {
+ float lineheight = ((*iter) - miny) / (maxy - miny);
+ lineheight = qBound(0.0f, lineheight, 1.0f) * (size.height() - labelygap - axiswidth - (labelheight / 2.0));
+ point[count] = QPointF(labelxgap + axiswidth + (pointfullwidth * count) + (pointfullwidth / 2.0), size.height() - labelygap - lineheight - axiswidth);
+ count++;
+ }
+ painter->setClipRect(0, 0, labelxgap + axiswidth + (pointfullwidth / 2.0) - 8.0 + (size.width() - labelxgap - axiswidth - pointfullwidth + 16.0) * animate, size.height(), Qt::ReplaceClip);
+ painter->setClipping(true);
+ painter->drawPolyline(point, points);
+ }
+
+ painter->setClipping(false);
+
QFont font = painter->font();
font.setPixelSize(fontsize);
painter->setFont(font);
painter->setPen(primary);
painter->setBrush(Qt::NoBrush);
- if ((bars > 0) && (labelsx.length() == bars)) {
+ if (labelsxcount > 0) {
for (count = 0; count < bars; count++) {
- QRectF rect(labelxgap + axiswidth + (barfullwidth * count), size.height() - labelygap + 8.0, barfullwidth, labelygap - 8.0);
+ QRectF rect(labelxgap + axiswidth + (labelfullwidth * count), size.height() - labelygap + 8.0, labelfullwidth, labelygap - 8.0);
painter->drawText(rect, Qt::AlignHCenter | Qt::NoClip | Qt::TextSingleLine, labelsx[count]);
//painter->drawRect(rect);
}
}
if (labelsy.length() > 0) {
- for (count = 0; count < labels; count++) {
+ for (count = 0; count < labelsycount; count++) {
QRectF rect(0, size.height() - (labelheight * (count + 0.5)) - labelygap, labelxgap - 8.0, labelheight);
painter->drawText(rect, Qt::AlignVCenter | Qt::AlignRight | Qt::NoClip | Qt::TextSingleLine, labelsy[count]);
//painter->drawRect(rect);
}
else {
float labelvalue = miny;
- for (count = 0; count < labels; count++) {
+ for (count = 0; count < labelsycount; count++) {
QString labeltext = unitsy == "%" ? locale.toString(labelvalue * 100, 'f', 0) + "%" : locale.toString(labelvalue, 'g', 2) + unitsy;
QRectF rect(0, size.height() - (labelheight * (count + 0.5)) - labelygap, labelxgap - 8.0, labelheight);
painter->drawText(rect, Qt::AlignVCenter | Qt::AlignRight | Qt::NoClip | Qt::TextSingleLine, labeltext);
}
}
-QList<float> Graph::getModel() const {
- return model;
+QList<float> Graph::getBarData() const {
+ return bardata;
}
-void Graph::setModel(QList<float> value) {
- model = value;
- emit modelChanged();
-
- if (model.length() > 0) {
- minmodel = model[0];
- maxmodel = minmodel;
- foreach (int y, model) {
- if (y < minmodel) {
- minmodel = y;
- }
- if (y > maxmodel) {
- maxmodel = y;
- }
- }
- }
+void Graph::setBarData(QList<float> value) {
+ bardata = value;
+ emit barDataChanged();
+}
+
+QList<float> Graph::getLineData() const {
+ return linedata;
+}
+
+void Graph::setLineData(QList<float> value) {
+ linedata = value;
+ emit lineDataChanged();
}
QStringList Graph::getLabelsx() const {
class Graph : public QQuickPaintedItem
{
Q_OBJECT
- Q_PROPERTY(QList<float> model READ getModel WRITE setModel NOTIFY modelChanged)
+ Q_PROPERTY(QList<float> bardata READ getBarData WRITE setBarData NOTIFY barDataChanged)
+ Q_PROPERTY(QList<float> linedata READ getLineData WRITE setLineData NOTIFY lineDataChanged)
Q_PROPERTY(QStringList labelsx READ getLabelsx WRITE setLabelsx NOTIFY labelsxChanged)
Q_PROPERTY(QStringList labelsy READ getLabelsy WRITE setLabelsy NOTIFY labelsyChanged)
Q_PROPERTY(QColor primary READ getPrimary WRITE setPrimary NOTIFY primaryChanged)
Graph(QQuickItem *parent = 0);
void paint(QPainter *painter);
- QList<float> getModel() const;
- void setModel(QList<float> value);
+ QList<float> getBarData() const;
+ void setBarData(QList<float> value);
+ QList<float> getLineData() const;
+ void setLineData(QList<float> value);
QStringList getLabelsx() const;
void setLabelsx(QStringList value);
QStringList getLabelsy() const;
void setAnimate(float value);
private:
- QList<float> model;
+ QList<float> bardata;
+ QList<float> linedata;
QStringList labelsx;
QStringList labelsy;
QColor primary;
QColor highlight;
float axisThickness;
int bars;
+ int points;
float gap;
- float minmodel;
- float maxmodel;
float miny;
float maxy;
float stepy;
float animate;
signals:
- void modelChanged();
+ void barDataChanged();
+ void lineDataChanged();
void labelsxChanged();
void labelsyChanged();
void primaryChanged(QColor primary);
StartRole = Qt::UserRole + 1,
DurationRole,
OvertookRole,
- OvertakenByRole
+ OvertakenByRole,
};
QHash<int, QByteArray> roleNames() const;
return labels;
}
-QList<float> Stats::getValues() const {
- return values;
+QList<float> Stats::getBarValues() const {
+ return barvalues;
+}
+
+QList<float> Stats::getLineValues() const {
+ return linevalues;
}
QString Stats::getUnits() const {
labels = value;
}
-void Stats::setValues(QList<float> &value) {
- values = value;
+void Stats::setBarValues(QList<float> &value) {
+ barvalues = value;
+}
+
+void Stats::setLineValues(QList<float> &value) {
+ linevalues = value;
}
void Stats::setUnits(QString &value) {
virtual QString getTitle() const;
virtual QStringList getLabels() const;
- virtual QList<float> getValues() const;
+ virtual QList<float> getBarValues() const;
+ virtual QList<float> getLineValues() const;
virtual QString getUnits() const;
virtual float getMinVal() const;
virtual float getMaxVal() const;
virtual void setTitle(QString &value);
virtual void setLabels(QStringList &value);
- virtual void setValues(QList<float> &value);
+ virtual void setBarValues(QList<float> &value);
+ virtual void setLineValues(QList<float> &value);
virtual void setUnits(QString &value);
virtual void setMinVal(float value);
virtual void setMaxVal(float value);
protected:
QString title;
QStringList labels;
- QList<float> values;
+ QList<float> barvalues;
+ QList<float> linevalues;
QString units;
float minval;
float maxval;
int pos;
qDebug() << "Calculating values";
- values.clear();
+ barvalues.clear();
for (pos = 0; pos < 24; pos++) {
passed[pos] = 0.0;
if (result > maxval) {
maxval = result;
}
- values << result;
+ barvalues << result;
}
step = (maxval > 5.0) ? qRound(maxval / 5.0) : (maxval / 5.0);
int pos;
qDebug() << "Calculating values";
- values.clear();
+ barvalues.clear();
for (pos = 0; pos < 24; pos++) {
minsperhour[pos] = 0u;
if (totalmins > 0) {
result = ((double)minsperhour[pos] / (double)totalmins);
}
- values << result;
+ barvalues << result;
}
qDebug() << "Calculated values";
#include "statsmodel.h"
-StatsModel::StatsModel(QObject *parent) : QAbstractListModel(parent) {
+StatsModel::StatsModel(QObject *parent) : QAbstractListModel(parent),
+ visibleIndex(-1)
+{
roles[TitleRole] = "title";
- roles[ValuesRole] = "values";
+ roles[BarValuesRole] = "barvalues";
+ roles[LineValuesRole] = "linevalues";
roles[LabelsRole] = "labels";
roles[UnitsRole] = "units";
roles[MinValRole] = "minval";
const Stats *stat = stats[index.row()];
if (role == TitleRole)
return stat->getTitle();
- else if (role == ValuesRole)
- return QVariant::fromValue<QList<float>>(stat->getValues());
+ else if (role == BarValuesRole)
+ return QVariant::fromValue<QList<float>>(stat->getBarValues());
+ else if (role == LineValuesRole)
+ return QVariant::fromValue<QList<float>>(stat->getLineValues());
else if (role == LabelsRole)
return stat->getLabels();
else if (role == UnitsRole)
public:
enum StatsRoles {
TitleRole = Qt::UserRole + 1,
- ValuesRole,
+ BarValuesRole,
+ LineValuesRole,
LabelsRole,
UnitsRole,
MinValRole,
MaxValRole,
- StepRole
+ StepRole,
};
QHash<int, QByteArray> roleNames() const;
private:
QHash<int, QByteArray> roles;
QList<Stats *> stats;
+ int visibleIndex;
};
#endif // STATSMODEL_H
int pos;
qDebug() << "Calculating values";
- values.clear();
+ barvalues.clear();
for (pos = 0; pos < 7; pos++) {
duration[pos] = 0.0;
if (result > maxval) {
maxval = result;
}
- values << result;
+ barvalues << result;
}
step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);
int pos;
qDebug() << "Calculating values";
- values.clear();
+ barvalues.clear();
for (pos = 0; pos < 7; pos++) {
passed[pos] = 0u;
if (result > maxval) {
maxval = result;
}
- values << result;
+ barvalues << result;
}
step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);