QtWidgets: Preparatory change for moving out QAction (or parts of it)

- Fix some spelling
- Use QT_CONFIG for shortcuts
- Quick C++ brush up, use member initialization
  Preemptively fix sanity bot warnings about missing space after flow
  control keyword, introducing range-based for on this occasion
- Remove unused member variable

Task-number: QTBUG-69478
Change-Id: I6af21886d5a0b48f4b2d11082991a877bd8d817d
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Friedemann Kleint 2019-06-20 12:52:15 +02:00
parent 6007120aa4
commit 168b18de2d
4 changed files with 36 additions and 45 deletions

View File

@ -75,23 +75,17 @@ static QString qt_strippedText(QString s)
}
QActionPrivate::QActionPrivate() : group(0), enabled(1), forceDisabled(0),
visible(1), forceInvisible(0), checkable(0), checked(0), separator(0), fontSet(false),
iconVisibleInMenu(-1),
shortcutVisibleInContextMenu(-1),
menuRole(QAction::TextHeuristicRole),
priority(QAction::NormalPriority)
{
#ifndef QT_NO_SHORTCUT
shortcutId = 0;
shortcutContext = Qt::WindowShortcut;
autorepeat = true;
QActionPrivate::QActionPrivate() :
#if QT_CONFIG(shortcut)
autorepeat(1),
#endif
enabled(1), forceDisabled(0), visible(1), forceInvisible(0), checkable(0),
checked(0), separator(0), fontSet(false),
iconVisibleInMenu(-1), shortcutVisibleInContextMenu(-1)
{
}
QActionPrivate::~QActionPrivate()
{
}
QActionPrivate::~QActionPrivate() = default;
bool QActionPrivate::showStatusText(QWidget *widget, const QString &str)
{
@ -127,7 +121,7 @@ void QActionPrivate::sendDataChanged()
emit q->changed();
}
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
void QActionPrivate::redoGrab(QShortcutMap &map)
{
Q_Q(QAction);
@ -345,7 +339,7 @@ QWidget *QAction::parentWidget() const
QObject *ret = parent();
while (ret && !ret->isWidgetType())
ret = ret->parent();
return (QWidget*)ret;
return static_cast<QWidget*>(ret);
}
/*!
@ -374,7 +368,7 @@ QList<QGraphicsWidget *> QAction::associatedGraphicsWidgets() const
}
#endif
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
/*!
\property QAction::shortcut
\brief the action's primary shortcut key
@ -573,7 +567,7 @@ QAction::~QAction()
#endif
if (d->group)
d->group->removeAction(this);
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
if (d->shortcutId && qApp) {
QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(d->shortcutId, this);
for(int i = 0; i < d->alternateShortcutIds.count(); ++i) {
@ -1027,7 +1021,7 @@ void QAction::setEnabled(bool b)
return;
QAPP_CHECK("setEnabled");
d->enabled = b;
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
d->setShortcutEnabled(b, QGuiApplicationPrivate::instance()->shortcutMap);
#endif
d->sendDataChanged();
@ -1080,7 +1074,7 @@ bool QAction::isVisible() const
bool
QAction::event(QEvent *e)
{
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
if (e->type() == QEvent::Shortcut) {
QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
Q_ASSERT_X(se->key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->key()),
@ -1351,7 +1345,7 @@ Q_WIDGETS_EXPORT QDebug operator<<(QDebug d, const QAction *action)
d << " toolTip=" << action->toolTip();
if (action->isCheckable())
d << " checked=" << action->isChecked();
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
if (!action->shortcut().isEmpty())
d << " shortcut=" << action->shortcut();
#endif

View File

@ -72,7 +72,7 @@ class Q_WIDGETS_EXPORT QAction : public QObject
Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed)
Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed)
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed)
Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed)
Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed)
@ -129,7 +129,7 @@ public:
void setSeparator(bool b);
bool isSeparator() const;
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
void setShortcut(const QKeySequence &shortcut);
QKeySequence shortcut() const;

View File

@ -89,15 +89,15 @@ public:
QString tooltip;
QString statustip;
QString whatsthis;
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
QKeySequence shortcut;
QList<QKeySequence> alternateShortcuts;
#endif
QVariant userData;
#ifndef QT_NO_SHORTCUT
int shortcutId;
#if QT_CONFIG(shortcut)
int shortcutId = 0;
QVector<int> alternateShortcutIds;
Qt::ShortcutContext shortcutContext;
Qt::ShortcutContext shortcutContext = Qt::WindowShortcut;
uint autorepeat : 1;
#endif
QFont font;
@ -112,19 +112,17 @@ public:
int iconVisibleInMenu : 2; // Only has values -1, 0, and 1
int shortcutVisibleInContextMenu : 2; // Only has values -1, 0, and 1
QAction::MenuRole menuRole;
QAction::Priority priority;
QAction::MenuRole menuRole = QAction::TextHeuristicRole;
QAction::Priority priority = QAction::NormalPriority;
QList<QWidget *> widgets;
QWidgetList widgets;
#if QT_CONFIG(graphicsview)
QList<QGraphicsWidget *> graphicsWidgets;
#endif
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
void redoGrab(QShortcutMap &map);
void redoGrabAlternate(QShortcutMap &map);
void setShortcutEnabled(bool enable, QShortcutMap &map);
static QShortcutMap *globalMap;
#endif // QT_NO_SHORTCUT
void sendDataChanged();

View File

@ -42,7 +42,6 @@
#ifndef QT_NO_ACTION
#include "qaction_p.h"
#include "qapplication.h"
#include "qevent.h"
#include "qlist.h"
@ -73,7 +72,7 @@ void QActionGroupPrivate::_q_actionChanged()
{
Q_Q(QActionGroup);
QAction *action = qobject_cast<QAction*>(q->sender());
Q_ASSERT_X(action != 0, "QWidgetGroup::_q_actionChanged", "internal error");
Q_ASSERT_X(action != nullptr, "QActionGroup::_q_actionChanged", "internal error");
if (exclusionPolicy != QActionGroup::ExclusionPolicy::None) {
if (action->isChecked()) {
if (action != current) {
@ -91,7 +90,7 @@ void QActionGroupPrivate::_q_actionTriggered()
{
Q_Q(QActionGroup);
QAction *action = qobject_cast<QAction*>(q->sender());
Q_ASSERT_X(action != 0, "QWidgetGroup::_q_actionTriggered", "internal error");
Q_ASSERT_X(action != nullptr, "QActionGroup::_q_actionTriggered", "internal error");
emit q->triggered(action);
}
@ -99,7 +98,7 @@ void QActionGroupPrivate::_q_actionHovered()
{
Q_Q(QActionGroup);
QAction *action = qobject_cast<QAction*>(q->sender());
Q_ASSERT_X(action != 0, "QWidgetGroup::_q_actionHovered", "internal error");
Q_ASSERT_X(action != nullptr, "QActionGroup::_q_actionHovered", "internal error");
emit q->hovered(action);
}
@ -363,10 +362,10 @@ void QActionGroup::setEnabled(bool b)
{
Q_D(QActionGroup);
d->enabled = b;
for(QList<QAction*>::const_iterator it = d->actions.constBegin(); it != d->actions.constEnd(); ++it) {
if(!(*it)->d_func()->forceDisabled) {
(*it)->setEnabled(b);
(*it)->d_func()->forceDisabled = false;
for (auto action : qAsConst(d->actions)) {
if (!action->d_func()->forceDisabled) {
action->setEnabled(b);
action->d_func()->forceDisabled = false;
}
}
}
@ -400,10 +399,10 @@ void QActionGroup::setVisible(bool b)
{
Q_D(QActionGroup);
d->visible = b;
for(QList<QAction*>::Iterator it = d->actions.begin(); it != d->actions.end(); ++it) {
if(!(*it)->d_func()->forceInvisible) {
(*it)->setVisible(b);
(*it)->d_func()->forceInvisible = false;
for (auto action : qAsConst(d->actions)) {
if (!action->d_func()->forceInvisible) {
action->setVisible(b);
action->d_func()->forceInvisible = false;
}
}
}