From 615dd097b7a03c73d0c9c922a652287d1e8a7466 Mon Sep 17 00:00:00 2001 From: UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> Date: Wed, 26 Oct 2022 16:53:07 +0200 Subject: 3 seperate graphs working --- client/mainwindow.cpp | 75 +++++++++++++++------- client/mainwindow.ui | 4 +- client/ui_dbconnector.h | 162 ------------------------------------------------ client/ui_mainwindow.h | 143 ------------------------------------------ 4 files changed, 55 insertions(+), 329 deletions(-) delete mode 100644 client/ui_dbconnector.h delete mode 100644 client/ui_mainwindow.h diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index d8b12cb..cc19b53 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -37,49 +37,80 @@ void MainWindow::on_actionDisconnenct_triggered() void MainWindow::drawGraph(){ -// QLineSeries *seriesTemperature; -// seriesTemperature = new QLineSeries(); + QLineSeries *seriesTemperature = new QLineSeries(); QLineSeries *seriesHumidity = new QLineSeries(); -// QLineSeries *seriesPressure = new QLineSeries(); + QLineSeries *seriesPressure = new QLineSeries(); + 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 * FROM `tblMain`ORDER BY `tblMain`.`ID` DESC limit 16;"); + queryGraphData.exec("select * FROM `tblMain` ORDER BY `tblMain`.`ID` ASC limit 16;"); for (int i = 0; queryGraphData.next(); ++i) { -// seriesTemp->append(queryGraphData.value(0).toInt(), queryGraphData.value(1).toInt()); +// int time = queryGraphData.value(4).toTime().hour()*100 + queryGraphData.value(4).toTime().minute(); + int time = i; +// seriesPressure->append(queryGraphData.value(0).toInt(), queryGraphData.value(1).toFloat()); // seriesTemperature->append(i, queryGraphData.value(1).toInt()); // seriesHumidity->append(i, queryGraphData.value(2).toFloat()); - seriesHumidity->append(i,i); -// seriesPressure->append(i, queryGraphData.value(3).toFloat()); - qDebug() << queryGraphData.value(2).toFloat(); +// seriesPressure->append(i, queryGraphData.value(3).toInt()); + + seriesTemperature->append(time, queryGraphData.value(1).toFloat()); + seriesHumidity->append(time, queryGraphData.value(2).toFloat()); + seriesPressure->append(time, (queryGraphData.value(3).toFloat()*100)); + +// qDebug() << time; } - QPen pen(QRgb(0x57FF00)); - pen.setWidth(5); - seriesHumidity->setPen(pen); +// QPen pen(QRgb(0x57FF00)); +// pen.setWidth(5); +// seriesHumidity->setPen(pen); + + + QChart *chartTemperature = new QChart(); + chartTemperature->legend()->hide(); + chartTemperature->addSeries(seriesTemperature); + chartTemperature->createDefaultAxes(); + chartTemperature->setTitle("Temperature!"); + QChartView *chartView1 = new QChartView(chartTemperature); + + QChart *chartHumidity = new QChart(); + chartHumidity->legend()->hide(); + chartHumidity->addSeries(seriesHumidity); + chartHumidity->createDefaultAxes(); + chartHumidity->setTitle("Humidity!"); + QChartView *chartView2 = new QChartView(chartHumidity); + QChart *chartPressure = new QChart(); + chartPressure->legend()->hide(); + chartPressure->addSeries(seriesPressure); + chartPressure->createDefaultAxes(); + chartPressure->setTitle("Pressure!"); + QChartView *chartView3 = new QChartView(chartPressure); - _pChart = new QChart(); - _pChart->legend()->show(); -// _pChart->addSeries(seriesTemperature); - _pChart->addSeries(seriesHumidity); -// _pChart->addSeries(seriesPressure); - _pChart->createDefaultAxes(); - _pChart->setTitle("Weather data:"); - _pChartView = new QChartView(_pChart); - MainWindow::setCentralWidget(_pChartView); + QWidget *window = new QWidget; + QGridLayout *layout = new QGridLayout(window); + layout->addWidget(chartView1, 0 ,0); + layout->addWidget(chartView2, 1 ,0); + layout->addWidget(chartView3, 2 ,0); + layout->setVerticalSpacing(0); + layout->setHorizontalSpacing(0); + layout->setContentsMargins(0,0,0,0); + + + +// window->show(); + + MainWindow::setCentralWidget(window); } else { QMessageBox::warning(this, "No connection", "Failed to connect"); } // delete seriesTemperature; - delete seriesHumidity; +// delete seriesHumidity; // delete seriesPressure; } - diff --git a/client/mainwindow.ui b/client/mainwindow.ui index eb17fe2..a31ffdc 100644 --- a/client/mainwindow.ui +++ b/client/mainwindow.ui @@ -17,8 +17,8 @@ - 300 - 210 + 270 + 190 181 51 diff --git a/client/ui_dbconnector.h b/client/ui_dbconnector.h deleted file mode 100644 index afb6f11..0000000 --- a/client/ui_dbconnector.h +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************** -** Form generated from reading UI file 'dbconnector.ui' -** -** Created by: Qt User Interface Compiler version 5.15.6 -** -** WARNING! All changes made in this file will be lost when recompiling UI file! -********************************************************************************/ - -#ifndef UI_DBCONNECTOR_H -#define UI_DBCONNECTOR_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Ui_dbConnector -{ -public: - QWidget *formLayoutWidget; - QFormLayout *formLayout; - QLabel *label_3; - QLineEdit *lineEdit_adress; - QLabel *label_4; - QLineEdit *lineEdit_database; - QFrame *line; - QLabel *label; - QLineEdit *lineEdit_username; - QLabel *label_2; - QLineEdit *lineEdit_password; - QLabel *connectLabel; - QHBoxLayout *horizontalLayout; - QPushButton *pushButton_login; - QPushButton *pushButton_cancel; - - void setupUi(QDialog *dbConnector) - { - if (dbConnector->objectName().isEmpty()) - dbConnector->setObjectName(QString::fromUtf8("dbConnector")); - dbConnector->resize(362, 273); - formLayoutWidget = new QWidget(dbConnector); - formLayoutWidget->setObjectName(QString::fromUtf8("formLayoutWidget")); - formLayoutWidget->setGeometry(QRect(60, 60, 241, 173)); - formLayout = new QFormLayout(formLayoutWidget); - formLayout->setObjectName(QString::fromUtf8("formLayout")); - formLayout->setContentsMargins(0, 0, 0, 0); - label_3 = new QLabel(formLayoutWidget); - label_3->setObjectName(QString::fromUtf8("label_3")); - - formLayout->setWidget(0, QFormLayout::LabelRole, label_3); - - lineEdit_adress = new QLineEdit(formLayoutWidget); - lineEdit_adress->setObjectName(QString::fromUtf8("lineEdit_adress")); - - formLayout->setWidget(0, QFormLayout::FieldRole, lineEdit_adress); - - label_4 = new QLabel(formLayoutWidget); - label_4->setObjectName(QString::fromUtf8("label_4")); - - formLayout->setWidget(1, QFormLayout::LabelRole, label_4); - - lineEdit_database = new QLineEdit(formLayoutWidget); - lineEdit_database->setObjectName(QString::fromUtf8("lineEdit_database")); - - formLayout->setWidget(1, QFormLayout::FieldRole, lineEdit_database); - - line = new QFrame(formLayoutWidget); - line->setObjectName(QString::fromUtf8("line")); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - - formLayout->setWidget(2, QFormLayout::SpanningRole, line); - - label = new QLabel(formLayoutWidget); - label->setObjectName(QString::fromUtf8("label")); - - formLayout->setWidget(3, QFormLayout::LabelRole, label); - - lineEdit_username = new QLineEdit(formLayoutWidget); - lineEdit_username->setObjectName(QString::fromUtf8("lineEdit_username")); - lineEdit_username->setEchoMode(QLineEdit::PasswordEchoOnEdit); - - formLayout->setWidget(3, QFormLayout::FieldRole, lineEdit_username); - - label_2 = new QLabel(formLayoutWidget); - label_2->setObjectName(QString::fromUtf8("label_2")); - - formLayout->setWidget(4, QFormLayout::LabelRole, label_2); - - lineEdit_password = new QLineEdit(formLayoutWidget); - lineEdit_password->setObjectName(QString::fromUtf8("lineEdit_password")); - QFont font; - font.setUnderline(false); - font.setStrikeOut(false); - font.setKerning(true); - lineEdit_password->setFont(font); - lineEdit_password->setEchoMode(QLineEdit::Password); - - formLayout->setWidget(4, QFormLayout::FieldRole, lineEdit_password); - - connectLabel = new QLabel(formLayoutWidget); - connectLabel->setObjectName(QString::fromUtf8("connectLabel")); - - formLayout->setWidget(5, QFormLayout::LabelRole, connectLabel); - - horizontalLayout = new QHBoxLayout(); - horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); - pushButton_login = new QPushButton(formLayoutWidget); - pushButton_login->setObjectName(QString::fromUtf8("pushButton_login")); - - horizontalLayout->addWidget(pushButton_login); - - pushButton_cancel = new QPushButton(formLayoutWidget); - pushButton_cancel->setObjectName(QString::fromUtf8("pushButton_cancel")); - - horizontalLayout->addWidget(pushButton_cancel); - - - formLayout->setLayout(5, QFormLayout::FieldRole, horizontalLayout); - - - retranslateUi(dbConnector); - - QMetaObject::connectSlotsByName(dbConnector); - } // setupUi - - void retranslateUi(QDialog *dbConnector) - { - dbConnector->setWindowTitle(QCoreApplication::translate("dbConnector", "Dialog", nullptr)); - label_3->setText(QCoreApplication::translate("dbConnector", "Adress", nullptr)); - lineEdit_adress->setText(QCoreApplication::translate("dbConnector", "localhost", nullptr)); - lineEdit_adress->setPlaceholderText(QCoreApplication::translate("dbConnector", "Hostname/IP-Adress", nullptr)); - label_4->setText(QCoreApplication::translate("dbConnector", "Database", nullptr)); - lineEdit_database->setPlaceholderText(QCoreApplication::translate("dbConnector", "Database name", nullptr)); - label->setText(QCoreApplication::translate("dbConnector", "Username", nullptr)); - lineEdit_username->setText(QCoreApplication::translate("dbConnector", "root", nullptr)); - lineEdit_username->setPlaceholderText(QCoreApplication::translate("dbConnector", "Username", nullptr)); - label_2->setText(QCoreApplication::translate("dbConnector", "Password", nullptr)); - lineEdit_password->setText(QString()); - lineEdit_password->setPlaceholderText(QCoreApplication::translate("dbConnector", "Password", nullptr)); - connectLabel->setText(QCoreApplication::translate("dbConnector", "Connect", nullptr)); - pushButton_login->setText(QCoreApplication::translate("dbConnector", "Login", nullptr)); - pushButton_cancel->setText(QCoreApplication::translate("dbConnector", "Cancel", nullptr)); - } // retranslateUi - -}; - -namespace Ui { - class dbConnector: public Ui_dbConnector {}; -} // namespace Ui - -QT_END_NAMESPACE - -#endif // UI_DBCONNECTOR_H diff --git a/client/ui_mainwindow.h b/client/ui_mainwindow.h deleted file mode 100644 index e91631c..0000000 --- a/client/ui_mainwindow.h +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************** -** Form generated from reading UI file 'mainwindow.ui' -** -** Created by: Qt User Interface Compiler version 5.15.6 -** -** WARNING! All changes made in this file will be lost when recompiling UI file! -********************************************************************************/ - -#ifndef UI_MAINWINDOW_H -#define UI_MAINWINDOW_H - -#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Ui_MainWindow -{ -public: - QAction *actionAbout; - QAction *actionRefresh; - QAction *actionLOAD; - QAction *actionQuerry; - QAction *actionConnection; - QAction *actionDisconnenct; - QAction *actionQuerry_2; - QAction *actionStatus; - QWidget *centralwidget; - QPushButton *pushButton; - QWidget *verticalLayoutWidget; - QVBoxLayout *verticalLayout; - QTableView *tableView; - QMenuBar *menubar; - QMenu *menuAbouy; - QMenu *menuTEMP; - QMenu *menuDatabase; - QStatusBar *statusbar; - - void setupUi(QMainWindow *MainWindow) - { - if (MainWindow->objectName().isEmpty()) - MainWindow->setObjectName(QString::fromUtf8("MainWindow")); - MainWindow->resize(800, 600); - actionAbout = new QAction(MainWindow); - actionAbout->setObjectName(QString::fromUtf8("actionAbout")); - actionRefresh = new QAction(MainWindow); - actionRefresh->setObjectName(QString::fromUtf8("actionRefresh")); - actionLOAD = new QAction(MainWindow); - actionLOAD->setObjectName(QString::fromUtf8("actionLOAD")); - actionQuerry = new QAction(MainWindow); - actionQuerry->setObjectName(QString::fromUtf8("actionQuerry")); - actionConnection = new QAction(MainWindow); - actionConnection->setObjectName(QString::fromUtf8("actionConnection")); - actionDisconnenct = new QAction(MainWindow); - actionDisconnenct->setObjectName(QString::fromUtf8("actionDisconnenct")); - actionQuerry_2 = new QAction(MainWindow); - actionQuerry_2->setObjectName(QString::fromUtf8("actionQuerry_2")); - actionStatus = new QAction(MainWindow); - actionStatus->setObjectName(QString::fromUtf8("actionStatus")); - centralwidget = new QWidget(MainWindow); - centralwidget->setObjectName(QString::fromUtf8("centralwidget")); - pushButton = new QPushButton(centralwidget); - pushButton->setObjectName(QString::fromUtf8("pushButton")); - pushButton->setEnabled(true); - pushButton->setGeometry(QRect(310, 0, 121, 41)); - verticalLayoutWidget = new QWidget(centralwidget); - verticalLayoutWidget->setObjectName(QString::fromUtf8("verticalLayoutWidget")); - verticalLayoutWidget->setGeometry(QRect(-10, 40, 801, 401)); - verticalLayout = new QVBoxLayout(verticalLayoutWidget); - verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); - verticalLayout->setContentsMargins(0, 0, 0, 0); - tableView = new QTableView(verticalLayoutWidget); - tableView->setObjectName(QString::fromUtf8("tableView")); - - verticalLayout->addWidget(tableView); - - MainWindow->setCentralWidget(centralwidget); - menubar = new QMenuBar(MainWindow); - menubar->setObjectName(QString::fromUtf8("menubar")); - menubar->setGeometry(QRect(0, 0, 800, 21)); - menuAbouy = new QMenu(menubar); - menuAbouy->setObjectName(QString::fromUtf8("menuAbouy")); - menuTEMP = new QMenu(menubar); - menuTEMP->setObjectName(QString::fromUtf8("menuTEMP")); - menuDatabase = new QMenu(menubar); - menuDatabase->setObjectName(QString::fromUtf8("menuDatabase")); - MainWindow->setMenuBar(menubar); - statusbar = new QStatusBar(MainWindow); - statusbar->setObjectName(QString::fromUtf8("statusbar")); - MainWindow->setStatusBar(statusbar); - - menubar->addAction(menuAbouy->menuAction()); - menubar->addAction(menuTEMP->menuAction()); - menubar->addAction(menuDatabase->menuAction()); - menuAbouy->addAction(actionAbout); - menuAbouy->addAction(actionRefresh); - menuTEMP->addAction(actionLOAD); - menuTEMP->addAction(actionQuerry); - menuDatabase->addAction(actionConnection); - menuDatabase->addAction(actionDisconnenct); - menuDatabase->addAction(actionStatus); - - retranslateUi(MainWindow); - - QMetaObject::connectSlotsByName(MainWindow); - } // setupUi - - void retranslateUi(QMainWindow *MainWindow) - { - MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr)); - actionAbout->setText(QCoreApplication::translate("MainWindow", "About", nullptr)); - actionRefresh->setText(QCoreApplication::translate("MainWindow", "Refresh", nullptr)); - actionLOAD->setText(QCoreApplication::translate("MainWindow", "Load", nullptr)); - actionQuerry->setText(QCoreApplication::translate("MainWindow", "Query", nullptr)); - actionConnection->setText(QCoreApplication::translate("MainWindow", "Connect", nullptr)); - actionDisconnenct->setText(QCoreApplication::translate("MainWindow", "Disconnenct", nullptr)); - actionQuerry_2->setText(QCoreApplication::translate("MainWindow", "Querry", nullptr)); - actionStatus->setText(QCoreApplication::translate("MainWindow", "Status", nullptr)); - pushButton->setText(QCoreApplication::translate("MainWindow", "DoesSomething", nullptr)); - menuAbouy->setTitle(QCoreApplication::translate("MainWindow", "Home", nullptr)); - menuTEMP->setTitle(QCoreApplication::translate("MainWindow", "TEMP", nullptr)); - menuDatabase->setTitle(QCoreApplication::translate("MainWindow", "Database", nullptr)); - } // retranslateUi - -}; - -namespace Ui { - class MainWindow: public Ui_MainWindow {}; -} // namespace Ui - -QT_END_NAMESPACE - -#endif // UI_MAINWINDOW_H -- cgit v1.2.3