qaction.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qaction.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qaction.h"-
41#include "qactiongroup.h"-
42-
43#ifndef QT_NO_ACTION-
44#include "qaction_p.h"-
45#include "qapplication.h"-
46#include "qevent.h"-
47#include "qlist.h"-
48#include <private/qshortcutmap_p.h>-
49#include <private/qapplication_p.h>-
50#include <private/qmenu_p.h>-
51#include <private/qdebug_p.h>-
52-
53#define QAPP_CHECK(functionName) \-
54 if (Q_UNLIKELY(!qApp)) { \-
55 qWarning("QAction: Initialize QApplication before calling '" functionName "'."); \-
56 return; \-
57 }-
58-
59QT_BEGIN_NAMESPACE-
60-
61/*-
62 internal: guesses a descriptive text from a text suited for a menu entry-
63 */-
64static QString qt_strippedText(QString s)-
65{-
66 s.remove( QString::fromLatin1("...") );-
67 for (int i = 0; i < s.size(); ++i) {
i < s.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
68 if (s.at(i) == QLatin1Char('&'))
s.at(i) == QLatin1Char('&')Description
TRUEnever evaluated
FALSEnever evaluated
0
69 s.remove(i, 1);
never executed: s.remove(i, 1);
0
70 }
never executed: end of block
0
71 return s.trimmed();
never executed: return s.trimmed();
0
72}-
73-
74-
75QActionPrivate::QActionPrivate() : group(0), enabled(1), forceDisabled(0),-
76 visible(1), forceInvisible(0), checkable(0), checked(0), separator(0), fontSet(false),-
77 iconVisibleInMenu(-1),-
78 menuRole(QAction::TextHeuristicRole),-
79 priority(QAction::NormalPriority)-
80{-
81#ifndef QT_NO_SHORTCUT-
82 shortcutId = 0;-
83 shortcutContext = Qt::WindowShortcut;-
84 autorepeat = true;-
85#endif-
86}
never executed: end of block
0
87-
88QActionPrivate::~QActionPrivate()-
89{-
90}-
91-
92bool QActionPrivate::showStatusText(QWidget *widget, const QString &str)-
93{-
94#ifdef QT_NO_STATUSTIP-
95 Q_UNUSED(widget);-
96 Q_UNUSED(str);-
97#else-
98 if(QObject *object = widget ? widget : parent) {
QObject *objec...idget : parentDescription
TRUEnever evaluated
FALSEnever evaluated
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
99 QStatusTipEvent tip(str);-
100 QApplication::sendEvent(object, &tip);-
101 return true;
never executed: return true;
0
102 }-
103#endif-
104 return false;
never executed: return false;
0
105}-
106-
107void QActionPrivate::sendDataChanged()-
108{-
109 Q_Q(QAction);-
110 QActionEvent e(QEvent::ActionChanged, q);-
111 for (int i = 0; i < widgets.size(); ++i) {
i < widgets.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
112 QWidget *w = widgets.at(i);-
113 QApplication::sendEvent(w, &e);-
114 }
never executed: end of block
0
115#ifndef QT_NO_GRAPHICSVIEW-
116 for (int i = 0; i < graphicsWidgets.size(); ++i) {
i < graphicsWidgets.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
117 QGraphicsWidget *w = graphicsWidgets.at(i);-
118 QApplication::sendEvent(w, &e);-
119 }
never executed: end of block
0
120#endif-
121 QApplication::sendEvent(q, &e);-
122-
123 emit q->changed();-
124}
never executed: end of block
0
125-
126#ifndef QT_NO_SHORTCUT-
127void QActionPrivate::redoGrab(QShortcutMap &map)-
128{-
129 Q_Q(QAction);-
130 if (shortcutId)
shortcutIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
131 map.removeShortcut(shortcutId, q);
never executed: map.removeShortcut(shortcutId, q);
0
132 if (shortcut.isEmpty())
shortcut.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
133 return;
never executed: return;
0
134 shortcutId = map.addShortcut(q, shortcut, shortcutContext, qWidgetShortcutContextMatcher);-
135 if (!enabled)
!enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
136 map.setShortcutEnabled(false, shortcutId, q);
never executed: map.setShortcutEnabled(false, shortcutId, q);
0
137 if (!autorepeat)
!autorepeatDescription
TRUEnever evaluated
FALSEnever evaluated
0
138 map.setShortcutAutoRepeat(false, shortcutId, q);
never executed: map.setShortcutAutoRepeat(false, shortcutId, q);
0
139}
never executed: end of block
0
140-
141void QActionPrivate::redoGrabAlternate(QShortcutMap &map)-
142{-
143 Q_Q(QAction);-
144 for(int i = 0; i < alternateShortcutIds.count(); ++i) {
i < alternateS...cutIds.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
145 if (const int id = alternateShortcutIds.at(i))
const int id =...rtcutIds.at(i)Description
TRUEnever evaluated
FALSEnever evaluated
0
146 map.removeShortcut(id, q);
never executed: map.removeShortcut(id, q);
0
147 }
never executed: end of block
0
148 alternateShortcutIds.clear();-
149 if (alternateShortcuts.isEmpty())
alternateShortcuts.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
150 return;
never executed: return;
0
151 for(int i = 0; i < alternateShortcuts.count(); ++i) {
i < alternateShortcuts.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
152 const QKeySequence& alternate = alternateShortcuts.at(i);-
153 if (!alternate.isEmpty())
!alternate.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
154 alternateShortcutIds.append(map.addShortcut(q, alternate, shortcutContext, qWidgetShortcutContextMatcher));
never executed: alternateShortcutIds.append(map.addShortcut(q, alternate, shortcutContext, qWidgetShortcutContextMatcher));
0
155 else-
156 alternateShortcutIds.append(0);
never executed: alternateShortcutIds.append(0);
0
157 }-
158 if (!enabled) {
!enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
159 for(int i = 0; i < alternateShortcutIds.count(); ++i) {
i < alternateS...cutIds.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
160 const int id = alternateShortcutIds.at(i);-
161 map.setShortcutEnabled(false, id, q);-
162 }
never executed: end of block
0
163 }
never executed: end of block
0
164 if (!autorepeat) {
!autorepeatDescription
TRUEnever evaluated
FALSEnever evaluated
0
165 for(int i = 0; i < alternateShortcutIds.count(); ++i) {
i < alternateS...cutIds.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
166 const int id = alternateShortcutIds.at(i);-
167 map.setShortcutAutoRepeat(false, id, q);-
168 }
never executed: end of block
0
169 }
never executed: end of block
0
170}
never executed: end of block
0
171-
172void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)-
173{-
174 Q_Q(QAction);-
175 if (shortcutId)
shortcutIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
176 map.setShortcutEnabled(enable, shortcutId, q);
never executed: map.setShortcutEnabled(enable, shortcutId, q);
0
177 for(int i = 0; i < alternateShortcutIds.count(); ++i) {
i < alternateS...cutIds.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
178 if (const int id = alternateShortcutIds.at(i))
const int id =...rtcutIds.at(i)Description
TRUEnever evaluated
FALSEnever evaluated
0
179 map.setShortcutEnabled(enable, id, q);
never executed: map.setShortcutEnabled(enable, id, q);
0
180 }
never executed: end of block
0
181}
never executed: end of block
0
182#endif // QT_NO_SHORTCUT-
183-
184-
185/*!-
186 \class QAction-
187 \brief The QAction class provides an abstract user interface-
188 action that can be inserted into widgets.-
189-
190 \ingroup mainwindow-classes-
191 \inmodule QtWidgets-
192-
193 \omit-
194 * parent and widget are different-
195 * parent does not define context-
196 \endomit-
197-
198 In applications many common commands can be invoked via menus,-
199 toolbar buttons, and keyboard shortcuts. Since the user expects-
200 each command to be performed in the same way, regardless of the-
201 user interface used, it is useful to represent each command as-
202 an \e action.-
203-
204 Actions can be added to menus and toolbars, and will-
205 automatically keep them in sync. For example, in a word processor,-
206 if the user presses a Bold toolbar button, the Bold menu item-
207 will automatically be checked.-
208-
209 Actions can be created as independent objects, but they may-
210 also be created during the construction of menus; the QMenu class-
211 contains convenience functions for creating actions suitable for-
212 use as menu items.-
213-
214 A QAction may contain an icon, menu text, a shortcut, status text,-
215 "What's This?" text, and a tooltip. Most of these can be set in-
216 the constructor. They can also be set independently with-
217 setIcon(), setText(), setIconText(), setShortcut(),-
218 setStatusTip(), setWhatsThis(), and setToolTip(). For menu items,-
219 it is possible to set an individual font with setFont().-
220-
221 Actions are added to widgets using QWidget::addAction() or-
222 QGraphicsWidget::addAction(). Note that an action must be added to a-
223 widget before it can be used; this is also true when the shortcut should-
224 be global (i.e., Qt::ApplicationShortcut as Qt::ShortcutContext).-
225-
226 Once a QAction has been created it should be added to the relevant-
227 menu and toolbar, then connected to the slot which will perform-
228 the action. For example:-
229-
230 \snippet mainwindows/application/mainwindow.cpp 19-
231 \codeline-
232 \code-
233 fileMenu->addAction(openAct);-
234 \endcode-
235-
236 We recommend that actions are created as children of the window-
237 they are used in. In most cases actions will be children of-
238 the application's main window.-
239-
240 \sa QMenu, QToolBar, {Application Example}-
241*/-
242-
243/*!-
244 \fn void QAction::trigger()-
245-
246 This is a convenience slot that calls activate(Trigger).-
247*/-
248-
249/*!-
250 \fn void QAction::hover()-
251-
252 This is a convenience slot that calls activate(Hover).-
253*/-
254-
255/*!-
256 \enum QAction::MenuRole-
257-
258 This enum describes how an action should be moved into the application menu on \macos.-
259-
260 \value NoRole This action should not be put into the application menu-
261 \value TextHeuristicRole This action should be put in the application menu based on the action's text-
262 as described in the QMenuBar documentation.-
263 \value ApplicationSpecificRole This action should be put in the application menu with an application specific role-
264 \value AboutQtRole This action handles the "About Qt" menu item.-
265 \value AboutRole This action should be placed where the "About" menu item is in the application menu. The text of-
266 the menu item will be set to "About <application name>". The application name is fetched from the-
267 \c{Info.plist} file in the application's bundle (See \l{Qt for macOS - Deployment}).-
268 \value PreferencesRole This action should be placed where the "Preferences..." menu item is in the application menu.-
269 \value QuitRole This action should be placed where the Quit menu item is in the application menu.-
270-
271 Setting this value only has effect on items that are in the immediate menus-
272 of the menubar, not the submenus of those menus. For example, if you have-
273 File menu in your menubar and the File menu has a submenu, setting the-
274 MenuRole for the actions in that submenu have no effect. They will never be moved.-
275*/-
276-
277/*!-
278 Constructs an action with \a parent. If \a parent is an action-
279 group the action will be automatically inserted into the group.-
280*/-
281QAction::QAction(QObject* parent)-
282 : QObject(*(new QActionPrivate), parent)-
283{-
284 Q_D(QAction);-
285 d->group = qobject_cast<QActionGroup *>(parent);-
286 if (d->group)
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
287 d->group->addAction(this);
never executed: d->group->addAction(this);
0
288}
never executed: end of block
0
289-
290-
291/*!-
292 Constructs an action with some \a text and \a parent. If \a-
293 parent is an action group the action will be automatically-
294 inserted into the group.-
295-
296 The action uses a stripped version of \a text (e.g. "\&Menu-
297 Option..." becomes "Menu Option") as descriptive text for-
298 tool buttons. You can override this by setting a specific-
299 description with setText(). The same text will be used for-
300 tooltips unless you specify a different text using-
301 setToolTip().-
302-
303*/-
304QAction::QAction(const QString &text, QObject* parent)-
305 : QObject(*(new QActionPrivate), parent)-
306{-
307 Q_D(QAction);-
308 d->text = text;-
309 d->group = qobject_cast<QActionGroup *>(parent);-
310 if (d->group)
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
311 d->group->addAction(this);
never executed: d->group->addAction(this);
0
312}
never executed: end of block
0
313-
314/*!-
315 Constructs an action with an \a icon and some \a text and \a-
316 parent. If \a parent is an action group the action will be-
317 automatically inserted into the group.-
318-
319 The action uses a stripped version of \a text (e.g. "\&Menu-
320 Option..." becomes "Menu Option") as descriptive text for-
321 tool buttons. You can override this by setting a specific-
322 description with setText(). The same text will be used for-
323 tooltips unless you specify a different text using-
324 setToolTip().-
325*/-
326QAction::QAction(const QIcon &icon, const QString &text, QObject* parent)-
327 : QObject(*(new QActionPrivate), parent)-
328{-
329 Q_D(QAction);-
330 d->icon = icon;-
331 d->text = text;-
332 d->group = qobject_cast<QActionGroup *>(parent);-
333 if (d->group)
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
334 d->group->addAction(this);
never executed: d->group->addAction(this);
0
335}
never executed: end of block
0
336-
337/*!-
338 \internal-
339*/-
340QAction::QAction(QActionPrivate &dd, QObject *parent)-
341 : QObject(dd, parent)-
342{-
343 Q_D(QAction);-
344 d->group = qobject_cast<QActionGroup *>(parent);-
345 if (d->group)
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
346 d->group->addAction(this);
never executed: d->group->addAction(this);
0
347}
never executed: end of block
0
348-
349/*!-
350 Returns the parent widget.-
351*/-
352QWidget *QAction::parentWidget() const-
353{-
354 QObject *ret = parent();-
355 while (ret && !ret->isWidgetType())
retDescription
TRUEnever evaluated
FALSEnever evaluated
!ret->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
356 ret = ret->parent();
never executed: ret = ret->parent();
0
357 return (QWidget*)ret;
never executed: return (QWidget*)ret;
0
358}-
359-
360/*!-
361 \since 4.2-
362 Returns a list of widgets this action has been added to.-
363-
364 \sa QWidget::addAction(), associatedGraphicsWidgets()-
365*/-
366QList<QWidget *> QAction::associatedWidgets() const-
367{-
368 Q_D(const QAction);-
369 return d->widgets;
never executed: return d->widgets;
0
370}-
371-
372#ifndef QT_NO_GRAPHICSVIEW-
373/*!-
374 \since 4.5-
375 Returns a list of widgets this action has been added to.-
376-
377 \sa QWidget::addAction(), associatedWidgets()-
378*/-
379QList<QGraphicsWidget *> QAction::associatedGraphicsWidgets() const-
380{-
381 Q_D(const QAction);-
382 return d->graphicsWidgets;
never executed: return d->graphicsWidgets;
0
383}-
384#endif-
385-
386#ifndef QT_NO_SHORTCUT-
387/*!-
388 \property QAction::shortcut-
389 \brief the action's primary shortcut key-
390-
391 Valid keycodes for this property can be found in \l Qt::Key and-
392 \l Qt::Modifier. There is no default shortcut key.-
393*/-
394void QAction::setShortcut(const QKeySequence &shortcut)-
395{-
396 QAPP_CHECK("setShortcut");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
397-
398 Q_D(QAction);-
399 if (d->shortcut == shortcut)
d->shortcut == shortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
400 return;
never executed: return;
0
401-
402 d->shortcut = shortcut;-
403 d->redoGrab(qApp->d_func()->shortcutMap);-
404 d->sendDataChanged();-
405}
never executed: end of block
0
406-
407/*!-
408 \since 4.2-
409-
410 Sets \a shortcuts as the list of shortcuts that trigger the-
411 action. The first element of the list is the primary shortcut.-
412-
413 \sa shortcut-
414*/-
415void QAction::setShortcuts(const QList<QKeySequence> &shortcuts)-
416{-
417 Q_D(QAction);-
418-
419 QList <QKeySequence> listCopy = shortcuts;-
420-
421 QKeySequence primary;-
422 if (!listCopy.isEmpty())
!listCopy.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
423 primary = listCopy.takeFirst();
never executed: primary = listCopy.takeFirst();
0
424-
425 if (d->shortcut == primary && d->alternateShortcuts == listCopy)
d->shortcut == primaryDescription
TRUEnever evaluated
FALSEnever evaluated
d->alternateSh...ts == listCopyDescription
TRUEnever evaluated
FALSEnever evaluated
0
426 return;
never executed: return;
0
427-
428 QAPP_CHECK("setShortcuts");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
429-
430 d->shortcut = primary;-
431 d->alternateShortcuts = listCopy;-
432 d->redoGrab(qApp->d_func()->shortcutMap);-
433 d->redoGrabAlternate(qApp->d_func()->shortcutMap);-
434 d->sendDataChanged();-
435}
never executed: end of block
0
436-
437/*!-
438 \since 4.2-
439-
440 Sets a platform dependent list of shortcuts based on the \a key.-
441 The result of calling this function will depend on the currently running platform.-
442 Note that more than one shortcut can assigned by this action.-
443 If only the primary shortcut is required, use setShortcut instead.-
444-
445 \sa QKeySequence::keyBindings()-
446*/-
447void QAction::setShortcuts(QKeySequence::StandardKey key)-
448{-
449 QList <QKeySequence> list = QKeySequence::keyBindings(key);-
450 setShortcuts(list);-
451}
never executed: end of block
0
452-
453/*!-
454 Returns the primary shortcut.-
455-
456 \sa setShortcuts()-
457*/-
458QKeySequence QAction::shortcut() const-
459{-
460 Q_D(const QAction);-
461 return d->shortcut;
never executed: return d->shortcut;
0
462}-
463-
464/*!-
465 \since 4.2-
466-
467 Returns the list of shortcuts, with the primary shortcut as-
468 the first element of the list.-
469-
470 \sa setShortcuts()-
471*/-
472QList<QKeySequence> QAction::shortcuts() const-
473{-
474 Q_D(const QAction);-
475 QList <QKeySequence> shortcuts;-
476 if (!d->shortcut.isEmpty())
!d->shortcut.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
477 shortcuts << d->shortcut;
never executed: shortcuts << d->shortcut;
0
478 if (!d->alternateShortcuts.isEmpty())
!d->alternateS...cuts.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
479 shortcuts << d->alternateShortcuts;
never executed: shortcuts << d->alternateShortcuts;
0
480 return shortcuts;
never executed: return shortcuts;
0
481}-
482-
483/*!-
484 \property QAction::shortcutContext-
485 \brief the context for the action's shortcut-
486-
487 Valid values for this property can be found in \l Qt::ShortcutContext.-
488 The default value is Qt::WindowShortcut.-
489*/-
490void QAction::setShortcutContext(Qt::ShortcutContext context)-
491{-
492 Q_D(QAction);-
493 if (d->shortcutContext == context)
d->shortcutContext == contextDescription
TRUEnever evaluated
FALSEnever evaluated
0
494 return;
never executed: return;
0
495 QAPP_CHECK("setShortcutContext");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
496 d->shortcutContext = context;-
497 d->redoGrab(qApp->d_func()->shortcutMap);-
498 d->redoGrabAlternate(qApp->d_func()->shortcutMap);-
499 d->sendDataChanged();-
500}
never executed: end of block
0
501-
502Qt::ShortcutContext QAction::shortcutContext() const-
503{-
504 Q_D(const QAction);-
505 return d->shortcutContext;
never executed: return d->shortcutContext;
0
506}-
507-
508/*!-
509 \property QAction::autoRepeat-
510 \brief whether the action can auto repeat-
511 \since 4.2-
512-
513 If true, the action will auto repeat when the keyboard shortcut-
514 combination is held down, provided that keyboard auto repeat is-
515 enabled on the system.-
516 The default value is true.-
517*/-
518void QAction::setAutoRepeat(bool on)-
519{-
520 Q_D(QAction);-
521 if (d->autorepeat == on)
d->autorepeat == onDescription
TRUEnever evaluated
FALSEnever evaluated
0
522 return;
never executed: return;
0
523 QAPP_CHECK("setAutoRepeat");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
524 d->autorepeat = on;-
525 d->redoGrab(qApp->d_func()->shortcutMap);-
526 d->redoGrabAlternate(qApp->d_func()->shortcutMap);-
527 d->sendDataChanged();-
528}
never executed: end of block
0
529-
530bool QAction::autoRepeat() const-
531{-
532 Q_D(const QAction);-
533 return d->autorepeat;
never executed: return d->autorepeat;
0
534}-
535#endif // QT_NO_SHORTCUT-
536-
537/*!-
538 \property QAction::font-
539 \brief the action's font-
540-
541 The font property is used to render the text set on the-
542 QAction. The font will can be considered a hint as it will not be-
543 consulted in all cases based upon application and style.-
544-
545 By default, this property contains the application's default font.-
546-
547 \sa QAction::setText(), QStyle-
548*/-
549void QAction::setFont(const QFont &font)-
550{-
551 Q_D(QAction);-
552 if (d->font == font)
d->font == fontDescription
TRUEnever evaluated
FALSEnever evaluated
0
553 return;
never executed: return;
0
554-
555 d->fontSet = true;-
556 d->font = font;-
557 d->sendDataChanged();-
558}
never executed: end of block
0
559-
560QFont QAction::font() const-
561{-
562 Q_D(const QAction);-
563 return d->font;
never executed: return d->font;
0
564}-
565-
566-
567/*!-
568 Destroys the object and frees allocated resources.-
569*/-
570QAction::~QAction()-
571{-
572 Q_D(QAction);-
573 for (int i = d->widgets.size()-1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
574 QWidget *w = d->widgets.at(i);-
575 w->removeAction(this);-
576 }
never executed: end of block
0
577#ifndef QT_NO_GRAPHICSVIEW-
578 for (int i = d->graphicsWidgets.size()-1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
579 QGraphicsWidget *w = d->graphicsWidgets.at(i);-
580 w->removeAction(this);-
581 }
never executed: end of block
0
582#endif-
583 if (d->group)
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
584 d->group->removeAction(this);
never executed: d->group->removeAction(this);
0
585#ifndef QT_NO_SHORTCUT-
586 if (d->shortcutId && qApp) {
d->shortcutIdDescription
TRUEnever evaluated
FALSEnever evaluated
(static_cast<Q...::instance()))Description
TRUEnever evaluated
FALSEnever evaluated
0
587 qApp->d_func()->shortcutMap.removeShortcut(d->shortcutId, this);-
588 for(int i = 0; i < d->alternateShortcutIds.count(); ++i) {
i < d->alterna...cutIds.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
589 const int id = d->alternateShortcutIds.at(i);-
590 qApp->d_func()->shortcutMap.removeShortcut(id, this);-
591 }
never executed: end of block
0
592 }
never executed: end of block
0
593#endif-
594}
never executed: end of block
0
595-
596/*!-
597 Sets this action group to \a group. The action will be automatically-
598 added to the group's list of actions.-
599-
600 Actions within the group will be mutually exclusive.-
601-
602 \sa QActionGroup, QAction::actionGroup()-
603*/-
604void QAction::setActionGroup(QActionGroup *group)-
605{-
606 Q_D(QAction);-
607 if(group == d->group)
group == d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
608 return;
never executed: return;
0
609-
610 if(d->group)
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
611 d->group->removeAction(this);
never executed: d->group->removeAction(this);
0
612 d->group = group;-
613 if(group)
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
614 group->addAction(this);
never executed: group->addAction(this);
0
615 d->sendDataChanged();-
616}
never executed: end of block
0
617-
618/*!-
619 Returns the action group for this action. If no action group manages-
620 this action then 0 will be returned.-
621-
622 \sa QActionGroup, QAction::setActionGroup()-
623*/-
624QActionGroup *QAction::actionGroup() const-
625{-
626 Q_D(const QAction);-
627 return d->group;
never executed: return d->group;
0
628}-
629-
630-
631/*!-
632 \property QAction::icon-
633 \brief the action's icon-
634-
635 In toolbars, the icon is used as the tool button icon; in menus,-
636 it is displayed to the left of the menu text. There is no default-
637 icon.-
638-
639 If a null icon (QIcon::isNull() is passed into this function,-
640 the icon of the action is cleared.-
641*/-
642void QAction::setIcon(const QIcon &icon)-
643{-
644 Q_D(QAction);-
645 d->icon = icon;-
646 d->sendDataChanged();-
647}
never executed: end of block
0
648-
649QIcon QAction::icon() const-
650{-
651 Q_D(const QAction);-
652 return d->icon;
never executed: return d->icon;
0
653}-
654-
655#ifndef QT_NO_MENU-
656/*!-
657 Returns the menu contained by this action. Actions that contain-
658 menus can be used to create menu items with submenus, or inserted-
659 into toolbars to create buttons with popup menus.-
660-
661 \sa QMenu::addAction()-
662*/-
663QMenu *QAction::menu() const-
664{-
665 Q_D(const QAction);-
666 return d->menu;
never executed: return d->menu;
0
667}-
668-
669/*!-
670 Sets the menu contained by this action to the specified \a menu.-
671*/-
672void QAction::setMenu(QMenu *menu)-
673{-
674 Q_D(QAction);-
675 if (d->menu)
d->menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
676 d->menu->d_func()->setOverrideMenuAction(0); //we reset the default action of any previous menu
never executed: d->menu->d_func()->setOverrideMenuAction(0);
0
677 d->menu = menu;-
678 if (menu)
menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
679 menu->d_func()->setOverrideMenuAction(this);
never executed: menu->d_func()->setOverrideMenuAction(this);
0
680 d->sendDataChanged();-
681}
never executed: end of block
0
682#endif // QT_NO_MENU-
683-
684/*!-
685 If \a b is true then this action will be considered a separator.-
686-
687 How a separator is represented depends on the widget it is inserted-
688 into. Under most circumstances the text, submenu, and icon will be-
689 ignored for separator actions.-
690-
691 \sa QAction::isSeparator()-
692*/-
693void QAction::setSeparator(bool b)-
694{-
695 Q_D(QAction);-
696 if (d->separator == b)
d->separator == bDescription
TRUEnever evaluated
FALSEnever evaluated
0
697 return;
never executed: return;
0
698-
699 d->separator = b;-
700 d->sendDataChanged();-
701}
never executed: end of block
0
702-
703/*!-
704 Returns \c true if this action is a separator action; otherwise it-
705 returns \c false.-
706-
707 \sa QAction::setSeparator()-
708*/-
709bool QAction::isSeparator() const-
710{-
711 Q_D(const QAction);-
712 return d->separator;
never executed: return d->separator;
0
713}-
714-
715/*!-
716 \property QAction::text-
717 \brief the action's descriptive text-
718-
719 If the action is added to a menu, the menu option will consist of-
720 the icon (if there is one), the text, and the shortcut (if there-
721 is one). If the text is not explicitly set in the constructor, or-
722 by using setText(), the action's description icon text will be-
723 used as text. There is no default text.-
724-
725 \sa iconText-
726*/-
727void QAction::setText(const QString &text)-
728{-
729 Q_D(QAction);-
730 if (d->text == text)
d->text == textDescription
TRUEnever evaluated
FALSEnever evaluated
0
731 return;
never executed: return;
0
732-
733 d->text = text;-
734 d->sendDataChanged();-
735}
never executed: end of block
0
736-
737QString QAction::text() const-
738{-
739 Q_D(const QAction);-
740 QString s = d->text;-
741 if(s.isEmpty()) {
s.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
742 s = d->iconText;-
743 s.replace(QLatin1Char('&'), QLatin1String("&&"));-
744 }
never executed: end of block
0
745 return s;
never executed: return s;
0
746}-
747-
748-
749-
750-
751-
752/*!-
753 \property QAction::iconText-
754 \brief the action's descriptive icon text-
755-
756 If QToolBar::toolButtonStyle is set to a value that permits text to-
757 be displayed, the text defined held in this property appears as a-
758 label in the relevant tool button.-
759-
760 It also serves as the default text in menus and tooltips if the action-
761 has not been defined with setText() or setToolTip(), and will-
762 also be used in toolbar buttons if no icon has been defined using setIcon().-
763-
764 If the icon text is not explicitly set, the action's normal text will be-
765 used for the icon text.-
766-
767 By default, this property contains an empty string.-
768-
769 \sa setToolTip(), setStatusTip()-
770*/-
771void QAction::setIconText(const QString &text)-
772{-
773 Q_D(QAction);-
774 if (d->iconText == text)
d->iconText == textDescription
TRUEnever evaluated
FALSEnever evaluated
0
775 return;
never executed: return;
0
776-
777 d->iconText = text;-
778 d->sendDataChanged();-
779}
never executed: end of block
0
780-
781QString QAction::iconText() const-
782{-
783 Q_D(const QAction);-
784 if (d->iconText.isEmpty())
d->iconText.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
785 return qt_strippedText(d->text);
never executed: return qt_strippedText(d->text);
0
786 return d->iconText;
never executed: return d->iconText;
0
787}-
788-
789/*!-
790 \property QAction::toolTip-
791 \brief the action's tooltip-
792-
793 This text is used for the tooltip. If no tooltip is specified,-
794 the action's text is used.-
795-
796 By default, this property contains the action's text.-
797-
798 \sa setStatusTip(), setShortcut()-
799*/-
800void QAction::setToolTip(const QString &tooltip)-
801{-
802 Q_D(QAction);-
803 if (d->tooltip == tooltip)
d->tooltip == tooltipDescription
TRUEnever evaluated
FALSEnever evaluated
0
804 return;
never executed: return;
0
805-
806 d->tooltip = tooltip;-
807 d->sendDataChanged();-
808}
never executed: end of block
0
809-
810QString QAction::toolTip() const-
811{-
812 Q_D(const QAction);-
813 if (d->tooltip.isEmpty()) {
d->tooltip.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
814 if (!d->text.isEmpty())
!d->text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
815 return qt_strippedText(d->text);
never executed: return qt_strippedText(d->text);
0
816 return qt_strippedText(d->iconText);
never executed: return qt_strippedText(d->iconText);
0
817 }-
818 return d->tooltip;
never executed: return d->tooltip;
0
819}-
820-
821/*!-
822 \property QAction::statusTip-
823 \brief the action's status tip-
824-
825 The status tip is displayed on all status bars provided by the-
826 action's top-level parent widget.-
827-
828 By default, this property contains an empty string.-
829-
830 \sa setToolTip(), showStatusText()-
831*/-
832void QAction::setStatusTip(const QString &statustip)-
833{-
834 Q_D(QAction);-
835 if (d->statustip == statustip)
d->statustip == statustipDescription
TRUEnever evaluated
FALSEnever evaluated
0
836 return;
never executed: return;
0
837-
838 d->statustip = statustip;-
839 d->sendDataChanged();-
840}
never executed: end of block
0
841-
842QString QAction::statusTip() const-
843{-
844 Q_D(const QAction);-
845 return d->statustip;
never executed: return d->statustip;
0
846}-
847-
848/*!-
849 \property QAction::whatsThis-
850 \brief the action's "What's This?" help text-
851-
852 The "What's This?" text is used to provide a brief description of-
853 the action. The text may contain rich text. There is no default-
854 "What's This?" text.-
855-
856 \sa QWhatsThis-
857*/-
858void QAction::setWhatsThis(const QString &whatsthis)-
859{-
860 Q_D(QAction);-
861 if (d->whatsthis == whatsthis)
d->whatsthis == whatsthisDescription
TRUEnever evaluated
FALSEnever evaluated
0
862 return;
never executed: return;
0
863-
864 d->whatsthis = whatsthis;-
865 d->sendDataChanged();-
866}
never executed: end of block
0
867-
868QString QAction::whatsThis() const-
869{-
870 Q_D(const QAction);-
871 return d->whatsthis;
never executed: return d->whatsthis;
0
872}-
873-
874/*!-
875 \enum QAction::Priority-
876 \since 4.6-
877-
878 This enum defines priorities for actions in user interface.-
879-
880 \value LowPriority The action should not be prioritized in-
881 the user interface.-
882-
883 \value NormalPriority-
884-
885 \value HighPriority The action should be prioritized in-
886 the user interface.-
887-
888 \sa priority-
889*/-
890-
891-
892/*!-
893 \property QAction::priority-
894 \since 4.6-
895-
896 \brief the actions's priority in the user interface.-
897-
898 This property can be set to indicate how the action should be prioritized-
899 in the user interface.-
900-
901 For instance, when toolbars have the Qt::ToolButtonTextBesideIcon-
902 mode set, then actions with LowPriority will not show the text-
903 labels.-
904*/-
905void QAction::setPriority(Priority priority)-
906{-
907 Q_D(QAction);-
908 if (d->priority == priority)
d->priority == priorityDescription
TRUEnever evaluated
FALSEnever evaluated
0
909 return;
never executed: return;
0
910-
911 d->priority = priority;-
912 d->sendDataChanged();-
913}
never executed: end of block
0
914-
915QAction::Priority QAction::priority() const-
916{-
917 Q_D(const QAction);-
918 return d->priority;
never executed: return d->priority;
0
919}-
920-
921/*!-
922 \property QAction::checkable-
923 \brief whether the action is a checkable action-
924-
925 A checkable action is one which has an on/off state. For example,-
926 in a word processor, a Bold toolbar button may be either on or-
927 off. An action which is not a toggle action is a command action;-
928 a command action is simply executed, e.g. file save.-
929 By default, this property is \c false.-
930-
931 In some situations, the state of one toggle action should depend-
932 on the state of others. For example, "Left Align", "Center" and-
933 "Right Align" toggle actions are mutually exclusive. To achieve-
934 exclusive toggling, add the relevant toggle actions to a-
935 QActionGroup with the QActionGroup::exclusive property set to-
936 true.-
937-
938 \sa QAction::setChecked()-
939*/-
940void QAction::setCheckable(bool b)-
941{-
942 Q_D(QAction);-
943 if (d->checkable == b)
d->checkable == bDescription
TRUEnever evaluated
FALSEnever evaluated
0
944 return;
never executed: return;
0
945-
946 d->checkable = b;-
947 d->checked = false;-
948 d->sendDataChanged();-
949}
never executed: end of block
0
950-
951bool QAction::isCheckable() const-
952{-
953 Q_D(const QAction);-
954 return d->checkable;
never executed: return d->checkable;
0
955}-
956-
957/*!-
958 \fn void QAction::toggle()-
959-
960 This is a convenience function for the \l checked property.-
961 Connect to it to change the checked state to its opposite state.-
962*/-
963void QAction::toggle()-
964{-
965 Q_D(QAction);-
966 setChecked(!d->checked);-
967}
never executed: end of block
0
968-
969/*!-
970 \property QAction::checked-
971 \brief whether the action is checked.-
972-
973 Only checkable actions can be checked. By default, this is false-
974 (the action is unchecked).-
975-
976 \sa checkable-
977*/-
978void QAction::setChecked(bool b)-
979{-
980 Q_D(QAction);-
981 if (!d->checkable || d->checked == b)
!d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
d->checked == bDescription
TRUEnever evaluated
FALSEnever evaluated
0
982 return;
never executed: return;
0
983-
984 QPointer<QAction> guard(this);-
985 d->checked = b;-
986 d->sendDataChanged();-
987 if (guard)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
988 emit toggled(b);
never executed: toggled(b);
0
989}
never executed: end of block
0
990-
991bool QAction::isChecked() const-
992{-
993 Q_D(const QAction);-
994 return d->checked;
never executed: return d->checked;
0
995}-
996-
997/*!-
998 \fn void QAction::setDisabled(bool b)-
999-
1000 This is a convenience function for the \l enabled property, that-
1001 is useful for signals--slots connections. If \a b is true the-
1002 action is disabled; otherwise it is enabled.-
1003*/-
1004-
1005/*!-
1006 \property QAction::enabled-
1007 \brief whether the action is enabled-
1008-
1009 Disabled actions cannot be chosen by the user. They do not-
1010 disappear from menus or toolbars, but they are displayed in a way-
1011 which indicates that they are unavailable. For example, they might-
1012 be displayed using only shades of gray.-
1013-
1014 \uicontrol{What's This?} help on disabled actions is still available, provided-
1015 that the QAction::whatsThis property is set.-
1016-
1017 An action will be disabled when all widgets to which it is added-
1018 (with QWidget::addAction()) are disabled or not visible. When an-
1019 action is disabled, it is not possible to trigger it through its-
1020 shortcut.-
1021-
1022 By default, this property is \c true (actions are enabled).-
1023-
1024 \sa text-
1025*/-
1026void QAction::setEnabled(bool b)-
1027{-
1028 Q_D(QAction);-
1029 if (b == d->enabled && b != d->forceDisabled)
b == d->enabledDescription
TRUEnever evaluated
FALSEnever evaluated
b != d->forceDisabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
1030 return;
never executed: return;
0
1031 d->forceDisabled = !b;-
1032 if (b && (!d->visible || (d->group && !d->group->isEnabled())))
bDescription
TRUEnever evaluated
FALSEnever evaluated
!d->visibleDescription
TRUEnever evaluated
FALSEnever evaluated
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
!d->group->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
1033 return;
never executed: return;
0
1034 QAPP_CHECK("setEnabled");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1035 d->enabled = b;-
1036#ifndef QT_NO_SHORTCUT-
1037 d->setShortcutEnabled(b, qApp->d_func()->shortcutMap);-
1038#endif-
1039 d->sendDataChanged();-
1040}
never executed: end of block
0
1041-
1042bool QAction::isEnabled() const-
1043{-
1044 Q_D(const QAction);-
1045 return d->enabled;
never executed: return d->enabled;
0
1046}-
1047-
1048/*!-
1049 \property QAction::visible-
1050 \brief whether the action can be seen (e.g. in menus and toolbars)-
1051-
1052 If \e visible is true the action can be seen (e.g. in menus and-
1053 toolbars) and chosen by the user; if \e visible is false the-
1054 action cannot be seen or chosen by the user.-
1055-
1056 Actions which are not visible are \e not grayed out; they do not-
1057 appear at all.-
1058-
1059 By default, this property is \c true (actions are visible).-
1060*/-
1061void QAction::setVisible(bool b)-
1062{-
1063 Q_D(QAction);-
1064 if (b == d->visible && b != d->forceInvisible)
b == d->visibleDescription
TRUEnever evaluated
FALSEnever evaluated
b != d->forceInvisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1065 return;
never executed: return;
0
1066 QAPP_CHECK("setVisible");
never executed: return;
__builtin_expe...e()))), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1067 d->forceInvisible = !b;-
1068 d->visible = b;-
1069 d->enabled = b && !d->forceDisabled && (!d->group || d->group->isEnabled()) ;
bDescription
TRUEnever evaluated
FALSEnever evaluated
!d->forceDisabledDescription
TRUEnever evaluated
FALSEnever evaluated
!d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
d->group->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
1070#ifndef QT_NO_SHORTCUT-
1071 d->setShortcutEnabled(d->enabled, qApp->d_func()->shortcutMap);-
1072#endif-
1073 d->sendDataChanged();-
1074}
never executed: end of block
0
1075-
1076-
1077bool QAction::isVisible() const-
1078{-
1079 Q_D(const QAction);-
1080 return d->visible;
never executed: return d->visible;
0
1081}-
1082-
1083/*!-
1084 \reimp-
1085*/-
1086bool-
1087QAction::event(QEvent *e)-
1088{-
1089#ifndef QT_NO_SHORTCUT-
1090 if (e->type() == QEvent::Shortcut) {
e->type() == QEvent::ShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
1091 QShortcutEvent *se = static_cast<QShortcutEvent *>(e);-
1092 Q_ASSERT_X(se->key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->key()),-
1093 "QAction::event",-
1094 "Received shortcut event from incorrect shortcut");-
1095 if (se->isAmbiguous())
se->isAmbiguous()Description
TRUEnever evaluated
FALSEnever evaluated
0
1096 qWarning("QAction::eventFilter: Ambiguous shortcut overload: %s", se->key().toString(QKeySequence::NativeText).toLatin1().constData());
never executed: QMessageLogger(__FILE__, 1096, __PRETTY_FUNCTION__).warning("QAction::eventFilter: Ambiguous shortcut overload: %s", se->key().toString(QKeySequence::NativeText).toLatin1().constData());
0
1097 else-
1098 activate(Trigger);
never executed: activate(Trigger);
0
1099 return true;
never executed: return true;
0
1100 }-
1101#endif-
1102 return QObject::event(e);
never executed: return QObject::event(e);
0
1103}-
1104-
1105/*!-
1106 Returns the user data as set in QAction::setData.-
1107-
1108 \sa setData()-
1109*/-
1110QVariant-
1111QAction::data() const-
1112{-
1113 Q_D(const QAction);-
1114 return d->userData;
never executed: return d->userData;
0
1115}-
1116-
1117/*!-
1118 \fn void QAction::setData(const QVariant &userData)-
1119-
1120 Sets the action's internal data to the given \a userData.-
1121-
1122 \sa data()-
1123*/-
1124void-
1125QAction::setData(const QVariant &data)-
1126{-
1127 Q_D(QAction);-
1128 d->userData = data;-
1129 d->sendDataChanged();-
1130}
never executed: end of block
0
1131-
1132-
1133/*!-
1134 Updates the relevant status bar for the \a widget specified by sending a-
1135 QStatusTipEvent to its parent widget. Returns \c true if an event was sent;-
1136 otherwise returns \c false.-
1137-
1138 If a null widget is specified, the event is sent to the action's parent.-
1139-
1140 \sa statusTip-
1141*/-
1142bool-
1143QAction::showStatusText(QWidget *widget)-
1144{-
1145 return d_func()->showStatusText(widget, statusTip());
never executed: return d_func()->showStatusText(widget, statusTip());
0
1146}-
1147-
1148/*!-
1149 Sends the relevant signals for ActionEvent \a event.-
1150-
1151 Action based widgets use this API to cause the QAction-
1152 to emit signals as well as emitting their own.-
1153*/-
1154void QAction::activate(ActionEvent event)-
1155{-
1156 Q_D(QAction);-
1157 if(event == Trigger) {
event == TriggerDescription
TRUEnever evaluated
FALSEnever evaluated
0
1158 QPointer<QObject> guard = this;-
1159 if(d->checkable) {
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1160 // the checked action of an exclusive group cannot be unchecked-
1161 if (d->checked && (d->group && d->group->isExclusive()
d->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
d->group->isExclusive()Description
TRUEnever evaluated
FALSEnever evaluated
0
1162 && d->group->checkedAction() == this)) {
d->group->chec...tion() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1163 if (!guard.isNull())
!guard.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1164 emit triggered(true);
never executed: triggered(true);
0
1165 return;
never executed: return;
0
1166 }-
1167 setChecked(!d->checked);-
1168 }
never executed: end of block
0
1169 if (!guard.isNull())
!guard.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1170 emit triggered(d->checked);
never executed: triggered(d->checked);
0
1171 } else if(event == Hover) {
never executed: end of block
event == HoverDescription
TRUEnever evaluated
FALSEnever evaluated
0
1172 emit hovered();-
1173 }
never executed: end of block
0
1174}
never executed: end of block
0
1175-
1176/*!-
1177 \fn void QAction::triggered(bool checked)-
1178-
1179 This signal is emitted when an action is activated by the user;-
1180 for example, when the user clicks a menu option, toolbar button,-
1181 or presses an action's shortcut key combination, or when trigger()-
1182 was called. Notably, it is \e not emitted when setChecked() or-
1183 toggle() is called.-
1184-
1185 If the action is checkable, \a checked is true if the action is-
1186 checked, or false if the action is unchecked.-
1187-
1188 \sa QAction::activate(), QAction::toggled(), checked-
1189*/-
1190-
1191/*!-
1192 \fn void QAction::toggled(bool checked)-
1193-
1194 This signal is emitted whenever a checkable action changes its-
1195 isChecked() status. This can be the result of a user interaction,-
1196 or because setChecked() was called.-
1197-
1198 \a checked is true if the action is checked, or false if the-
1199 action is unchecked.-
1200-
1201 \sa QAction::activate(), QAction::triggered(), checked-
1202*/-
1203-
1204/*!-
1205 \fn void QAction::hovered()-
1206-
1207 This signal is emitted when an action is highlighted by the user;-
1208 for example, when the user pauses with the cursor over a menu option,-
1209 toolbar button, or presses an action's shortcut key combination.-
1210-
1211 \sa QAction::activate()-
1212*/-
1213-
1214/*!-
1215 \fn void QAction::changed()-
1216-
1217 This signal is emitted when an action has changed. If you-
1218 are only interested in actions in a given widget, you can-
1219 watch for QWidget::actionEvent() sent with an-
1220 QEvent::ActionChanged.-
1221-
1222 \sa QWidget::actionEvent()-
1223*/-
1224-
1225/*!-
1226 \enum QAction::ActionEvent-
1227-
1228 This enum type is used when calling QAction::activate()-
1229-
1230 \value Trigger this will cause the QAction::triggered() signal to be emitted.-
1231-
1232 \value Hover this will cause the QAction::hovered() signal to be emitted.-
1233*/-
1234-
1235/*!-
1236 \property QAction::menuRole-
1237 \brief the action's menu role-
1238 \since 4.2-
1239-
1240 This indicates what role the action serves in the application menu on-
1241 \macos. By default all actions have the TextHeuristicRole, which means that-
1242 the action is added based on its text (see QMenuBar for more information).-
1243-
1244 The menu role can only be changed before the actions are put into the menu-
1245 bar in \macos (usually just before the first application window is-
1246 shown).-
1247*/-
1248void QAction::setMenuRole(MenuRole menuRole)-
1249{-
1250 Q_D(QAction);-
1251 if (d->menuRole == menuRole)
d->menuRole == menuRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1252 return;
never executed: return;
0
1253-
1254 d->menuRole = menuRole;-
1255 d->sendDataChanged();-
1256}
never executed: end of block
0
1257-
1258QAction::MenuRole QAction::menuRole() const-
1259{-
1260 Q_D(const QAction);-
1261 return d->menuRole;
never executed: return d->menuRole;
0
1262}-
1263-
1264/*!-
1265 \property QAction::iconVisibleInMenu-
1266 \brief Whether or not an action should show an icon in a menu-
1267 \since 4.4-
1268-
1269 In some applications, it may make sense to have actions with icons in the-
1270 toolbar, but not in menus. If true, the icon (if valid) is shown in the menu, when it-
1271 is false, it is not shown.-
1272-
1273 The default is to follow whether the Qt::AA_DontShowIconsInMenus attribute-
1274 is set for the application. Explicitly settings this property overrides-
1275 the presence (or abscence) of the attribute.-
1276-
1277 For example:-
1278 \snippet code/src_gui_kernel_qaction.cpp 0-
1279-
1280 \sa QAction::icon, QCoreApplication::setAttribute()-
1281*/-
1282void QAction::setIconVisibleInMenu(bool visible)-
1283{-
1284 Q_D(QAction);-
1285 if (d->iconVisibleInMenu == -1 || visible != bool(d->iconVisibleInMenu)) {
d->iconVisibleInMenu == -1Description
TRUEnever evaluated
FALSEnever evaluated
visible != boo...VisibleInMenu)Description
TRUEnever evaluated
FALSEnever evaluated
0
1286 int oldValue = d->iconVisibleInMenu;-
1287 d->iconVisibleInMenu = visible;-
1288 // Only send data changed if we really need to.-
1289 if (oldValue != -1
oldValue != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1290 || (oldValue == -1
oldValue == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1291 && visible == !QApplication::instance()->testAttribute(Qt::AA_DontShowIconsInMenus))) {
visible == !QA...wIconsInMenus)Description
TRUEnever evaluated
FALSEnever evaluated
0
1292 d->sendDataChanged();-
1293 }
never executed: end of block
0
1294 }
never executed: end of block
0
1295}
never executed: end of block
0
1296-
1297bool QAction::isIconVisibleInMenu() const-
1298{-
1299 Q_D(const QAction);-
1300 if (d->iconVisibleInMenu == -1) {
d->iconVisibleInMenu == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1301 return !QApplication::instance()->testAttribute(Qt::AA_DontShowIconsInMenus);
never executed: return !QApplication::instance()->testAttribute(Qt::AA_DontShowIconsInMenus);
0
1302 }-
1303 return d->iconVisibleInMenu;
never executed: return d->iconVisibleInMenu;
0
1304}-
1305-
1306#ifndef QT_NO_DEBUG_STREAM-
1307Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QAction *action)-
1308{-
1309 QDebugStateSaver saver(d);-
1310 d.nospace();-
1311 d << "QAction(" << static_cast<const void *>(action);-
1312 if (action) {
actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1313 d << " text=" << action->text();-
1314 if (!action->toolTip().isEmpty())
!action->toolTip().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1315 d << " toolTip=" << action->toolTip();
never executed: d << " toolTip=" << action->toolTip();
0
1316 if (action->isCheckable())
action->isCheckable()Description
TRUEnever evaluated
FALSEnever evaluated
0
1317 d << " checked=" << action->isChecked();
never executed: d << " checked=" << action->isChecked();
0
1318 if (!action->shortcut().isEmpty())
!action->shortcut().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1319 d << " shortcut=" << action->shortcut();
never executed: d << " shortcut=" << action->shortcut();
0
1320 d << " menuRole=";-
1321 QtDebugUtils::formatQEnum(d, action->menuRole());-
1322 d << " visible=" << action->isVisible();-
1323 } else {
never executed: end of block
0
1324 d << '0';-
1325 }
never executed: end of block
0
1326 d << ')';-
1327 return d;
never executed: return d;
0
1328}-
1329#endif // QT_NO_DEBUG_STREAM-
1330-
1331QT_END_NAMESPACE-
1332-
1333#include "moc_qaction.cpp"-
1334-
1335#endif // QT_NO_ACTION-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9