Core: Some ActionBuilder API polish

Change-Id: I8a59b5dd9277833361a7c8ed848e2da80972afcb
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-12-15 08:07:45 +01:00
parent b1413e35f0
commit 4de2ec6bb7
2 changed files with 21 additions and 10 deletions

View File

@@ -141,6 +141,12 @@ void ActionBuilder::addToContainer(Id containerId, Id groupId, bool needsToExist
QTC_CHECK(!needsToExist); QTC_CHECK(!needsToExist);
} }
void ActionBuilder::addToContainers(QList<Id> containerIds, Id groupId, bool needsToExist)
{
for (const Id &containerId : containerIds)
addToContainer(containerId, groupId, needsToExist);
}
void ActionBuilder::addOnTriggered(const std::function<void ()> &func) void ActionBuilder::addOnTriggered(const std::function<void ()> &func)
{ {
QObject::connect(d->contextAction, &QAction::triggered, d->contextAction, func); QObject::connect(d->contextAction, &QAction::triggered, d->contextAction, func);
@@ -176,6 +182,11 @@ void ActionBuilder::setTouchBarIcon(const QIcon &icon)
d->command->setTouchBarIcon(icon); d->command->setTouchBarIcon(icon);
} }
void ActionBuilder::setTouchBarText(const QString &text)
{
d->command->setTouchBarText(text);
}
void ActionBuilder::setEnabled(bool on) void ActionBuilder::setEnabled(bool on)
{ {
d->contextAction->setEnabled(on); d->contextAction->setEnabled(on);
@@ -221,6 +232,11 @@ void ActionBuilder::setParameterText(const QString &parameterText,
d->contextAction->setText(emptyText); d->contextAction->setText(emptyText);
} }
Id ActionBuilder::id() const
{
return d->actionId;
}
Command *ActionBuilder::command() const Command *ActionBuilder::command() const
{ {
return d->command; return d->command;
@@ -258,11 +274,6 @@ void ActionBuilder::augmentActionWithShortcutToolTip()
d->command->augmentActionWithShortcutToolTip(d->contextAction); d->command->augmentActionWithShortcutToolTip(d->contextAction);
} }
void ActionBuilder::setId(Id id)
{
d->actionId = id;
}
void ActionBuilder::setContext(Id id) void ActionBuilder::setContext(Id id)
{ {
d->context = Context(id); d->context = Context(id);

View File

@@ -9,7 +9,6 @@
#include "command.h" #include "command.h"
#include <QAction> #include <QAction>
#include <QList>
#include <functional> #include <functional>
@@ -18,8 +17,6 @@ namespace Utils { class ParameterAction; }
namespace Core { namespace Core {
class ActionContainer; class ActionContainer;
class Command;
class Context;
class ICore; class ICore;
namespace Internal { namespace Internal {
@@ -31,10 +28,9 @@ class MainWindow;
class CORE_EXPORT ActionBuilder class CORE_EXPORT ActionBuilder
{ {
public: public:
ActionBuilder(QObject *contextActionParent, const Utils::Id actionId = {}); ActionBuilder(QObject *contextActionParent, const Utils::Id actionId);
~ActionBuilder(); ~ActionBuilder();
void setId(Utils::Id id);
void setContext(const Utils::Id id); void setContext(const Utils::Id id);
void setContext(const Core::Context &context); void setContext(const Core::Context &context);
void setText(const QString &text); void setText(const QString &text);
@@ -43,6 +39,8 @@ public:
void setCommandAttribute(Core::Command::CommandAttribute attr); void setCommandAttribute(Core::Command::CommandAttribute attr);
void setCommandDescription(const QString &desc); void setCommandDescription(const QString &desc);
void addToContainer(Utils::Id containerId, Utils::Id groupId = {}, bool needsToExist = true); void addToContainer(Utils::Id containerId, Utils::Id groupId = {}, bool needsToExist = true);
void addToContainers(QList<Utils::Id> containerIds, Utils::Id groupId = {},
bool needsToExist = true);
void addOnTriggered(const std::function<void()> &func); void addOnTriggered(const std::function<void()> &func);
template<class T, typename F> template<class T, typename F>
@@ -75,6 +73,7 @@ public:
void setIcon(const QIcon &icon); void setIcon(const QIcon &icon);
void setIconVisibleInMenu(bool on); void setIconVisibleInMenu(bool on);
void setTouchBarIcon(const QIcon &icon); void setTouchBarIcon(const QIcon &icon);
void setTouchBarText(const QString &text);
void setEnabled(bool on); void setEnabled(bool on);
void setChecked(bool on); void setChecked(bool on);
void setVisible(bool on); void setVisible(bool on);
@@ -88,6 +87,7 @@ public:
EnablingMode mode = EnabledWithParameter); EnablingMode mode = EnabledWithParameter);
Utils::Id id() const;
Command *command() const; Command *command() const;
QAction *commandAction() const; QAction *commandAction() const;
QAction *contextAction() const; QAction *contextAction() const;