From c774343a6fe4dee49a7ca3f9e1f51a970bfa5fda Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Sun, 27 Jun 2021 23:56:11 +0200 Subject: [PATCH] WINDOW: Wrap all the documents->addTab to have a coherent naming sceme and icons on all the document tabs --- src/MainWindow.cc | 19 +++++++++++++------ src/MainWindow.hh | 4 ++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 43b18086..1a131209 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -166,9 +166,7 @@ MainWindow::newDocument(bool default_) noexcept std::weak_ptr<VivyDocument> document = vivyApp->documentStore.newDocument(default_); try { - VivyDocumentView *documentView = new VivyDocumentView(document); - documents->addTab(documentView, QIcon(":/icons/vivy.png"), document.lock()->getName()); - qDebug() << "View constructed successfully"; + addTab(new VivyDocumentView(document)); } catch (const std::runtime_error &e) { qCritical() << "Failed to create a new empty document"; if (auto locked = document.lock()) { @@ -197,9 +195,7 @@ MainWindow::openDocument() noexcept if (auto document = vivyApp->documentStore.loadDocument(filename).lock()) { try { - VivyDocumentView *documentView = new VivyDocumentView(document); - qDebug() << "View constructed successfully"; - documents->addTab(documentView, document->getName()); + addTab(new VivyDocumentView(document)); if (auto doc = reinterpret_cast<const VivyDocumentView *>(documents->widget(0))->getDocument().lock()) { if (doc->isUntouchedDefault() && documents->count() == 2) { closeDocument(0); @@ -253,3 +249,14 @@ MainWindow::loadSubDocumentAudio() noexcept currDoc->setAudioSubDocument(filename); } } + +void +MainWindow::addTab(VivyDocumentView *tab) +{ + if (auto document = tab->getDocument().lock()) { + documents->addTab(tab, QIcon(":/icons/vivy.png"), document->getName()); + qDebug() << "View constructed successfully"; + } else { + throw std::runtime_error("failed to lock document from the view"); + } +} diff --git a/src/MainWindow.hh b/src/MainWindow.hh index d53031cc..d7841a30 100644 --- a/src/MainWindow.hh +++ b/src/MainWindow.hh @@ -8,6 +8,7 @@ #include "Utils.hh" #include "AudioVisualizer.hh" #include "Document/VivyDocumentStore.hh" +#include "VivyDocumentView.hh" #include <QMainWindow> namespace Vivy @@ -24,6 +25,9 @@ public: std::weak_ptr<VivyDocument> getCurrentDocument() const; +private: + void addTab(VivyDocumentView *); + private slots: void newDocument(bool = false) noexcept; void openDocument() noexcept; -- GitLab