BibleTime
crossrefrendering.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 "crossrefrendering.h"
14 
15 #include <QtGlobal>
16 #include "../drivers/cswordmoduleinfo.h"
17 #include "../keys/cswordversekey.h"
18 #include "../managers/referencemanager.h"
19 
20 
21 namespace Rendering {
22 
24  const FilterOptions &filterOptions)
25  : CTextRendering(true, displayOptions, filterOptions)
26 {
27  // Intentionally empty
28 }
29 
30 QString CrossRefRendering::finishText(QString const & text,
31  KeyTree const & tree) const
32 {
33  Q_UNUSED(tree)
34  return text;
35 }
36 
38  CSwordModuleInfo const & module) const
39 {
40 
41  bool const isBible = (module.type() == CSwordModuleInfo::Bible);
42  CSwordVerseKey vk(&module); // only valid for bible modules, i.e. isBible == true
43  if (isBible)
44  vk.setKey(item.key());
45 
46  QString linkText;
47  switch (item.settings().keyRenderingFace) {
48  case KeyTreeItem::Settings::NoKey:
49  return {}; //no key is valid for all modules
50  case KeyTreeItem::Settings::CompleteShort:
51  if (isBible) {
52  linkText = vk.shortText();
53  break;
54  }
55  //fall through for non-Bible modules
56  [[fallthrough]];
57  case KeyTreeItem::Settings::CompleteLong:
58  if (isBible) {
59  linkText = vk.key();
60  break;
61  }
62  //fall through for non-Bible modules
63  [[fallthrough]];
64  case KeyTreeItem::Settings::SimpleKey:
65  if (isBible) {
66  linkText = QString::number(vk.verse());
67  break;
68  }
69  //fall through for non-Bible modules
70  [[fallthrough]];
71  default: { //default behaviour to return the passed key
72  linkText = item.key();
73  break;
74  }
75  }
76 
77  if (linkText.isEmpty()) // if we have an invalid link text
78  return {};
79 
80  return QStringLiteral("<a href=\"%1\">%2</a>")
81  .arg(ReferenceManager::encodeHyperlink(module, item.key()),
82  linkText);
83 }
84 
85 } // namespace Rendering
ModuleType type() const
CSwordKey implementation for Sword's VerseKey.
QString key() const final override
bool setKey(const QString &key) final override
int verse() const
QString shortText() const
Settings const & settings() const
Text rendering based on trees.
std::list< KeyTreeItem > KeyTree
CrossRefRendering(const DisplayOptions &displayOptions=btConfig().getDisplayOptions(), const FilterOptions &filterOptions=btConfig().getFilterOptions())
QString entryLink(KeyTreeItem const &item, CSwordModuleInfo const &module) const override
QString finishText(QString const &text, KeyTree const &tree) const override
QString encodeHyperlink(CSwordModuleInfo const &module, QString const &key)