ShortcutTableModel.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package MemoryX::gui-plugins::SceneEditor
19 * @date 2015
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24#include "ShortcutTableModel.h"
25
26gui::ShortcutTableModel::ShortcutTableModel(QObject* parent) : QAbstractTableModel(parent)
27{
28}
29
30gui::ShortcutTableModel::ShortcutTableModel(QHash<QString, QKeySequence> Shortcuts,
31 QObject* parent) :
32 QAbstractTableModel(parent)
33{
34 registeredShortcuts = Shortcuts;
35}
36
37void
38gui::ShortcutTableModel::setShortcutHashTable(QHash<QString, QKeySequence> Shortcuts)
39{
40 registeredShortcuts = Shortcuts;
41 emit(layoutChanged());
42}
43
44int
45gui::ShortcutTableModel::rowCount(const QModelIndex& parent) const
46{
47 return registeredShortcuts.size();
48}
49
50int
51gui::ShortcutTableModel::columnCount(const QModelIndex& parent) const
52{
53 return 2;
54}
55
56QVariant
57gui::ShortcutTableModel::data(const QModelIndex& index, int role) const
58{
59 if (!index.isValid())
60 {
61 return QVariant();
62 }
63
64 if (index.row() >= registeredShortcuts.size() || index.row() < 0)
65 {
66 return QVariant();
67 }
68
69 if (role == Qt::DisplayRole)
70 {
71 if (index.column() == 0)
72 {
73 return tr(registeredShortcuts.keys().at(index.row()).toStdString().c_str());
74 }
75 else if (index.column() == 1)
76 {
77 return tr(
78 registeredShortcuts.values().at(index.row()).toString().toStdString().c_str());
79 }
80 }
81
82 return QVariant();
83}
84
85QVariant
86gui::ShortcutTableModel::headerData(int section, Qt::Orientation orientation, int role) const
87{
88 if (role != Qt::DisplayRole)
89 {
90 return QVariant();
91 }
92
93 if (orientation == Qt::Horizontal)
94 {
95 switch (section)
96 {
97 case 0:
98 return tr("Name");
99
100 case 1:
101 return tr("Key-Sequence");
102
103 default:
104 return QVariant();
105 }
106 }
107
108 return QVariant();
109}
110
111QVariant
112gui::ShortcutTableModel::actionName(const QModelIndex& index, int role) const
113{
114 if (!index.isValid())
115 {
116 return QVariant();
117 }
118
119 if (index.row() >= registeredShortcuts.size() || index.row() < 0)
120 {
121 return QVariant();
122 }
123
124 if (role == Qt::DisplayRole)
125 {
126 return registeredShortcuts.keys().at(index.row()).toStdString().c_str();
127 }
128
129 return QVariant();
130}
uint8_t index
int rowCount(const QModelIndex &parent) const override
Returns the number of given rows.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns the header of a given Section by orientation.
QVariant actionName(const QModelIndex &index, int role) const
Returns the Name of the Action of the given Row.
int columnCount(const QModelIndex &parent) const override
Returns the number of given columns (standard = 2).
ShortcutTableModel(QObject *parent=0)
A constructor.
QVariant data(const QModelIndex &index, int role) const override
Returns the value of a given Position in the model.
void setShortcutHashTable(QHash< QString, QKeySequence > Shortcuts)
Sets a predefined Shortcuts-Hash as new Hash of this ShortcutTableModel.