BibleTime
btactioncollection.h
Go to the documentation of this file.
1/*********
2*
3* In the name of the Father, and of the Son, and of the Holy Spirit.
4*
5* This file is part of BibleTime's source code, https://bibletime.info/
6*
7* Copyright 1999-2025 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
13#pragma once
14
15#include <QObject>
16
17#include <QAction>
18#include <QKeySequence>
19#include <QMap>
20#include <QString>
21#include "../../util/btassert.h"
22
23
25
26 Q_OBJECT
27
28public: // methods:
29
30 BtActionCollection(QObject * const parent = nullptr)
31 : QObject{parent}
32 {}
33
34 QMap<QString, QAction *> const & actions() const noexcept
35 { return m_actions; }
36
37 void addAction(QString const & name, QAction * const action);
38
39 QAction & action(QString const & name) const;
40
41 template <typename T>
42 T & actionAs(QString const & name) const {
43 QAction & a = action(name);
44 BT_ASSERT(dynamic_cast<T *>(&a));
45 return static_cast<T &>(a);
46 }
47
48 /*!
49 * \brief Read shortcuts from config.
50 *
51 * Read the shortcuts for the given group
52 * from the configuration and add them to
53 * this action collection.
54 *
55 * \param[in] group Shortcut group to read actions from.
56 */
57 void readShortcuts(QString const & group);
58
59 /*!
60 * \brief Write shortcuts to config.
61 *
62 * Write the shortcuts of this action collection
63 * to the given group in the configuration.
64 *
65 * \param[in] group Shortcut group to write actions to.
66 */
67 void writeShortcuts(QString const & group) const;
68
69 static QKeySequence getDefaultShortcut(QAction & action);
70
71private: // fields:
72
73 QMap<QString, QAction *> m_actions;
74
75};
#define BT_ASSERT(...)
Definition btassert.h:17
BtActionCollection(QObject *const parent=nullptr)
void readShortcuts(QString const &group)
Read shortcuts from config.
void writeShortcuts(QString const &group) const
Write shortcuts to config.
QMap< QString, QAction * > const & actions() const noexcept
QMap< QString, QAction * > m_actions
void addAction(QString const &name, QAction *const action)
QAction & action(QString const &name) const
static QKeySequence getDefaultShortcut(QAction &action)
T & actionAs(QString const &name) const
#define T(f)