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-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#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 layout->setDirection( QBoxLayout::LeftToRight );
37
38 m_widget = new BtBibleKeyWidget(m_modules.first(), m_key, this);
39 setFocusProxy(m_widget);
40 layout->addWidget(m_widget);
41
43 [this](CSwordVerseKey * key) {
46
47 if (!updatesEnabled())
48 return;
49
50 setUpdatesEnabled(false);
51 m_key = key;
52 Q_EMIT keyChanged(m_key);
53
54 setUpdatesEnabled(true);
55 });
56
57 setKey(m_key); //set the key without changing it, setKey(key()) would change it
58}
59
63
65 BT_ASSERT(dynamic_cast<CSwordVerseKey *>(key));
66 if (dynamic_cast<CSwordVerseKey*>(key) == nullptr) return;
67
68 m_key = dynamic_cast<CSwordVerseKey*>(key);
70 Q_EMIT keyChanged(m_key);
71}
72
74 bool refresh)
75{
76 using CSBMI = CSwordBibleModuleInfo;
77
78 m_modules.clear();
79
80 for (auto const * const mod : modules)
81 if (mod->type() == CSwordModuleInfo::Bible
82 || mod->type() == CSwordModuleInfo::Commentary)
83 if (CSBMI const * const bible = dynamic_cast<CSBMI const *>(mod))
84 m_modules.append(bible);
85
86 // First time this is called we havnt set up m_widget.
87 if (m_widget)
89 if (refresh) refreshContent();
90}
91
95
#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.