aboutsummaryrefslogtreecommitdiff
path: root/client/mainwindow.cpp
blob: 1e74ed0165c5d03863ca4a743cccab5cf05b535c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <QSqlDatabase>

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "main.h"

//#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    dbRef.close();
    delete ui;
}

void MainWindow::on_actionConnection_triggered()
{
    _dbConenctor = new dbConnector(this);
    _dbConenctor->show();
}


void MainWindow::on_actionRefresh_triggered()
{
    QLineSeries *seriesTemperature = new QLineSeries();
    QLineSeries *seriesHumidity = new QLineSeries();
    _pChart = new QChart();

    if(dbRef.open()){
        QSqlQuery queryGraphData;
        queryGraphData.exec("select `tblMain`.`ID`, `temperature`, `humidity`, `pressure` FROM `tblMain` ORDER BY `tblMain`.`ID` DESC limit 16;");
//        queryGraphData.exec("select `tblMain`.`ID`, `temperature`, `humidity`, `pressure` FROM `tblMain`;");

        for (int i = 0; queryGraphData.next(); ++i) {
//            seriesTemp->append(queryGraphData.value(0).toInt(), queryGraphData.value(1).toInt());
            seriesTemperature->append(i, queryGraphData.value(1).toFloat());
            seriesHumidity->append(i, queryGraphData.value(2).toFloat()*100);
        }

        _pChart->legend()->show();
        _pChart->addSeries(seriesTemperature);
        _pChart->addSeries(seriesHumidity);
        _pChart->createDefaultAxes();
        _pChart->setTitle("Weather data:");
        _pChartView = new QChartView(_pChart);

        MainWindow::setCentralWidget(_pChartView);


    } else {
        QMessageBox::warning(this, "No connection", "Failed to connect");
    }
//    delete seriesTemperature;
//    delete seriesHumidity;
}