From 1f9ef7e2d498eeb4f3781c483c80b971bded0dc2 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 18 Aug 2020 10:31:03 +0100 Subject: [PATCH] Fix code style --- src/delegates/ProfileShortcutDelegate.cpp | 33 ++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/delegates/ProfileShortcutDelegate.cpp b/src/delegates/ProfileShortcutDelegate.cpp index ef2a7681..560e92a7 100644 --- a/src/delegates/ProfileShortcutDelegate.cpp +++ b/src/delegates/ProfileShortcutDelegate.cpp @@ -6,23 +6,23 @@ using namespace Konsole; -ShortcutItemDelegate::ShortcutItemDelegate(QObject* parent) +ShortcutItemDelegate::ShortcutItemDelegate(QObject *parent) : QStyledItemDelegate(parent), - _modifiedEditors(QSet()), + _modifiedEditors(QSet()), _itemsBeingEdited(QSet()) { } void ShortcutItemDelegate::editorModified() { - auto* editor = qobject_cast(sender()); + auto *editor = qobject_cast(sender()); Q_ASSERT(editor); _modifiedEditors.insert(editor); emit commitData(editor); emit closeEditor(editor); } -void ShortcutItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, - const QModelIndex& index) const +void ShortcutItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const { _itemsBeingEdited.remove(index); @@ -30,25 +30,28 @@ void ShortcutItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* mod return; } - QString shortcut = qobject_cast(editor)->keySequence().toString(); + const auto shortcut = qobject_cast(editor)->keySequence().toString(); model->setData(index, shortcut, Qt::DisplayRole); _modifiedEditors.remove(editor); } -QWidget* ShortcutItemDelegate::createEditor(QWidget* aParent, const QStyleOptionViewItem&, const QModelIndex& index) const +QWidget* ShortcutItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex &index) const { _itemsBeingEdited.insert(index); - auto editor = new FilteredKeySequenceEdit(aParent); - QString shortcutString = index.data(Qt::DisplayRole).toString(); + auto editor = new FilteredKeySequenceEdit(parent); + const auto shortcutString = index.data(Qt::DisplayRole).toString(); + editor->setKeySequence(QKeySequence::fromString(shortcutString)); - connect(editor, &QKeySequenceEdit::editingFinished, this, &Konsole::ShortcutItemDelegate::editorModified); editor->setFocus(Qt::FocusReason::MouseFocusReason); + + connect(editor, &QKeySequenceEdit::editingFinished, this, &Konsole::ShortcutItemDelegate::editorModified); + return editor; } -void ShortcutItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const +void ShortcutItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const { if (_itemsBeingEdited.contains(index)) { StyledBackgroundPainter::drawBackground(painter, option, index); @@ -59,8 +62,8 @@ void ShortcutItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& QSize ShortcutItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - const QString shortcutString = index.data(Qt::DisplayRole).toString(); - QFontMetrics fm = option.fontMetrics; + const auto shortcutString = index.data(Qt::DisplayRole).toString(); + const auto fm = option.fontMetrics; static const int editorMargins = 16; // chosen empirically const int width = fm.boundingRect(shortcutString + QStringLiteral(", ...")).width() @@ -99,7 +102,7 @@ void FilteredKeySequenceEdit::keyPressEvent(QKeyEvent *event) QKeySequenceEdit::keyPressEvent(event); } -void StyledBackgroundPainter::drawBackground(QPainter* painter, const QStyleOptionViewItem& option, +void StyledBackgroundPainter::drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex&) { const auto* opt = qstyleoption_cast(&option); -- GitLab