diff --git a/packaging/main_window.png b/packaging/main_window.png index 045f7fc00510ef709b9374ba857263ef89b0e018..a710a3e018e49f9ca98c7f329c455b0e99474297 100644 Binary files a/packaging/main_window.png and b/packaging/main_window.png differ diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml index 6b3b7fa13f3f4e5c263d0945b7cacecd21dba40a..dc25b93722eeb5302fd1f9ce724a93a036507714 100644 --- a/src/contents/ui/main.qml +++ b/src/contents/ui/main.qml @@ -29,24 +29,53 @@ Kirigami.ApplicationWindow { } } title: "Monitor" - - Component.onCompleted: { - monitorTypes.append({"chartType": "temperature", "title": i18n("Temperature"), "icon": "filename-bpm-amarok", "lineColor": "red", "modelCol": 1}); - monitorTypes.append({"chartType": "moisture", "title": i18n("Moisture"), "icon": "colors-chromablue", "lineColor": "cyan", "modelCol": 3}); - monitorTypes.append({"chartType": "conductivity", "title": i18n("Conductivity"), "icon": "quickopen", "lineColor": "yellow", "modelCol": 4}); - monitorTypes.append({"chartType": "brightness", "title": i18n("Brightness"), "icon": "contrast", "lineColor": "orange", "modelCol": 2}); - } Kirigami.CardsListView { id: monitorView model: ListModel { id: monitorTypes + ListElement{ + chartType: "temperature" + title: "Temperature" + icon: "filename-bpm-amarok" + lineColor: "red" + yMin: -20 + yMax: 40 + modelCol: 1 + } + ListElement{ + chartType: "moisture" + title: "Moisture" + icon: "colors-chromablue" + lineColor: "cyan" + yMin: 0 + yMax: 75 + modelCol: 3 + } + ListElement{ + chartType: "conductivity" + title: "Conductivity" + icon: "quickopen" + lineColor: "gold" + yMin: 0 + yMax: 6000 + modelCol: 4 + } + ListElement{ + chartType: "brightness" + title: "Brightness" + icon: "contrast" + lineColor: "orange" + yMin: 0 + yMax: 30000 + modelCol: 2 + } } delegate: Kirigami.Card { id: card banner { - title: model.title + title: i18n(model.title) titleIcon: model.icon titleLevel: 2 } @@ -76,20 +105,33 @@ Kirigami.ApplicationWindow { implicitWidth: 300 implicitHeight: 200 Charts.ChartView { + id: chart antialiasing: true - backgroundColor: Kirigami.Theme.backgroundColor + backgroundColor: Kirigami.Theme.buttonBackgroundColor titleColor: Kirigami.Theme.textColor legend.visible: false anchors.fill: parent + Charts.LineSeries { + id: series axisX: Charts.DateTimeAxis { + id: dateAx labelsColor: Kirigami.Theme.textColor format: "MMM d yyyy ha" + + Component.onCompleted: { + //On load, change date span to last 24 to remove awkward 1969 empty dates. + var yesterday = new Date(); + yesterday.setDate(yesterday.getDate() -1); + dateAx.min = yesterday; + dateAx.max = new Date(); + } } axisY: Charts.ValueAxis { + id: valueAx labelsColor: Kirigami.Theme.textColor - min: 0 - max: 50 + min: yMin + max: yMax } color: model.lineColor name: model.title @@ -97,10 +139,18 @@ Kirigami.ApplicationWindow { Charts.VXYModelMapper { model: qiflora.model xColumn: 0 - yColumn: 1 + yColumn: modelCol } - } + } + Connections { + target: qiflora.model + onRowsInserted: { + //Readjust graphs to show date range from earliest item. + dateAx.max = new Date(); + dateAx.min = qiflora.model.data(qiflora.model.index(0,0)); + } + } } } } diff --git a/src/miflora/florahistory.cpp b/src/miflora/florahistory.cpp index 8032e6c35fb47efba411848ca1e9a85605d82ad4..bb12483c3f8d7e458240ce6eb6c58e1446529911 100644 --- a/src/miflora/florahistory.cpp +++ b/src/miflora/florahistory.cpp @@ -16,12 +16,13 @@ */ #include "florahistory.h" +#include QVariant FloraHistory::data(const QModelIndex& index, int role) const { if(role == Qt::DisplayRole && tableData.size()-1 >= index.row()) { if(index.column() == 0) { - return QVariant(tableData[index.row()].time.toMSecsSinceEpoch()); + return QVariant(tableData[index.row()].time); } else if(index.column() == 1) { return QVariant(tableData[index.row()].temperature); } else if(index.column() == 2) { @@ -45,43 +46,14 @@ int FloraHistory::columnCount(const QModelIndex& parent) const int FloraHistory::rowCount(const QModelIndex& parent) const { - //return tableData.size(); - return 23; -} - -QVariant FloraHistory::headerData(int section, Qt::Orientation orientation, int role) const -{ - if(role == Qt::DisplayRole) { - if(section == 0) { - return QVariant("Time"); - } else if(section == 1) { - return QVariant("Temperature"); - } else if(section == 2) { - return QVariant("Brightness"); - } else if(section == 3) { - return QVariant("Moisture"); - } else if(section == 4) { - return QVariant("Conductivity"); - } else { - return QVariant(); - } - } else { - return QVariant(); - } -} - -Qt::ItemFlags FloraHistory::flags(const QModelIndex& index) const -{ - return QAbstractTableModel::flags(index); + return tableData.size(); } void FloraHistory::addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity) { - //beginInsertRows(QModelIndex(),tableData.size(),tableData.size()); + beginInsertRows(QModelIndex(),tableData.size(),tableData.size()); tableData.append(flora_data{time, temperature, brightness, moisture, conductivity}); - //emit dataChanged(createIndex(0,0), createIndex(tableData.size()-1,4)); - //endInsertRows(); - emit dataChanged(createIndex(0,0),createIndex(23,4)); + endInsertRows(); } void FloraHistory::clear() diff --git a/src/miflora/florahistory.h b/src/miflora/florahistory.h index 1fc2883999b46014ab5c99cdf5acdc9ecab77dc6..93cf3ba285f0a542d063dd5d19e66812103f214f 100644 --- a/src/miflora/florahistory.h +++ b/src/miflora/florahistory.h @@ -31,16 +31,12 @@ class FloraHistory : public QAbstractTableModel public: - QVariant data(const QModelIndex& index, int role) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; int columnCount(const QModelIndex& parent) const override; int rowCount(const QModelIndex& parent) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - - Qt::ItemFlags flags(const QModelIndex & index) const override; - void clear(); void addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity); diff --git a/src/miflora/miflora.cpp b/src/miflora/miflora.cpp index b09295e598a0f2081bb35242ac5e0db0e0dfc0ce..06f4a1e32ae08bd17aab4a557f4c938e75575daa 100644 --- a/src/miflora/miflora.cpp +++ b/src/miflora/miflora.cpp @@ -173,10 +173,10 @@ void MiFlora::historyServiceCharRead(QLowEnergyCharacteristic readChar, QByteArr connect(historyService, &QLowEnergyService::characteristicRead, this, &MiFlora::historyServiceCharReadData); disconnect(historyService, &QLowEnergyService::characteristicWritten, this, &MiFlora::historyServiceCharWritten); connect(historyService, &QLowEnergyService::characteristicWritten, this, &MiFlora::historyServiceCharWrittenData); - //Take size given and start by giving the last 24 numbers(if that many) to represent the last day of data. TODO: look to have amount of time be configurable. + //Take size given and start by giving the last 48 numbers(if that many) to represent the last day of data. TODO: look to have amount of time be configurable. lastHistoryEntry = 0; - if(size > 24) { - currentHistoryEntry = 24; + if(size > 48) { + currentHistoryEntry = 48; } else { currentHistoryEntry = size; } @@ -225,10 +225,8 @@ void MiFlora::historyServiceCharReadData(QLowEnergyCharacteristic readChar, QByt parser >> conduct; QDateTime convTime; convTime.setSecsSinceEpoch(deviceStartTime+time); - qDebug() << convTime.toString(Qt::ISODate) << temp << bright << moisture << conduct; //Write out items to table floraModel->addData(convTime, temp, bright, moisture, conduct); - //emit historyUpdated(); } if(lastHistoryEntry == currentHistoryEntry) { diff --git a/src/miflora/miflora.h b/src/miflora/miflora.h index 55f3718d88a9da10a1c3d1732a4cfd795bc346db..3bc910256f43b492d2ba7d3ee642759b680dd8d0 100644 --- a/src/miflora/miflora.h +++ b/src/miflora/miflora.h @@ -28,8 +28,8 @@ #include #include #include -#include #include "florahistory.h" +#include /** * Class using QtBluetooth to find and retrive info from Mi Flora devices. @@ -43,19 +43,20 @@ class MiFlora : public QObject Q_PROPERTY(quint16 conduction NOTIFY conductionChanged MEMBER conduct) Q_PROPERTY(quint8 battery NOTIFY batteryChanged MEMBER battery) Q_PROPERTY(QQmlListProperty devices READ getDeviceList NOTIFY newDeviceFound) - Q_PROPERTY(QAbstractTableModel* model READ getModel NOTIFY historyUpdated) + Q_PROPERTY(QAbstractTableModel* model READ getModel NOTIFY modelUpdated) public: Q_INVOKABLE void startSearch(); Q_INVOKABLE void stopSearch(); Q_INVOKABLE void updateDataFromDevice(QString mac); + QQmlListProperty getDeviceList(); QAbstractTableModel* getModel(); signals: void newDeviceFound(); - void historyUpdated(); + void modelUpdated(); void temperatureChanged(float temperature); void brightnessChanged(quint32 brightness); void moistureChanged(quint8 moisture);