src/settingseditor/keyboardshortcutseditor.cpp

Tue, 27 Jul 2021 16:29:00 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 27 Jul 2021 16:29:00 +0300
changeset 118
8e1c9f18ae15
parent 16
aeb5f203b3eb
child 259
c27612f0eac0
permissions
-rw-r--r--

Add vertex rendering

#include <QAction>
#include "keyboardshortcutseditor.h"
#include "uiutilities.h"

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

int KeyboardShortcutsEditor::rowCount(const QModelIndex&) const
{
	return 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[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