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 
27  QAbstractTableModel(parent)
28 {
29 }
30 
31 gui::ShortcutTableModel::ShortcutTableModel(QHash<QString, QKeySequence> Shortcuts, QObject* parent) :
32  QAbstractTableModel(parent)
33 {
34  registeredShortcuts = Shortcuts;
35 }
36 
37 void gui::ShortcutTableModel::setShortcutHashTable(QHash<QString, QKeySequence> Shortcuts)
38 {
39  registeredShortcuts = Shortcuts;
40  emit(layoutChanged());
41 }
42 
43 int gui::ShortcutTableModel::rowCount(const QModelIndex& parent) const
44 {
45  return registeredShortcuts.size();
46 }
47 
48 int gui::ShortcutTableModel::columnCount(const QModelIndex& parent) const
49 {
50  return 2;
51 }
52 
53 QVariant gui::ShortcutTableModel::data(const QModelIndex& index, int role) const
54 {
55  if (!index.isValid())
56  {
57  return QVariant();
58  }
59 
60  if (index.row() >= registeredShortcuts.size() || index.row() < 0)
61  {
62  return QVariant();
63  }
64 
65  if (role == Qt::DisplayRole)
66  {
67  if (index.column() == 0)
68  {
69  return tr(registeredShortcuts.keys().at(index.row()).toStdString().c_str());
70  }
71  else if (index.column() == 1)
72  {
73  return tr(registeredShortcuts.values().at(index.row()).toString().toStdString().c_str());
74  }
75  }
76 
77  return QVariant();
78 }
79 
80 QVariant gui::ShortcutTableModel::headerData(int section, Qt::Orientation orientation, int role) const
81 {
82  if (role != Qt::DisplayRole)
83  {
84  return QVariant();
85  }
86 
87  if (orientation == Qt::Horizontal)
88  {
89  switch (section)
90  {
91  case 0:
92  return tr("Name");
93 
94  case 1:
95  return tr("Key-Sequence");
96 
97  default:
98  return QVariant();
99  }
100  }
101 
102  return QVariant();
103 }
104 
105 QVariant gui::ShortcutTableModel::actionName(const QModelIndex& index, int role) const
106 {
107  if (!index.isValid())
108  {
109  return QVariant();
110  }
111 
112  if (index.row() >= registeredShortcuts.size() || index.row() < 0)
113  {
114  return QVariant();
115  }
116 
117  if (role == Qt::DisplayRole)
118  {
119  return registeredShortcuts.keys().at(index.row()).toStdString().c_str();
120  }
121 
122  return QVariant();
123 }
gui::ShortcutTableModel::columnCount
int columnCount(const QModelIndex &parent) const override
Returns the number of given columns (standard = 2).
Definition: ShortcutTableModel.cpp:48
gui::ShortcutTableModel::data
QVariant data(const QModelIndex &index, int role) const override
Returns the value of a given Position in the model.
Definition: ShortcutTableModel.cpp:53
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
index
uint8_t index
Definition: EtherCATFrame.h:59
gui::ShortcutTableModel::ShortcutTableModel
ShortcutTableModel(QObject *parent=0)
A constructor.
Definition: ShortcutTableModel.cpp:26
gui::ShortcutTableModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns the header of a given Section by orientation.
Definition: ShortcutTableModel.cpp:80
gui::ShortcutTableModel::setShortcutHashTable
void setShortcutHashTable(QHash< QString, QKeySequence > Shortcuts)
Sets a predefined Shortcuts-Hash as new Hash of this ShortcutTableModel.
Definition: ShortcutTableModel.cpp:37
gui::ShortcutTableModel::rowCount
int rowCount(const QModelIndex &parent) const override
Returns the number of given rows.
Definition: ShortcutTableModel.cpp:43
ShortcutTableModel.h
gui::ShortcutTableModel::actionName
QVariant actionName(const QModelIndex &index, int role) const
Returns the Name of the Action of the given Row.
Definition: ShortcutTableModel.cpp:105