BibleTime
btbookshelfgroupingmenu.cpp
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
14
15#include <QAction>
16#include <QActionGroup>
17#include <QVariant>
18#include "../backend/bookshelfmodel/btbookshelftreemodel.h"
19#include "../util/btconnect.h"
20#include "../util/cresmgr.h"
21
22
23namespace {
24
26 a->setProperty("groupingPointer",
27 QVariant::fromValue(
28 const_cast<void *>(static_cast<void const *>(&g))));
29}
30
32 return *static_cast<BtBookshelfTreeModel::Grouping const *>(
33 a->property("groupingPointer").value<void *>());
34}
35
36} // anonymous namespace
37
38
40 BtBookshelfTreeModel::Grouping const & grouping)
41{
43 if (grouping == G::CAT_LANG) {
44 m_groupingCatLangAction->setChecked(true);
45 } else if (grouping == G::CAT) {
46 m_groupingCatAction->setChecked(true);
47 } else if (grouping == G::LANG_CAT) {
48 m_groupingLangCatAction->setChecked(true);
49 } else if (grouping == G::LANG) {
50 m_groupingLangAction->setChecked(true);
51 } else {
52 BT_ASSERT(grouping == G::NONE);
54 m_groupingNoneAction->setChecked(true);
55 }
56}
57
58void BtBookshelfGroupingMenu::initMenu(bool showNoGrouping) {
59 setIcon(CResMgr::mainIndex::grouping::icon());
60
61 m_groupingActionGroup = new QActionGroup(this);
62 m_groupingActionGroup->setExclusive(true);
63 BT_CONNECT(m_groupingActionGroup, &QActionGroup::triggered,
64 [this](QAction * const action)
65 { Q_EMIT signalGroupingOrderChanged(getActionRef(action)); });
66
68
70 m_groupingCatLangAction->setCheckable(true);
71 setActionRef(m_groupingCatLangAction, G::CAT_LANG);
73 addAction(m_groupingCatLangAction);
74
75 m_groupingCatAction = new QAction(this);
76 m_groupingCatAction->setCheckable(true);
77 setActionRef(m_groupingCatAction, G::CAT);
79 addAction(m_groupingCatAction);
80
82 m_groupingLangCatAction->setCheckable(true);
83 setActionRef(m_groupingLangCatAction, G::LANG_CAT);
85 addAction(m_groupingLangCatAction);
86
87 m_groupingLangAction = new QAction(this);
88 m_groupingLangAction->setCheckable(true);
89 setActionRef(m_groupingLangAction, G::LANG);
91 addAction(m_groupingLangAction);
92
93 if (showNoGrouping) {
94 m_groupingNoneAction = new QAction(this);
95 m_groupingNoneAction->setCheckable(true);
96 setActionRef(m_groupingNoneAction, G::NONE);
98 addAction(m_groupingNoneAction);
99 } else {
100 m_groupingNoneAction = nullptr;
101 }
102
104}
105
107 m_groupingCatLangAction->setText(tr("Category/Language"));
108 m_groupingCatAction->setText(tr("Category"));
109 m_groupingLangCatAction->setText(tr("Language/Category"));
110 m_groupingLangAction->setText(tr("Language"));
111
112 if (m_groupingNoneAction != nullptr) {
113 m_groupingNoneAction->setText(tr("No grouping"));
114 }
115}
#define BT_ASSERT(...)
Definition btassert.h:17
#define BT_CONNECT(...)
Definition btconnect.h:20
void setGrouping(BtBookshelfTreeModel::Grouping const &grouping)
void signalGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &)
void initMenu(bool showNoGrouping)
const BtBookshelfTreeModel::Grouping & getActionRef(const QAction *a)
void setActionRef(QAction *a, const BtBookshelfTreeModel::Grouping &g)