1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file KwBibleModule.cpp
22 * @brief An abstract bible module (analagous to a SWORD module).
23 * @author James Hogan <james@albanarts.com>
26 #include "KwBibleModule.h"
29 * Constructors + destructor
32 /// Default constructor.
33 KwBibleModule::KwBibleModule()
39 KwBibleModule::~KwBibleModule()
47 /// Create a key from a string.
48 KwBibleModule::Key
KwBibleModule::createKey(const QString
& text
)
51 //Key key = { { -1, -1, -1 },
53 Key key
= { { 0, 1, 1 },
58 /// Create a key from individual values.
59 KwBibleModule::Key
KwBibleModule::createKey(const QString
& book
, int chapter
, int verse
)
61 int bookId
= bookIndex(book
);
62 Key key
= { { bookId
, chapter
, verse
},
67 /// Create a range key between two verses in the same chapter.
68 KwBibleModule::Key
KwBibleModule::createKey(const QString
& book
, int chapter
, int verseStart
,
71 int bookId
= bookIndex(book
);
72 Key key
= { { bookId
, chapter
, verseStart
},
73 { bookId
, chapter
, verseEnd
} };
77 /// Create a range key between two verses in different chapters.
78 KwBibleModule::Key
KwBibleModule::createKey(const QString
& book
, int chapterStart
, int verseStart
,
79 int chapterEnd
, int verseEnd
)
81 int bookId
= bookIndex(book
);
82 Key key
= { { bookId
, chapterStart
, verseStart
},
83 { bookId
, chapterEnd
, verseEnd
} };
87 /// Create a range key between two verses in different books.
88 KwBibleModule::Key
KwBibleModule::createKey(const QString
& bookStart
, int chapterStart
, int verseStart
,
89 const QString
& bookEnd
, int chapterEnd
, int verseEnd
)
91 int bookIdStart
= bookIndex(bookStart
);
92 int bookIdEnd
= bookIndex(bookEnd
);
93 Key key
= { { bookIdStart
, chapterStart
, verseStart
},
94 { bookIdEnd
, chapterEnd
, verseEnd
} };
98 /// List the books in this module.
99 const QStringList
& KwBibleModule::books()
101 if (m_books
.isEmpty())
108 /// Get the index of a book from it's name.
109 int KwBibleModule::bookIndex(const QString
& name
)
111 if (m_books
.isEmpty())
115 return m_books
.indexOf(name
);
118 /// Get the name of a book from it's index.
119 QString
KwBibleModule::bookName(int book
)
121 if (m_books
.isEmpty())
125 if (book
>= 0 && book
< m_books
.size())
127 return m_books
[book
];
136 * Protected virtual interface
139 /// Ensure that the book list is up to date.
140 void KwBibleModule::obtainBooks()
145 * Protected interface
148 /// Update the list of books.
149 void KwBibleModule::setBooks(const QStringList
& books
)