From f8f9f6ca42c54c25be0ee13917dab4ee14c4c2cf Mon Sep 17 00:00:00 2001 From: pascal Date: Sun, 20 Oct 2024 13:00:40 +0200 Subject: [PATCH] remove ProjectEditor --- src/CMakeLists.txt | 3 -- src/mainwindow.cpp | 8 +---- src/projecteditor.cpp | 79 ------------------------------------------- src/projecteditor.h | 36 -------------------- src/projecteditor.ui | 55 ------------------------------ 5 files changed, 1 insertion(+), 180 deletions(-) delete mode 100644 src/projecteditor.cpp delete mode 100644 src/projecteditor.h delete mode 100644 src/projecteditor.ui diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 760ed9c..85bb224 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,9 +32,6 @@ target_sources(tire-impl PRIVATE plantableview.h project.cpp project.h - projecteditor.cpp - projecteditor.h - projecteditor.ui projectmodel.cpp projectmodel.h serialization.cpp diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c41871c..f006a64 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -8,7 +8,6 @@ #include "exceptions.h" #include "intervalmodel.h" #include "plan.h" -#include "projecteditor.h" #include "projectmodel.h" #include "serialization.h" #include "timerangeslider.h" @@ -158,13 +157,8 @@ void MainWindow::switch_task() return; } - ProjectEditor d(m_time_sheet->project_model()); - if (d.exec() == QDialog::Rejected) { - return; - } - const auto timestamp = Application::current_date_time(); - auto new_interval = std::make_unique(&d.current_project()); + auto new_interval = std::make_unique(nullptr); new_interval->swap_begin(timestamp); auto add_interval_command = make(interval_model, std::move(new_interval)); const auto macro = Application::undo_stack().start_macro(add_interval_command->text()); diff --git a/src/projecteditor.cpp b/src/projecteditor.cpp deleted file mode 100644 index 416ad8e..0000000 --- a/src/projecteditor.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "projecteditor.h" - -#include "application.h" -#include "commands/addremovecommand.h" -#include "commands/undostack.h" -#include "project.h" -#include "projectmodel.h" -#include "ui_projecteditor.h" -#include -#include -#include -#include - -ProjectEditor::ProjectEditor(ProjectModel& project_model, QWidget* parent) - : QDialog(parent), m_ui(std::make_unique()), m_project_model(project_model) -{ - m_ui->setupUi(this); - - update_project_list(); - connect(m_ui->cb_name, &QComboBox::currentTextChanged, this, &ProjectEditor::update_enabledness); - connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &ProjectEditor::about_to_accept); -} - -ProjectEditor::~ProjectEditor() = default; - -void ProjectEditor::set_project(const Project& project) -{ - m_ui->cb_name->setCurrentIndex(m_project_model.index_of(project)); -} - -const Project& ProjectEditor::current_project() const -{ - return m_project_model.project(m_ui->cb_name->currentIndex()); -} - -std::unique_ptr ProjectEditor::create_project() const -{ - return std::make_unique(m_ui->cb_name->currentText(), m_project_model.generate_color()); -} - -void ProjectEditor::showEvent(QShowEvent* event) -{ - m_ui->cb_name->lineEdit()->selectAll(); - QDialog::showEvent(event); -} - -void ProjectEditor::update_enabledness() const -{ - m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_ui->cb_name->currentText().isEmpty()); -} - -void ProjectEditor::update_project_list() const -{ - const QSignalBlocker _(m_ui->cb_name); - m_ui->cb_name->clear(); - for (const auto& project : m_project_model.projects()) { - m_ui->cb_name->addItem(project->name()); - } -} - -void ProjectEditor::about_to_accept() -{ - if (m_ui->cb_name->currentText() != m_ui->cb_name->itemText(m_ui->cb_name->currentIndex())) { - if (QMessageBox::question( - this, QApplication::applicationDisplayName(), - tr("There is no project '%1'. Do you want to create it?").arg(m_ui->cb_name->currentText()), - QMessageBox::Yes | QMessageBox::No) - == QMessageBox::No) - { - return; - } - auto new_project = create_project(); - const auto& project_ref = *new_project; - Application::undo_stack().push(::make(m_project_model, std::move(new_project))); - update_project_list(); - set_project(project_ref); // must be after update_project_list! - } - accept(); -} diff --git a/src/projecteditor.h b/src/projecteditor.h deleted file mode 100644 index db97994..0000000 --- a/src/projecteditor.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "project.h" -#include -#include - -class UndoStack; -class Project; -class ProjectModel; -namespace Ui -{ -class ProjectEditor; -} - -class ProjectEditor final : public QDialog -{ - Q_OBJECT - -public: - explicit ProjectEditor(ProjectModel& project_model, QWidget* parent = nullptr); - ~ProjectEditor() override; - void set_project(const Project& project); - - [[nodiscard]] const Project& current_project() const; - [[nodiscard]] std::unique_ptr create_project() const; - -protected: - void showEvent(QShowEvent* event) override; - -private: - std::unique_ptr m_ui; - ProjectModel& m_project_model; - void update_enabledness() const; - void update_project_list() const; - void about_to_accept(); -}; diff --git a/src/projecteditor.ui b/src/projecteditor.ui deleted file mode 100644 index d6b0ba0..0000000 --- a/src/projecteditor.ui +++ /dev/null @@ -1,55 +0,0 @@ - - - ProjectEditor - - - - 0 - 0 - 251 - 71 - - - - ProjectEditor - - - - - - true - - - QComboBox::InsertPolicy::NoInsert - - - - - - - QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok - - - - - - - - - buttonBox - rejected() - ProjectEditor - reject() - - - 153 - 61 - - - 149 - 71 - - - - -