From 94db9a165fbb95d951d76cebb0937240b5d39545 Mon Sep 17 00:00:00 2001 From: UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> Date: Mon, 24 Oct 2022 17:02:09 +0200 Subject: 't worked just a minute ago' --- client/dbconnector.cpp | 9 +++------ client/dbconnector.h | 4 ---- client/dbconnector.ui | 5 ++++- client/main.cpp | 9 +++++---- client/mainwindow.cpp | 54 ++++++++++++++++++++++++-------------------------- client/mainwindow.h | 9 +++++---- client/mainwindow.ui | 54 +++++++++++++++++++++----------------------------- client/ui_mainwindow.h | 2 +- 8 files changed, 67 insertions(+), 79 deletions(-) diff --git a/client/dbconnector.cpp b/client/dbconnector.cpp index 5ed1efc..e925851 100644 --- a/client/dbconnector.cpp +++ b/client/dbconnector.cpp @@ -26,19 +26,16 @@ void dbConnector::on_pushButton_login_clicked() QString hostname = ui->lineEdit_adress->text(); QString username = ui->lineEdit_username->text(); QString password = ui->lineEdit_password->text(); - QString databaseName = "thecrapbox"; + QString databaseName = ui->lineEdit_database->text(); -// QSqlDatabase db = MainWindow.loginDb(adress, username, password); - -// QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); -// return; dbRef.setHostName(hostname); dbRef.setUserName(username); dbRef.setPassword(password); - dbRef.setDatabaseName("thecrapbox"); + dbRef.setDatabaseName(databaseName); if(dbRef.open()){ QMessageBox::information(this, "Connection", "GREAT SUCCES!"); + dbConnector::~dbConnector(); } else { QMessageBox::warning(this, "No connection", "Failed to connect"); } diff --git a/client/dbconnector.h b/client/dbconnector.h index cd722eb..db8ac4e 100644 --- a/client/dbconnector.h +++ b/client/dbconnector.h @@ -6,7 +6,6 @@ //#include //#include -//#include "database.h" namespace Ui { class dbConnector; @@ -21,7 +20,6 @@ public: ~dbConnector(); private slots: -// void on_pushButton_clicked(); void on_pushButton_cancel_clicked(); @@ -29,6 +27,4 @@ private slots: private: Ui::dbConnector *ui; - -// Database database; }; diff --git a/client/dbconnector.ui b/client/dbconnector.ui index 21d241f..1159faf 100644 --- a/client/dbconnector.ui +++ b/client/dbconnector.ui @@ -49,6 +49,9 @@ + + WSdb + Database name @@ -98,7 +101,7 @@ - + Ab12345! QLineEdit::Password diff --git a/client/main.cpp b/client/main.cpp index 0f6b816..8561786 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -9,8 +9,8 @@ #include #include -#include "chart.h" -#include "chartview.h" +//#include "chart.h" +//#include "chartview.h" #include "mainwindow.h" #include "main.h" #include "ui_mainwindow.h" @@ -25,8 +25,9 @@ int main(int argc, char *argv[]) TimeTest time; MyTcpSocket s; // s.doConnect(); - MainWindow w; - dbRef = QSqlDatabase::addDatabase("QMYSQL"); + MainWindow w; + + dbRef = QSqlDatabase::addDatabase("QMYSQL"); w.show(); return a.exec(); 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 + 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; } diff --git a/client/mainwindow.h b/client/mainwindow.h index 78f2ce6..cf3c6e4 100644 --- a/client/mainwindow.h +++ b/client/mainwindow.h @@ -34,14 +34,15 @@ private slots: void on_actionConnection_triggered(); + void on_actionRefresh_triggered(); + private: Ui::MainWindow *ui; dbConnector *_dbConenctor; -// QSqlDatabase db; - QLineSeries *series; - QChartView *chartView; + QChart *_pChart; +// QLineSeries *_pSeries; + QChartView *_pChartView; -// Database database; }; diff --git a/client/mainwindow.ui b/client/mainwindow.ui index e55caa0..4ced639 100644 --- a/client/mainwindow.ui +++ b/client/mainwindow.ui @@ -14,35 +14,35 @@ MainWindow - - - true - - - - 310 - 0 - 121 - 41 - - - - DoesSomething - - - + - -10 - 40 - 801 - 401 + 90 + 80 + 621 + 301 - - + + + QLayout::SetDefaultConstraint + + + + + + + + + + + + Reload + + + @@ -62,13 +62,6 @@ - - - TEMP - - - - Database @@ -78,7 +71,6 @@ - diff --git a/client/ui_mainwindow.h b/client/ui_mainwindow.h index 8854685..e91631c 100644 --- a/client/ui_mainwindow.h +++ b/client/ui_mainwindow.h @@ -10,7 +10,7 @@ #define UI_MAINWINDOW_H #include -#include +//#include #include #include #include -- cgit v1.2.3