Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
shortcutsmodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 by the Quassel Project *
3  * devel@quassel-irc.org *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) version 3. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but 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, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef SHORTCUTSMODEL_H
22 #define SHORTCUTSMODEL_H
23 
24 #include <QAbstractItemModel>
25 #include <QKeySequence>
26 
27 class Action;
28 class ActionCollection;
29 
31 
35 class ShortcutsModel : public QAbstractItemModel
36 {
37  Q_OBJECT
38 public:
39  enum Role {
40  ActionRole = Qt::UserRole,
44  };
45 
46  ShortcutsModel(const QHash<QString, ActionCollection *> &actionCollections, QObject *parent = 0);
48 
49  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
50  QModelIndex parent(const QModelIndex &child) const;
51  int columnCount(const QModelIndex &parent = QModelIndex()) const;
52  int rowCount(const QModelIndex &parent = QModelIndex()) const;
53  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
54  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
55  bool setData(const QModelIndex &index, const QVariant &value, int role = ActiveShortcutRole);
56 
57 public slots:
59 
63  void load();
64 
66 
70  void defaults();
71 
73  void commit();
74 
75  inline bool hasChanged() const { return _changedCount; }
76 
77 signals:
79  void hasChanged(bool changed);
80 
81 private:
82  struct Item {
83  inline Item() { parentItem = 0; collection = 0; action = 0; }
84  inline ~Item() { qDeleteAll(actionItems); }
85  int row;
89  QKeySequence shortcut;
90  QList<Item *> actionItems;
91  };
92 
93  QList<Item *> _categoryItems;
95 };
96 
97 
98 #endif // SHORTCUTSMODEL_H