From 4625b939aad3537bd130617944e01f5da693b23d Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 5 Oct 2022 20:57:10 +0200 Subject: initial merge of qt client --- .gitignore | 3 +- MySqlDatabaseScript/build.sql | 9 - Qt/dbconnector.cpp | 49 ----- Qt/dbconnector.h | 34 ---- Qt/dbconnector.ui | 141 ------------- Qt/main.cpp | 27 --- Qt/main.h | 7 - Qt/mainwindow.cpp | 48 ----- Qt/mainwindow.h | 42 ---- Qt/mainwindow.ui | 128 ------------ Qt/whetherOrNot.pro | 28 --- Qt/whetherOrNot.pro.user | 423 --------------------------------------- Qt/whetherOrNot.pro.user.ea03b89 | 262 ------------------------ client/client.pro | 21 +- client/dbconnector.cpp | 49 +++++ client/dbconnector.h | 34 ++++ client/dbconnector.ui | 141 +++++++++++++ client/main.cpp | 57 +++--- client/main.h | 8 + client/mainwindow.cpp | 50 +++++ client/mainwindow.h | 42 ++++ client/mainwindow.ui | 128 ++++++++++++ createDB.sql | 9 - scripts/db-init.sql | 9 + 24 files changed, 502 insertions(+), 1247 deletions(-) delete mode 100644 MySqlDatabaseScript/build.sql delete mode 100644 Qt/dbconnector.cpp delete mode 100644 Qt/dbconnector.h delete mode 100644 Qt/dbconnector.ui delete mode 100644 Qt/main.cpp delete mode 100644 Qt/main.h delete mode 100644 Qt/mainwindow.cpp delete mode 100644 Qt/mainwindow.h delete mode 100644 Qt/mainwindow.ui delete mode 100644 Qt/whetherOrNot.pro delete mode 100644 Qt/whetherOrNot.pro.user delete mode 100644 Qt/whetherOrNot.pro.user.ea03b89 create mode 100644 client/dbconnector.cpp create mode 100644 client/dbconnector.h create mode 100644 client/dbconnector.ui create mode 100644 client/main.h create mode 100644 client/mainwindow.cpp create mode 100644 client/mainwindow.h create mode 100644 client/mainwindow.ui delete mode 100644 createDB.sql create mode 100644 scripts/db-init.sql diff --git a/.gitignore b/.gitignore index cc3cefc..1c68c8a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,10 @@ copyright **/*.o stm32f091/main.elf stm32f091/main.bin -stm32f091/.cache +**/.cache **/compile_commands.json client/makefile client/client +client/moc_* .qmake.stash .vscode/.cortex-debug.registers.state.json diff --git a/MySqlDatabaseScript/build.sql b/MySqlDatabaseScript/build.sql deleted file mode 100644 index 4c4c4d4..0000000 --- a/MySqlDatabaseScript/build.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE SCHEMA `WSdb`; -CREATE TABLE `DAB1Pract1`.`tblMain` ( - `ID` INT GENERATED ALWAYS AS (), - `temperature` DECIMAL(5,2) NULL, - `humidity` DECIMAL(5,2) NULL, - `pressure` DECIMAL(5,2) NULL, - `time` DATETIME NULL, - PRIMARY KEY (`ID`), - UNIQUE INDEX `ID_UNIQUE` (`ID` ASC) VISIBLE); diff --git a/Qt/dbconnector.cpp b/Qt/dbconnector.cpp deleted file mode 100644 index 5ed1efc..0000000 --- a/Qt/dbconnector.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "dbconnector.h" -#include "ui_dbconnector.h" -#include "main.h" - -//#include "mainwindow.h" - -dbConnector::dbConnector(QWidget *parent) : - QDialog(parent), - ui(new Ui::dbConnector) -{ - ui->setupUi(this); -} - -dbConnector::~dbConnector() -{ - delete ui; -} - -void dbConnector::on_pushButton_cancel_clicked() -{ - dbConnector::~dbConnector(); -} - -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"; - -// 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"); - - if(dbRef.open()){ - QMessageBox::information(this, "Connection", "GREAT SUCCES!"); - } else { - QMessageBox::warning(this, "No connection", "Failed to connect"); - } -} - - - - diff --git a/Qt/dbconnector.h b/Qt/dbconnector.h deleted file mode 100644 index cd722eb..0000000 --- a/Qt/dbconnector.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include - -#include -//#include -//#include - -//#include "database.h" - -namespace Ui { -class dbConnector; -} - -class dbConnector : public QDialog -{ - Q_OBJECT - -public: - explicit dbConnector(QWidget *parent = nullptr); - ~dbConnector(); - -private slots: -// void on_pushButton_clicked(); - - void on_pushButton_cancel_clicked(); - - void on_pushButton_login_clicked(); - -private: - Ui::dbConnector *ui; - -// Database database; -}; diff --git a/Qt/dbconnector.ui b/Qt/dbconnector.ui deleted file mode 100644 index 21d241f..0000000 --- a/Qt/dbconnector.ui +++ /dev/null @@ -1,141 +0,0 @@ - - - dbConnector - - - - 0 - 0 - 362 - 273 - - - - Dialog - - - - - 60 - 60 - 241 - 173 - - - - - - - Adress - - - - - - - localhost - - - Hostname/IP-Adress - - - - - - - Database - - - - - - - Database name - - - - - - - Qt::Horizontal - - - - - - - Username - - - - - - - root - - - QLineEdit::PasswordEchoOnEdit - - - Username - - - - - - - Password - - - - - - - - false - false - true - - - - - - - QLineEdit::Password - - - Password - - - - - - - Connect - - - - - - - - - Login - - - - - - - Cancel - - - - - - - - - - - diff --git a/Qt/main.cpp b/Qt/main.cpp deleted file mode 100644 index 6de43ac..0000000 --- a/Qt/main.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "mainwindow.h" -#include "main.h" -#include "./ui_mainwindow.h" - -#include -#include -#include -#include - -QSqlDatabase dbRef = QSqlDatabase(); - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; -// dbRef = new QSqlDatabase(); - dbRef = QSqlDatabase::addDatabase("QMYSQL"); - - - - w.show(); -// QMessageBox::information(NULL, "AAAAAAAAA", dbRef.driverName().toStdString()); - std::cout << "AAAAAAAA: \"" << dbRef.driverName().toStdString() << "\"\n"; - fflush(0); - return a.exec(); - -} diff --git a/Qt/main.h b/Qt/main.h deleted file mode 100644 index 6c7c5c9..0000000 --- a/Qt/main.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include -#include - -int main(int argc, char *argv[]); -extern QSqlDatabase dbRef; diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp deleted file mode 100644 index c475414..0000000 --- a/Qt/mainwindow.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "mainwindow.h" -#include "./ui_mainwindow.h" -#include "main.h" - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) - , ui(new Ui::MainWindow) -{ -// db = QSqlDatabase::addDatabase("QMYSQL"); - ui->setupUi(this); -} - -MainWindow::~MainWindow() -{ - dbRef.close(); - delete ui; -} - -void MainWindow::on_actionAbout_triggered() -{ - QMessageBox::warning(this, "Oops..", "Task Failed succesfully ;)"); -} - - -void MainWindow::on_pushButton_clicked() -{ -// dbRef = QSqlDatabase::addDatabase("QMYSQL"); -// dbRef.setHostName("localhost"); -// dbRef.setUserName("root"); -// dbRef.setPassword("Ab12345!"); -// dbRef.setDatabaseName("thecrapbox"); - - if(dbRef.open()){ - QMessageBox::information(this, "Connection", "GREAT SUCCES!"); - pQueryModel = new QSqlQueryModel(); - pQueryModel->setQuery("SELECT * FROM opleiding;"); - ui->tableView->setModel(pQueryModel); - } else { - QMessageBox::warning(this, "No connection", "Failed to connect"); - } -} - -void MainWindow::on_actionConnection_triggered() -{ - _dbConenctor = new dbConnector(this); - _dbConenctor->show(); -} - diff --git a/Qt/mainwindow.h b/Qt/mainwindow.h deleted file mode 100644 index 49b548c..0000000 --- a/Qt/mainwindow.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include - -//#include "database.h" -#include "dbconnector.h" - -#include -#include -#include -#include "main.h" - - -QT_BEGIN_NAMESPACE -namespace Ui { class MainWindow; } -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = nullptr); - ~MainWindow(); - -private slots: - void on_actionAbout_triggered(); - - void on_pushButton_clicked(); - - void on_actionConnection_triggered(); - -private: - Ui::MainWindow *ui; - - dbConnector *_dbConenctor; -// QSqlDatabase db; - -// QSqlQueryModel *pQueryModel; - -// Database database; -}; diff --git a/Qt/mainwindow.ui b/Qt/mainwindow.ui deleted file mode 100644 index f827c85..0000000 --- a/Qt/mainwindow.ui +++ /dev/null @@ -1,128 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 800 - 600 - - - - MainWindow - - - - - true - - - - 310 - 0 - 121 - 41 - - - - DoesSomething - - - - - - -10 - 40 - 801 - 401 - - - - - - - - - - - - - 0 - 0 - 800 - 21 - - - - - Home - - - - - - - TEMP - - - - - - - Database - - - - - - - - - - - - - About - - - - - Refresh - - - - - Load - - - - - Query - - - - - Connect - - - - - Disconnenct - - - - - Querry - - - - - Status - - - - - - diff --git a/Qt/whetherOrNot.pro b/Qt/whetherOrNot.pro deleted file mode 100644 index 78a221a..0000000 --- a/Qt/whetherOrNot.pro +++ /dev/null @@ -1,28 +0,0 @@ -QT += core gui sql charts - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++17 - -# You can make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += \ - dbconnector.cpp \ - main.cpp \ - mainwindow.cpp - -HEADERS += \ - dbconnector.h \ - main.h \ - mainwindow.h - -FORMS += \ - dbconnector.ui \ - mainwindow.ui - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target diff --git a/Qt/whetherOrNot.pro.user b/Qt/whetherOrNot.pro.user deleted file mode 100644 index 44cfff2..0000000 --- a/Qt/whetherOrNot.pro.user +++ /dev/null @@ -1,423 +0,0 @@ - - - - - - EnvironmentId - {a6295b94-3610-4713-99f8-326a2d818dd2} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - true - Builtin.DefaultTidyAndClazy - 6 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop (x86-windows-msvc2022-pe-64bit) - Desktop (x86-windows-msvc2022-pe-64bit) - {4e2ed91e-8126-4abf-9e42-2fed06ebf8b3} - 0 - 0 - 0 - - 0 - C:\Users\joshu\Desktop\Dev\Whether-station\avans-whether-station-Qt\build-whetherOrNot-Desktop_x86_windows_msvc2022_pe_64bit-Debug - C:/Users/joshu/Desktop/Dev/Whether-station/avans-whether-station-Qt/build-whetherOrNot-Desktop_x86_windows_msvc2022_pe_64bit-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - C:\Users\joshu\Desktop\Dev\Whether-station\avans-whether-station-Qt\build-whetherOrNot-Desktop_x86_windows_msvc2022_pe_64bit-Release - C:/Users/joshu/Desktop/Dev/Whether-station/avans-whether-station-Qt/build-whetherOrNot-Desktop_x86_windows_msvc2022_pe_64bit-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - C:\Users\joshu\Desktop\Dev\Whether-station\avans-whether-station-Qt\build-whetherOrNot-Desktop_x86_windows_msvc2022_pe_64bit-Profile - C:/Users/joshu/Desktop/Dev/Whether-station/avans-whether-station-Qt/build-whetherOrNot-Desktop_x86_windows_msvc2022_pe_64bit-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - ProjectExplorer.CustomExecutableRunConfiguration - - false - true - false - true - - 1 - - - - ProjectExplorer.Project.Target.1 - - Desktop - Desktop Qt 6.3.1 MinGW 64-bit - Desktop Qt 6.3.1 MinGW 64-bit - qt.qt6.631.win64_mingw_kit - 0 - 0 - 0 - - 0 - C:\Users\joshu\Desktop\Dev\Whether-station\avans-whether-station-Qt\build-whetherOrNot-Desktop_Qt_6_3_1_MinGW_64_bit-Debug - C:/Users/joshu/Desktop/Dev/Whether-station/avans-whether-station-Qt/build-whetherOrNot-Desktop_Qt_6_3_1_MinGW_64_bit-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - C:\Users\joshu\Desktop\Dev\Whether-station\avans-whether-station-Qt\build-whetherOrNot-Desktop_Qt_6_3_1_MinGW_64_bit-Release - C:/Users/joshu/Desktop/Dev/Whether-station/avans-whether-station-Qt/build-whetherOrNot-Desktop_Qt_6_3_1_MinGW_64_bit-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - C:\Users\joshu\Desktop\Dev\Whether-station\avans-whether-station-Qt\build-whetherOrNot-Desktop_Qt_6_3_1_MinGW_64_bit-Profile - C:/Users/joshu/Desktop/Dev/Whether-station/avans-whether-station-Qt/build-whetherOrNot-Desktop_Qt_6_3_1_MinGW_64_bit-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - ProjectExplorer.CustomExecutableRunConfiguration - - false - true - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 2 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/Qt/whetherOrNot.pro.user.ea03b89 b/Qt/whetherOrNot.pro.user.ea03b89 deleted file mode 100644 index 4669d08..0000000 --- a/Qt/whetherOrNot.pro.user.ea03b89 +++ /dev/null @@ -1,262 +0,0 @@ - - - - - - EnvironmentId - {ea03b890-8d0a-4e25-9c8a-4324595ed9f6} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - true - Builtin.DefaultTidyAndClazy - 4 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - degoede - degoede - {1e436ae3-d7a2-4102-aca0-911720324ec1} - 0 - 0 - 0 - - 0 - /Users/jregnier/gitOnline/newqt/build-whetherOrNot-degoede-Debug - /Users/jregnier/gitOnline/newqt/build-whetherOrNot-degoede-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /Users/jregnier/gitOnline/newqt/build-whetherOrNot-degoede-Release - /Users/jregnier/gitOnline/newqt/build-whetherOrNot-degoede-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /Users/jregnier/gitOnline/newqt/build-whetherOrNot-degoede-Profile - /Users/jregnier/gitOnline/newqt/build-whetherOrNot-degoede-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:/Users/jregnier/gitOnline/newqt/wheather/whetherOrNot.pro - /Users/jregnier/gitOnline/newqt/wheather/whetherOrNot.pro - false - true - true - false - true - /Users/jregnier/gitOnline/newqt/build-whetherOrNot-degoede-Debug/whetherOrNot.app/Contents/MacOS - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/client/client.pro b/client/client.pro index cd0990a..0de0a33 100644 --- a/client/client.pro +++ b/client/client.pro @@ -1,14 +1,23 @@ -QT += charts +QT += core gui sql charts HEADERS += \ - chart.h \ - chartview.h + dbconnector.h \ + main.h \ + mainwindow.h +# chart.h \ +# chartview.h SOURCES += \ + dbconnector.cpp \ main.cpp \ - chart.cpp \ - chartview.cpp + mainwindow.cpp +# chart.cpp \ +# chartview.cpp + + +FORMS += \ + dbconnector.ui \ + mainwindow.ui -target.path = $$[QT_INSTALL_EXAMPLES]/charts/zoomlinechart INSTALLS += target CONFIG += force_debug_info diff --git a/client/dbconnector.cpp b/client/dbconnector.cpp new file mode 100644 index 0000000..5ed1efc --- /dev/null +++ b/client/dbconnector.cpp @@ -0,0 +1,49 @@ +#include "dbconnector.h" +#include "ui_dbconnector.h" +#include "main.h" + +//#include "mainwindow.h" + +dbConnector::dbConnector(QWidget *parent) : + QDialog(parent), + ui(new Ui::dbConnector) +{ + ui->setupUi(this); +} + +dbConnector::~dbConnector() +{ + delete ui; +} + +void dbConnector::on_pushButton_cancel_clicked() +{ + dbConnector::~dbConnector(); +} + +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"; + +// 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"); + + if(dbRef.open()){ + QMessageBox::information(this, "Connection", "GREAT SUCCES!"); + } else { + QMessageBox::warning(this, "No connection", "Failed to connect"); + } +} + + + + diff --git a/client/dbconnector.h b/client/dbconnector.h new file mode 100644 index 0000000..cd722eb --- /dev/null +++ b/client/dbconnector.h @@ -0,0 +1,34 @@ +#pragma once + +#include + +#include +//#include +//#include + +//#include "database.h" + +namespace Ui { +class dbConnector; +} + +class dbConnector : public QDialog +{ + Q_OBJECT + +public: + explicit dbConnector(QWidget *parent = nullptr); + ~dbConnector(); + +private slots: +// void on_pushButton_clicked(); + + void on_pushButton_cancel_clicked(); + + void on_pushButton_login_clicked(); + +private: + Ui::dbConnector *ui; + +// Database database; +}; diff --git a/client/dbconnector.ui b/client/dbconnector.ui new file mode 100644 index 0000000..21d241f --- /dev/null +++ b/client/dbconnector.ui @@ -0,0 +1,141 @@ + + + dbConnector + + + + 0 + 0 + 362 + 273 + + + + Dialog + + + + + 60 + 60 + 241 + 173 + + + + + + + Adress + + + + + + + localhost + + + Hostname/IP-Adress + + + + + + + Database + + + + + + + Database name + + + + + + + Qt::Horizontal + + + + + + + Username + + + + + + + root + + + QLineEdit::PasswordEchoOnEdit + + + Username + + + + + + + Password + + + + + + + + false + false + true + + + + + + + QLineEdit::Password + + + Password + + + + + + + Connect + + + + + + + + + Login + + + + + + + Cancel + + + + + + + + + + + diff --git a/client/main.cpp b/client/main.cpp index 28a3d91..84706bf 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -1,42 +1,33 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Charts module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "chart.h" -#include "chartview.h" #include #include #include #include #include #include +#include +#include +#include +#include + +#include "chart.h" +#include "chartview.h" +#include "mainwindow.h" +#include "main.h" +#include "ui_mainwindow.h" -QT_CHARTS_USE_NAMESPACE +QSqlDatabase dbRef = QSqlDatabase(); + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + dbRef = QSqlDatabase::addDatabase("QMYSQL"); + + w.show(); + return a.exec(); +} + +/* QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { @@ -69,4 +60,4 @@ int main(int argc, char *argv[]) window.show(); return a.exec(); -} +} */ diff --git a/client/main.h b/client/main.h new file mode 100644 index 0000000..010f2e6 --- /dev/null +++ b/client/main.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +int main(int argc, char *argv[]); +extern QSqlDatabase dbRef; + diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp new file mode 100644 index 0000000..955307e --- /dev/null +++ b/client/mainwindow.cpp @@ -0,0 +1,50 @@ +#include + +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "main.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ +// db = QSqlDatabase::addDatabase("QMYSQL"); + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + dbRef.close(); + delete ui; +} + +void MainWindow::on_actionAbout_triggered() +{ + QMessageBox::warning(this, "Oops..", "Task Failed succesfully ;)"); +} + + +void MainWindow::on_pushButton_clicked() +{ +// dbRef = QSqlDatabase::addDatabase("QMYSQL"); +// dbRef.setHostName("localhost"); +// dbRef.setUserName("root"); +// dbRef.setPassword("Ab12345!"); +// dbRef.setDatabaseName("thecrapbox"); + + if(dbRef.open()){ + QMessageBox::information(this, "Connection", "GREAT SUCCES!"); + pQueryModel = new QSqlQueryModel(); + pQueryModel->setQuery("SELECT * FROM opleiding;"); + ui->tableView->setModel(pQueryModel); + } else { + QMessageBox::warning(this, "No connection", "Failed to connect"); + } +} + +void MainWindow::on_actionConnection_triggered() +{ + _dbConenctor = new dbConnector(this); + _dbConenctor->show(); +} + diff --git a/client/mainwindow.h b/client/mainwindow.h new file mode 100644 index 0000000..1e73657 --- /dev/null +++ b/client/mainwindow.h @@ -0,0 +1,42 @@ +#pragma once + +#include + +//#include "database.h" +#include "dbconnector.h" + +#include +#include +#include +#include "main.h" + + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + void on_actionAbout_triggered(); + + void on_pushButton_clicked(); + + void on_actionConnection_triggered(); + +private: + Ui::MainWindow *ui; + + dbConnector *_dbConenctor; +// QSqlDatabase db; + + QSqlQueryModel *pQueryModel; + +// Database database; +}; diff --git a/client/mainwindow.ui b/client/mainwindow.ui new file mode 100644 index 0000000..f827c85 --- /dev/null +++ b/client/mainwindow.ui @@ -0,0 +1,128 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + true + + + + 310 + 0 + 121 + 41 + + + + DoesSomething + + + + + + -10 + 40 + 801 + 401 + + + + + + + + + + + + + 0 + 0 + 800 + 21 + + + + + Home + + + + + + + TEMP + + + + + + + Database + + + + + + + + + + + + + About + + + + + Refresh + + + + + Load + + + + + Query + + + + + Connect + + + + + Disconnenct + + + + + Querry + + + + + Status + + + + + + diff --git a/createDB.sql b/createDB.sql deleted file mode 100644 index 4c4c4d4..0000000 --- a/createDB.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE SCHEMA `WSdb`; -CREATE TABLE `DAB1Pract1`.`tblMain` ( - `ID` INT GENERATED ALWAYS AS (), - `temperature` DECIMAL(5,2) NULL, - `humidity` DECIMAL(5,2) NULL, - `pressure` DECIMAL(5,2) NULL, - `time` DATETIME NULL, - PRIMARY KEY (`ID`), - UNIQUE INDEX `ID_UNIQUE` (`ID` ASC) VISIBLE); diff --git a/scripts/db-init.sql b/scripts/db-init.sql new file mode 100644 index 0000000..4c4c4d4 --- /dev/null +++ b/scripts/db-init.sql @@ -0,0 +1,9 @@ +CREATE SCHEMA `WSdb`; +CREATE TABLE `DAB1Pract1`.`tblMain` ( + `ID` INT GENERATED ALWAYS AS (), + `temperature` DECIMAL(5,2) NULL, + `humidity` DECIMAL(5,2) NULL, + `pressure` DECIMAL(5,2) NULL, + `time` DATETIME NULL, + PRIMARY KEY (`ID`), + UNIQUE INDEX `ID_UNIQUE` (`ID` ASC) VISIBLE); -- cgit v1.2.3