diff options
author | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2022-10-24 17:02:09 +0200 |
---|---|---|
committer | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2022-10-24 17:02:09 +0200 |
commit | 94db9a165fbb95d951d76cebb0937240b5d39545 (patch) | |
tree | 7aca9c28a4b28e1dd0e89e0f5ef0bf52c4310939 | |
parent | 093f18ab363840fff796c14e6c7ad7b93dd0ffc6 (diff) |
't worked just a minute ago'
-rw-r--r-- | client/dbconnector.cpp | 9 | ||||
-rw-r--r-- | client/dbconnector.h | 4 | ||||
-rw-r--r-- | client/dbconnector.ui | 5 | ||||
-rw-r--r-- | client/main.cpp | 9 | ||||
-rw-r--r-- | client/mainwindow.cpp | 54 | ||||
-rw-r--r-- | client/mainwindow.h | 9 | ||||
-rw-r--r-- | client/mainwindow.ui | 54 | ||||
-rw-r--r-- | 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 <QtSql> //#include <QSqlDatabase> -//#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 @@ </item> <item row="1" column="1"> <widget class="QLineEdit" name="lineEdit_database"> + <property name="text"> + <string>WSdb</string> + </property> <property name="placeholderText"> <string>Database name</string> </property> @@ -98,7 +101,7 @@ </font> </property> <property name="text"> - <string/> + <string>Ab12345!</string> </property> <property name="echoMode"> <enum>QLineEdit::Password</enum> 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 <iostream> #include <stdio.h> -#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 <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; } 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 @@ <string>MainWindow</string> </property> <widget class="QWidget" name="centralwidget"> - <widget class="QPushButton" name="pushButton"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="geometry"> - <rect> - <x>310</x> - <y>0</y> - <width>121</width> - <height>41</height> - </rect> - </property> - <property name="text"> - <string>DoesSomething</string> - </property> - </widget> - <widget class="QWidget" name="verticalLayoutWidget"> + <widget class="QWidget" name="formLayoutWidget"> <property name="geometry"> <rect> - <x>-10</x> - <y>40</y> - <width>801</width> - <height>401</height> + <x>90</x> + <y>80</y> + <width>621</width> + <height>301</height> </rect> </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> + <layout class="QFormLayout" name="centralFrom"> + <property name="sizeConstraint"> + <enum>QLayout::SetDefaultConstraint</enum> + </property> + <item row="0" column="0"> <widget class="QWidget" name="widget" native="true"/> </item> + <item row="1" column="0"> + <widget class="QWidget" name="widget_2" native="true"/> + </item> + <item row="2" column="0"> + <widget class="QWidget" name="widget_3" native="true"/> + </item> + <item row="3" column="0"> + <widget class="QPushButton" name="reLoad"> + <property name="text"> + <string>Reload</string> + </property> + </widget> + </item> </layout> </widget> </widget> @@ -62,13 +62,6 @@ <addaction name="actionAbout"/> <addaction name="actionRefresh"/> </widget> - <widget class="QMenu" name="menuTEMP"> - <property name="title"> - <string>TEMP</string> - </property> - <addaction name="actionLOAD"/> - <addaction name="actionQuerry"/> - </widget> <widget class="QMenu" name="menuDatabase"> <property name="title"> <string>Database</string> @@ -78,7 +71,6 @@ <addaction name="actionStatus"/> </widget> <addaction name="menuAbouy"/> - <addaction name="menuTEMP"/> <addaction name="menuDatabase"/> </widget> <widget class="QStatusBar" name="statusbar"/> 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 <QtCore/QVariant> -#include <QtWidgets/QAction> +//#include <QtWidgets/QAction> #include <QtWidgets/QApplication> #include <QtWidgets/QHeaderView> #include <QtWidgets/QMainWindow> |