diff options
Diffstat (limited to 'client/mainwindow.cpp')
-rw-r--r-- | client/mainwindow.cpp | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index 80a7658..1e74ed0 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -4,11 +4,12 @@ #include "ui_mainwindow.h" #include "main.h" +//#include <QDebug> + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { -// db = QSqlDatabase::addDatabase("QMYSQL"); ui->setupUi(this); } @@ -18,47 +19,44 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::on_actionAbout_triggered() +void MainWindow::on_actionConnection_triggered() { - QMessageBox::warning(this, "Oops..", "Task Failed succesfully ;)"); + _dbConenctor = new dbConnector(this); + _dbConenctor->show(); } -void MainWindow::on_pushButton_clicked() +void MainWindow::on_actionRefresh_triggered() { -// dbRef = QSqlDatabase::addDatabase("QMYSQL"); -// dbRef.setHostName("localhost"); -// dbRef.setUserName("root"); -// dbRef.setPassword("Ab12345!"); -// dbRef.setDatabaseName("thecrapbox"); - - series = new QLineSeries(); - QChart *chart = new QChart(); + QLineSeries *seriesTemperature = new QLineSeries(); + QLineSeries *seriesHumidity = new QLineSeries(); + _pChart = new QChart(); if(dbRef.open()){ - QMessageBox::information(this, "Connection", "GREAT SUCCES!"); QSqlQuery queryGraphData; - queryGraphData.exec("SELECT id, temp FROM tblMain LIMIT 16 ORDER BY desc;"); -// ui->tableView->setModel(pQueryModel); + 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) { - series->append(queryGraphData.value(0).toInt(), queryGraphData.value(1).toInt()); +// 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); } - chart->legend()->show(); - chart->addSeries(series); - chart->createDefaultAxes(); - chart->setTitle("Hellow!"); - chartView = new QChartView(chart); - MainWindow::setCentralWidget(chartView); + _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"); } -} - -void MainWindow::on_actionConnection_triggered() -{ - _dbConenctor = new dbConnector(this); - _dbConenctor->show(); +// delete seriesTemperature; +// delete seriesHumidity; } |