src/settingseditor/keyboardshortcutseditor.cpp

Mon, 27 Jun 2022 02:00:49 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 27 Jun 2022 02:00:49 +0300
changeset 270
1202b102a10b
parent 264
76a025db4948
permissions
-rw-r--r--

Fix qrc path in mainwindow.ui

#include <QAction>
#include "src/uiutilities.h"
#include "src/settingseditor/keyboardshortcutseditor.h"

KeyboardShortcutsEditor::KeyboardShortcutsEditor(QObject* subject, QObject* parent) :
	QAbstractTableModel{parent},
	actions{uiutilities::collectActions(subject)}
{
}

int KeyboardShortcutsEditor::rowCount(const QModelIndex&) const
{
	return static_cast<int>(this->actions.size());
}

int KeyboardShortcutsEditor::columnCount(const QModelIndex&) const
{
	return 2;
}

QVariant KeyboardShortcutsEditor::data(
	const QModelIndex& index,
	int role) const
{
	QAction* const action = this->actions[static_cast<std::size_t>(index.row())];
	const Column column = static_cast<Column>(index.column());
	switch(role)
	{
	case Qt::DisplayRole:
		switch (column) {
		case TitleColumn:
			return action->text();
		case ShortcutColumn:
			return action->shortcut().toString(QKeySequence::NativeText);
		}
		break;
	}
	return {};
}

QVariant KeyboardShortcutsEditor::headerData(
	int section,
	Qt::Orientation orientation,
	int role) const
{
	if (orientation == Qt::Horizontal and role == Qt::DisplayRole)
	{
		switch (static_cast<Column>(section))
		{
		case TitleColumn:
			return tr("Action");
		case ShortcutColumn:
			return tr("Shortcut");
		}
	}
	return {};
}

mercurial