Gui: use new-style connect and add curly braces to improve readability

This commit is contained in:
wmayer
2022-11-10 20:08:31 +01:00
committed by wwmayer
parent ee4e64328e
commit 07224605dc
5 changed files with 55 additions and 26 deletions

View File

@@ -156,9 +156,11 @@ CommandCompleter::CommandCompleter(QLineEdit *lineedit, QObject *parent)
this->setCaseSensitivity(Qt::CaseInsensitive);
this->setCompletionMode(QCompleter::PopupCompletion);
this->setWidget(lineedit);
connect(lineedit, SIGNAL(textEdited(QString)), this, SLOT(onTextChanged(QString)));
connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(onCommandActivated(QModelIndex)));
connect(this, SIGNAL(highlighted(QString)), lineedit, SLOT(setText(QString)));
connect(lineedit, &QLineEdit::textEdited, this, &CommandCompleter::onTextChanged);
connect(this, qOverload<const QModelIndex&>(&CommandCompleter::activated),
this, &CommandCompleter::onCommandActivated);
connect(this, qOverload<const QString&>(&CommandCompleter::highlighted),
lineedit, &QLineEdit::setText);
}
bool CommandCompleter::eventFilter(QObject *o, QEvent *ev)

View File

@@ -23,6 +23,7 @@
#ifndef GUI_COMMAND_COMPLETER_H
#define GUI_COMMAND_COMPLETER_H
#include <FCGlobal.h>
#include <QCompleter>
class QLineEdit;

View File

@@ -101,9 +101,12 @@ DlgCustomKeyboardImp::DlgCustomKeyboardImp( QWidget* parent )
ui->shortcutTimeout->onRestore();
QTimer *timer = new QTimer(this);
QObject::connect(ui->shortcutTimeout, QOverload<int>::of(&QSpinBox::valueChanged),
timer, [=](int) {timer->start(100);});
QObject::connect(timer, &QTimer::timeout, [=](){ui->shortcutTimeout->onSave();});
QObject::connect(ui->shortcutTimeout, QOverload<int>::of(&QSpinBox::valueChanged), timer, [=](int) {
timer->start(100);
});
QObject::connect(timer, &QTimer::timeout, [=]() {
ui->shortcutTimeout->onSave();
});
}
/** Destroys the object and frees any allocated resources */
@@ -153,11 +156,14 @@ void DlgCustomKeyboardImp::populateCommandList(QTreeWidget *commandTreeWidget,
if (auto item = commandTreeWidget->currentItem())
current = item->data(1, Qt::UserRole).toByteArray();
if (separatorItem)
if (separatorItem) {
commandTreeWidget->takeTopLevelItem(commandTreeWidget->indexOfTopLevelItem(separatorItem));
}
commandTreeWidget->clear();
if (separatorItem)
if (separatorItem) {
commandTreeWidget->addTopLevelItem(separatorItem);
}
CommandManager & cCmdMgr = Application::Instance->commandManager();
auto group = combo->itemData(combo->currentIndex(), Qt::UserRole).toByteArray();
auto cmds = group == "All" ? cCmdMgr.getAllCommands()
@@ -210,11 +216,13 @@ DlgCustomKeyboardImp::initCommandList(QTreeWidget *commandTreeWidget,
populateCommandList(commandTreeWidget, separatorItem, combo);
});
QObject::connect(ShortcutManager::instance(), &ShortcutManager::shortcutChanged,
timer, [timer]() { timer->start(100); });
QObject::connect(ShortcutManager::instance(), &ShortcutManager::shortcutChanged, timer, [timer]() {
timer->start(100);
});
QObject::connect(combo, QOverload<int>::of(&QComboBox::activated),
timer, [timer]() { timer->start(100); });
QObject::connect(combo, QOverload<int>::of(&QComboBox::activated), timer, [timer]() {
timer->start(100);
});
return Application::Instance->commandManager().signalChanged.connect([timer](){
timer->start(100);
@@ -285,11 +293,18 @@ DlgCustomKeyboardImp::initCommandWidgets(QTreeWidget *commandTreeWidget,
auto timer = new QTimer(priorityList);
timer->setSingleShot(true);
if (currentShortcut)
QObject::connect(currentShortcut, &QLineEdit::textChanged, timer, [timer](){timer->start(200);});
QObject::connect(editShortcut, &QLineEdit::textChanged, timer, [timer](){timer->start(200);});
QObject::connect(ShortcutManager::instance(), &ShortcutManager::priorityChanged, timer, [timer](){timer->start(200);});
QObject::connect(timer, &QTimer::timeout, [=](){
if (currentShortcut) {
QObject::connect(currentShortcut, &QLineEdit::textChanged, timer, [timer]() {
timer->start(200);
});
}
QObject::connect(editShortcut, &QLineEdit::textChanged, timer, [timer]() {
timer->start(200);
});
QObject::connect(ShortcutManager::instance(), &ShortcutManager::priorityChanged, timer, [timer](){
timer->start(200);
});
QObject::connect(timer, &QTimer::timeout, [=]() {
populatePriorityList(priorityList, editShortcut, currentShortcut);
});
}
@@ -510,8 +525,9 @@ void DlgCustomKeyboardImp::onModifyMacroAction(const QByteArray&)
{
QVariant data = ui->categoryBox->itemData(ui->categoryBox->currentIndex(), Qt::UserRole);
QString group = data.toString();
if (group == QLatin1String("Macros"))
if (group == QLatin1String("Macros")) {
ui->categoryBox->activated(ui->categoryBox->currentIndex());
}
}
void DlgCustomKeyboardImp::changeEvent(QEvent *e)
@@ -531,8 +547,10 @@ void DlgCustomKeyboardImp::changeEvent(QEvent *e)
}
ui->categoryBox->activated(ui->categoryBox->currentIndex());
}
else if (e->type() == QEvent::StyleChange)
else if (e->type() == QEvent::StyleChange) {
ui->categoryBox->activated(ui->categoryBox->currentIndex());
}
QWidget::changeEvent(e);
}

View File

@@ -532,8 +532,10 @@ void DlgCustomToolbars::changeEvent(QEvent *e)
}
ui->categoryBox->activated(ui->categoryBox->currentIndex());
}
else if (e->type() == QEvent::StyleChange)
else if (e->type() == QEvent::StyleChange) {
ui->categoryBox->activated(ui->categoryBox->currentIndex());
}
QWidget::changeEvent(e);
}

View File

@@ -180,8 +180,9 @@ void ToolBarManager::setup(ToolBarItem* toolBarItems)
return; // empty menu bar
static QPointer<QWidget> _ActionWidget;
if (!_ActionWidget)
if (!_ActionWidget) {
_ActionWidget = new QWidget(getMainWindow());
}
else {
for (auto action : _ActionWidget->actions())
_ActionWidget->removeAction(action);
@@ -231,8 +232,9 @@ void ToolBarManager::setup(ToolBarItem* toolBarItems)
// setup the toolbar
setup(*it, toolbar);
for (auto action : toolbar->actions())
for (auto action : toolbar->actions()) {
_ActionWidget->addAction(action);
}
// try to add some breaks to avoid to have all toolbars in one line
if (toolbar_added) {
@@ -287,15 +289,19 @@ void ToolBarManager::setup(ToolBarItem* item, QToolBar* toolbar) const
if (!action) {
if ((*it)->command() == "Separator") {
action = toolbar->addSeparator();
} else {
}
else {
// Check if action was added successfully
if (mgr.addTo((*it)->command().c_str(), toolbar))
action = toolbar->actions().constLast();
}
// set the tool button user data
if (action) action->setData(QString::fromLatin1((*it)->command().c_str()));
} else {
if (action) {
action->setData(QString::fromLatin1((*it)->command().c_str()));
}
}
else {
// Note: For toolbars we do not remove and re-add the actions
// because this causes flicker effects. So, it could happen that the order of
// buttons doesn't match with the order of commands in the workbench.
@@ -421,4 +427,4 @@ void ToolBarManager::setToolbarVisibility(bool show, const QString& name) {
tb->toggleViewAction()->setVisible(false);
}
}
}
}