Utils: Start replacing SavedActions by QAction or Utils::Aspect

First mechanical step here is to derive SavedActions from BaseAspect
instead of QAction.

Change-Id: I2ec95883b825462c1d867f83cc2b3bd2c2732055
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-10-05 05:27:30 +02:00
parent f4beb6314c
commit fcaa6801cf
20 changed files with 73 additions and 56 deletions

View File

@@ -54,9 +54,9 @@ namespace Utils {
*/
SavedAction::SavedAction(QObject *parent)
: QAction(parent)
{
connect(this, &QAction::triggered, this, &SavedAction::actionTriggered);
setParent(parent);
connect(&m_action, &QAction::triggered, this, &SavedAction::actionTriggered);
}
@@ -82,8 +82,8 @@ void SavedAction::setValue(const QVariant &value, bool doemit)
if (value == m_value)
return;
m_value = value;
if (this->isCheckable())
this->setChecked(m_value.toBool());
if (m_action.isCheckable())
m_action.setChecked(m_value.toBool());
if (doemit)
emit valueChanged(m_value);
}
@@ -187,7 +187,7 @@ void SavedAction::readSettings(const QSettings *settings)
return;
QVariant var = settings->value(m_settingsGroup + QLatin1Char('/') + m_settingsKey, m_defaultValue);
// work around old ini files containing @Invalid() entries
if (isCheckable() && !var.isValid())
if (m_action.isCheckable() && !var.isValid())
var = false;
setValue(var);
}
@@ -274,7 +274,7 @@ void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode)
// Copy tooltip, but only if there's nothing explcitly set on the widget yet.
if (widget->toolTip().isEmpty())
widget->setToolTip(toolTip());
widget->setToolTip(m_action.toolTip());
}
/*
@@ -329,21 +329,26 @@ void SavedAction::setDialogText(const QString &dialogText)
void SavedAction::actionTriggered(bool)
{
if (isCheckable())
setValue(isChecked());
if (actionGroup() && actionGroup()->isExclusive()) {
if (m_action.isCheckable())
setValue(m_action.isChecked());
if (m_action.actionGroup() && m_action.actionGroup()->isExclusive()) {
// FIXME: should be taken care of more directly
const QList<QAction *> actions = actionGroup()->actions();
const QList<QAction *> actions = m_action.actionGroup()->actions();
for (QAction *act : actions)
if (auto dact = qobject_cast<SavedAction *>(act))
dact->setValue(bool(act == this));
dact->setValue(bool(act == &m_action));
}
}
QAction *SavedAction::action()
{
return &m_action;
}
void SavedAction::trigger(const QVariant &data)
{
setData(data);
QAction::trigger();
m_action.setData(data);
m_action.trigger();
}
//////////////////////////////////////////////////////////////////////////

View File

@@ -27,6 +27,8 @@
#include "utils_global.h"
#include "aspects.h"
#include <QAction>
QT_BEGIN_NAMESPACE
@@ -37,7 +39,7 @@ namespace Utils {
enum ApplyMode { ImmediateApply, DeferedApply };
class QTCREATOR_UTILS_EXPORT SavedAction : public QAction
class QTCREATOR_UTILS_EXPORT SavedAction : public BaseAspect
{
Q_OBJECT
@@ -72,6 +74,15 @@ public:
QString dialogText() const;
void setDialogText(const QString &dialogText);
QAction *action();
void setText(const QString &text) { m_action.setText(text); }
void setToolTip(const QString &toolTip) { m_action.setToolTip(toolTip); }
void setCheckable(bool checkable) { m_action.setCheckable(checkable); }
void setChecked(bool checked) { m_action.setChecked(checked); }
void setEnabled(bool enabled) { m_action.setEnabled(enabled); }
void setIcon(const QIcon &icon) { m_action.setIcon(icon); }
signals:
void valueChanged(const QVariant &newValue);
@@ -84,6 +95,7 @@ private:
QString m_settingsGroup;
QString m_dialogText;
QWidget *m_widget = nullptr;
QAction m_action;
};
class QTCREATOR_UTILS_EXPORT SavedActionSet

View File

@@ -1671,9 +1671,9 @@ bool BreakHandler::contextMenuEvent(const ItemViewEvent &ev)
menu->addSeparator();
menu->addAction(action(UseToolTipsInBreakpointsView));
menu->addAction(action(UseToolTipsInBreakpointsView)->action());
Internal::addHideColumnActions(menu, ev.view());
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
menu->popup(ev.globalPos());
@@ -2632,9 +2632,9 @@ bool BreakpointManager::contextMenuEvent(const ItemViewEvent &ev)
menu->addSeparator();
menu->addAction(action(UseToolTipsInBreakpointsView));
menu->addAction(action(UseToolTipsInBreakpointsView)->action());
Internal::addHideColumnActions(menu, ev.view());
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
menu->popup(ev.globalPos());

View File

@@ -204,7 +204,7 @@ CdbEngine::CdbEngine() :
wh->addTypeFormats("QImage", imageFormats);
wh->addTypeFormats("QImage *", imageFormats);
connect(action(CreateFullBacktrace), &QAction::triggered,
connect(action(CreateFullBacktrace)->action(), &QAction::triggered,
this, &CdbEngine::createFullBacktrace);
connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &CdbEngine::processFinished);
@@ -216,7 +216,7 @@ CdbEngine::CdbEngine() :
connect(action(UseDebuggingHelpers), &SavedAction::valueChanged,
this, &CdbEngine::updateLocals);
if (action(UseCodeModel)->isChecked())
if (action(UseCodeModel)->action()->isChecked())
m_codeModelSnapshot = CppTools::CppModelManager::instance()->snapshot();
}

View File

@@ -203,7 +203,7 @@ public:
if (HostOsInfo::isWindowsHost()) {
SavedAction *registerAction = action(RegisterForPostMortem);
m_group.insert(registerAction, checkBoxRegisterForPostMortem);
connect(registerAction, &QAction::toggled,
connect(registerAction->action(), &QAction::toggled,
checkBoxRegisterForPostMortem, &QAbstractButton::setChecked);
} else {
checkBoxRegisterForPostMortem->setVisible(false);

View File

@@ -108,9 +108,9 @@ Console::Console()
m_showDebugButtonAction->setCheckable(true);
m_showDebugButtonAction->setChecked(true);
m_showDebugButtonAction->setIcon(Utils::Icons::INFO_TOOLBAR.icon());
connect(m_showDebugButtonAction, &Utils::SavedAction::toggled,
connect(m_showDebugButtonAction->action(), &QAction::toggled,
proxyModel, &ConsoleProxyModel::setShowLogs);
m_showDebugButton->setDefaultAction(m_showDebugButtonAction);
m_showDebugButton->setDefaultAction(m_showDebugButtonAction->action());
m_showWarningButton = new QToolButton(m_consoleWidget);
@@ -121,9 +121,9 @@ Console::Console()
m_showWarningButtonAction->setCheckable(true);
m_showWarningButtonAction->setChecked(true);
m_showWarningButtonAction->setIcon(Utils::Icons::WARNING_TOOLBAR.icon());
connect(m_showWarningButtonAction, &Utils::SavedAction::toggled,
connect(m_showWarningButtonAction->action(), &QAction::toggled,
proxyModel, &ConsoleProxyModel::setShowWarnings);
m_showWarningButton->setDefaultAction(m_showWarningButtonAction);
m_showWarningButton->setDefaultAction(m_showWarningButtonAction->action());
m_showErrorButton = new QToolButton(m_consoleWidget);
@@ -134,9 +134,9 @@ Console::Console()
m_showErrorButtonAction->setCheckable(true);
m_showErrorButtonAction->setChecked(true);
m_showErrorButtonAction->setIcon(Utils::Icons::CRITICAL_TOOLBAR.icon());
connect(m_showErrorButtonAction, &Utils::SavedAction::toggled,
connect(m_showErrorButtonAction->action(), &QAction::toggled,
proxyModel, &ConsoleProxyModel::setShowErrors);
m_showErrorButton->setDefaultAction(m_showErrorButtonAction);
m_showErrorButton->setDefaultAction(m_showErrorButtonAction->action());
m_spacer = new QWidget(m_consoleWidget);
m_spacer->setMinimumWidth(30);

View File

@@ -1197,7 +1197,7 @@ DebuggerPluginPrivate::DebuggerPluginPrivate(const QStringList &arguments)
this, &DebuggerPluginPrivate::updateBreakMenuItem);
// Application interaction
connect(action(SettingsDialog), &QAction::triggered,
connect(action(SettingsDialog)->action(), &QAction::triggered,
[] { ICore::showOptionsDialog(DEBUGGER_COMMON_SETTINGS_ID); });
m_perspective.useSubPerspectiveSwitcher(EngineManager::engineChooser());
@@ -2047,7 +2047,7 @@ SavedAction *DebuggerPluginPrivate::action(int code)
QWidget *DebuggerPluginPrivate::addSearch(BaseTreeView *treeView)
{
QAction *act = action(UseAlternatingRowColors);
QAction *act = action(UseAlternatingRowColors)->action();
treeView->setAlternatingRowColors(act->isChecked());
treeView->setProperty(PerspectiveState::savesHeaderKey(), true);
connect(act, &QAction::toggled, treeView, &BaseTreeView::setAlternatingRowColors);

View File

@@ -135,7 +135,7 @@ GdbEngine::GdbEngine()
connect(action(AutoDerefPointers), &SavedAction::valueChanged,
this, &GdbEngine::reloadLocals);
connect(action(CreateFullBacktrace), &QAction::triggered,
connect(action(CreateFullBacktrace)->action(), &QAction::triggered,
this, &GdbEngine::createFullBacktrace);
connect(action(UseDebuggingHelpers), &SavedAction::valueChanged,
this, &GdbEngine::reloadLocals);

View File

@@ -89,7 +89,7 @@ LldbEngine::LldbEngine()
connect(action(AutoDerefPointers), &SavedAction::valueChanged,
this, &LldbEngine::updateLocals);
connect(action(CreateFullBacktrace), &QAction::triggered,
connect(action(CreateFullBacktrace)->action(), &QAction::triggered,
this, &LldbEngine::fetchFullBacktrace);
connect(action(UseDebuggingHelpers), &SavedAction::valueChanged,
this, &LldbEngine::updateLocals);

View File

@@ -220,10 +220,10 @@ public:
QMenu *menu = createStandardContextMenu();
menu->addAction(m_clearContentsAction);
menu->addAction(m_saveContentsAction); // X11 clipboard is unreliable for long texts
menu->addAction(action(LogTimeStamps));
menu->addAction(action(LogTimeStamps)->action());
menu->addAction(m_reloadDebuggingHelpersAction);
menu->addSeparator();
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
menu->exec(ev->globalPos());
delete menu;
}

View File

@@ -224,7 +224,7 @@ bool ModulesModel::contextMenuEvent(const ItemViewEvent &ev)
[this, modulePath] { engine->requestModuleSections(modulePath); });
Internal::addHideColumnActions(menu, ev.view());
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
menu->popup(ev.globalPos());
return true;

View File

@@ -787,7 +787,7 @@ bool PeripheralRegisterHandler::contextMenuEvent(const ItemViewEvent &ev)
}
Internal::addHideColumnActions(menu, ev.view());
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
menu->popup(ev.globalPos());
return true;
}

View File

@@ -68,7 +68,7 @@ QmlInspectorAgent::QmlInspectorAgent(QmlEngine *engine, QmlDebugConnection *conn
: m_qmlEngine(engine)
, m_inspectorToolsContext("Debugger.QmlInspector")
, m_selectAction(new QAction(this))
, m_showAppOnTopAction(action(ShowAppOnTop))
, m_showAppOnTopAction(action(ShowAppOnTop)->action())
{
m_debugIdToIname.insert(WatchItem::InvalidId, "inspect");
connect(action(ShowQmlObjectTree),

View File

@@ -757,7 +757,7 @@ bool RegisterHandler::contextMenuEvent(const ItemViewEvent &ev)
addFormatAction(tr("Binary"), BinaryFormat);
Internal::addHideColumnActions(menu, ev.view());
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
menu->popup(ev.globalPos());
return true;
}

View File

@@ -138,7 +138,7 @@ bool SourceFilesHandler::setData(const QModelIndex &idx, const QVariant &data, i
[this, name] { m_engine->gotoLocation(FilePath::fromString(name)); });
Internal::addHideColumnActions(menu, ev.view());
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
menu->popup(ev.globalPos());
return true;
}

View File

@@ -70,10 +70,10 @@ StackHandler::StackHandler(DebuggerEngine *engine)
setObjectName("StackModel");
setHeader({tr("Level"), tr("Function"), tr("File"), tr("Line"), tr("Address") });
connect(action(ExpandStack), &QAction::triggered,
this, &StackHandler::reloadFullStack);
connect(action(MaximalStackDepth), &QAction::triggered,
this, &StackHandler::reloadFullStack);
connect(action(ExpandStack)->action(), &QAction::triggered,
this, &StackHandler::reloadFullStack);
connect(action(MaximalStackDepth)->action(), &QAction::triggered,
this, &StackHandler::reloadFullStack);
// For now there's always only "the" current thread.
rootItem()->appendChild(new ThreadDummyItem);
@@ -390,13 +390,13 @@ bool StackHandler::contextMenuEvent(const ItemViewEvent &ev)
frame = frameAt(row);
const quint64 address = frame.address;
menu->addAction(action(ExpandStack));
menu->addAction(action(ExpandStack)->action());
addAction(menu, tr("Copy Contents to Clipboard"), true, [this] { copyContentsToClipboard(); });
addAction(menu, tr("Save as Task File..."), true, [this] { saveTaskFile(); });
if (m_engine->hasCapability(CreateFullBacktraceCapability))
menu->addAction(action(CreateFullBacktrace));
menu->addAction(action(CreateFullBacktrace)->action());
if (m_engine->hasCapability(AdditionalQmlStackCapability))
addAction(menu, tr("Load QML Stack"), true, [this] { m_engine->loadAdditionalQmlStack(); });
@@ -444,9 +444,9 @@ bool StackHandler::contextMenuEvent(const ItemViewEvent &ev)
}
menu->addSeparator();
menu->addAction(action(UseToolTipsInStackView));
menu->addAction(action(UseToolTipsInStackView)->action());
Internal::addHideColumnActions(menu, ev.view());
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
menu->popup(ev.globalPos());
return true;
}

View File

@@ -259,7 +259,7 @@ bool ThreadsHandler::setData(const QModelIndex &idx, const QVariant &data, int r
if (ev.as<QContextMenuEvent>()) {
auto menu = new QMenu;
Internal::addHideColumnActions(menu, ev.view());
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
menu->popup(ev.globalPos());
return true;
}

View File

@@ -1738,15 +1738,15 @@ bool WatchModel::contextMenuEvent(const ItemViewEvent &ev)
menu->addSeparator();
menu->addAction(action(UseDebuggingHelpers));
menu->addAction(action(UseToolTipsInLocalsView));
menu->addAction(action(AutoDerefPointers));
menu->addAction(action(SortStructMembers));
menu->addAction(action(UseDynamicType));
menu->addAction(action(SettingsDialog));
menu->addAction(action(UseDebuggingHelpers)->action());
menu->addAction(action(UseToolTipsInLocalsView)->action());
menu->addAction(action(AutoDerefPointers)->action());
menu->addAction(action(SortStructMembers)->action());
menu->addAction(action(UseDynamicType)->action());
menu->addAction(action(SettingsDialog)->action());
Internal::addHideColumnActions(menu, ev.view());
menu->addAction(action(SettingsDialog));
menu->addAction(action(SettingsDialog)->action());
connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater);
menu->popup(ev.globalPos());
return true;

View File

@@ -54,7 +54,7 @@ WatchTreeView::WatchTreeView(WatchType type)
connect(this, &QTreeView::expanded, this, &WatchTreeView::expandNode);
connect(this, &QTreeView::collapsed, this, &WatchTreeView::collapseNode);
connect(action(LogTimeStamps), &QAction::triggered,
connect(action(LogTimeStamps)->action(), &QAction::triggered,
this, &WatchTreeView::updateTimeColumn);
}

View File

@@ -1194,7 +1194,7 @@ bool FakeVimPluginPrivate::initialize()
readSettings();
Command *cmd = nullptr;
cmd = ActionManager::registerAction(theFakeVimSetting(ConfigUseFakeVim),
cmd = ActionManager::registerAction(theFakeVimSetting(ConfigUseFakeVim)->action(),
INSTALL_HANDLER, Context(Core::Constants::C_GLOBAL), true);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+V,Meta+Shift+V") : Tr::tr("Alt+V,Alt+V")));