From 4148e06f340ce70684800815435249878effeec3 Mon Sep 17 00:00:00 2001 From: Hello_User Date: Tue, 29 Mar 2022 18:38:53 +0200 Subject: [PATCH] alles --- codeslot.cpp | 28 ++++ codeslot.h | 17 +++ deur.cpp | 29 +++- deur.h | 12 +- gebouw.pro | 12 +- gebouw.pro.user | 134 ++++++----------- gebouw.pro.user.daf7231 | 308 ++++++++++++++++++++++++++++++++++++++++ herkenningsslot.cpp | 28 ++++ herkenningsslot.h | 24 ++++ mainwindow.cpp | 46 ++++-- mainwindow.h | 12 +- mainwindow.ui | 10 ++ schuifdeur.cpp | 3 + schuifdeur.h | 3 +- sleutelslot.cpp | 18 +++ sleutelslot.h | 18 +++ slot.cpp | 5 + slot.h | 16 +++ 18 files changed, 617 insertions(+), 106 deletions(-) create mode 100644 codeslot.cpp create mode 100644 codeslot.h create mode 100644 gebouw.pro.user.daf7231 create mode 100644 herkenningsslot.cpp create mode 100644 herkenningsslot.h create mode 100644 sleutelslot.cpp create mode 100644 sleutelslot.h create mode 100644 slot.cpp create mode 100644 slot.h diff --git a/codeslot.cpp b/codeslot.cpp new file mode 100644 index 0000000..dc6e9ba --- /dev/null +++ b/codeslot.cpp @@ -0,0 +1,28 @@ +#include "codeslot.h" +#include +#include + +CodeSlot::CodeSlot(int code): vergrendeld(true), code(code){ +} + +bool CodeSlot::isVergrendeld(){ + return vergrendeld; +} + +void CodeSlot::ontgrendel(string code){ + try{ + if (stoi(code) == this->code){ + vergrendeld = false; + } + else{ + vergrendeld = true; + } + } + catch(const std::invalid_argument &error){ + return; + } +} + +void CodeSlot::vergrendel(){ + vergrendeld = true; +} diff --git a/codeslot.h b/codeslot.h new file mode 100644 index 0000000..4105bb6 --- /dev/null +++ b/codeslot.h @@ -0,0 +1,17 @@ +#ifndef CODESLOT_H +#define CODESLOT_H + +#include "slot.h" + +class CodeSlot : public Slot{ +private: + bool vergrendeld; + int code; +public: + CodeSlot(int); + void vergrendel(); + bool isVergrendeld(); + void ontgrendel(string); +}; + +#endif // CODESLOT_H diff --git a/deur.cpp b/deur.cpp index 640164d..9c7158e 100644 --- a/deur.cpp +++ b/deur.cpp @@ -1,5 +1,6 @@ #include "deur.h" #include +#include Deur::Deur(int x, int y, int lengte): x_coordinaat(x), y_coordinaat(y), lengte(lengte){ @@ -13,11 +14,27 @@ pair Deur::coordinaten() const { } void Deur::open(){ - status = true; + if(!sloten.empty()){ + for(std::list::iterator i = sloten.begin(); i != sloten.end(); ++i){ + if (!(*i)->isVergrendeld()){ + status = true; + } + else{ + status = false; + return; + } + } + } + else status = true; } void Deur::sluit(){ status = false; + if(!sloten.empty()){ + for(std::list::iterator i = sloten.begin(); i != sloten.end(); ++i){ + (*i)->vergrendel(); + } + } } bool Deur::isDeurOpen(){ @@ -27,3 +44,13 @@ bool Deur::isDeurOpen(){ unsigned int Deur::deurLengte(){ return lengte; } + +void Deur::addSlot(Slot *s){ + sloten.push_back(s); +} + +Slot* Deur::geefSleutel(int i){ + std::list::iterator it = sloten.begin(); + advance(it, i); + return *it; +} diff --git a/deur.h b/deur.h index dbd42ff..9b6d112 100644 --- a/deur.h +++ b/deur.h @@ -3,6 +3,10 @@ #include #include +#include "slot.h" +#include + +//class Slot; using namespace std; @@ -11,14 +15,20 @@ private: bool status; int x_coordinaat, y_coordinaat; unsigned lengte; + //Slot *slot; + std::list sloten; public: void open(); - void sluit(); + virtual void sluit(); virtual void teken(QPaintDevice*) = 0; bool isDeurOpen(); unsigned int deurLengte(); std::pair coordinaten() const; Deur(int, int, int); + void addSlot(Slot*); + //std::list geefSleutel(); + Slot* geefSleutel(int); + //Deur(int, int, int, Slot*); }; #endif // DEUR_H diff --git a/gebouw.pro b/gebouw.pro index 9afb0ab..5e6128c 100644 --- a/gebouw.pro +++ b/gebouw.pro @@ -24,18 +24,26 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += main.cpp\ + codeslot.cpp \ deur.cpp \ draaideur.cpp \ hallsensor.cpp \ + herkenningsslot.cpp \ mainwindow.cpp \ schuifdeur.cpp \ - sensor.cpp + sensor.cpp \ + sleutelslot.cpp \ + slot.cpp HEADERS += mainwindow.h \ + codeslot.h \ deur.h \ draaideur.h \ hallsensor.h \ + herkenningsslot.h \ schuifdeur.h \ - sensor.h + sensor.h \ + sleutelslot.h \ + slot.h FORMS += mainwindow.ui diff --git a/gebouw.pro.user b/gebouw.pro.user index 9d450a5..7f46cfa 100644 --- a/gebouw.pro.user +++ b/gebouw.pro.user @@ -1,14 +1,14 @@ - + EnvironmentId - {daf7231d-d0bf-4367-8947-ae949d9f2d27} + {d5e58b13-852b-4aba-9708-c119893ef783} ProjectExplorer.Project.ActiveTarget - 0 + 0 ProjectExplorer.Project.EditorSettings @@ -28,7 +28,7 @@ QmlJSGlobal - 2 + 2 UTF-8 false 4 @@ -37,6 +37,7 @@ true true 1 + false true false 0 @@ -45,6 +46,7 @@ 0 8 true + false 1 true true @@ -59,6 +61,7 @@ true + false true true true @@ -68,8 +71,8 @@ 0 true - false - {52ee9352-13f8-4418-955f-9ca6cac4ac63} + true + Builtin.BuildSystem true true @@ -80,6 +83,9 @@ true + + true + @@ -88,18 +94,18 @@ Desktop Desktop Desktop - {56611235-07dd-4b90-81ed-415f033053fc} - 0 - 0 - 0 + {86ebf10c-c997-4c55-b145-d0d809c0f0ea} + 0 + 0 + 0 - /home/shaquille/Downloads/build-gebouw-Desktop-Debug - /home/shaquille/Downloads/build-gebouw-Desktop-Debug + 0 + /home/shaquilles/Downloads/build-gebouw-Desktop-Debug + /home/shaquilles/Downloads/build-gebouw-Desktop-Debug true QtProjectManager.QMakeBuildStep - false @@ -107,7 +113,7 @@ true Qt4ProjectManager.MakeStep - 2 + 2 Build Build ProjectExplorer.BuildSteps.Build @@ -118,7 +124,7 @@ Qt4ProjectManager.MakeStep clean - 1 + 1 Clean Clean ProjectExplorer.BuildSteps.Clean @@ -126,18 +132,19 @@ 2 false + false + Debug Qt4ProjectManager.Qt4BuildConfiguration 2 - /home/shaquille/Downloads/build-gebouw-Desktop-Release - /home/shaquille/Downloads/build-gebouw-Desktop-Release + /home/shaquilles/Downloads/build-gebouw-Desktop-Release + /home/shaquilles/Downloads/build-gebouw-Desktop-Release true QtProjectManager.QMakeBuildStep - false @@ -145,7 +152,7 @@ true Qt4ProjectManager.MakeStep - 2 + 2 Build Build ProjectExplorer.BuildSteps.Build @@ -156,7 +163,7 @@ Qt4ProjectManager.MakeStep clean - 1 + 1 Clean Clean ProjectExplorer.BuildSteps.Clean @@ -164,18 +171,21 @@ 2 false + false + Release Qt4ProjectManager.Qt4BuildConfiguration 0 + 0 - /home/shaquille/Downloads/build-gebouw-Desktop-Profile - /home/shaquille/Downloads/build-gebouw-Desktop-Profile + 0 + /home/shaquilles/Downloads/build-gebouw-Desktop-Profile + /home/shaquilles/Downloads/build-gebouw-Desktop-Profile true QtProjectManager.QMakeBuildStep - false @@ -183,7 +193,7 @@ true Qt4ProjectManager.MakeStep - 2 + 2 Build Build ProjectExplorer.BuildSteps.Build @@ -194,7 +204,7 @@ Qt4ProjectManager.MakeStep clean - 1 + 1 Clean Clean ProjectExplorer.BuildSteps.Clean @@ -202,14 +212,18 @@ 2 false + false + Profile Qt4ProjectManager.Qt4BuildConfiguration 0 + 0 + 0 - 3 + 3 - 0 + 0 Deploy Deploy ProjectExplorer.BuildSteps.Deploy @@ -219,83 +233,29 @@ false ProjectExplorer.DefaultDeployConfiguration - 1 + 1 - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F true - 4096 - false - false - 1000 - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 2 - Qt4ProjectManager.Qt4RunConfiguration:/home/shaquille/Downloads/gebouw/gebouw.pro - /home/shaquille/Downloads/gebouw/gebouw.pro + Qt4ProjectManager.Qt4RunConfiguration:/home/shaquilles/Downloads/gebouw/gebouw.pro + /home/shaquilles/Downloads/gebouw/gebouw.pro false true true false true - /home/shaquille/Downloads/build-gebouw-Desktop-Debug + /home/shaquilles/Downloads/build-gebouw-Desktop-Debug - 1 + 1 ProjectExplorer.Project.TargetCount - 1 + 1 ProjectExplorer.Project.Updater.FileVersion diff --git a/gebouw.pro.user.daf7231 b/gebouw.pro.user.daf7231 new file mode 100644 index 0000000..7510b4b --- /dev/null +++ b/gebouw.pro.user.daf7231 @@ -0,0 +1,308 @@ + + + + + + EnvironmentId + {daf7231d-d0bf-4367-8947-ae949d9f2d27} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + true + true + true + true + + + 0 + true + + false + {52ee9352-13f8-4418-955f-9ca6cac4ac63} + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Desktop + {56611235-07dd-4b90-81ed-415f033053fc} + 0 + 0 + 0 + + /home/shaquille/Downloads/build-gebouw-Desktop-Debug + /home/shaquille/Downloads/build-gebouw-Desktop-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 + + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /home/shaquille/Downloads/build-gebouw-Desktop-Release + /home/shaquille/Downloads/build-gebouw-Desktop-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 + + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + /home/shaquille/Downloads/build-gebouw-Desktop-Profile + /home/shaquille/Downloads/build-gebouw-Desktop-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 + + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/home/shaquille/Downloads/gebouw/gebouw.pro + /home/shaquille/Downloads/gebouw/gebouw.pro + false + true + true + false + true + /home/shaquille/Downloads/build-gebouw-Desktop-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/herkenningsslot.cpp b/herkenningsslot.cpp new file mode 100644 index 0000000..4356e73 --- /dev/null +++ b/herkenningsslot.cpp @@ -0,0 +1,28 @@ +#include "herkenningsslot.h" + +HerkenningsSlot::HerkenningsSlot(){ + +} + +void HerkenningsSlot::voegAutorisatieToe(string naam, bool access){ + kaartenbak[naam] = access; +} + +void HerkenningsSlot::ontgrendel(string naam){ + if (kaartenbak.count(naam) && kaartenbak[naam]){ + vergrendeld = false; + } + else vergrendeld = true; +} + +bool HerkenningsSlot::isVergrendeld(){ + return vergrendeld; +} + +void HerkenningsSlot::vergrendel(){ + vergrendeld = true; +} + +void HerkenningsSlot::toonKaartenBack(){ + +} diff --git a/herkenningsslot.h b/herkenningsslot.h new file mode 100644 index 0000000..5252dd9 --- /dev/null +++ b/herkenningsslot.h @@ -0,0 +1,24 @@ +#ifndef HERKENNINGSSLOT_H +#define HERKENNINGSSLOT_H + +#include "slot.h" +#include + +class Afdrukker; + +class HerkenningsSlot : public Slot +{ +private: + std::map kaartenbak; + bool vergrendeld; + Afdrukker* afdrukker; +public: + HerkenningsSlot(); + void vergrendel(); + bool isVergrendeld(); + void ontgrendel(string); + void toonKaartenBack(); + void voegAutorisatieToe(string,bool); +}; + +#endif // HERKENNINGSSLOT_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 84b8d10..7c8eee5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,21 +7,25 @@ #include "draaideur.h" #include #include +#include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); s1=new Hallsensor(515,160); - deuren.push_back(std::shared_ptr (new Schuifdeur(503,250,80,s1))); - deuren.push_back(std::shared_ptr (new draaideur(248,140,40,false))); - deuren.push_back(std::shared_ptr (new draaideur(295,290,30,true))); -// vd = (new Schuifdeur(503,250,80,s1)); -// d1 = (new draaideur(248,140,40,false)); -// d2 = (new draaideur(295,290,30,true)); -// deuren.push_back(vd); -// deuren.push_back(d1); -// deuren.push_back(d2); + //sleutelSlot0 = new SleutelSlot("cisco"); + //sleutelSlot1 = new SleutelSlot("cisco"); + deuren.emplace_back(std::shared_ptr (new Schuifdeur(503,250,80,s1))); + deuren[0]->addSlot(new SleutelSlot("cisco")); + deuren[0]->addSlot(new SleutelSlot("cisco2")); + deuren.emplace_back(std::shared_ptr (new draaideur(248,140,40,false))); + deuren[1]->addSlot(new CodeSlot(1234)); + deuren[1]->addSlot(new CodeSlot(5678)); + deuren.emplace_back(std::shared_ptr (new draaideur(295,290,30,true))); + deuren[2]->addSlot(new CodeSlot(0000)); } MainWindow::~MainWindow(){ @@ -33,7 +37,7 @@ void MainWindow::paintEvent(QPaintEvent *event){ QPainter painter(this); QPen pen; - QImage image("/home/shaquille/Downloads/gebouw/Gebouw.png"); + QImage image("/home/shaquilles/Downloads/gebouw/Gebouw.png"); pen.setColor(Qt::green); pen.setWidth(4); @@ -56,7 +60,7 @@ void MainWindow::on_schuifdeurSensorKnop_clicked(){ void MainWindow::on_vd_clicked(){ if(deuren.at(0)->isDeurOpen()){ - deuren.at(0)->sluit(); + deuren[0]->sluit(); } else{ deuren.at(0)->open(); @@ -84,3 +88,23 @@ void MainWindow::on_d2_clicked(){ } update(); } + +void MainWindow::on_lineEdit_returnPressed(){ + string eenSleutel = ui->lineEdit->text().toStdString(); + Slot* sleutelSlot0 = deuren[0]->geefSleutel(0); + Slot* sleutelSlot1 = deuren[0]->geefSleutel(1); + Slot* codeSlot0 = deuren[1]->geefSleutel(0); + Slot* codeSlot1 = deuren[1]->geefSleutel(1); + Slot* codeSlot2 = deuren[2]->geefSleutel(0); + sleutelSlot0->ontgrendel(eenSleutel); + sleutelSlot1->ontgrendel(eenSleutel); + codeSlot0->ontgrendel(eenSleutel); + codeSlot1->ontgrendel(eenSleutel); + codeSlot2->ontgrendel(eenSleutel); + +} + +void MainWindow::on_textBrowser_textChanged(){ + update(); +} + diff --git a/mainwindow.h b/mainwindow.h index 2582b02..cae3c79 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,6 +2,8 @@ #define MAINWINDOW_H #include +#include +#include namespace Ui { class MainWindow; @@ -11,8 +13,9 @@ class Sensor; class Schuifdeur; class draaideur; class Deur; -class MainWindow : public QMainWindow -{ +class SleutelSlot; +class Slot; +class MainWindow : public QMainWindow{ Q_OBJECT public: @@ -25,15 +28,18 @@ private slots: void on_d1_clicked(); void on_d2_clicked(); + void on_lineEdit_returnPressed(); + private: Ui::MainWindow *ui; Hallsensor *s1; std::shared_ptr *vd; std::shared_ptr *d1, *d2; + //Slot *sleutelSlot0; // std::vector> deuren; // Schuifdeur *vd; // draaideur *d1, *d2; - std::vector> deuren; + std::vector> deuren; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 337a667..3dc8d11 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -78,6 +78,16 @@ false + + + + 550 + 10 + 113 + 30 + + + diff --git a/schuifdeur.cpp b/schuifdeur.cpp index 08260b1..480a834 100644 --- a/schuifdeur.cpp +++ b/schuifdeur.cpp @@ -3,11 +3,14 @@ #include #include #include "hallsensor.h" +#include "slot.h" +#include "iostream" Schuifdeur::Schuifdeur(int x, int y, int lengte, Sensor *sensor): Deur(x,y,lengte), s(sensor){ } + void Schuifdeur::teken(QPaintDevice *tp){ QPainter p(tp); QColor kleur=Qt::black; diff --git a/schuifdeur.h b/schuifdeur.h index 90490be..e4544bf 100644 --- a/schuifdeur.h +++ b/schuifdeur.h @@ -9,8 +9,9 @@ class Sensor; class Schuifdeur : public Deur{ public: Schuifdeur(int, int, int, Sensor*); + //Schuifdeur(int, int, int, Sensor*, Slot*); void teken(QPaintDevice*) override; - void sluit(); + void sluit() override; Sensor* s; }; diff --git a/sleutelslot.cpp b/sleutelslot.cpp new file mode 100644 index 0000000..4f043d2 --- /dev/null +++ b/sleutelslot.cpp @@ -0,0 +1,18 @@ +#include "sleutelslot.h" + +SleutelSlot::SleutelSlot(string sleutel): vergrendeld(true), sleutel(sleutel){ +} + +bool SleutelSlot::isVergrendeld(){ + return vergrendeld; +} + +void SleutelSlot::ontgrendel(string sleutel){ + if (sleutel == this->sleutel){ + vergrendeld = false; + } +} + +void SleutelSlot::vergrendel(){ + vergrendeld = true; +} diff --git a/sleutelslot.h b/sleutelslot.h new file mode 100644 index 0000000..84092ea --- /dev/null +++ b/sleutelslot.h @@ -0,0 +1,18 @@ +#ifndef SLEUTELSLOT_H +#define SLEUTELSLOT_H + +#include "slot.h" + +class SleutelSlot : public Slot +{ +private: + bool vergrendeld; + string sleutel; +public: + SleutelSlot(string); + void vergrendel(); + bool isVergrendeld(); + void ontgrendel(string); +}; + +#endif // SLEUTELSLOT_H diff --git a/slot.cpp b/slot.cpp new file mode 100644 index 0000000..845033c --- /dev/null +++ b/slot.cpp @@ -0,0 +1,5 @@ +#include "slot.h" + +Slot::Slot(){ + +} diff --git a/slot.h b/slot.h new file mode 100644 index 0000000..44f9b78 --- /dev/null +++ b/slot.h @@ -0,0 +1,16 @@ +#ifndef SLOT_H +#define SLOT_H + +#include + +using namespace std; + +class Slot{ +public: + Slot(); + virtual void ontgrendel(string) = 0; + virtual void vergrendel() = 0; + virtual bool isVergrendeld() = 0; +}; + +#endif // SLOT_H