From 09f803860613c048f36c1cc65878db060414710b Mon Sep 17 00:00:00 2001 From: tobiglaser <76131623+tobiglaser@users.noreply.github.com> Date: Thu, 4 Aug 2022 02:16:41 +0200 Subject: [PATCH] Worksheet 4: 3.1 done with Proxy for CommandType --- CMakeLists.txt | 16 +++++++++-- src/ComTypeListWidgetItem.h | 22 ++++++++++++++++ src/ControlDeveloper.cpp | 4 +-- src/ControlUI.cpp | 10 +++++++ src/{mainwindow.h => ControlUI.h} | 6 ++--- src/PanelCommandTypes.cpp | 44 +++++++++++++++++++++++++++++++ src/PanelCommandTypes.h | 24 +++++++++++++++++ src/mainwindow.cpp | 17 ------------ 8 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 src/ComTypeListWidgetItem.h create mode 100644 src/ControlUI.cpp rename src/{mainwindow.h => ControlUI.h} (55%) create mode 100644 src/PanelCommandTypes.cpp create mode 100644 src/PanelCommandTypes.h delete mode 100644 src/mainwindow.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c23b9ed..7e736ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,17 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(PROJECT_SOURCES src/ControlDeveloper.cpp - src/mainwindow.cpp - src/mainwindow.h + src/ControlUI.cpp + src/ControlModel.cpp + src/ControlModelRegistry.cpp + src/PanelCommandTypes.cpp + src/CommandType.cpp + src/CommandListOWN.cpp + include/ComHandler.cpp + include/ObjectFileHandler.cpp + src/Gear.cpp + src/Direction.cpp + src/Pause.cpp ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) @@ -46,6 +55,9 @@ else() endif() endif() +# Add include directory +target_include_directories(ControlDeveloper PUBLIC include/) + target_link_libraries(ControlDeveloper PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) set_target_properties(ControlDeveloper PROPERTIES diff --git a/src/ComTypeListWidgetItem.h b/src/ComTypeListWidgetItem.h new file mode 100644 index 0000000..c470651 --- /dev/null +++ b/src/ComTypeListWidgetItem.h @@ -0,0 +1,22 @@ +#pragma once +#include <QListWidgetItem> + +#include "CommandType.h" + + +class ComTypeListWidgetItem : public QListWidgetItem +{ + +private: + CommandType *cT; + +public: + + ComTypeListWidgetItem(CommandType *_cT) + { + cT = _cT; + if (cT) + setText(cT->getName().c_str()); + } + CommandType *getCommandType() { return cT; } +}; diff --git a/src/ControlDeveloper.cpp b/src/ControlDeveloper.cpp index 46d850b..9ae0712 100644 --- a/src/ControlDeveloper.cpp +++ b/src/ControlDeveloper.cpp @@ -1,11 +1,11 @@ #include <QApplication> -#include "mainwindow.h" +#include "ControlUI.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow w; + ControlUI w; w.show(); return a.exec(); } \ No newline at end of file diff --git a/src/ControlUI.cpp b/src/ControlUI.cpp new file mode 100644 index 0000000..06eee0d --- /dev/null +++ b/src/ControlUI.cpp @@ -0,0 +1,10 @@ +#include "ControlUI.h" +#include "PanelCommandTypes.h" + +ControlUI::ControlUI(QWidget *parent) + : QMainWindow(parent) +{ + setWindowTitle("ControlDeveloper"); + PanelCommandTypes *pct = new PanelCommandTypes(&ControlModel::getInstance()); + setCentralWidget(pct); +} diff --git a/src/mainwindow.h b/src/ControlUI.h similarity index 55% rename from src/mainwindow.h rename to src/ControlUI.h index e38abb1..ec91558 100644 --- a/src/mainwindow.h +++ b/src/ControlUI.h @@ -3,15 +3,13 @@ #include <QMainWindow> -class MainWindow : public QMainWindow +class ControlUI : public QMainWindow { Q_OBJECT private: public: - MainWindow(QWidget *parent = nullptr); - ~MainWindow(); - + ControlUI(QWidget *parent = nullptr); }; #endif // MAINWINDOW_H diff --git a/src/PanelCommandTypes.cpp b/src/PanelCommandTypes.cpp new file mode 100644 index 0000000..776bf1e --- /dev/null +++ b/src/PanelCommandTypes.cpp @@ -0,0 +1,44 @@ +#include <QBoxLayout> + +#include "PanelCommandTypes.h" +#include "ComTypeListWidgetItem.h" + + +PanelCommandTypes::PanelCommandTypes(ControlModel *_cM) +{ + cM = _cM; + setView(); + setController(); +} + +void PanelCommandTypes::setView() +{ + QBoxLayout *layout = new QBoxLayout(QBoxLayout::Direction::TopToBottom); + setLayout(layout); + commandTypeList = new QListWidget(); + layout->addWidget(commandTypeList); + bAdd = new QPushButton("Add"); + layout->addWidget(bAdd); + + for (auto &&i : cM->getCommandTypes()) + { + commandTypeList->addItem(new ComTypeListWidgetItem(&i)); + } +} + +void PanelCommandTypes::setController() +{ + connect(bAdd, SIGNAL(clicked()), this, SLOT(onAddButton())); +} + +void PanelCommandTypes::onAddButton() +{ + ComTypeListWidgetItem *listItem = dynamic_cast<ComTypeListWidgetItem*>(commandTypeList->currentItem()); + if (listItem) + { + std::shared_ptr<ICommand> newCommand = listItem->getCommandType()->createInstance(); + cM->getCommandList().add(newCommand); + + cM->getCommandList().printCommands(); + } +} \ No newline at end of file diff --git a/src/PanelCommandTypes.h b/src/PanelCommandTypes.h new file mode 100644 index 0000000..fced766 --- /dev/null +++ b/src/PanelCommandTypes.h @@ -0,0 +1,24 @@ +#pragma once +#include <QListWidget> +#include <QPushButton> +#include "ControlModel.h" + +class PanelCommandTypes : public QWidget +{ + +Q_OBJECT + +private: + QListWidget *commandTypeList; + QPushButton *bAdd; + ControlModel *cM; + + void setView(); + void setController(); + +private slots: + void onAddButton(); + +public: + PanelCommandTypes(ControlModel *_cM); +}; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp deleted file mode 100644 index 2f94d13..0000000 --- a/src/mainwindow.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include <QPushButton> -#include <QLineEdit> -#include <QBoxLayout> - -#include "mainwindow.h" - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) -{ -//general - setWindowTitle("ControlDeveloper"); -} - -MainWindow::~MainWindow() -{ -} - -- GitLab