From 093f18ab363840fff796c14e6c7ad7b93dd0ffc6 Mon Sep 17 00:00:00 2001 From: UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:03:30 +0200 Subject: testing charts --- client/mainwindow.cpp | 20 +++++++++++++++++--- client/mainwindow.h | 7 ++++++- client/mainwindow.ui | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index 955307e..80a7658 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -32,11 +32,25 @@ void MainWindow::on_pushButton_clicked() // dbRef.setPassword("Ab12345!"); // dbRef.setDatabaseName("thecrapbox"); + series = new QLineSeries(); + QChart *chart = new QChart(); + if(dbRef.open()){ QMessageBox::information(this, "Connection", "GREAT SUCCES!"); - pQueryModel = new QSqlQueryModel(); - pQueryModel->setQuery("SELECT * FROM opleiding;"); - ui->tableView->setModel(pQueryModel); + QSqlQuery queryGraphData; + queryGraphData.exec("SELECT id, temp FROM tblMain LIMIT 16 ORDER BY desc;"); +// ui->tableView->setModel(pQueryModel); + for (int i = 0; queryGraphData.next(); ++i) { + series->append(queryGraphData.value(0).toInt(), queryGraphData.value(1).toInt()); + } + chart->legend()->show(); + chart->addSeries(series); + chart->createDefaultAxes(); + chart->setTitle("Hellow!"); + chartView = new QChartView(chart); + + MainWindow::setCentralWidget(chartView); + } else { QMessageBox::warning(this, "No connection", "Failed to connect"); } diff --git a/client/mainwindow.h b/client/mainwindow.h index 1e73657..78f2ce6 100644 --- a/client/mainwindow.h +++ b/client/mainwindow.h @@ -8,6 +8,10 @@ #include #include #include +#include +#include +#include + #include "main.h" @@ -36,7 +40,8 @@ private: dbConnector *_dbConenctor; // QSqlDatabase db; - QSqlQueryModel *pQueryModel; + QLineSeries *series; + QChartView *chartView; // Database database; }; diff --git a/client/mainwindow.ui b/client/mainwindow.ui index f827c85..e55caa0 100644 --- a/client/mainwindow.ui +++ b/client/mainwindow.ui @@ -41,7 +41,7 @@ - + @@ -52,7 +52,7 @@ 0 0 800 - 21 + 24 -- cgit v1.2.3