11
#include "cbookdisplay.h"
12
#include "cdisplayrendering.h"
10
#include "backend/rendering/cbookdisplay.h"
12
#include <boost/scoped_ptr.hpp>
13
#include <QtAlgorithms>
13
15
#include "backend/drivers/cswordbookmoduleinfo.h"
14
16
#include "backend/keys/cswordtreekey.h"
17
#include "backend/rendering/cdisplayrendering.h"
17
#include <boost/scoped_ptr.hpp>
19
20
/** Returns the rendered text using the modules in the list and using the key parameter. The displayoptions and filter options are used, too. */
20
21
const QString Rendering::CBookDisplay::text( const QList<CSwordModuleInfo*>& modules, const QString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) {
21
CSwordBookModuleInfo* book = dynamic_cast<CSwordBookModuleInfo*>(modules.first());
24
CSwordBackend::DisplayOptions dOpts = displayOptions;
25
dOpts.lineBreaks = true; //books should render with blocks, not with inlined sections
27
CDisplayRendering render(dOpts, filterOptions);
28
CDisplayRendering::KeyTree tree;
29
CDisplayRendering::KeyTreeItem::Settings itemSettings;
31
// the number of levels which should be display together, 1 means display no entries together
32
int displayLevel = book->config( CSwordModuleInfo::DisplayLevel ).toInt();
34
boost::scoped_ptr<CSwordTreeKey> key (
35
dynamic_cast<CSwordTreeKey*>( CSwordKey::createInstance(book) )
37
key->key(keyName); //set the key to position we'd like to get
39
const unsigned long offset = key->getOffset();
41
// standard of DisplayLevel, display nothing together
42
// if the current key is the root entry don't display anything together!
44
if ((displayLevel <= 1) || (key->key().isEmpty() || (key->key() == "/") )) {
45
tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
47
const QString renderedText = render.renderKeyTree(tree);
48
key->setOffset( offset );
53
* Check whether displaying displayLevel levels together is possible.
54
* For this count the childs and parents
55
* of the required position
58
int possibleLevels = 1; //we start with the default value of displayLevel, which means no entries together
60
while( key->parent() && (key->key() != "/") && !key->key().isEmpty() ) {//add parents
64
// key->key(keyName); //set the key to the start position
66
key->setOffset( offset );
68
while( key->firstChild( )) { //add childs
72
if (possibleLevels < displayLevel) { //too few levels available!
73
//display current level, we could also decide to display the available levels together
74
tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
76
const QString renderedText = render.renderKeyTree(tree);
77
key->setOffset( offset );
81
if ((displayLevel > 2) && (displayLevel == possibleLevels)) { //fix not to diplay the whole module
85
// at this point we're sure that we can display the required levels toogether
86
// at the moment we're at the lowest level, so we only have to go up!
87
for (int currentLevel = 1; currentLevel < displayLevel; ++currentLevel) { //we start again with 1 == standard of displayLevel
89
if ( !key->parent() ) { //something went wrong although we checked before! Be safe and return entry's text
90
tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
92
const QString renderedText = render.renderKeyTree(tree);
93
key->setOffset( offset );
98
// no we can display all sub levels together! We checked before that this is possible!
99
itemSettings.highlight = (key->key() == keyName);
101
tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
103
//const bool hasToplevelText = !key->strippedText().isEmpty();
104
key->firstChild(); //go to the first sibling on the same level
106
setupRenderTree(key.get(), &tree, keyName);
108
const QString renderedText = render.renderKeyTree(tree);
110
key->setOffset( offset ); //restore key
22
CSwordBookModuleInfo* book = dynamic_cast<CSwordBookModuleInfo*>(modules.first());
25
CSwordBackend::DisplayOptions dOpts = displayOptions;
26
dOpts.lineBreaks = true; //books should render with blocks, not with inlined sections
28
CDisplayRendering render(dOpts, filterOptions);
29
CDisplayRendering::KeyTree tree;
30
CDisplayRendering::KeyTreeItem::Settings itemSettings;
32
// the number of levels which should be display together, 1 means display no entries together
33
int displayLevel = book->config( CSwordModuleInfo::DisplayLevel ).toInt();
35
boost::scoped_ptr<CSwordTreeKey> key (
36
dynamic_cast<CSwordTreeKey*>( CSwordKey::createInstance(book) )
38
key->key(keyName); //set the key to position we'd like to get
40
const unsigned long offset = key->getOffset();
42
// standard of DisplayLevel, display nothing together
43
// if the current key is the root entry don't display anything together!
45
if ((displayLevel <= 1) || (key->key().isEmpty() || (key->key() == "/") )) {
46
tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
48
const QString renderedText = render.renderKeyTree(tree);
49
key->setOffset( offset );
51
qDeleteAll(tree); // Dispose of the heap allocated objects pointed to in tree.
56
* Check whether displaying displayLevel levels together is possible.
57
* For this count the childs and parents
58
* of the required position
61
int possibleLevels = 1; //we start with the default value of displayLevel, which means no entries together
63
while ( key->parent() && (key->key() != "/") && !key->key().isEmpty() ) {//add parents
67
// key->key(keyName); //set the key to the start position
69
key->setOffset( offset );
71
while ( key->firstChild( )) { //add childs
75
if (possibleLevels < displayLevel) { //too few levels available!
76
//display current level, we could also decide to display the available levels together
77
tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
79
const QString renderedText = render.renderKeyTree(tree);
80
key->setOffset( offset );
81
qDeleteAll(tree); // Dispose of the heap allocated objects pointed to in tree.
85
if ((displayLevel > 2) && (displayLevel == possibleLevels)) { //fix not to diplay the whole module
89
// at this point we're sure that we can display the required levels toogether
90
// at the moment we're at the lowest level, so we only have to go up!
91
for (int currentLevel = 1; currentLevel < displayLevel; ++currentLevel) { //we start again with 1 == standard of displayLevel
93
if ( !key->parent() ) { //something went wrong although we checked before! Be safe and return entry's text
94
tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
96
const QString renderedText = render.renderKeyTree(tree);
97
key->setOffset( offset );
98
qDeleteAll(tree); // Dispose of the heap allocated objects pointed to in tree.
103
// no we can display all sub levels together! We checked before that this is possible!
104
itemSettings.highlight = (key->key() == keyName);
106
tree.append( new CDisplayRendering::KeyTreeItem( key->key(), modules, itemSettings ) );
108
//const bool hasToplevelText = !key->strippedText().isEmpty();
109
key->firstChild(); //go to the first sibling on the same level
111
setupRenderTree(key.get(), &tree, keyName);
113
const QString renderedText = render.renderKeyTree(tree);
115
key->setOffset( offset ); //restore key
117
qDeleteAll(tree); // Dispose of the heap allocated objects pointed to in tree.
115
121
void Rendering::CBookDisplay::setupRenderTree(CSwordTreeKey * swordTree, CTextRendering::KeyTree * renderTree, const QString& highlightKey) {
117
const QString key = swordTree->key();
118
const unsigned long offset = swordTree->getOffset();
120
CTextRendering::KeyTreeItem::Settings settings;
121
settings.highlight = (key == highlightKey);
123
CTextRendering::KeyTreeItem* item = new CTextRendering::KeyTreeItem(key, swordTree->module(0), settings );
124
renderTree->append( item );
126
if (swordTree->hasChildren()) { //print tree for the child items
127
swordTree->firstChild();
128
setupRenderTree(swordTree, item->childList(), highlightKey);
129
swordTree->setOffset( offset ); //go back where we came from
132
if (swordTree->nextSibling()) { //print tree for next entry on the same depth
133
setupRenderTree(swordTree, renderTree, highlightKey);
134
swordTree->setOffset( offset ); //return to the value we had at the beginning of this block!
123
const QString key = swordTree->key();
124
const unsigned long offset = swordTree->getOffset();
126
CTextRendering::KeyTreeItem::Settings settings;
127
settings.highlight = (key == highlightKey);
129
CTextRendering::KeyTreeItem* item = new CTextRendering::KeyTreeItem(key, swordTree->module(0), settings );
130
renderTree->append( item );
132
if (swordTree->hasChildren()) { //print tree for the child items
133
swordTree->firstChild();
134
setupRenderTree(swordTree, item->childList(), highlightKey);
135
swordTree->setOffset( offset ); //go back where we came from
138
if (swordTree->nextSibling()) { //print tree for next entry on the same depth
139
setupRenderTree(swordTree, renderTree, highlightKey);
140
swordTree->setOffset( offset ); //return to the value we had at the beginning of this block!