BibleTime
cbiblekeychooser.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-2026 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 "cbiblekeychooser.h"
14
15#include <QDebug>
16#include <QHBoxLayout>
17#include "../../../backend/drivers/cswordbiblemoduleinfo.h"
18#include "../../../backend/drivers/cswordmoduleinfo.h"
19#include "../../../backend/keys/cswordversekey.h"
20#include "../../../util/btassert.h"
21#include "../../../util/btconnect.h"
22#include "btbiblekeywidget.h"
23
24
26 CSwordKey * key,
27 QWidget * parent)
28 : CKeyChooser(parent)
29 , m_key(dynamic_cast<CSwordVerseKey *>(key))
30{
31 setModules(modules, false);
32 BT_ASSERT(!m_modules.empty());
33 QHBoxLayout* layout = new QHBoxLayout(this);
34 layout->setSpacing(0);
35 layout->setContentsMargins(0, 0, 0, 0);
36
37 m_widget = new BtBibleKeyWidget(m_modules.first(), m_key, this);
38 setFocusProxy(m_widget);
39 layout->addWidget(m_widget);
40
42 [this](CSwordVerseKey * key) {
45
46 if (!updatesEnabled())
47 return;
48
49 setUpdatesEnabled(false);
50 m_key = key;
51 Q_EMIT keyChanged(m_key);
52
53 setUpdatesEnabled(true);
54 });
55
56 setKey(m_key); //set the key without changing it, setKey(key()) would change it
57}
58
62
64 BT_ASSERT(dynamic_cast<CSwordVerseKey *>(key));
65 if (dynamic_cast<CSwordVerseKey*>(key) == nullptr) return;
66
67 m_key = dynamic_cast<CSwordVerseKey*>(key);
69 Q_EMIT keyChanged(m_key);
70}
71
73 bool refresh)
74{
75 using CSBMI = CSwordBibleModuleInfo;
76
77 m_modules.clear();
78
79 for (auto const * const mod : modules)
80 if (mod->type() == CSwordModuleInfo::Bible
81 || mod->type() == CSwordModuleInfo::Commentary)
82 if (CSBMI const * const bible = dynamic_cast<CSBMI const *>(mod))
83 m_modules.append(bible);
84
85 // First time this is called we havnt set up m_widget.
86 if (m_widget)
88 if (refresh) refreshContent();
89}
90
94
#define BT_ASSERT(...)
Definition btassert.h:17
#define BT_CONNECT(...)
Definition btconnect.h:20
QList< CSwordModuleInfo const * > BtConstModuleList
void setModule(const CSwordBibleModuleInfo *m=nullptr)
void changed(CSwordVerseKey *key)
bool setKey(CSwordVerseKey *key)
CSwordVerseKey * m_key
BtBibleKeyWidget * m_widget
void setKey(CSwordKey *key) final override
CBibleKeyChooser(BtConstModuleList const &modules, CSwordKey *key=nullptr, QWidget *parent=nullptr)
void refreshContent() final override
QList< CSwordBibleModuleInfo const * > m_modules
void updateKey(CSwordKey *key) final override
void setModules(BtConstModuleList const &modules, bool refresh=true) final override
CSwordKey * key() final override
void keyChanged(CSwordKey *newKey)
Implementation for Sword Bibles.
CSwordKey implementation for Sword's VerseKey.