Core: Drop Q_OBJECT from OptionsPopup

Not needed.

Also slim down header a bit.

Change-Id: I6ac828fdfc42173e0b5aeca5d92e920745b424c9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-06-28 10:48:37 +02:00
parent 0406f543eb
commit 5867d986a8
2 changed files with 16 additions and 25 deletions

View File

@@ -18,6 +18,21 @@ using namespace Utils;
namespace Core {
static QCheckBox *createCheckboxForCommand(QObject *owner, Id id)
{
QAction *action = ActionManager::command(id)->action();
QCheckBox *checkbox = new QCheckBox(action->text());
checkbox->setToolTip(action->toolTip());
checkbox->setChecked(action->isChecked());
checkbox->setEnabled(action->isEnabled());
checkbox->installEventFilter(owner); // enter key handling
QObject::connect(checkbox, &QCheckBox::clicked, action, &QAction::setChecked);
QObject::connect(action, &QAction::changed, checkbox, [action, checkbox] {
checkbox->setEnabled(action->isEnabled());
});
return checkbox;
}
/*!
\class Core::OptionsPopup
\inmodule QtCreator
@@ -35,7 +50,7 @@ OptionsPopup::OptionsPopup(QWidget *parent, const QVector<Id> &commands)
bool first = true;
for (const Id &command : commands) {
QCheckBox *checkBox = createCheckboxForCommand(command);
QCheckBox *checkBox = createCheckboxForCommand(this, command);
if (first) {
checkBox->setFocus();
first = false;
@@ -73,19 +88,4 @@ bool OptionsPopup::eventFilter(QObject *obj, QEvent *ev)
return QWidget::eventFilter(obj, ev);
}
QCheckBox *OptionsPopup::createCheckboxForCommand(Id id)
{
QAction *action = ActionManager::command(id)->action();
QCheckBox *checkbox = new QCheckBox(action->text());
checkbox->setToolTip(action->toolTip());
checkbox->setChecked(action->isChecked());
checkbox->setEnabled(action->isEnabled());
checkbox->installEventFilter(this); // enter key handling
QObject::connect(checkbox, &QCheckBox::clicked, action, &QAction::setChecked);
QObject::connect(action, &QAction::changed, checkbox, [action, checkbox] {
checkbox->setEnabled(action->isEnabled());
});
return checkbox;
}
} // namespace Core

View File

@@ -9,25 +9,16 @@
#include <QWidget>
QT_BEGIN_NAMESPACE
class QCheckBox;
QT_END_NAMESPACE
namespace Core {
class CORE_EXPORT OptionsPopup : public QWidget
{
Q_OBJECT
public:
OptionsPopup(QWidget *parent, const QVector<Utils::Id> &commands);
protected:
bool event(QEvent *ev) override;
bool eventFilter(QObject *obj, QEvent *ev) override;
private:
QCheckBox *createCheckboxForCommand(Utils::Id id);
};
} // namespace Core