forked from qt-creator/qt-creator
TaskTree: Introduce onGroup...() functions
The OnGroup... elements are going to be replaced with these functions. Change-Id: Ia271a89062cc9c6b18384607b20b1f68d273bcde Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -40,6 +40,16 @@ private:
|
|||||||
Guard &m_guard;
|
Guard &m_guard;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TaskItem onGroupDone(const TaskItem::GroupEndHandler &handler)
|
||||||
|
{
|
||||||
|
return Group::onGroupDone(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskItem onGroupError(const TaskItem::GroupEndHandler &handler)
|
||||||
|
{
|
||||||
|
return Group::onGroupError(handler);
|
||||||
|
}
|
||||||
|
|
||||||
static TaskAction toTaskAction(bool success)
|
static TaskAction toTaskAction(bool success)
|
||||||
{
|
{
|
||||||
return success ? TaskAction::StopWithDone : TaskAction::StopWithError;
|
return success ? TaskAction::StopWithDone : TaskAction::StopWithError;
|
||||||
|
@@ -183,6 +183,7 @@ protected:
|
|||||||
void setTaskSetupHandler(const TaskSetupHandler &handler);
|
void setTaskSetupHandler(const TaskSetupHandler &handler);
|
||||||
void setTaskDoneHandler(const TaskEndHandler &handler);
|
void setTaskDoneHandler(const TaskEndHandler &handler);
|
||||||
void setTaskErrorHandler(const TaskEndHandler &handler);
|
void setTaskErrorHandler(const TaskEndHandler &handler);
|
||||||
|
static TaskItem createGroupHandler(const GroupHandler &handler) { return TaskItem(handler); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type m_type = Type::Group;
|
Type m_type = Type::Group;
|
||||||
@@ -199,8 +200,47 @@ class TASKING_EXPORT Group : public TaskItem
|
|||||||
public:
|
public:
|
||||||
Group(const QList<TaskItem> &children) { addChildren(children); }
|
Group(const QList<TaskItem> &children) { addChildren(children); }
|
||||||
Group(std::initializer_list<TaskItem> children) { addChildren(children); }
|
Group(std::initializer_list<TaskItem> children) { addChildren(children); }
|
||||||
|
|
||||||
|
template <typename SetupHandler>
|
||||||
|
static TaskItem onGroupSetup(SetupHandler &&handler) {
|
||||||
|
return createGroupHandler({wrapGroupSetup(std::forward<SetupHandler>(handler))});
|
||||||
|
}
|
||||||
|
static TaskItem onGroupDone(const GroupEndHandler &handler) {
|
||||||
|
return createGroupHandler({{}, handler});
|
||||||
|
}
|
||||||
|
static TaskItem onGroupError(const GroupEndHandler &handler) {
|
||||||
|
return createGroupHandler({{}, {}, handler});
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename SetupHandler>
|
||||||
|
static GroupSetupHandler wrapGroupSetup(SetupHandler &&handler)
|
||||||
|
{
|
||||||
|
static constexpr bool isDynamic
|
||||||
|
= std::is_same_v<TaskAction, std::invoke_result_t<std::decay_t<SetupHandler>>>;
|
||||||
|
constexpr bool isVoid
|
||||||
|
= std::is_same_v<void, std::invoke_result_t<std::decay_t<SetupHandler>>>;
|
||||||
|
static_assert(isDynamic || isVoid,
|
||||||
|
"Group setup handler needs to take no arguments and has to return "
|
||||||
|
"void or TaskAction. The passed handler doesn't fulfill these requirements.");
|
||||||
|
return [=] {
|
||||||
|
if constexpr (isDynamic)
|
||||||
|
return std::invoke(handler);
|
||||||
|
std::invoke(handler);
|
||||||
|
return TaskAction::Continue;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename SetupHandler>
|
||||||
|
static TaskItem onGroupSetup(SetupHandler &&handler)
|
||||||
|
{
|
||||||
|
return Group::onGroupSetup(std::forward<SetupHandler>(handler));
|
||||||
|
}
|
||||||
|
|
||||||
|
TASKING_EXPORT TaskItem onGroupDone(const TaskItem::GroupEndHandler &handler);
|
||||||
|
TASKING_EXPORT TaskItem onGroupError(const TaskItem::GroupEndHandler &handler);
|
||||||
|
|
||||||
class TASKING_EXPORT Storage : public TaskItem
|
class TASKING_EXPORT Storage : public TaskItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -276,10 +316,10 @@ private:
|
|||||||
static_assert(isBool || isVoid,
|
static_assert(isBool || isVoid,
|
||||||
"Sync element: The synchronous function has to return void or bool.");
|
"Sync element: The synchronous function has to return void or bool.");
|
||||||
if constexpr (isBool) {
|
if constexpr (isBool) {
|
||||||
return {OnGroupSetup([function] { return function() ? TaskAction::StopWithDone
|
return {onGroupSetup([function] { return function() ? TaskAction::StopWithDone
|
||||||
: TaskAction::StopWithError; })};
|
: TaskAction::StopWithError; })};
|
||||||
}
|
}
|
||||||
return {OnGroupSetup([function] { function(); return TaskAction::StopWithDone; })};
|
return {onGroupSetup([function] { function(); return TaskAction::StopWithDone; })};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user