[rkward-cvs] rkward/rkward/misc multistringselector.cpp,1.1,1.2 multistringselector.h,1.1,1.2 rkmenu.cpp,1.3,1.4 rkmenu.h,1.3,1.4 rkmenulist.cpp,1.2,1.3 rkmenulist.h,1.2,1.3

Thomas Friedrichsmeier tfry at users.sourceforge.net
Sun Sep 11 18:53:06 UTC 2005


Update of /cvsroot/rkward/rkward/rkward/misc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23838/rkward/misc

Modified Files:
	multistringselector.cpp multistringselector.h rkmenu.cpp 
	rkmenu.h rkmenulist.cpp rkmenulist.h 
Log Message:
Finish restructuring plugin-hierarchy creation. Allow to select several .pluginmap files in Settings->Configure RKWard. Some fixes and cleanups

Index: multistringselector.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/multistringselector.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** multistringselector.h	9 Sep 2005 23:14:56 -0000	1.1
--- multistringselector.h	11 Sep 2005 18:53:04 -0000	1.2
***************
*** 26,30 ****
  class QPushButton;
  
! /** This convenience widget allows to select one or more strings (e.g. filenames) and sort them in any order. The function to acutally select a new string to add to the selection is not implemented in this class for more flexibility. Rather, connect to the getNewString () signal and assign the desired QString in a custom slot.
  
  @author Thomas Friedrichsmeier
--- 26,30 ----
  class QPushButton;
  
! /** This convenience widget allows to select one or more strings (e.g. filenames) and sort them in any order. The function to acutally select new strings to add to the selection is not implemented in this class for more flexibility. Rather, connect to the getNewStrings () signal and assign the desired QString(s) in a custom slot.
  
  @author Thomas Friedrichsmeier
***************
*** 54,59 ****
  	QPushButton* down_button;
  signals:
! /** This signal is triggered, when the "Add"-button is pressed. Connect to this to your custom slot, and change the string. If you don't touch the string or set it to empty, nothing will be added to the list. Of course it does not make much sense to connect multiple slots to this signal, as only the last one called would be effective. */
! 	void getNewString (QString *string);
  };
  
--- 54,61 ----
  	QPushButton* down_button;
  signals:
! /** This signal is triggered, when the "Add"-button is pressed. Connect to this to your custom slot, and add strings to the (empty) string_list. If you don't touch the string_list or set it to empty, nothing will be added to the list. Of course it does not make much sense to connect multiple slots to this signal, as only the last one called would be effective. */
! 	void getNewStrings (QStringList *string_list);
! /** emitted whenever there is a change in the user selection */
! 	void listChanged ();
  };
  

Index: rkmenulist.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkmenulist.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** rkmenulist.h	9 Sep 2005 13:02:57 -0000	1.2
--- rkmenulist.h	11 Sep 2005 18:53:04 -0000	1.3
***************
*** 26,30 ****
  
  /**
! This class holds the entries in the menu-bar. Together with RKMenu it is used to identify where dynamically generated entries should go in the menu-hierarchy.
  
  @author Thomas Friedrichsmeier
--- 26,33 ----
  
  /**
! This class holds the entries in the menu-bar. Together with RKMenu it is used to identify where dynamically generated entries should go in the menu-hierarchy. I.e. the most important function is to identify, when we try to create a menu with the same id as an already existing one. In this case,
! instead of creating a new menu, the old one is returned.
! 
! In contrast to RKMenu, the RKMenuList is associated with the menu-bar, not a single menu.
  
  @author Thomas Friedrichsmeier
***************
*** 36,42 ****
      ~RKMenuList ();
  /** register an existing QPopupMenu in the menu-list, giving it the identifier tag "id". If a menu by that id already exists, no new menu will be created,
! but rather the corresponding RKMenu will be returned. */
  	RKMenu *registerMenu (QPopupMenu *qmenu, const QString &id);
! /** like registerMenu, except that a new QPopupMenu is created with the given label. */
  	RKMenu *createMenu (const QString &id, const QString &label, int index);
  /** clears all menus created via RKMenuList */
--- 39,47 ----
      ~RKMenuList ();
  /** register an existing QPopupMenu in the menu-list, giving it the identifier tag "id". If a menu by that id already exists, no new menu will be created,
! but rather the corresponding RKMenu will be returned. This function can be used to give access to a pre-existing menu (i.e. one that has been created
! by static rather than dynamic methods, such as the "File"-menu). */
  	RKMenu *registerMenu (QPopupMenu *qmenu, const QString &id);
! /** create a new Menu with given id, label and at the given index. If a menu by that id is already known, no menu is actually created, but
! rather a pointer to the existing menu gets returned. */
  	RKMenu *createMenu (const QString &id, const QString &label, int index);
  /** clears all menus created via RKMenuList */
***************
*** 46,49 ****
--- 51,55 ----
  	MenuMap menu_map;
  	
+ 	QValueList<int> created_menu_ids;
  	QMenuBar *menu_bar;
  };

Index: rkmenu.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkmenu.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rkmenu.h	27 Aug 2004 10:17:35 -0000	1.3
--- rkmenu.h	11 Sep 2005 18:53:04 -0000	1.4
***************
*** 28,54 ****
  class QDomElement;
  
! /**
    *@author Thomas Friedrichsmeier
    */
  
  class RKMenu {
! public: 
! 	~RKMenu();
  /** adds a new submenu to this menu at the given index. If a menu with the given tag already exists, that menu will be returned, so entries can be merged (and the index will be ignored) */
  	RKMenu *addSubMenu (const QString &id, const QString &label, int index=-1);
  /** adds a new plugin to this menu at the given index. If a plugin with the given tag already exists, it will be deleted and overwritten, i.e. replaced with the newer plugin */
  	void addEntry (const QString &id, RKPluginHandle *plugin, const QString &label, int index=-1);
- protected:
- 	RKMenu ();
  private:
- friend class RKMenuList;
- 	RKMenu *createSubMenu ();
- /** TODO: Probably we neither need to keep the tag, nor is_top_level. */
  	QMap<QString, int> submenu_ids;
  	QMap<int, RKMenu*> submenus;
  	QMap<QString, int> entry_ids;
- 	QMap<int, RKPluginHandle*> entry_plugins;
  /** the associated menu, the entries get placed in */
  	QPopupMenu *menu;
  };
  
--- 28,56 ----
  class QDomElement;
  
! /** The purpose of this class is to attach some additional information to a QPopupMenu, needed to create and delete dynamic menu-entries. See RKMenuList for more detailed information.
    *@author Thomas Friedrichsmeier
    */
  
  class RKMenu {
! public:
! /** create a new RKMenu. If pre_existing==false, when the RKMenu gets deleted, the corresponding QPopupMenu will be deleted as well
! Use this for menus that are entirely dynamically created.
! 
! If pre_existing==true, when the RKMenu gets deleted, this QPopupMenu will continue to live. Use this for pre-existing menus that only contain some dynamic items. */
! 	RKMenu (QPopupMenu *menu, bool pre_existing=false);
! /** destructor */
! 	~RKMenu ();
  /** adds a new submenu to this menu at the given index. If a menu with the given tag already exists, that menu will be returned, so entries can be merged (and the index will be ignored) */
  	RKMenu *addSubMenu (const QString &id, const QString &label, int index=-1);
  /** adds a new plugin to this menu at the given index. If a plugin with the given tag already exists, it will be deleted and overwritten, i.e. replaced with the newer plugin */
  	void addEntry (const QString &id, RKPluginHandle *plugin, const QString &label, int index=-1);
  private:
  	QMap<QString, int> submenu_ids;
  	QMap<int, RKMenu*> submenus;
  	QMap<QString, int> entry_ids;
  /** the associated menu, the entries get placed in */
  	QPopupMenu *menu;
+ /** whether the QPopupMenu should be deleted along with the RKMenu. See constructor. */
+ 	bool delete_q_menu;
  };
  

Index: rkmenu.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkmenu.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rkmenu.cpp	27 Aug 2004 10:17:35 -0000	1.3
--- rkmenu.cpp	11 Sep 2005 18:53:04 -0000	1.4
***************
*** 25,49 ****
  #include "../debug.h"
  
! RKMenu::RKMenu () {
  	RK_TRACE (MISC);
  }
  
  RKMenu::~RKMenu() {
  	RK_TRACE (MISC);
  	for (QMap<int, RKMenu*>::iterator it = submenus.begin (); it != submenus.end (); ++it) {
  		delete it.data ();
  	}
- 	for (QMap<int, RKPluginHandle*>::iterator it = entry_plugins.begin (); it != entry_plugins.end (); ++it) {
- 		delete it.data ();
- 	}
- }
  
! RKMenu *RKMenu::createSubMenu () {
! 	RK_TRACE (MISC);
! 	QPopupMenu *qmenu = new QPopupMenu (menu);
! 	RKMenu *ret = new RKMenu ();
! 	ret->menu = qmenu;
! 	
! 	return ret;
  }
  
--- 25,51 ----
  #include "../debug.h"
  
! RKMenu::RKMenu (QPopupMenu *menu, bool pre_existing) {
  	RK_TRACE (MISC);
+ 
+ 	RKMenu::menu = menu;
+ 	delete_q_menu = !pre_existing;
  }
  
  RKMenu::~RKMenu() {
  	RK_TRACE (MISC);
+ 
  	for (QMap<int, RKMenu*>::iterator it = submenus.begin (); it != submenus.end (); ++it) {
+ 		menu->removeItem (it.key ());
  		delete it.data ();
  	}
  
! 	if (delete_q_menu) {
! 		delete menu;
! 	} else{
! 		// delete the dynamically created entries
! 		for (QMap<QString, int>::iterator it = entry_ids.begin (); it != entry_ids.end (); ++it) {
! 			menu->removeItem (it.data ());
! 		}
! 	}
  }
  
***************
*** 53,57 ****
  	RKMenu *ret;
  	if (submenu_ids.find (id) == submenu_ids.end ()) {
! 		ret = createSubMenu ();
  		mid = menu->insertItem (label, ret->menu, -1, index);
  	} else {
--- 55,59 ----
  	RKMenu *ret;
  	if (submenu_ids.find (id) == submenu_ids.end ()) {
! 		ret = new RKMenu (new QPopupMenu (menu, false));
  		mid = menu->insertItem (label, ret->menu, -1, index);
  	} else {
***************
*** 73,81 ****
  	} else {
  		mid = entry_ids[id];
- 		delete entry_plugins[mid];
  		menu->removeItem (mid);
  		mid = menu->insertItem (label, plugin, SLOT (activated ()), 0, mid, index);
  	}
- 	entry_plugins.insert (mid, plugin);
  	entry_ids.insert (id, mid);
  }
--- 75,81 ----

Index: multistringselector.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/multistringselector.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** multistringselector.cpp	9 Sep 2005 23:14:56 -0000	1.1
--- multistringselector.cpp	11 Sep 2005 18:53:04 -0000	1.2
***************
*** 96,99 ****
--- 96,100 ----
  	}
  	listSelectionChanged ();
+ 	emit (listChanged ());
  }
  
***************
*** 101,110 ****
  	RK_TRACE (MISC);
  
! 	QString new_string;
! 	emit (getNewString (&new_string));
! 	if (!new_string.isEmpty ()) {
  		QListViewItem *item = new QListViewItem (list_view, list_view->lastItem ());
! 		item->setText (0, new_string);
  	}
  	listSelectionChanged ();		// update button states
  }
--- 102,112 ----
  	RK_TRACE (MISC);
  
! 	QStringList new_strings;
! 	emit (getNewStrings (&new_strings));
! 	for (QStringList::const_iterator it = new_strings.begin (); it != new_strings.end (); ++it) {
  		QListViewItem *item = new QListViewItem (list_view, list_view->lastItem ());
! 		item->setText (0, (*it));
  	}
+ 	emit (listChanged ());
  	listSelectionChanged ();		// update button states
  }
***************
*** 114,117 ****
--- 116,120 ----
  
  	delete (list_view->selectedItem ());
+ 	emit (listChanged ());
  }
  
***************
*** 123,126 ****
--- 126,130 ----
  
  	sel->moveItem (sel->itemAbove ());
+ 	emit (listChanged ());
  }
  
***************
*** 132,135 ****
--- 136,140 ----
  
  	if (sel->nextSibling ()) sel->moveItem (sel->nextSibling ());
+ 	emit (listChanged ());
  }
  

Index: rkmenulist.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkmenulist.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** rkmenulist.cpp	9 Sep 2005 13:02:57 -0000	1.2
--- rkmenulist.cpp	11 Sep 2005 18:53:04 -0000	1.3
***************
*** 36,42 ****
--- 36,50 ----
  void RKMenuList::clear () {
  	RK_TRACE (MISC);
+ 
+ 	for (QValueList<int>::const_iterator it = created_menu_ids.begin (); it != created_menu_ids.end (); ++it) {
+ 		menu_bar->removeItem (*it);
+ 	}
+ 	created_menu_ids.clear ();
+ 
  	for (MenuMap::iterator it = menu_map.begin (); it != menu_map.end (); ++it) {
  		delete it.data ();
  	}
+ 
+ 	menu_map.clear ();
  }
  
***************
*** 45,50 ****
  	RKMenu *ret;
  	if (menu_map.find (id) == menu_map.end ()) {
! 		ret = new RKMenu ();
! 		ret->menu = qmenu;
  		menu_map.insert (id, ret);
  	} else {
--- 53,57 ----
  	RKMenu *ret;
  	if (menu_map.find (id) == menu_map.end ()) {
! 		ret = new RKMenu (qmenu, true);
  		menu_map.insert (id, ret);
  	} else {
***************
*** 58,65 ****
  	RKMenu *ret;
  	if (menu_map.find (id) == menu_map.end ()) {
- 		ret = new RKMenu ();
  		QPopupMenu *qmenu = new QPopupMenu (menu_bar);
! 		menu_bar->insertItem (label, qmenu, -1, index);
! 		ret->menu = qmenu;
  		menu_map.insert (id, ret);
  	} else {
--- 65,71 ----
  	RKMenu *ret;
  	if (menu_map.find (id) == menu_map.end ()) {
  		QPopupMenu *qmenu = new QPopupMenu (menu_bar);
! 		created_menu_ids.append (menu_bar->insertItem (label, qmenu, -1, index));
! 		ret = new RKMenu (qmenu, false);
  		menu_map.insert (id, ret);
  	} else {





More information about the rkward-tracker mailing list