[sword-devel] Understanding the structure of generic books and their relationship with TreeKey.

Rendezvous junk_and_mail at yahoo.com
Mon Nov 2 21:09:09 MST 2009


--- On Sun, 11/1/09, Greg Hellings <greg.hellings at gmail.com> wrote:

> From: Greg Hellings <greg.hellings at gmail.com>
> Subject: Re: [sword-devel] Understanding the structure of generic books and their relationship with TreeKey.
> To: "SWORD Developers' Collaboration Forum" <sword-devel at crosswire.org>
> Date: Sunday, November 1, 2009, 5:33 PM
> Rendezvous,
> 
> On Sun, Nov 1, 2009 at 4:01 PM, Rendezvous <junk_and_mail at yahoo.com>
> wrote:
> > Through browsing through some source code i've managed
> to figure out that you need to convert a SWKey
> (SWModule::getKey()) to a TreeKey to be able to iterate
> through the sections/chapters of a GenBook. However, i have
> yet to figure out how to obtain the children for each
> section/chapter. Rather than taking a guess with trial and
> error and searching through more Sword frontends' source
> code, i would prefer to have a _full_ understanding on how
> Sword handles GenBooks and how frontends can make use of
> those methods.
> >
> > My questions: Is TreeKey the only way to obtain the
> sections/chapters of a Genbook? And how do i get a list of
> the children for each section/chapter? Am i right to assume
> that i have to use SWModule::setKey() to set the current key
> to one of the root sections and then  re-cast
> SWModule::getKey() to a TreeKey and iterate through that? Or
> is another method required?
> >
> >
> 
> You might want to look into the documentation on
> http://www.crosswire.org/~ghellings/1_6_0classdocs/ for
> version 1.6.0
> of the engine.  Particularly look under
> TreeKey::firstChild() and
> TreeKey::nextSibling/previousSibling.
> 
> --Greg
> 

The code i was using already made use of those methods. However, i could go down no further than the root level. I am wondering how to obtain the children for the keys i've only been able to get. Here's is the current, relevant part of the code i am using:
//
{
	QList<DSword::TreeNode> sectionsList;
	sword::TreeKey *tk = dynamic_cast<sword::TreeKey*>(swModule->getKey());
	if (tk->firstChild())
	{
		while (tk->nextSibling())
		{
			DSword::TreeNode node;
			node.name = tk->getText();
			node.parent = NULL;
			sectionsList << node;
		}
	}
	return sectionsList;
}
//

Let's say i load the English GenBook, "Immitation." I only get the following:
/Foreword
/Book 1
/Book 2
/Book 3
/Book 4
though the last four have children. Trying to figure out how to obtain the children through trial and error have so far led me no where.


      



More information about the sword-devel mailing list