[rkward] /: Use separate buttons for adding / removing items in multi-varslots / valueslots

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Wed Jun 3 11:15:40 UTC 2015


Git commit 069ac406ac0564b9e7086b894e66795d1dfd7b29 by Thomas Friedrichsmeier.
Committed on 03/06/2015 at 11:15.
Pushed by tfry into branch 'master'.

Use separate buttons for adding / removing items in multi-varslots / valueslots

M  +1    -0    ChangeLog
M  +31   -20   rkward/plugin/rkvarslot.cpp
M  +6    -6    rkward/plugin/rkvarslot.h

http://commits.kde.org/rkward/069ac406ac0564b9e7086b894e66795d1dfd7b29

diff --git a/ChangeLog b/ChangeLog
index a618f49..5534840 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- For multi-item varslots and valueslots, use separate buttons for adding / removing items
 - Don't show (useless) index number in mutli-value varslots and valueslots
 - Make the option to disable / enable editing more visible (in the data editor's toolbar)
 - Do not invoke symbol name completion while in the middle (not end) of a word
diff --git a/rkward/plugin/rkvarslot.cpp b/rkward/plugin/rkvarslot.cpp
index 67976ea..184b751 100644
--- a/rkward/plugin/rkvarslot.cpp
+++ b/rkward/plugin/rkvarslot.cpp
@@ -23,6 +23,7 @@
 #include <QHeaderView>
 #include <qstringlist.h>
 #include <QGridLayout>
+#include <QVBoxLayout>
 
 #include <klocale.h>
 
@@ -48,10 +49,17 @@ RKVarSlot::RKVarSlot (const QDomElement &element, RKComponent *parent_component,
 		g_layout->addWidget (label, 0, 2);
 	}
 
-	select = new QPushButton (QString (), this);
-	setSelectButton (false);
-	connect (select, SIGNAL (clicked()), this, SLOT (selectPressed()));
-	g_layout->addWidget (select, 1, 0);
+	QVBoxLayout *button_layout = new QVBoxLayout ();
+	select_button = new QPushButton (QString (), this);
+	select_button->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionAddRight));
+	connect (select_button, SIGNAL (clicked()), this, SLOT (selectPressed()));
+	button_layout->addWidget (select_button);
+	remove_button = new QPushButton (QString (), this);
+	remove_button->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionRemoveLeft));
+	connect (remove_button, SIGNAL (clicked()), this, SLOT (removePressed()));
+	button_layout->addWidget (remove_button);
+	button_layout->addStretch ();
+	g_layout->addLayout (button_layout, 1, 0);
 	g_layout->addItem (new QSpacerItem (5, 0), 0, 1);
 
 	list = new QTreeWidget (this);
@@ -107,23 +115,13 @@ RKVarSlot::RKVarSlot (const QDomElement &element, RKComponent *parent_component,
 	setRequired (xml->getBoolAttribute (element, "required", false, DL_INFO));
 
 	connect (available, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (availablePropertyChanged(RKComponentPropertyBase*)));
-	availablePropertyChanged (available);		// initialize
+	availablePropertyChanged (available);	// initialize
 }
 
 RKVarSlot::~RKVarSlot (){
 	RK_TRACE (PLUGIN);
 }
 
-void RKVarSlot::setSelectButton (bool add) {
-	if (add) {
-		select->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionAddRight));
-		add_mode = true;
-	} else {
-		select->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionRemoveLeft));
-		add_mode = false;
-	}
-}
-
 void RKVarSlot::listSelectionChanged () {
 	RK_TRACE (PLUGIN);
 
@@ -138,7 +136,11 @@ void RKVarSlot::listSelectionChanged () {
 		static_cast<RKComponentPropertyRObjects*> (selected)->setObjectList (sellist);
 	}
 
-	setSelectButton (((!multi) || (selrows.isEmpty ())) && (!available->atMaxLength ()));
+	if (multi) remove_button->setEnabled (!selrows.isEmpty ());
+	else {
+		select_button->setVisible (available->listLength () == 0);
+		remove_button->setVisible (available->listLength () > 0);
+	}
 }
 
 void RKVarSlot::availablePropertyChanged (RKComponentPropertyBase *) {
@@ -190,14 +192,13 @@ void RKVarSlot::updateLook () {
 	list->setPalette(palette);
 }
 
-void RKVarSlot::selectPressed () {
+void RKVarSlot::addOrRemove (bool add) {
 	RK_TRACE (PLUGIN);
-
-	RK_DEBUG (PLUGIN, DL_DEBUG, "select press in varslot: mode %d, source %s, selected %s", add_mode, qPrintable (fetchStringValue (source)), qPrintable (fetchStringValue (selected)));
+	RK_DEBUG (PLUGIN, DL_DEBUG, "select press in varslot: mode %d, source %s, selected %s", add, qPrintable (fetchStringValue (source)), qPrintable (fetchStringValue (selected)));
 
 	updating = true;
 	// first update the properties
-	if (add_mode) {
+	if (add) {
 		if (!multi) available->setValueList (QStringList ());  // replace
 		int len = source->listLength ();
 		for (int i = 0; i < len; ++i) {
@@ -224,6 +225,16 @@ void RKVarSlot::selectPressed () {
 	availablePropertyChanged (available);
 }
 
+void RKVarSlot::selectPressed () {
+	RK_TRACE (PLUGIN);
+	addOrRemove (true);
+}
+
+void RKVarSlot::removePressed () {
+	RK_TRACE (PLUGIN);
+	addOrRemove (false);
+}
+
 QStringList RKVarSlot::getUiLabelPair () const {
 	RK_TRACE (PLUGIN);
 
diff --git a/rkward/plugin/rkvarslot.h b/rkward/plugin/rkvarslot.h
index 09ec022..97a6cbd 100644
--- a/rkward/plugin/rkvarslot.h
+++ b/rkward/plugin/rkvarslot.h
@@ -2,7 +2,7 @@
                           rkvarslot.h  -  description
                              -------------------
     begin                : Thu Nov 7 2002
-    copyright            : (C) 2002 - 2014 by Thomas Friedrichsmeier
+    copyright            : (C) 2002 - 2015 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -49,20 +49,19 @@ public:
 public slots:
 /** Called when the select-button is pressed */
 	void selectPressed ();
+	void removePressed ();
 	void listSelectionChanged ();
 	void availablePropertyChanged (RKComponentPropertyBase *);
 protected:
 /** Calls updateLook (), when enabledness changes */
 	void enabledChange (bool old) { updateLook (); QWidget::enabledChange (old); };
 private:
+	void addOrRemove (bool add);
 	enum {
 		Varslot,
 		Valueslot
 	} mode;
-/** change the select button to left/right / add/remove
- at param add if true, button shows arrow right, or signifies more values would be added. Else the other way around */
-	void setSelectButton (bool add);
-	bool add_mode;
+
 	bool multi;
 	bool updating;
 	QString label_string;
@@ -75,7 +74,8 @@ private:
 	RKComponentPropertyAbstractList *selected;
 
 	QTreeWidget *list;
-	QPushButton *select;
+	QPushButton *select_button;
+	QPushButton *remove_button;
 };
 
 #endif



More information about the rkward-tracker mailing list