forked from qt-creator/qt-creator
Core: Fix Action setters
In some cases the data needs to be forwarded to the command's action. Change-Id: I3ae066cbac393d78808d697beb3df29cbdee3315 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -78,14 +78,13 @@ public:
|
|||||||
{
|
{
|
||||||
if (!command) {
|
if (!command) {
|
||||||
QTC_ASSERT(actionId.isValid(), return);
|
QTC_ASSERT(actionId.isValid(), return);
|
||||||
QTC_ASSERT(!context.isEmpty(), return);
|
|
||||||
command = ActionManager::registerAction(&action, actionId, context);
|
command = ActionManager::registerAction(&action, actionId, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction action;
|
QAction action;
|
||||||
Id actionId;
|
Id actionId;
|
||||||
Context context;
|
Context context{Constants::C_GLOBAL};
|
||||||
Command *command = nullptr;
|
Command *command = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,6 +101,8 @@ Action::~Action()
|
|||||||
void Action::setText(const QString &text)
|
void Action::setText(const QString &text)
|
||||||
{
|
{
|
||||||
d->action.setText(text);
|
d->action.setText(text);
|
||||||
|
if (d->command)
|
||||||
|
d->command->action()->setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Action::setCommandAttribute(Command::CommandAttribute attr)
|
void Action::setCommandAttribute(Command::CommandAttribute attr)
|
||||||
@@ -126,7 +127,12 @@ void Action::setOnTriggered(const std::function<void ()> &func)
|
|||||||
QObject::connect(&d->action, &QAction::triggered, &d->action, func);
|
QObject::connect(&d->action, &QAction::triggered, &d->action, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Action::setOnTriggered(QObject *guard, const std::function<void ()> &func)
|
void Action::setOnTriggered(QObject *guard, const std::function<void()> &func)
|
||||||
|
{
|
||||||
|
QObject::connect(&d->action, &QAction::triggered, guard, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Action::setOnTriggered(QObject *guard, const std::function<void(bool)> &func)
|
||||||
{
|
{
|
||||||
QObject::connect(&d->action, &QAction::triggered, guard, func);
|
QObject::connect(&d->action, &QAction::triggered, guard, func);
|
||||||
}
|
}
|
||||||
@@ -148,11 +154,15 @@ void Action::setDefaultKeySequence(const QString &mac, const QString &nonMac)
|
|||||||
void Action::setIcon(const QIcon &icon)
|
void Action::setIcon(const QIcon &icon)
|
||||||
{
|
{
|
||||||
d->action.setIcon(icon);
|
d->action.setIcon(icon);
|
||||||
|
if (d->command)
|
||||||
|
d->command->action()->setIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Action::setIconVisibleInMenu(bool on)
|
void Action::setIconVisibleInMenu(bool on)
|
||||||
{
|
{
|
||||||
d->action.setIconVisibleInMenu(on);
|
d->action.setIconVisibleInMenu(on);
|
||||||
|
if (d->command)
|
||||||
|
d->command->action()->setIconVisibleInMenu(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Action::setTouchBarIcon(const QIcon &icon)
|
void Action::setTouchBarIcon(const QIcon &icon)
|
||||||
@@ -165,6 +175,32 @@ void Action::setTouchBarIcon(const QIcon &icon)
|
|||||||
void Action::setEnabled(bool on)
|
void Action::setEnabled(bool on)
|
||||||
{
|
{
|
||||||
d->action.setEnabled(on);
|
d->action.setEnabled(on);
|
||||||
|
// Explicitly not needed, done via context update:
|
||||||
|
// if (d->command)
|
||||||
|
// d->command->action()->...
|
||||||
|
}
|
||||||
|
|
||||||
|
void Action::setChecked(bool on)
|
||||||
|
{
|
||||||
|
d->action.setChecked(on);
|
||||||
|
// Explicitly not needed, done via context update:
|
||||||
|
// if (d->command)
|
||||||
|
// d->command->action()->...
|
||||||
|
}
|
||||||
|
|
||||||
|
void Action::setVisible(bool on)
|
||||||
|
{
|
||||||
|
d->action.setVisible(on);
|
||||||
|
// Explicitly not needed, done via context update:
|
||||||
|
// if (d->command)
|
||||||
|
// d->command->action()->....
|
||||||
|
}
|
||||||
|
|
||||||
|
void Action::setCheckable(bool on)
|
||||||
|
{
|
||||||
|
d->action.setCheckable(on);
|
||||||
|
if (d->command)
|
||||||
|
d->command->action()->setCheckable(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command *Action::command() const
|
Command *Action::command() const
|
||||||
@@ -174,6 +210,18 @@ Command *Action::command() const
|
|||||||
return d->command;
|
return d->command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QAction *Action::commandAction() const
|
||||||
|
{
|
||||||
|
d->ensureCommand();
|
||||||
|
QTC_ASSERT(d->command, return nullptr);
|
||||||
|
return d->command->action();
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction *Action::contextAction() const
|
||||||
|
{
|
||||||
|
return &d->action;
|
||||||
|
}
|
||||||
|
|
||||||
void Action::setId(Id id)
|
void Action::setId(Id id)
|
||||||
{
|
{
|
||||||
d->actionId = id;
|
d->actionId = id;
|
||||||
@@ -186,6 +234,7 @@ void Action::setContext(Id id)
|
|||||||
|
|
||||||
void Action::setContext(const Context &context)
|
void Action::setContext(const Context &context)
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(!context.isEmpty(), return);
|
||||||
d->context = context;
|
d->context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,14 +45,20 @@ public:
|
|||||||
void setContainer(Utils::Id containerId, Utils::Id groupId = {});
|
void setContainer(Utils::Id containerId, Utils::Id groupId = {});
|
||||||
void setOnTriggered(const std::function<void()> &func);
|
void setOnTriggered(const std::function<void()> &func);
|
||||||
void setOnTriggered(QObject *guard, const std::function<void()> &func);
|
void setOnTriggered(QObject *guard, const std::function<void()> &func);
|
||||||
|
void setOnTriggered(QObject *guard, const std::function<void(bool)> &func);
|
||||||
void setDefaultKeySequence(const QKeySequence &seq);
|
void setDefaultKeySequence(const QKeySequence &seq);
|
||||||
void setDefaultKeySequence(const QString &mac, const QString &nonMac);
|
void setDefaultKeySequence(const QString &mac, const QString &nonMac);
|
||||||
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 setEnabled(bool on);
|
void setEnabled(bool on);
|
||||||
|
void setChecked(bool on);
|
||||||
|
void setVisible(bool on);
|
||||||
|
void setCheckable(bool on);
|
||||||
|
|
||||||
Command *command() const;
|
Command *command() const;
|
||||||
|
QAction *commandAction() const;
|
||||||
|
QAction *contextAction() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class ActionPrivate *d = nullptr;
|
class ActionPrivate *d = nullptr;
|
||||||
|
Reference in New Issue
Block a user