/* * Copyright (C) 2019 Kevin Whitaker * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "florahistory.h" #include #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); } else if(index.column() == 1) { return QVariant(std::round(tableData[index.row()].temperature*10)/10); //temp in C } else if(index.column() == 2) { return QVariant(tableData[index.row()].brightness); } else if(index.column() == 3) { return QVariant(tableData[index.row()].moisture); } else if(index.column() == 4) { return QVariant(tableData[index.row()].conductivity); } else if(index.column() == 5) { return QVariant((std::round((tableData[index.row()].temperature*1.8+32)*10)/10)); //temp in F } else { return QVariant(); } } else { return QVariant(); } } int FloraHistory::columnCount(const QModelIndex& parent) const { return 6; } int FloraHistory::rowCount(const QModelIndex& parent) const { return tableData.size(); } void FloraHistory::addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity) { beginInsertRows(QModelIndex(),tableData.size(),tableData.size()); tableData.append(flora_data{time, temperature, brightness, moisture, conductivity}); endInsertRows(); } void FloraHistory::clear() { tableData.clear(); emit layoutChanged(); }