-
Notifications
You must be signed in to change notification settings - Fork 1
commit #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
commit #1
Changes from 5 commits
9a4ceb5
f732c61
df90803
a133817
1726d0e
94167fc
2198964
48f0ba6
f3e3f12
0f95f34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| cmake_minimum_required(VERSION 3.24) | ||
| project(CourseProject) | ||
|
|
||
| set(CXX_STANDARD_REQUIRED ON) | ||
| set(CMAKE_CXX_STANDARD 20) | ||
| set(CMAKE_AUTOMOC ON) | ||
| set(CMAKE_AUTORCC ON) | ||
| set(CMAKE_AUTOUIC ON) | ||
|
|
||
| set(CMAKE_PREFIX_PATH "/opt/homebrew/opt/qt/lib/cmake") | ||
|
|
||
| find_package(Qt6 COMPONENTS | ||
| Core | ||
| Gui | ||
| Widgets | ||
| REQUIRED) | ||
|
|
||
| add_executable(CourseProject main.cpp mainwindow.cpp mainwindow.ui Model.cpp View.cpp Controller.cpp Connection.cpp InfoTree.cpp aboutwindow.cpp) | ||
| target_link_libraries(CourseProject | ||
| Qt::Core | ||
| Qt::Gui | ||
| Qt::Widgets | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #include "Connection.h" | ||
|
|
||
| namespace mvc { | ||
| Application::Application() { | ||
| view_.subscribe(controller_.input()); | ||
| model_.subscribe(view_.input()); | ||
| } | ||
| } |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Переименуй файл в Application |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #ifndef COURSEPROJECT_CONNECTION_H | ||
| #define COURSEPROJECT_CONNECTION_H | ||
|
|
||
| #include "Controller.h" | ||
|
|
||
|
||
| namespace mvc { | ||
| class Application { | ||
| public: | ||
| Application(); | ||
|
|
||
| private: | ||
| AVLTree model_; | ||
| View view_; | ||
| Controller controller_{&model_}; | ||
| }; | ||
| } | ||
| #endif //COURSEPROJECT_CONNECTION_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #include "Controller.h" | ||
|
|
||
| namespace mvc { | ||
| Controller::Controller(AVLTree *model) | ||
| : model_(model) { | ||
| } | ||
|
|
||
| void Controller::action(const ViewData &data) { | ||
| if(data.operation == View::Operation::Add) | ||
|
||
| model_->insert(data.value); | ||
| else if(data.operation == View::Operation::Delete) | ||
| model_->deleteNode(data.value); | ||
| else if(data.operation == View::Operation::Search) | ||
| model_->search(data.value); | ||
| else if(data.operation == View::Operation::Traversal && data.type == View::Type::InOrder) | ||
| model_->inOrder(); | ||
|
||
| else if(data.operation == View::Operation::Traversal && data.type == View::Type::PreOrder) | ||
| model_->preOrder(); | ||
| else | ||
| model_->postOrder(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #ifndef COURSEPROJECT_CONTROLLER_H | ||
| #define COURSEPROJECT_CONTROLLER_H | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "Model.h" | ||
| #include "View.h" | ||
|
|
||
| namespace mvc { | ||
| class Controller { | ||
| private: | ||
| using ViewData = View::Command; | ||
| using Observer = NSLibrary::CObserver<ViewData >; | ||
| using Input = NSLibrary::CColdInput<ViewData >; | ||
|
|
||
| public: | ||
| Controller(AVLTree *ptr); | ||
| Observer *input() { return &observer_; } | ||
|
|
||
| private: | ||
| void action(const ViewData& data); | ||
|
|
||
| AVLTree *model_; | ||
| Input observer_ = [this](const ViewData &data) { action(data); }; | ||
| }; | ||
| } | ||
|
|
||
| #endif //COURSEPROJECT_CONTROLLER_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| #include "InfoTree.h" | ||
|
|
||
| namespace mvc { | ||
| InfoTree::~InfoTree() { | ||
| clear(root_); | ||
| } | ||
|
|
||
| std::pair<int, bool> InfoTree::findValue(int x, int y) { | ||
| if(this == nullptr) | ||
| return {0, false}; | ||
| std::queue<Info *> que; | ||
| que.push(root_); | ||
| Info *cur; | ||
| while (!que.empty()) { | ||
| cur = que.front(); | ||
| que.pop(); | ||
| if((x > cur->x - RADIUS && x < cur->x + RADIUS) && (y > cur->y - RADIUS && y < cur->y + RADIUS)) | ||
| return {cur->key, true}; | ||
| if (cur->left != nullptr) | ||
| que.push(cur->left); | ||
| if (cur->right != nullptr) | ||
| que.push(cur->right); | ||
| } | ||
| return {0, false}; | ||
| } | ||
|
|
||
| void InfoTree::clear(Info *treeInfo) { | ||
| if (treeInfo != nullptr) { | ||
| clear(treeInfo->left); | ||
| clear(treeInfo->right); | ||
| delete treeInfo; | ||
| } | ||
| } | ||
|
|
||
| void InfoTree::setWidth(Info *cur) { | ||
| if (cur == nullptr) | ||
| return; | ||
| setWidth(cur->left); | ||
| setWidth(cur->right); | ||
|
|
||
| if (cur->right == nullptr && cur->left == nullptr) | ||
| cur->width = 2 * RADIUS; | ||
| else if (cur->left == nullptr) | ||
| cur->width = 2 * cur->right->width + WIDTH; | ||
| else if (cur->right == nullptr) | ||
| cur->width = 2 * cur->left->width + WIDTH; | ||
| else | ||
| cur->width = 2 * std::max(cur->left->width, cur->right->width) + WIDTH; | ||
| } | ||
|
|
||
| void InfoTree::calcXCoord() { | ||
| Info *coord = root_; | ||
| setWidth(coord); | ||
| Info *root = root_; | ||
| if (root == nullptr) | ||
| return; | ||
| std::queue<Info *> que; | ||
| que.push(root); | ||
| Info *cur; | ||
| int count = 0, timesNow = 1, timesNext = 0; | ||
| while (!que.empty()) { | ||
DimaTrushin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cur = que.front(); | ||
| que.pop(); | ||
| if (cur->left != nullptr) { | ||
| que.push(cur->left); | ||
| ++timesNext; | ||
| cur->left->x = cur->x - WIDTH / 2 - cur->left->width / 2; | ||
| } | ||
| if (cur->right != nullptr) { | ||
| que.push(cur->right); | ||
| ++timesNext; | ||
| cur->right->x = cur->x + WIDTH / 2 + cur->right->width / 2; | ||
| } | ||
| --timesNow; | ||
| if (timesNow == 0) { | ||
| ++count; | ||
| timesNow = timesNext; | ||
| timesNext = 0; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Info *InfoTree::copy(const Node *node) { | ||
| if (node == nullptr) | ||
| return nullptr; | ||
| else { | ||
| Info *temp = new Info; | ||
| temp->key = node->key; | ||
| temp->left = copy(node->leftCh); | ||
| temp->right = copy(node->rightCh); | ||
| return temp; | ||
| } | ||
| } | ||
|
|
||
| void InfoTree::calcYCoord(const Node *rootGet) { | ||
| root_ = copy(rootGet); | ||
|
||
| Info *root = root_; | ||
| if (root == nullptr) | ||
| return; | ||
| std::queue<Info *> que; | ||
| que.push(root); | ||
|
Comment on lines
+121
to
+122
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это ты от рекурсии избавлялась? |
||
| Info *cur; | ||
| int count = 0, timesNow = 1, timesNext = 0; | ||
| while (!que.empty()) { | ||
| cur = que.front(); | ||
| que.pop(); | ||
| cur->y = count * (2 * RADIUS + HEIGHT); | ||
| if (cur->left != nullptr) { | ||
| que.push(cur->left); | ||
| ++timesNext; | ||
| } | ||
| if (cur->right != nullptr) { | ||
| que.push(cur->right); | ||
| ++timesNext; | ||
| } | ||
| --timesNow; | ||
| if (timesNow == 0) { | ||
| ++count; | ||
| timesNow = timesNext; | ||
| timesNext = 0; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #ifndef COURSEPROJECT_INFOTREE_H | ||
| #define COURSEPROJECT_INFOTREE_H | ||
|
|
||
| #include "Model.h" | ||
| #include <queue> | ||
|
|
||
| namespace mvc { | ||
|
|
||
| struct Info{ | ||
| int x = 0; | ||
| int y = 0; | ||
| int key; | ||
| Info* left; | ||
| Info* right; | ||
| int width; | ||
| }; | ||
|
|
||
| class InfoTree { | ||
| public: | ||
| InfoTree(const Node* rootGet){ | ||
| calcYCoord(rootGet); | ||
| calcXCoord(); | ||
| } | ||
| ~InfoTree(); | ||
| Info* getRoot() { return root_; } | ||
| std::pair<int, bool> findValue(int x, int y); | ||
|
|
||
| private: | ||
| void clear(Info* treeInfo); | ||
| void setWidth(Info* cur); | ||
| void calcXCoord(); | ||
| Info* copy(const Node* node); | ||
| void calcYCoord(const Node* node); | ||
|
|
||
| static constexpr int RADIUS = 40; | ||
|
||
| static constexpr int HEIGHT = 30; | ||
| static constexpr int WIDTH = 15; | ||
| Info* root_ = nullptr; | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| #endif//COURSEPROJECT_INFOTREE_H | ||
Uh oh!
There was an error while loading. Please reload this page.