BibleTime
src
frontend
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-2021 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
#include "
btbookshelfgroupingmenu.h
"
14
15
#include <QAction>
16
#include <QActionGroup>
17
#include <QVariant>
18
#include "../backend/bookshelfmodel/btbookshelftreemodel.h"
19
#include "../util/btassert.h"
20
#include "../util/btconnect.h"
21
#include "../util/cresmgr.h"
22
23
24
namespace
{
25
bool
groupsInitialized
=
false
;
26
BtBookshelfTreeModel::Grouping
groupingNone
(
true
);
27
BtBookshelfTreeModel::Grouping
groupingCat
(
true
);
28
BtBookshelfTreeModel::Grouping
groupingCatLang
;
29
BtBookshelfTreeModel::Grouping
groupingLang
(
true
);
30
BtBookshelfTreeModel::Grouping
groupingLangCat
(
true
);
31
32
inline
void
initializeGroups
() {
33
BT_ASSERT
(
groupingNone
.empty());
34
groupingCat
.append(
BtBookshelfTreeModel::GROUP_CATEGORY
);
35
BT_ASSERT
(
groupingCatLang
.size() == 2);
36
BT_ASSERT
(
groupingCatLang
.at(0) ==
BtBookshelfTreeModel::GROUP_CATEGORY
);
37
BT_ASSERT
(
groupingCatLang
.at(1) ==
BtBookshelfTreeModel::GROUP_LANGUAGE
);
38
groupingLang
.append(
BtBookshelfTreeModel::GROUP_LANGUAGE
);
39
groupingLangCat
.append(
BtBookshelfTreeModel::GROUP_LANGUAGE
);
40
groupingLangCat
.append(
BtBookshelfTreeModel::GROUP_CATEGORY
);
41
groupsInitialized
=
true
;
42
}
43
44
inline
void
setActionRef
(
QAction
*a,
const
BtBookshelfTreeModel::Grouping
&g) {
45
a->setProperty(
"groupingPointer"
,
46
QVariant::fromValue(
47
const_cast<
void
*
>
(
static_cast<
void
const
*
>
(&g))));
48
}
49
50
inline
const
BtBookshelfTreeModel::Grouping
&
getActionRef
(
const
QAction
*a) {
51
return
*
static_cast<
BtBookshelfTreeModel::Grouping
const
*
>
(
52
a->property(
"groupingPointer"
).value<
void
*>());
53
}
54
55
}
// anonymous namespace
56
57
58
void
BtBookshelfGroupingMenu::initMenu
(
bool
showNoGrouping) {
59
if
(!
groupsInitialized
)
initializeGroups
();
60
61
setIcon(CResMgr::mainIndex::grouping::icon());
62
63
m_groupingActionGroup
=
new
QActionGroup(
this
);
64
m_groupingActionGroup
->setExclusive(
true
);
65
BT_CONNECT
(
m_groupingActionGroup
, &QActionGroup::triggered,
66
[
this
](
QAction
*
const
action)
67
{ Q_EMIT
signalGroupingOrderChanged
(
getActionRef
(action)); });
68
69
m_groupingCatLangAction
=
new
QAction
(
this
);
70
m_groupingCatLangAction
->setCheckable(
true
);
71
setActionRef
(
m_groupingCatLangAction
,
groupingCatLang
);
72
m_groupingActionGroup
->addAction(
m_groupingCatLangAction
);
73
addAction(
m_groupingCatLangAction
);
74
75
m_groupingCatAction
=
new
QAction
(
this
);
76
m_groupingCatAction
->setCheckable(
true
);
77
setActionRef
(
m_groupingCatAction
,
groupingCat
);
78
m_groupingActionGroup
->addAction(
m_groupingCatAction
);
79
addAction(
m_groupingCatAction
);
80
81
m_groupingLangCatAction
=
new
QAction
(
this
);
82
m_groupingLangCatAction
->setCheckable(
true
);
83
setActionRef
(
m_groupingLangCatAction
,
groupingLangCat
);
84
m_groupingActionGroup
->addAction(
m_groupingLangCatAction
);
85
addAction(
m_groupingLangCatAction
);
86
87
m_groupingLangAction
=
new
QAction
(
this
);
88
m_groupingLangAction
->setCheckable(
true
);
89
setActionRef
(
m_groupingLangAction
,
groupingLang
);
90
m_groupingActionGroup
->addAction(
m_groupingLangAction
);
91
addAction(
m_groupingLangAction
);
92
93
if
(showNoGrouping) {
94
m_groupingNoneAction
=
new
QAction
(
this
);
95
m_groupingNoneAction
->setCheckable(
true
);
96
setActionRef
(
m_groupingNoneAction
,
groupingNone
);
97
m_groupingActionGroup
->addAction(
m_groupingNoneAction
);
98
addAction(
m_groupingNoneAction
);
99
}
else
{
100
m_groupingNoneAction
=
nullptr
;
101
}
102
103
retranslateUi
();
104
}
105
106
void
BtBookshelfGroupingMenu::retranslateUi
() {
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
}
BT_ASSERT
#define BT_ASSERT(...)
Definition:
btassert.h:17
btbookshelfgroupingmenu.h
BT_CONNECT
#define BT_CONNECT(...)
Definition:
btconnect.h:20
BtBookshelfGroupingMenu::signalGroupingOrderChanged
void signalGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &)
BtBookshelfGroupingMenu::m_groupingLangAction
QAction * m_groupingLangAction
Definition:
btbookshelfgroupingmenu.h:48
BtBookshelfGroupingMenu::retranslateUi
void retranslateUi()
Definition:
btbookshelfgroupingmenu.cpp:106
BtBookshelfGroupingMenu::m_groupingLangCatAction
QAction * m_groupingLangCatAction
Definition:
btbookshelfgroupingmenu.h:47
BtBookshelfGroupingMenu::m_groupingCatAction
QAction * m_groupingCatAction
Definition:
btbookshelfgroupingmenu.h:46
BtBookshelfGroupingMenu::initMenu
void initMenu(bool showNoGrouping)
Definition:
btbookshelfgroupingmenu.cpp:58
BtBookshelfGroupingMenu::m_groupingCatLangAction
QAction * m_groupingCatLangAction
Definition:
btbookshelfgroupingmenu.h:45
BtBookshelfGroupingMenu::m_groupingNoneAction
QAction * m_groupingNoneAction
Definition:
btbookshelfgroupingmenu.h:49
BtBookshelfGroupingMenu::m_groupingActionGroup
QActionGroup * m_groupingActionGroup
Definition:
btbookshelfgroupingmenu.h:44
BtBookshelfTreeModel::Grouping
Definition:
btbookshelftreemodel.h:66
BtBookshelfTreeModel::GROUP_CATEGORY
@ GROUP_CATEGORY
Definition:
btbookshelftreemodel.h:54
BtBookshelfTreeModel::GROUP_LANGUAGE
@ GROUP_LANGUAGE
Definition:
btbookshelftreemodel.h:55
QAction
anonymous_namespace{btbookshelfgroupingmenu.cpp}::groupingLangCat
BtBookshelfTreeModel::Grouping groupingLangCat(true)
anonymous_namespace{btbookshelfgroupingmenu.cpp}::groupingCat
BtBookshelfTreeModel::Grouping groupingCat(true)
anonymous_namespace{btbookshelfgroupingmenu.cpp}::groupingLang
BtBookshelfTreeModel::Grouping groupingLang(true)
anonymous_namespace{btbookshelfgroupingmenu.cpp}::getActionRef
const BtBookshelfTreeModel::Grouping & getActionRef(const QAction *a)
Definition:
btbookshelfgroupingmenu.cpp:50
anonymous_namespace{btbookshelfgroupingmenu.cpp}::initializeGroups
void initializeGroups()
Definition:
btbookshelfgroupingmenu.cpp:32
anonymous_namespace{btbookshelfgroupingmenu.cpp}::groupingNone
BtBookshelfTreeModel::Grouping groupingNone(true)
anonymous_namespace{btbookshelfgroupingmenu.cpp}::groupingCatLang
BtBookshelfTreeModel::Grouping groupingCatLang
Definition:
btbookshelfgroupingmenu.cpp:28
anonymous_namespace{btbookshelfgroupingmenu.cpp}::groupsInitialized
bool groupsInitialized
Definition:
btbookshelfgroupingmenu.cpp:25
anonymous_namespace{btbookshelfgroupingmenu.cpp}::setActionRef
void setActionRef(QAction *a, const BtBookshelfTreeModel::Grouping &g)
Definition:
btbookshelfgroupingmenu.cpp:44
Generated by
1.9.1