From 4e0c072e6b2b7789555def3dcc049e04865d292c Mon Sep 17 00:00:00 2001 From: Elliu <goyard.louis@gmail.com> Date: Wed, 18 Aug 2021 18:40:13 +0200 Subject: [PATCH] Add getCurrentVivyDocument --- src/VivyApplication.cc | 11 +++++++++++ src/VivyApplication.hh | 1 + 2 files changed, 12 insertions(+) diff --git a/src/VivyApplication.cc b/src/VivyApplication.cc index f4bf46f0..0cce1bc7 100644 --- a/src/VivyApplication.cc +++ b/src/VivyApplication.cc @@ -91,3 +91,14 @@ VivyApplication::getMainWindow() const throw std::logic_error("No main window in the graphic VivyApplication"); return mainWindowPtr.get(); } + +/* + * @return the current VivyDocument, or null if there isn't one or if the current document is not a VivyDocument + */ +VivyDocument * +VivyApplication::getCurrentVivyDocument() const +{ + if (!mainWindowPtr) + throw std::logic_error("No main window in the graphic VivyApplication"); + return dynamic_cast<VivyDocument*>(mainWindowPtr.get()->getCurrentDocument()); +} diff --git a/src/VivyApplication.hh b/src/VivyApplication.hh index 06e04780..d992f5e1 100644 --- a/src/VivyApplication.hh +++ b/src/VivyApplication.hh @@ -71,6 +71,7 @@ public: QFont getApplicationFont(Font) const noexcept; [[nodiscard("handle-it")]] MainWindow *getMainWindow() const; + [[nodiscard("handle-it")]] VivyDocument *getCurrentVivyDocument() const; void setTheme(Theme) noexcept; }; -- GitLab