[rkward] rkward/misc: Add button to reset filters.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Sun Nov 15 20:15:55 UTC 2015


Git commit ba7cf22b7baef7775dacb2aede6788534822b5ab by Thomas Friedrichsmeier.
Committed on 15/11/2015 at 20:15.
Pushed by tfry into branch 'master'.

Add button to reset filters.

M  +37   -5    rkward/misc/rkobjectlistview.cpp
M  +4    -0    rkward/misc/rkobjectlistview.h

http://commits.kde.org/rkward/ba7cf22b7baef7775dacb2aede6788534822b5ab

diff --git a/rkward/misc/rkobjectlistview.cpp b/rkward/misc/rkobjectlistview.cpp
index f497602..a5aebbf 100644
--- a/rkward/misc/rkobjectlistview.cpp
+++ b/rkward/misc/rkobjectlistview.cpp
@@ -230,9 +230,7 @@ RKObjectListViewSettings::RKObjectListViewSettings (bool tool_window, QObject* p
 	connect (update_timer, SIGNAL(timeout()), this, SLOT(updateSelfNow()));
 
 	filter_widget = 0;
-	hide_functions = hide_non_functions = false;
-	filter_on_class = filter_on_label = filter_on_name = true;
-	depth_limit = 1;
+	in_reset_filters = false;
 
 	persistent_settings_actions[ShowObjectsHidden] = new QAction (i18n ("Show Hidden Objects"), this);
 	persistent_settings_actions[ShowFieldsType] = new QAction (i18n ("Type"), this);
@@ -246,6 +244,8 @@ RKObjectListViewSettings::RKObjectListViewSettings (bool tool_window, QObject* p
 		persistent_settings_actions[i]->setChecked (persistent_settings[i]);
 		connect (persistent_settings_actions[i], SIGNAL (toggled(bool)), this, SLOT(filterSettingsChanged ()));
 	}
+
+	resetFilters (); // inits defaults
 }
 
 RKObjectListViewSettings::~RKObjectListViewSettings () {
@@ -308,7 +308,7 @@ QWidget* RKObjectListViewSettings::filterWidget (QWidget *parent) {
 	                                      "<li><i>%2</i> includes direct child objects. In this case, the list will show matching objects on the search path, <i>and</i> objects on the search path that hold matching child objects.</li>", depth_box->itemText (0), depth_box->itemText (1)), depth_box);
 	boxvlayout->addWidget (depth_box);
 
-	depth_box->setCurrentIndex (depth_limit);
+	depth_box->setCurrentIndex (1);
 	connect (depth_box, SIGNAL (currentIndexChanged(QString)), this, SLOT (filterSettingsChanged()));
 
 	type_box = new QComboBox ();
@@ -323,18 +323,48 @@ QWidget* RKObjectListViewSettings::filterWidget (QWidget *parent) {
 	else type_box->setCurrentIndex (0);
 	connect (type_box, SIGNAL (currentIndexChanged(QString)), this, SLOT (filterSettingsChanged()));
 
+	QHBoxLayout *bottom_layout = new QHBoxLayout (filter_widget);
+	layout->addLayout (bottom_layout);
 	QCheckBox* hidden_objects_box = new QCheckBox (i18n ("Show Hidden Objects"));
 	hidden_objects_box->setChecked (persistent_settings[ShowObjectsHidden]);
 	connect (hidden_objects_box, SIGNAL (clicked(bool)), persistent_settings_actions[ShowObjectsHidden], SLOT (setChecked(bool)));
 	connect (persistent_settings_actions[ShowObjectsHidden], SIGNAL (triggered(bool)), hidden_objects_box, SLOT (setChecked(bool)));
-	layout->addWidget (hidden_objects_box);
+	bottom_layout->addWidget (hidden_objects_box);
+
+	reset_filters_button = new QPushButton (i18n ("Reset filters"), filter_widget);
+	connect (reset_filters_button, SIGNAL (clicked(bool)), this, SLOT(resetFilters()));
+	RKCommonFunctions::setTips (i18n ("Discards the current object search filters"), reset_filters_button);
+	reset_filters_button->hide ();
+	bottom_layout->addWidget (reset_filters_button);
 
 	return filter_widget;
 }
 
+void RKObjectListViewSettings::resetFilters () {
+	RK_TRACE (APP);
+
+	in_reset_filters = true;
+	if (filter_widget) {
+		type_box->setCurrentIndex (0);
+		filter_on_name_box->setChecked (true);
+		filter_on_label_box->setChecked (true);
+		filter_on_class_box->setChecked (true);
+		depth_box->setCurrentIndex (1);
+#warning TODO: reset search line
+	} else {
+		hide_functions = hide_non_functions = false;
+		filter_on_class = filter_on_label = filter_on_name = true;
+		depth_limit = 1;
+	}
+	in_reset_filters = false;
+	updateSelf ();
+}
+
 void RKObjectListViewSettings::filterSettingsChanged () {
 	RK_TRACE (APP);
 
+	if (in_reset_filters) return;  // Avoid updating for each setting, individually, when many are changed at once.
+
 	if (filter_widget) {
 		filter_on_name = filter_on_name_box->isChecked ();
 		filter_on_label = filter_on_label_box->isChecked ();
@@ -342,6 +372,8 @@ void RKObjectListViewSettings::filterSettingsChanged () {
 		depth_limit = depth_box->currentIndex ();
 		hide_functions = type_box->currentIndex () == 2;
 		hide_non_functions = type_box->currentIndex () == 1;
+
+		reset_filters_button->setVisible (!filter_on_name || !filter_on_class || !filter_on_label || (depth_limit != 1) || hide_functions || hide_non_functions);
 	}
 
 	for (int i = 0; i < SettingsCount; ++i) {
diff --git a/rkward/misc/rkobjectlistview.h b/rkward/misc/rkobjectlistview.h
index af64bbd..95e1c30 100644
--- a/rkward/misc/rkobjectlistview.h
+++ b/rkward/misc/rkobjectlistview.h
@@ -29,6 +29,7 @@ class RKObjectListViewSettings;
 class QTimer;
 class QCheckBox;
 class QComboBox;
+class QPushButton;
 
 /**
 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?
@@ -107,6 +108,7 @@ signals:
 public slots:
 	void filterSettingsChanged ();
 	void updateSelfNow ();
+	void resetFilters ();
 protected:
 	bool filterAcceptsRow (int source_row, const QModelIndex& source_parent) const;
 	bool acceptRow (int source_row, const QModelIndex& source_parent) const;
@@ -131,6 +133,8 @@ private:
 	QComboBox* type_box;
 	bool hide_functions;
 	bool hide_non_functions;
+	QPushButton* reset_filters_button;
+	bool in_reset_filters;
 
 	bool is_tool_window;
 



More information about the rkward-tracker mailing list