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-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 
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;
31 
32 inline void initializeGroups() {
33  BT_ASSERT(groupingNone.empty());
35  BT_ASSERT(groupingCatLang.size() == 2);
41  groupsInitialized = true;
42 }
43 
45  a->setProperty("groupingPointer",
46  QVariant::fromValue(
47  const_cast<void *>(static_cast<void const *>(&g))));
48 }
49 
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) {
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);
73  addAction(m_groupingCatLangAction);
74 
75  m_groupingCatAction = new QAction(this);
76  m_groupingCatAction->setCheckable(true);
79  addAction(m_groupingCatAction);
80 
81  m_groupingLangCatAction = new QAction(this);
82  m_groupingLangCatAction->setCheckable(true);
85  addAction(m_groupingLangCatAction);
86 
87  m_groupingLangAction = new QAction(this);
88  m_groupingLangAction->setCheckable(true);
91  addAction(m_groupingLangAction);
92 
93  if (showNoGrouping) {
94  m_groupingNoneAction = new QAction(this);
95  m_groupingNoneAction->setCheckable(true);
98  addAction(m_groupingNoneAction);
99  } else {
100  m_groupingNoneAction = nullptr;
101  }
102 
103  retranslateUi();
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 signalGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &)
void initMenu(bool showNoGrouping)
BtBookshelfTreeModel::Grouping groupingLangCat(true)
BtBookshelfTreeModel::Grouping groupingCat(true)
BtBookshelfTreeModel::Grouping groupingLang(true)
const BtBookshelfTreeModel::Grouping & getActionRef(const QAction *a)
BtBookshelfTreeModel::Grouping groupingNone(true)
void setActionRef(QAction *a, const BtBookshelfTreeModel::Grouping &g)