12#if QT_CONFIG(shortcut)
13# include <private/qshortcutmap_p.h>
15#include <private/qguiapplication_p.h>
16#include <private/qdebug_p.h>
18#define QAPP_CHECK(functionName) \
19 if (Q_UNLIKELY(!QCoreApplication::instance())) { \
20 qWarning("QAction: Initialize Q(Gui)Application before calling '" functionName "'."); \
34 for (
int i = 0;
i <
s.size(); ++
i) {
50 enabled(1), explicitEnabled(0), explicitEnabledValue(1), visible(1), forceInvisible(0), checkable(0),
51 checked(0), separator(0), fontSet(
false),
52 iconVisibleInMenu(-1), shortcutVisibleInContextMenu(-1)
56#if QT_CONFIG(shortcut)
80#if QT_CONFIG(shortcut)
84 for (
int id :
std::as_const(shortcutIds)) {
86 map.removeShortcut(
id,
q);
92 shortcutIds.append(
map.addShortcut(
q,
shortcut, shortcutContext, contextMatcher()));
94 shortcutIds.append(0);
97 for (
int id :
std::as_const(shortcutIds)) {
99 map.setShortcutEnabled(
false,
id,
q);
103 for (
int id :
std::as_const(shortcutIds)) {
105 map.setShortcutAutoRepeat(
false,
id,
q);
113 for (
int id :
std::as_const(shortcutIds)) {
278 d->group = qobject_cast<QActionGroup *>(
parent);
280 d->group->addAction(
this);
283#if QT_CONFIG(shortcut)
316 if (
d->shortcuts == shortcuts)
319 d->shortcuts = shortcuts;
321 d->sendDataChanged();
346 if (
d->shortcuts.isEmpty())
348 return d->shortcuts.first();
378 d->sendDataChanged();
384 return d->shortcutContext;
396void QAction::setAutoRepeat(
bool on)
399 if (
d->autorepeat == on)
404 d->sendDataChanged();
407bool QAction::autoRepeat()
const
410 return d->autorepeat;
434 d->sendDataChanged();
454 d->group->removeAction(
this);
455#if QT_CONFIG(shortcut)
457 for (
int id : std::as_const(
d->shortcutIds)) {
480 d->group->removeAction(
this);
483 group->addAction(
this);
484 d->sendDataChanged();
508 return d->associatedObjects;
551 d->sendDataChanged();
572 if (
d->separator ==
b)
576 d->sendDataChanged();
618 d->sendDataChanged();
627 s.replace(u
'&',
"&&"_L1);
654 if (
d->iconText ==
text)
658 d->sendDataChanged();
664 if (
d->iconText.isEmpty())
683 if (
d->tooltip == tooltip)
686 d->tooltip = tooltip;
687 d->sendDataChanged();
693 if (
d->tooltip.isEmpty()) {
694 if (!
d->text.isEmpty())
715 if (
d->statustip == statustip)
718 d->statustip = statustip;
719 d->sendDataChanged();
739 return d->showStatusText(
object,
statusTip());
755 if (
d->whatsthis == whatsthis)
758 d->whatsthis = whatsthis;
759 d->sendDataChanged();
804 d->sendDataChanged();
835 if (
d->checkable ==
b)
840 d->sendDataChanged();
843 if (guard &&
d->checked)
887 d->sendDataChanged();
895 return d->checked &&
d->checkable;
930 if (
d->explicitEnabledValue ==
b &&
d->explicitEnabled)
932 d->explicitEnabledValue =
b;
933 d->explicitEnabled =
true;
935 d->setEnabled(
b,
false);
943 if (
b && !byGroup && (
group && !
group->isEnabled()))
952#if QT_CONFIG(shortcut)
958 emit q->enabledChanged(
b);
965 if (!
d->explicitEnabled)
967 d->explicitEnabled =
false;
968 d->setEnabled(
true,
false);
993 if (
b !=
d->forceInvisible)
995 d->forceInvisible = !
b;
996 if (
b &&
d->group && !
d->group->isVisible())
1015 emit q->visibleChanged();
1031 for (
auto object : std::as_const(
d->associatedObjects))
1035#if QT_CONFIG(shortcut)
1038 Q_ASSERT_X(d_func()->shortcutIds.contains(se->shortcutId()),
1040 "Received shortcut event from incorrect shortcut");
1041 if (se->isAmbiguous())
1070 if (
d->userData ==
data)
1073 d->sendDataChanged();
1087 if ((
d->explicitEnabled && !
d->explicitEnabledValue) || (
d->group && !
d->group->isEnabled()))
1092 if (
d->checked && (
d->group
1094 &&
d->group->checkedAction() ==
this)) {
1187 d->sendDataChanged();
1206QObject* QAction::menuObject()
const
1217void QAction::setMenuObject(
QObject *
object)
1243 if (
d->iconVisibleInMenu == -1 ||
visible !=
bool(
d->iconVisibleInMenu)) {
1244 int oldValue =
d->iconVisibleInMenu;
1249 d->sendDataChanged();
1257 if (
d->iconVisibleInMenu == -1) {
1260 return d->iconVisibleInMenu;
1279 if (
d->shortcutVisibleInContextMenu == -1 ||
visible !=
bool(
d->shortcutVisibleInContextMenu)) {
1280 int oldValue =
d->shortcutVisibleInContextMenu;
1281 d->shortcutVisibleInContextMenu =
visible;
1285 d->sendDataChanged();
1293 if (
d->shortcutVisibleInContextMenu == -1)
1295 return d->shortcutVisibleInContextMenu;
1298#ifndef QT_NO_DEBUG_STREAM
1303 d <<
"QAction(" <<
static_cast<const void *
>(action);
1305 d <<
" text=" << action->
text();
1307 d <<
" toolTip=" << action->
toolTip();
1310#if QT_CONFIG(shortcut)
1311 if (!action->shortcuts().isEmpty())
1312 d <<
" shortcuts=" << action->shortcuts();
1328#include "moc_qaction.cpp"
The QActionEvent class provides an event that is generated when a QAction is added,...
The QActionGroup class groups actions together.
bool showStatusText(QObject *widget, const QString &str)
virtual void setMenu(QObject *menu)
virtual QObject * menu() const
bool setEnabled(bool enable, bool byGroup)
uint explicitEnabledValue
The QAction class provides an abstraction for user commands that can be added to different user inter...
void setMenuRole(MenuRole menuRole)
QVariant data() const
Returns the user data as set in QAction::setData.
void setShortcutVisibleInContextMenu(bool show)
QString iconText
the action's descriptive icon text
void setWhatsThis(const QString &what)
void setStatusTip(const QString &statusTip)
void setActionGroup(QActionGroup *group)
Sets this action group to group.
QAction(QObject *parent=nullptr)
Constructs an action with parent.
void checkableChanged(bool checkable)
ActionEvent
This enum type is used when calling QAction::activate()
bool event(QEvent *) override
\reimp
void toggled(bool)
This signal is emitted whenever a checkable action changes its isChecked() status.
void setIconVisibleInMenu(bool visible)
QList< QObject * > associatedObjects() const
void hovered()
This signal is emitted when an action is highlighted by the user; for example, when the user pauses w...
MenuRole
This enum describes how an action should be moved into the application menu on \macos.
void setIcon(const QIcon &icon)
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
QActionGroup * actionGroup() const
Returns the action group for this action.
bool isShortcutVisibleInContextMenu() const
void toggle()
This is a convenience function for the \l checked property.
Priority
This enum defines priorities for actions in user interface.
void setSeparator(bool b)
If b is true then this action will be considered a separator.
QString statusTip
the action's status tip
bool visible
whether the action can be seen (e.g.
void setFont(const QFont &font)
QString whatsThis
the action's "What's This?" help text
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
QFont font
the action's font
void setText(const QString &text)
void setIconText(const QString &text)
void setPriority(Priority priority)
Priority priority
the actions's priority in the user interface.
bool showStatusText(QObject *object=nullptr)
Updates the relevant status bar for the UI represented by object by sending a QStatusTipEvent.
~QAction()
Destroys the object and frees allocated resources.
bool isIconVisibleInMenu() const
void activate(ActionEvent event)
Sends the relevant signals for ActionEvent event.
void setToolTip(const QString &tip)
QString text
the action's descriptive text
QString toolTip
the action's tooltip
MenuRole menuRole
the action's menu role
QIcon icon
the action's icon
void setData(const QVariant &var)
Sets the action's internal data to the given data.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
virtual QActionPrivate * createActionPrivate() const
static QGuiApplicationPrivate * instance()
The QIcon class provides scalable icons in different modes and states.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
static QList< QKeySequence > keyBindings(StandardKey key)
QObject * parent() const
Returns a pointer to the parent object.
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
bool(* ContextMatcher)(QObject *object, Qt::ShortcutContext context)
The QStatusTipEvent class provides an event that is used to show messages in a status bar.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString trimmed() const &
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
QMap< QString, QString > map
[6]
Combined button and popup list for selecting options.
static void formatQEnum(QDebug &debug, QEnum value)
@ AA_DontShowShortcutsInContextMenus
@ AA_DontShowIconsInMenus
#define QAPP_CHECK(functionName)
Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAction *action)
static QString qt_strippedText(QString s)
GLboolean GLboolean GLboolean b
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
#define Q_ASSERT_X(cond, x, msg)
#define QT_CONFIG(feature)
if(qFloatDistance(a, b)<(1<< 7))
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent