[bt-devel] Saving Search Analysis To Disk

Joachim Ansorg bt-devel@crosswire.org
Tue, 26 Jun 2001 20:21:12 +0200


Hi!

It's my task as administrator to help you as far as I can. And it's my messy 
code ;)

> I am now trying to modify bibletime to allow a user to save the search
> analysis to the disk.  However I have encountered some code that I do not
> really understand.  It is from csearchdialoganalysis.cpp and I will list it
> below.

> I know that count is the number of times the search criteria appears in the
> module.  However, I do not know what represents the "book" that is being
> searched through.  

I think you want an explanation of this section:

[...]
analysisItem->setCountForModule(moduleIndex, (count = 
getCount(key.book(),m_moduleList.current())));
[...]

moduleIndex is the number of the used book.
m_moduleList.current() is the currently used module.

> I had planned on adding code to the end of the main loop
> that would take the "book" name that is being searched through, write it to
> a file, insert a tab in the file, and then write the number of occurrences
> in that book.  For example,
>
> John	8
> Acts 	9
> etc...

I would not add it at the end of the main loop because the user does not want 
a file with the searchanalysis-result everytime he starts a search (the 
analysis is executed everytime the search is finished).

I would add a new public slot (maybe "void 
CSearchDialogAnalysis::saveResultAsText()" ?) which saves the result in the 
text file. The slot should be connected to a button "Save result as text..." .
Is this reasonable?
The task is now to solve the problem you mentioned above ("how may I get the 
books and number of found items of each book?").

Please have a look at CSearchDialogAnylsisItem, it is a small QCanvasItem 
which holds the information about one book (e.g. Genesis with the number of 
found items for Genesis). The member variables for this are
	QString m_bookName; //the used bookname, e.g. Genesis or Exodus
and
 	QArray<int> m_resultCountArray; //holds the number of found items for the 
different modules

If it is my task I would add a new function in CSearchDialogAnalysisItem to 
get the number of found items (e.g. "const int getCount( CSwordModuleInfo* 
module)").
Use the member ListCSwordModuleInfo* m_moduleList; of the CSearchDialogItem 
class to get the index of the desired module in the list and then use the 
member m_resultCountArray (see above) to get the cound for the module.

Now you know how to get the count of the modules for one book. The question 
is now "How do I get a list of available books?". 

In CSearchDialogAnalysis::analyse I used this code:

// create a key without a module -> we do only want parsing functions like 
// NextBook() etc.
	CSwordVerseKey key(0); 
	key.key("Genesis 1:1"); //set first book of bible
//a loop to get all books	
	CSearchDialogAnalysisItem* analysisItem = m_canvasItemList[key.book()]; 
//get the item for the desired book
	bool ok = true;
	while (ok && analysisItem) {
		for (moduleIndex = 0,m_moduleList.first(); m_moduleList.current(); 
m_moduleList.next(),++moduleIndex) {
			//get here the count for the current module and boook
		}
		
		ok = key.NextBook(); //next book of the Bible
//get the correct canvas item for this
	   	analysisItem = m_canvasItemList[key.book()]; 
	}
	
I hope you can now solve the problem. I'ts hard to get started with totally 
new GUI stuff in a short time.

I would add the button in CSearchDialog::initView into the 
searchanalysis_page using a QButtonGroup widget. A QButtonGroup because new 
buttons may be added later.

> I thought about using regular fstream to do it, but since we are using a
> KDE application I think it would be better to use kfile to write the
> information to the file.  Unfortunately I have never dealt with any of this
> before so it is doing to be a learning experience also.  Any hints, tips,
> suggestions, etc... would be greatly appreciated.

Use QFile :)
KDE is based on Qt, so it's ok to use Qt classes.

Have a look into the Qt API documentation and read the documentation for the 
classes QFile.
Please have also a look into 
CSearchDialogResultModuleView::slotSaveSearchResult(). This function saves 
text into a file.
Basically it uses the functions CToolClass::getSaveFileName(...);
and CToolClass::savePlainFile(...);

CToolClass is one of our classes. Have a look into it's function to know 
howto use QFile, QFileDialog and KFileDialog.

If you other questions please ask us!


BTW, if you want to implement saving the search analysis as an image try to 
use something like QPainter::redirect.
But I'm not sure if saving the analysis as an image is possible with the 
QCanvas engine.

Joachim