From aef960a68c04d30634f556533e7352bb009313e1 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 31 Oct 2023 16:27:46 +0100 Subject: [PATCH] TaskTree: Get rid of the fluent interface It wasn't really used and it interferes when refactoring. Change-Id: I8b8ba1740fef24502855e896e9b33ba816e1229f Reviewed-by: Qt CI Bot Reviewed-by: Marcus Tillmanns --- src/libs/solutions/tasking/tasktree.cpp | 82 -------------------- src/libs/solutions/tasking/tasktree.h | 17 ---- tests/auto/solutions/tasking/tst_tasking.cpp | 16 ---- 3 files changed, 115 deletions(-) diff --git a/src/libs/solutions/tasking/tasktree.cpp b/src/libs/solutions/tasking/tasktree.cpp index 5dc743f1324..a8a2ad3615d 100644 --- a/src/libs/solutions/tasking/tasktree.cpp +++ b/src/libs/solutions/tasking/tasktree.cpp @@ -452,53 +452,6 @@ private: When the running task finishes, one of \a done or \a error handlers is called, depending on whether it finished with success or an error, respectively. Both handlers are of std::function type. - - \sa onSetup(), onDone(), onError() -*/ - -/*! - \fn template template CustomTask &CustomTask::onSetup(SetupHandler &&handler) - - Attaches the setup \a handler to \c this task. - The \a handler is invoked when the task is about to be started. - - This function enables defining the task's details with a - \l {https://en.wikipedia.org/wiki/Fluent_interface}{fluent interface} style: - - \code - const auto onQuerySetup = [](NetworkQuery &task) { ... }; - const auto onQueryError = [](const NetworkQuery &task) { ... }; - - const Group group { - NetworkQueryTask(onQuerySetup, {}, onQueryError), - NetworkQueryTask().onSetup(onQuerySetup).onError(onQueryError), // fluent interface style - NetworkQueryTask(onQuerySetup, {}, onQueryError).withTimeout(500ms) - } - \endcode - - \sa CustomTask(), onDone(), onError() -*/ - -/*! - \fn template CustomTask &CustomTask::onDone(const EndHandler &handler) - - Attaches the done \a handler to \c this task. - The handler is invoked when the task finishes with success. - - This function enables defining the task's details with a fluent interface style. - - \sa CustomTask(), onSetup(), onError() -*/ - -/*! - \fn template CustomTask &CustomTask::onError(const EndHandler &handler) - - Attaches the error \a handler to \c this task. - The handler is invoked when the task finishes with an error. - - This function enables defining the task's details with a fluent interface style. - - \sa CustomTask(), onSetup(), onDone() */ /*! @@ -511,8 +464,6 @@ private: the returned item finishes immediately with the task's result. Otherwise, the \a handler is invoked (if provided), the task is stopped, and the returned item finishes with an error. - - \sa onSetup() */ /*! @@ -1002,39 +953,6 @@ void GroupItem::addChildren(const QList &children) } } -void GroupItem::setTaskSetupHandler(const TaskSetupHandler &handler) -{ - if (!handler) { - qWarning("Setting empty Setup Handler is no-op, skipping..."); - return; - } - if (m_taskHandler.m_setupHandler) - qWarning("Setup Handler redefinition, overriding..."); - m_taskHandler.m_setupHandler = handler; -} - -void GroupItem::setTaskDoneHandler(const TaskEndHandler &handler) -{ - if (!handler) { - qWarning("Setting empty Done Handler is no-op, skipping..."); - return; - } - if (m_taskHandler.m_doneHandler) - qWarning("Done Handler redefinition, overriding..."); - m_taskHandler.m_doneHandler = handler; -} - -void GroupItem::setTaskErrorHandler(const TaskEndHandler &handler) -{ - if (!handler) { - qWarning("Setting empty Error Handler is no-op, skipping..."); - return; - } - if (m_taskHandler.m_errorHandler) - qWarning("Error Handler redefinition, overriding..."); - m_taskHandler.m_errorHandler = handler; -} - GroupItem GroupItem::withTimeout(const GroupItem &item, milliseconds timeout, const GroupEndHandler &handler) { diff --git a/src/libs/solutions/tasking/tasktree.h b/src/libs/solutions/tasking/tasktree.h index ac6146eace1..f3b84eb32c2 100644 --- a/src/libs/solutions/tasking/tasktree.h +++ b/src/libs/solutions/tasking/tasktree.h @@ -189,9 +189,6 @@ protected: , m_taskHandler(handler) {} void addChildren(const QList &children); - void setTaskSetupHandler(const TaskSetupHandler &handler); - void setTaskDoneHandler(const TaskEndHandler &handler); - void setTaskErrorHandler(const TaskEndHandler &handler); static GroupItem groupHandler(const GroupHandler &handler) { return GroupItem({handler}); } static GroupItem parallelLimit(int limit) { return GroupItem({{}, limit}); } static GroupItem workflowPolicy(WorkflowPolicy policy) { return GroupItem({{}, {}, policy}); } @@ -336,20 +333,6 @@ public: : GroupItem({&createAdapter, wrapSetup(std::forward(setup)), wrapEnd(done), wrapEnd(error)}) {} - template - CustomTask &onSetup(SetupHandler &&handler) { - setTaskSetupHandler(wrapSetup(std::forward(handler))); - return *this; - } - CustomTask &onDone(const EndHandler &handler) { - setTaskDoneHandler(wrapEnd(handler)); - return *this; - } - CustomTask &onError(const EndHandler &handler) { - setTaskErrorHandler(wrapEnd(handler)); - return *this; - } - GroupItem withTimeout(std::chrono::milliseconds timeout, const GroupEndHandler &handler = {}) const { return GroupItem::withTimeout(*this, timeout, handler); diff --git a/tests/auto/solutions/tasking/tst_tasking.cpp b/tests/auto/solutions/tasking/tst_tasking.cpp index cd476670c8f..08161020528 100644 --- a/tests/auto/solutions/tasking/tst_tasking.cpp +++ b/tests/auto/solutions/tasking/tst_tasking.cpp @@ -114,8 +114,6 @@ void tst_Tasking::validConstructs() const auto doneHandler = [](const TaskObject &) {}; const auto errorHandler = [](const TaskObject &) {}; - // Not fluent interface - const Group task2 { parallel, TestTask(setupHandler), @@ -125,20 +123,6 @@ void tst_Tasking::validConstructs() TestTask(setupHandler, {}, errorHandler) }; - // Fluent interface - - const Group fluent { - parallel, - TestTask().onSetup(setupHandler), - TestTask().onSetup(setupHandler).onDone(doneHandler), - TestTask().onSetup(setupHandler).onDone(doneHandler).onError(errorHandler), - // possible to skip the empty done - TestTask().onSetup(setupHandler).onError(errorHandler), - // possible to set handlers in a different order - TestTask().onError(errorHandler).onDone(doneHandler).onSetup(setupHandler), - }; - - // When turning each of below blocks on, you should see the specific compiler error message. #if 0