[bt-devel] Nikolay: C++ design question

Nikolay Igotti bt-devel@crosswire.org
Mon, 16 Sep 2002 13:53:19 -0700 (PDT)


On Mon, 16 Sep 2002, Joachim Ansorg wrote:
> I have a C++ question for you.
 First of all I'm mainly C programmer :) - anyway I'll try to help.

> 
> I want to create a new class called CHelpMgr which manages the Tooltip and 
> WhatsThis? help texts for all the GUI parts of BibleTime. We're using ugly 
> #defines at the moment! This is really bad!
 Good idea! 

> e.g. the user should be able to use something like this:
> 	const QString myTooltip = CHelpMgr::tooltip( CHelpMgr::mainMenu.file.quit );
> or like
> 	const QString myTooltip = CHelpMgr::tooltip( CHelpMgr::searchDialog.start );
> 
> How do I create such a tree-like structure? I have no idea since I don't know 
> C++ well enough. I'd be glad to get some help with this!
 Several solutions comes to mind.
1. Use integer #define'ed id's, like this
#define MAIN_MENU_FILE_QUIT 100

And in separate file keep pais like this:
100|Quit Bibletime|Select this menu item to quit BibleTime
This file could help us with i18n. BTW, how other KDE programs do it?

2. Hashtables (i.e.  Java-like properties)
 The same as before, but keys are strings instead of ints, 
so it'll be like this
 const QString myTooltip = CHelpMgr::tooltip("mainMenu.file.quit");
And in separate resourse file - have similar mappings. 

 Really I don't think you need hardcore C++ to acomplish this task, it's 
doable with normal structures.


 Thanks,
   Nikolay.