[rkward-cvs] SF.net SVN: rkward: [805] trunk/rkward/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Oct 4 15:00:01 UTC 2006


Revision: 805
          http://svn.sourceforge.net/rkward/?rev=805&view=rev
Author:   tfry
Date:     2006-10-04 07:59:55 -0700 (Wed, 04 Oct 2006)

Log Message:
-----------
Add configuration options to RKListView. Not complete, and still buggy

Modified Paths:
--------------
    trunk/rkward/rkward/misc/rkobjectlistview.cpp
    trunk/rkward/rkward/misc/rkobjectlistview.h
    trunk/rkward/rkward/plugin/rkcomponentproperties.cpp

Modified: trunk/rkward/rkward/misc/rkobjectlistview.cpp
===================================================================
--- trunk/rkward/rkward/misc/rkobjectlistview.cpp	2006-10-04 12:23:50 UTC (rev 804)
+++ trunk/rkward/rkward/misc/rkobjectlistview.cpp	2006-10-04 14:59:55 UTC (rev 805)
@@ -53,13 +53,16 @@
 	addColumn (i18n("Label"));
 	addColumn (i18n("Type"));
 	addColumn (i18n("Class"));
+	settings = new RKObjectListViewSettings ();
+	connect (settings, SIGNAL (settingsChanged ()), this, SLOT (objectBrowserSettingsChanged ()));
 
 	menu = new QPopupMenu (this);
-	menu->insertItem (i18n ("Configure View"), this, SLOT (popupConfigure ()));
+	menu->insertItem (i18n ("Show Objects"), settings->showObjectsMenu ());
+	menu->insertItem (i18n ("Show Fields"), settings->showFieldsMenu ());
+	menu->insertItem (i18n ("Configure Defaults"), this, SLOT (popupConfigure ()));
 	connect (this, SIGNAL (contextMenuRequested (QListViewItem *, const QPoint &, int)), this, SLOT (requestedContextMenu (QListViewItem*, const QPoint&, int)));
 
 	objectBrowserSettingsChanged ();
-	connect (RKSettings::tracker (), SIGNAL (objectBrowserSettingsChanged ()), this, SLOT (objectBrowserSettingsChanged ()));
 }
 
 RKObjectListView::~RKObjectListView () {
@@ -67,10 +70,9 @@
 }
 
 void RKObjectListView::objectBrowserSettingsChanged () {
-	setColumnWidth (0, 50);
 	setColumnWidthMode (0, QListView::Maximum);
 	if (RKSettingsModuleObjectBrowser::showLabelField ()) {
-		setColumnWidth (1, 50);
+		if (columnWidth (1) == 0) setColumnWidth (1, 50);
 		setColumnWidthMode (1, QListView::Maximum);
 	} else {
 		setColumnWidthMode (1, QListView::Manual);
@@ -78,7 +80,7 @@
 	}
 
 	if (RKSettingsModuleObjectBrowser::showTypeField ()) {
-		setColumnWidth (2, 50);
+		if (columnWidth (2) == 0) setColumnWidth (2, 50);
 		setColumnWidthMode (2, QListView::Maximum);
 	} else {
 		setColumnWidthMode (2, QListView::Manual);
@@ -86,7 +88,7 @@
 	}
 
 	if (RKSettingsModuleObjectBrowser::showClassField ()) {
-		setColumnWidth (3, 50);
+		if (columnWidth (3) == 0) setColumnWidth (3, 50);
 		setColumnWidthMode (3, QListView::Maximum);
 	} else {
 		setColumnWidthMode (3, QListView::Manual);
@@ -99,7 +101,7 @@
 		RObject *object = findItemObject (static_cast<RKListViewItem*> (it.current ()));
 		RK_ASSERT (object);
 
-		if (object->getFullName ().startsWith (".")) it.current ()->setVisible (RKSettingsModuleObjectBrowser::showHiddenVars ());
+		it.current ()->setVisible (settings->shouldShowObject (object));
 	}
 }
 
@@ -255,10 +257,7 @@
 		item->setPixmap (0, *environment);
 	}
 
-	if (!RKSettingsModuleObjectBrowser::showHiddenVars ()) {
-		// if the object is hidden, it shouldn't appear
-		if (object->getFullName ().startsWith (".")) item->setVisible (false);
-	}
+	if (!settings->shouldShowObject (object)) item->setVisible (false);
 }
 
 void RKObjectListView::addObject (RKListViewItem *parent, RObject *object, bool recursive) {
@@ -282,8 +281,6 @@
 		}
 	}
 
-
-	
 // special treatment for the workspace object
 	if (!parent) {
 		item->setPixmap (0, SmallIcon("view_tree"));
@@ -293,7 +290,9 @@
 
 	if (!RKSettingsModuleObjectBrowser::showHiddenVars ()) {
 		// if the object is hidden, it shouldn't appear
-		if (object->getFullName ().startsWith (".")) item->setVisible (false);
+		if (!object->isType (RObject::GlobalEnv)) {
+			if (object->getShortName ().startsWith (".")) item->setVisible (false);
+		}
 	}
 
 // code below won't work, as objects get added before editor is opened. Need to call from RKEditor(Manager)
@@ -321,4 +320,151 @@
 	return ret;
 }
 
+
+//////////////////// RKObjectListViewSettings //////////////////////////
+
+RKObjectListViewSettings::RKObjectListViewSettings () {
+	RK_TRACE (APP);
+
+	settings = new State[SettingsCount];
+	settings_default = new bool[SettingsCount];
+	for (int i = 0; i < SettingsCount; ++i) settings_default[i] = true;
+
+	createContextMenus ();
+	globalSettingsChanged ();
+}
+
+RKObjectListViewSettings::~RKObjectListViewSettings () {
+	RK_TRACE (APP);
+
+	delete settings;
+	delete settings_default;
+	delete show_fields_menu;
+	delete show_objects_menu;
+}
+
+void RKObjectListViewSettings::setSetting (Settings setting, State to) {
+	RK_TRACE (APP);
+
+	settings[setting] = to;
+	settings_default[setting] = false;
+
+	updateSelf ();
+}
+
+RKObjectListViewSettings::State RKObjectListViewSettings::getSetting (Settings setting) {
+	RK_TRACE (APP);
+
+	return (settings[setting]);
+}
+
+bool RKObjectListViewSettings::shouldShowObject (RObject *object) {
+	RK_TRACE (APP);
+
+	if (object->getShortName ().startsWith (".")) {
+		if (object->isType (RObject::GlobalEnv)) return true;
+		return (settings[ShowObjectsHidden] >= Yes);
+	} else if (object->isType (RObject::ToplevelEnv)) {
+		if (object->isType (RObject::GlobalEnv)) return true;
+		return (settings[ShowObjectsAllEnvironments] >= Yes);
+	} else if (object->isType (RObject::Function)) {
+		return (settings[ShowObjectsFunction] >= Yes);
+	} else if (object->isType (RObject::Container)) {
+		return (settings[ShowObjectsContainer] >= Yes);
+	} else if (object->isVariable ()) {
+		return (settings[ShowObjectsVariable] >= Yes);
+	}
+	return true;
+}
+
+void RKObjectListViewSettings::createContextMenus () {
+	RK_TRACE (APP);
+
+	show_objects_menu = new QPopupMenu (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"));
+
+	show_fields_menu = new QPopupMenu (0);
+	insertPopupItem (show_fields_menu, ShowFieldsType, i18n ("Type"));
+	insertPopupItem (show_fields_menu, ShowFieldsLabel, i18n ("Label"));
+	insertPopupItem (show_fields_menu, ShowFieldsClass, i18n ("Class"));
+}
+
+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 = ShowFieldsType; i <= ShowFieldsLabel; ++i) {
+		show_fields_menu->setItemChecked (i, settings[(Settings) i] >= Yes);
+		show_fields_menu->setItemEnabled (i, optionConfigurable ((Settings) i));
+	}
+
+	emit (settingsChanged ());
+}
+
+void RKObjectListViewSettings::insertPopupItem (QPopupMenu *menu, Settings setting, const QString &text) {
+	RK_TRACE (APP);
+
+	menu->insertItem (text, setting);
+	menu->setItemParameter (setting, setting);
+	menu->connectItem (setting, this, SLOT (toggleSetting (int)));
+}
+
+void RKObjectListViewSettings::globalSettingsChanged () {
+	RK_TRACE (APP);
+
+	// TODO: copy global settings
+	for (int i = 0; i < SettingsCount; ++i) {
+		settings[i] = Yes;
+	}
+
+	updateSelf ();
+}
+
+void RKObjectListViewSettings::toggleSetting (int which) {
+	RK_TRACE (APP);
+	RK_ASSERT (which < SettingsCount);
+
+	if (settings[which] == Yes) {
+		settings[which] = No;
+	} else if (settings[which] == No) {
+		settings[which] = Yes;
+	} else {
+		RK_ASSERT (false);
+	}
+	settings_default[which] = false;
+
+	updateSelf ();
+}
+
+bool RKObjectListViewSettings::optionConfigurable (Settings setting) {
+	RK_TRACE (APP);
+
+	if (settings[setting] == Always) return false;
+	if (settings[setting] == Never) return false;
+	return true;
+}
+
+//////////////////// RKObjectListViewSettingsWidget //////////////////////////
+RKObjectListViewSettingsWidget::RKObjectListViewSettingsWidget (RKObjectListViewSettings *settings, QWidget *parent) : QWidget (parent) {
+	RK_TRACE (APP);
+}
+
+RKObjectListViewSettingsWidget::~RKObjectListViewSettingsWidget () {
+	RK_TRACE (APP);
+}
+
+void RKObjectListViewSettingsWidget::settingsChanged () {
+	RK_TRACE (APP);
+}
+
+
 #include "rkobjectlistview.moc"

Modified: trunk/rkward/rkward/misc/rkobjectlistview.h
===================================================================
--- trunk/rkward/rkward/misc/rkobjectlistview.h	2006-10-04 12:23:50 UTC (rev 804)
+++ trunk/rkward/rkward/misc/rkobjectlistview.h	2006-10-04 14:59:55 UTC (rev 805)
@@ -24,6 +24,7 @@
 class QPixmap;
 class QPopupMenu;
 class RKListViewItem;
+class RKObjectListViewSettings;
 
 /**
 This class provides the common functionality for the list-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?
@@ -49,6 +50,8 @@
 /** 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 () { return menu_object; };
+
+	RKObjectListViewSettings *getSettings () { return settings; };
 signals:
 	void listChanged ();
 /** This signal is emitted just before the context-menu is shown. If you connect to this signal, you can make some adjustments to the context-menu.
@@ -83,6 +86,8 @@
 	QPopupMenu *menu;
 	RObject *menu_object;
 
+	RKObjectListViewSettings *settings;
+
 	static QPixmap *icon_function;
 	static QPixmap *icon_list;
 	static QPixmap *package_environment;
@@ -102,4 +107,66 @@
 	int width (const QFontMetrics &fm, const QListView * lv, int c) const;
 };
 
+/** Represents the filter/view settings possible for an RKListView. */
+class RKObjectListViewSettings : public QObject {
+	Q_OBJECT
+public:
+/** ctor. copies the default settings from RKSettingsModuleObjectBrowser */ 
+	RKObjectListViewSettings ();
+	~RKObjectListViewSettings ();
+
+	enum Settings {
+		ShowObjectsVariable=0,
+		ShowObjectsAllEnvironments=1,
+		ShowObjectsFunction=2,
+		ShowObjectsContainer=3,
+		ShowObjectsHidden=4,
+		ShowFieldsType=5,
+		ShowFieldsClass=6,
+		ShowFieldsLabel=7,
+		SettingsCount=8
+	};
+
+	enum State {
+		Never,
+		No,
+		Yes,
+		Always
+	};
+
+	void setSetting (Settings setting, State to);
+	State getSetting (Settings setting);
+
+	bool shouldShowObject (RObject *object);
+
+	QPopupMenu *showObjectsMenu () { return show_objects_menu; };
+	QPopupMenu *showFieldsMenu () { return show_fields_menu; };
+signals:
+	void settingsChanged ();
+public slots:
+	void globalSettingsChanged ();
+	void toggleSetting (int which);
+private:
+	State *settings;
+	bool *settings_default;
+	bool optionConfigurable (Settings setting);
+	void insertPopupItem (QPopupMenu *menu, Settings setting, const QString &text);
+	void createContextMenus ();
+	void updateSelf ();
+
+	QPopupMenu *show_objects_menu;
+	QPopupMenu *show_fields_menu;
+};
+
+class RKObjectListViewSettingsWidget : public QWidget {
+	Q_OBJECT
+public:
+	RKObjectListViewSettingsWidget (RKObjectListViewSettings *settings, QWidget *parent);
+	~RKObjectListViewSettingsWidget ();
+public slots:
+	void settingsChanged ();
+private:
+	RKObjectListViewSettings *settings;
+};
+
 #endif

Modified: trunk/rkward/rkward/plugin/rkcomponentproperties.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2006-10-04 12:23:50 UTC (rev 804)
+++ trunk/rkward/rkward/plugin/rkcomponentproperties.cpp	2006-10-04 14:59:55 UTC (rev 805)
@@ -717,7 +717,7 @@
 
 	// first check dimensionality
 	if (dims > 0) {
-		if (object->numDimensions () != dims) return false;
+		if ((int) object->numDimensions () != dims) return false;
 	}
 	int olength = object->getLength ();
 	if ((min_length > 0) && (olength < min_length)) return 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