src/status.cpp \
src/settings.cpp \
src/imageprovider.cpp \
- src/graph.cpp
+ src/graph.cpp \
+ src/statsmodel.cpp \
+ src/stats.cpp
DISTFILES += qml/harbour-pedalo.qml \
qml/cover/CoverPage.qml \
src/settings.h \
src/harbour-pedalo.h \
src/imageprovider.h \
- src/graph.h
+ src/graph.h \
+ src/statsmodel.h \
+ src/stats.h
}
}
+ SlideshowView {
+ id: graphsView
+ width: isPortrait ? parent.width : parent.width * 0.5
+ height: (isPortrait ? statsPage.height / 2.0 : statsPage.height) - Theme.paddingLarge
+ itemWidth: width
+ clip: true
+
+ y: (isPortrait ? (statsPage.height / 2.0) : statsColumn.y)
+
+ model: statsmodel
+ delegate: Rectangle {
+ width: graphsView.itemWidth
+ height: graphsView.height
+ color: "transparent"
+
+ SectionHeader {
+ id: sectionHeaderItem
+ text: "item " + index
+ }
+
+ Graph {
+ id: graph
+ width: parent.width - 2 * Theme.horizontalPageMargin
+ anchors.top: sectionHeaderItem.bottom
+ height: (isPortrait ? (statsPage.height / 2.0) - Theme.paddingLarge : statsPage.height - Theme.paddingLarge - headerItem.height) - sectionHeaderItem.height
+ anchors.horizontalCenter: parent.horizontalCenter
+ model: values
+ labelsx: labels
+ //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 {
+ id: animx
+ duration: 2000
+ easing.type: Easing.InOutExpo
+ from: 0.0
+ to: 1.0
+ }
+ */
+ }
+
+ }
+ }
+
+ /*
Column {
id: graphsColumn
spacing: Theme.paddingLarge
}
}
}
+ */
}
}
#include "journey.h"
#include "journeymodel.h"
+#include "statsmodel.h"
#include "status.h"
#include "settings.h"
#include "imageprovider.h"
Settings::getInstance().setMainStatus(currentStatus);
Settings::getInstance().loadSettings();
+ StatsModel statsmodel;
+ Stats stats;
+ QList<float> data{0.1, 0.1, 0.2};
+ QStringList labels{"A", "B", "C"};
+ stats.setValues(data);
+ stats.setLabels(labels);
+ statsmodel.addStats(stats);
+
+ data = QList<float>{0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.5};
+ labels = QStringList{"M", "T", "W", "Th", "F", "S", "Su"};
+ stats.setValues(data);
+ stats.setLabels(labels);
+ statsmodel.addStats(stats);
+
+
QFile file;
file.setFileName(Settings::getConfigDir() + "/journeys.csv");
journeys.importFromFile(file);
ctxt->setContextProperty("journeymodel", &journeys);
ctxt->setContextProperty("currentStatus", ¤tStatus);
+ ctxt->setContextProperty("statsmodel", &statsmodel);
view->show();
int result = app->exec();
--- /dev/null
+#include "stats.h"
+
+Stats::Stats()
+{
+
+}
+
+QStringList Stats::getLabels() const {
+ return labels;
+}
+
+QList<float> Stats::getValues() const {
+ return values;
+}
+
+void Stats::setLabels(QStringList &value) {
+ labels = value;
+}
+
+void Stats::setValues(QList<float> &value) {
+ values = value;
+}
+
--- /dev/null
+#ifndef STATS_H
+#define STATS_H
+
+#include <QStringList>
+
+class Stats
+{
+public:
+ Stats();
+
+ QStringList getLabels() const;
+ QList<float> getValues() const;
+
+ void setLabels(QStringList &value);
+ void setValues(QList<float> &value);
+
+private:
+ QStringList labels;
+ QList<float> values;
+};
+
+#endif // STATS_H
--- /dev/null
+#include "statsmodel.h"
+
+StatsModel::StatsModel(QObject *parent) : QAbstractListModel(parent) {
+ roles[ValuesRole] = "values";
+ roles[LabelsRole] = "labels";
+}
+
+void StatsModel::addStats(const Stats &stats) {
+ this->stats.append(stats);
+}
+
+QHash<int, QByteArray> StatsModel::roleNames() const {
+ return roles;
+}
+
+int StatsModel::rowCount(const QModelIndex & parent) const {
+ Q_UNUSED(parent)
+ return stats.count();
+}
+
+QVariant StatsModel::data(const QModelIndex & index, int role) const {
+ if (index.row() < 0 || index.row() > stats.count())
+ return QVariant();
+
+ const Stats &stat = stats[index.row()];
+ if (role == ValuesRole)
+ return QVariant::fromValue<QList<float>>(stat.getValues());
+ else if (role == LabelsRole)
+ return stat.getLabels();
+ return QVariant();
+}
+
+void StatsModel::clear() {
+ stats.clear();
+}
+
--- /dev/null
+#ifndef STATSMODEL_H
+#define STATSMODEL_H
+
+#include <QAbstractListModel>
+#include <QStringList>
+
+#include "stats.h"
+
+class StatsModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ enum StatsRoles {
+ ValuesRole = Qt::UserRole + 1,
+ LabelsRole
+ };
+
+ QHash<int, QByteArray> roleNames() const;
+
+ StatsModel(QObject *parent = 0);
+
+ void addStats(const Stats &stats);
+
+ int rowCount(const QModelIndex & parent = QModelIndex()) const;
+
+ QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+
+ void clear();
+
+private:
+ QHash<int, QByteArray> roles;
+ QList<Stats> stats;
+};
+
+#endif // STATSMODEL_H