[rkward-cvs] SF.net SVN: rkward: [2170] branches/KDE4_port/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun Nov 4 18:25:15 UTC 2007


Revision: 2170
          http://rkward.svn.sourceforge.net/rkward/?rev=2170&view=rev
Author:   tfry
Date:     2007-11-04 10:25:15 -0800 (Sun, 04 Nov 2007)

Log Message:
-----------
Cleanups and removals of Qt3 support code

Modified Paths:
--------------
    branches/KDE4_port/rkward/misc/rkobjectlistview.cpp
    branches/KDE4_port/rkward/misc/rkobjectlistview.h
    branches/KDE4_port/rkward/robjectbrowser.cpp

Modified: branches/KDE4_port/rkward/misc/rkobjectlistview.cpp
===================================================================
--- branches/KDE4_port/rkward/misc/rkobjectlistview.cpp	2007-11-04 17:13:35 UTC (rev 2169)
+++ branches/KDE4_port/rkward/misc/rkobjectlistview.cpp	2007-11-04 18:25:15 UTC (rev 2170)
@@ -17,21 +17,16 @@
 #include "rkobjectlistview.h"
 
 #include <klocale.h>
-#include <kiconloader.h>
 
-#include <q3popupmenu.h>
-#include <qpixmap.h>
-#include <qimage.h>
 #include <QHelpEvent>
+#include <QMenu>
 
 #include "../rkglobals.h"
 #include "../core/robjectlist.h"
 #include "../core/renvironmentobject.h"
-#include "../core/rfunctionobject.h"
-#include "../core/rkvariable.h"
 #include "../core/rkmodificationtracker.h"
 #include "../settings/rksettingsmoduleobjectbrowser.h"
-#include "../misc/rkcommonfunctions.h"
+
 #include "../debug.h"
 
 RKObjectListView::RKObjectListView (QWidget *parent) : QTreeView (parent) {
@@ -40,10 +35,10 @@
 	settings = new RKObjectListViewSettings (this);
 	setSortingEnabled (true);
 
-	menu = new Q3PopupMenu (this);
-	menu->insertItem (i18n ("Show Objects"), settings->showObjectsMenu ());
-	menu->insertItem (i18n ("Show Fields"), settings->showFieldsMenu ());
-	menu->insertItem (i18n ("Configure Defaults"), this, SLOT (popupConfigure ()));
+	menu = new QMenu (this);
+	menu->addMenu (settings->showObjectsMenu ());
+	menu->addMenu (settings->showFieldsMenu ());
+	menu->addAction (i18n ("Configure Defaults"), this, SLOT (popupConfigure ()));
 }
 
 RKObjectListView::~RKObjectListView () {
@@ -96,7 +91,7 @@
 void RKObjectListView::contextMenuEvent (QContextMenuEvent* event) {
 	RK_TRACE (APP);
 
-	QModelIndex index = indexAt (event->pos ());
+	QModelIndex index = settings->mapToSource (indexAt (event->pos ()));
 	menu_object = static_cast<RObject*> (index.internalPointer ());
 
 	bool suppress = false;
@@ -108,7 +103,7 @@
 void RKObjectListView::initialize () {
 	RK_TRACE (APP);
 
-	setUniformRowHeights (true);		// KDE4: can we do this?
+	setUniformRowHeights (true);
 
 	settings->setSourceModel (RKGlobals::tracker ());
 	setModel (settings);
@@ -145,8 +140,6 @@
 RKObjectListViewSettings::RKObjectListViewSettings (QObject* parent) : QSortFilterProxyModel (parent) {
 	RK_TRACE (APP);
 
-	settings = new State[SettingsCount];
-	settings_default = new bool[SettingsCount];
 	for (int i = 0; i < SettingsCount; ++i) settings_default[i] = true;
 	connect (RKSettings::tracker (), SIGNAL (settingsChanged (RKSettings::SettingsPage)), this, SLOT (globalSettingsChanged (RKSettings::SettingsPage)));
 
@@ -157,8 +150,6 @@
 RKObjectListViewSettings::~RKObjectListViewSettings () {
 	RK_TRACE (APP);
 
-	delete settings;
-	delete settings_default;
 	delete show_fields_menu;
 	delete show_objects_menu;
 }
@@ -207,7 +198,7 @@
 	object = static_cast<RContainerObject*> (object)->findChildByIndex (source_row);
 	RK_ASSERT (object);
 
-	// always show the global evnt
+	// always show the global env
 	if (object->isType (RObject::GlobalEnv)) return true;
 
 	if (settings[ShowObjectsHidden] <= No) {
@@ -252,33 +243,43 @@
 void RKObjectListViewSettings::createContextMenus () {
 	RK_TRACE (APP);
 
-	show_objects_menu = new QMenu (0);
-	insertPopupItem (show_objects_menu, ShowObjectsAllEnvironments, i18n ("All Environments"));
-	insertPopupItem (show_objects_menu, ShowObjectsContainer, i18n ("Objects with children"));
-	insertPopupItem (show_objects_menu, ShowObjectsVariable, i18n ("Variables"));
-	insertPopupItem (show_objects_menu, ShowObjectsFunction, i18n ("Functions"));
-	show_objects_menu->insertSeparator ();
-	insertPopupItem (show_objects_menu, ShowObjectsHidden, i18n ("Hidden Objects"));
+	action_group = new QActionGroup (this);
+	action_group->setExclusive (false);
+	actions[ShowObjectsAllEnvironments] = new QAction (i18n ("All Environments"), action_group);
+	actions[ShowObjectsContainer] = new QAction (i18n ("Objects with children"), action_group);
+	actions[ShowObjectsVariable] = new QAction (i18n ("Variables"), action_group);
+	actions[ShowObjectsFunction] = new QAction (i18n ("Functions"), action_group);
+	actions[ShowObjectsHidden] = new QAction (i18n ("Hidden Objects"), action_group);
+	actions[ShowFieldsType] = new QAction (i18n ("Type"), action_group);
+	actions[ShowFieldsLabel] = new QAction (i18n ("Label"), action_group);
+	actions[ShowFieldsClass] = new QAction (i18n ("Class"), action_group);
+	for (int i = 0; i < SettingsCount; ++i) actions[i]->setCheckable (true);
 
-	show_fields_menu = new QMenu (0);
-	insertPopupItem (show_fields_menu, ShowFieldsType, i18n ("Type"));
-	insertPopupItem (show_fields_menu, ShowFieldsLabel, i18n ("Label"));
-	insertPopupItem (show_fields_menu, ShowFieldsClass, i18n ("Class"));
+	show_objects_menu = new QMenu (i18n ("Show Objects"), 0);
+	show_objects_menu->addAction (actions[ShowObjectsAllEnvironments]);
+	show_objects_menu->addAction (actions[ShowObjectsContainer]);
+	show_objects_menu->addAction (actions[ShowObjectsVariable]);
+	show_objects_menu->addAction (actions[ShowObjectsFunction]);
+	show_objects_menu->addSeparator ();
+	show_objects_menu->addAction (actions[ShowObjectsHidden]);
+
+	show_fields_menu = new QMenu (i18n ("Show Fields"), 0);
+	show_fields_menu->addAction (actions[ShowFieldsType]);
+	show_fields_menu->addAction (actions[ShowFieldsLabel]);
+	show_fields_menu->addAction (actions[ShowFieldsClass]);
+
+	connect (action_group, SIGNAL (triggered(QAction*)), this, SLOT(settingToggled(QAction*)));
+	updateSelf ();
 }
 
 void RKObjectListViewSettings::updateSelf () {
 	RK_TRACE (APP);
 
-	for (int i = 0; i <= ShowObjectsHidden; ++i) {
-		show_objects_menu->setItemChecked (i, settings[(Settings) i] >= Yes);
-		show_objects_menu->setItemEnabled (i, optionConfigurable ((Settings) i));
+	for (int i = 0; i < SettingsCount; ++i) {
+		actions[i]->setChecked (settings[(Settings) i] >= Yes);
+		actions[i]->setEnabled (optionConfigurable ((Settings) i));
 	}
 
-	for (int i = ShowFieldsType; i <= ShowFieldsLabel; ++i) {
-		show_fields_menu->setItemChecked (i, settings[(Settings) i] >= Yes);
-		show_fields_menu->setItemEnabled (i, optionConfigurable ((Settings) i));
-	}
-
 	invalidateFilter ();
 	emit (settingsChanged ());
 }
@@ -306,20 +307,22 @@
 	updateSelf ();
 }
 
-void RKObjectListViewSettings::toggleSetting (int which) {
+void RKObjectListViewSettings::settingToggled (QAction* which) {
 	RK_TRACE (APP);
-	RK_ASSERT (which < SettingsCount);
 
-	if (settings[which] == Yes) {
-		settings[which] = No;
-	} else if (settings[which] == No) {
-		settings[which] = Yes;
-	} else {
+	int setting = -1;
+	for (int i = 0; i < SettingsCount; ++i) {
+		if (actions[i] == which) {
+			setting = i;
+			break;
+		}
+	}
+	if (setting < 0) {
 		RK_ASSERT (false);
+		return;
 	}
-	settings_default[which] = false;
 
-	updateSelf ();
+	setSetting (static_cast<Settings> (setting), which->isChecked () ? Yes : No);
 }
 
 bool RKObjectListViewSettings::optionConfigurable (Settings setting) {

Modified: branches/KDE4_port/rkward/misc/rkobjectlistview.h
===================================================================
--- branches/KDE4_port/rkward/misc/rkobjectlistview.h	2007-11-04 17:13:35 UTC (rev 2169)
+++ branches/KDE4_port/rkward/misc/rkobjectlistview.h	2007-11-04 18:25:15 UTC (rev 2170)
@@ -19,17 +19,14 @@
 
 #include <QTreeView>
 #include <QSortFilterProxyModel>
-#include <qtooltip.h>
-#include <qmap.h>
-#include <Q3PopupMenu>
 
 #include "../settings/rksettings.h"
 #include "../core/robject.h"
 
-class QPixmap;
-class Q3PopupMenu;
+class QMenu;
 class RKListViewItem;
 class RKObjectListViewSettings;
+class QActionGroup;
 
 /**
 This class provides the common functionality for the tree views in the RObjectBrowser and RKVarselector(s). The caps it (will) provide are: keeping the list up to date and emitting change-signals when appropriate, filtering for certain types of objects, sorting, mapping items to objects. Maybe some GUI-stuff like popup-menus should also be added to this class?
@@ -46,7 +43,7 @@
 /** This function returns a pointer to the context menu of the RKObjectListView. It is provided so you can add your own items.
 @returns a pointer to the context menu
 @see aboutToShowContextMenu */
-	Q3PopupMenu *contextMenu () { return menu; };
+	QMenu *contextMenu () { return menu; };
 /** This function returns the RObject the context menu has last been invoked on (or 0 if not invoked on an RObject). You can use this in slots called
 from your custom menu items, to figure out, which object you should operate on. */
 	RObject *menuObject () const { return menu_object; };
@@ -74,7 +71,7 @@
 protected:
 	void contextMenuEvent (QContextMenuEvent* event);
 private:
-	Q3PopupMenu *menu;
+	QMenu *menu;
 	RObject *menu_object;
 
 	RKObjectListViewSettings *settings;
@@ -90,16 +87,18 @@
 
 	enum Settings {
 		ShowObjectsVariable=0,
-		ShowObjectsAllEnvironments=1,
-		ShowObjectsFunction=2,
-		ShowObjectsContainer=3,
-		ShowObjectsHidden=4,
-		ShowFieldsType=5,
-		ShowFieldsClass=6,
-		ShowFieldsLabel=7,
-		SettingsCount=8
+		ShowObjectsAllEnvironments,
+		ShowObjectsFunction,
+		ShowObjectsContainer,
+		ShowObjectsHidden,
+		ShowFieldsType,
+		ShowFieldsClass,
+		ShowFieldsLabel,
+		SettingsCount=ShowFieldsLabel + 1
 	};
 
+	//KDE 4: TODO: do we really need non-configurable settings? Changing this to only Yes/No would allow
+	// for considerable simplifications
 	enum State {
 		Never,
 		No,
@@ -120,14 +119,16 @@
 	void settingsChanged ();
 public slots:
 	void globalSettingsChanged (RKSettings::SettingsPage);
-	void toggleSetting (int which);
+	void settingToggled (QAction* which);
 protected:
 	bool filterAcceptsRow (int source_row, const QModelIndex& source_parent) const;
 	bool filterAcceptsColumn (int source_column, const QModelIndex& source_parent) const;
 	bool lessThan (const QModelIndex& left, const QModelIndex& right) const;
 private:
-	State *settings;
-	bool *settings_default;
+	State settings[SettingsCount];
+	QAction* actions[SettingsCount];
+	QActionGroup* action_group;
+	bool settings_default[SettingsCount];
 	void insertPopupItem (QMenu *menu, Settings setting, const QString &text);
 	void createContextMenus ();
 	void updateSelf ();

Modified: branches/KDE4_port/rkward/robjectbrowser.cpp
===================================================================
--- branches/KDE4_port/rkward/robjectbrowser.cpp	2007-11-04 17:13:35 UTC (rev 2169)
+++ branches/KDE4_port/rkward/robjectbrowser.cpp	2007-11-04 18:25:15 UTC (rev 2170)
@@ -119,6 +119,7 @@
 	
 	setCaption (i18n ("Objects in the R workspace"));
 
+// KDE4: TODO: insertItem is Qt3. Use addAction instead.
 	list_view->contextMenu ()->insertItem (i18n ("Search Help"), this, SLOT (popupHelp ()), 0, Help, 0);
 	list_view->contextMenu ()->insertItem (i18n ("Edit"), this, SLOT (popupEdit ()), 0, Edit, 1);
 	list_view->contextMenu ()->insertItem (i18n ("View"), this, SLOT (popupView ()), 0, View, 2);
@@ -218,7 +219,7 @@
 void RObjectBrowserInternal::contextMenuCallback (RObject *, bool *) {
 	RK_TRACE (APP);
 	RObject *object = list_view->menuObject ();
-	Q3PopupMenu *menu = list_view->contextMenu ();
+	QMenu *menu = list_view->contextMenu ();
 
 	if (!object) {
 		menu->setItemVisible (Help, false);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list