[rkward/work/workspace_browser_redesign] rkward: More restructuring of filter settings, both in UI and internally. Work in progress.
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Nov 10 21:08:11 UTC 2015
Git commit 808067b33fa18505d9e5be39b78279cb71f9d15a by Thomas Friedrichsmeier.
Committed on 10/11/2015 at 21:07.
Pushed by tfry into branch 'work/workspace_browser_redesign'.
More restructuring of filter settings, both in UI and internally. Work in progress.
M +116 -19 rkward/misc/rkobjectlistview.cpp
M +25 -6 rkward/misc/rkobjectlistview.h
M +1 -3 rkward/settings/rksettingsmoduleobjectbrowser.cpp
M +2 -91 rkward/windows/robjectbrowser.cpp
M +0 -26 rkward/windows/robjectbrowser.h
http://commits.kde.org/rkward/808067b33fa18505d9e5be39b78279cb71f9d15a
diff --git a/rkward/misc/rkobjectlistview.cpp b/rkward/misc/rkobjectlistview.cpp
index a57c231..1468f83 100644
--- a/rkward/misc/rkobjectlistview.cpp
+++ b/rkward/misc/rkobjectlistview.cpp
@@ -17,17 +17,24 @@
#include "rkobjectlistview.h"
#include <klocale.h>
+#include <kfilterproxysearchline.h>
#include <QContextMenuEvent>
#include <QMenu>
#include <QTimer>
#include <QStyledItemDelegate>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QGroupBox>
+#include <QCheckBox>
#include "../rkglobals.h"
#include "../core/robjectlist.h"
#include "../core/renvironmentobject.h"
#include "../core/rkmodificationtracker.h"
#include "rkstandardicons.h"
+#include "rkcommonfunctions.h"
#include "../settings/rksettingsmoduleobjectbrowser.h"
#include "../debug.h"
@@ -220,21 +227,23 @@ void RKObjectListView::settingsChanged () {
//////////////////// RKObjectListViewSettings //////////////////////////
-RKObjectListViewSettings::RKObjectListViewSettings (QObject* parent) : QSortFilterProxyModel (parent) {
+RKObjectListViewSettings::RKObjectListViewSettings (QObject* parent) : KRecursiveFilterProxyModel (parent) {
RK_TRACE (APP);
update_timer = new QTimer (this);
update_timer->setSingleShot (true);
connect (update_timer, SIGNAL(timeout()), this, SLOT(updateSelfNow()));
+ filter_widget = 0;
+ show_containers = show_functions = show_variables = true;
+ filter_on_class = filter_on_label = filter_on_name = true;
+ show_hidden_objects = RKSettingsModuleObjectBrowser::isSettingActive (ShowObjectsHidden);
+
connect (RKSettings::tracker (), SIGNAL (settingsChanged(RKSettings::SettingsPage)), this, SLOT (globalSettingsChanged(RKSettings::SettingsPage)));
action_group = new QActionGroup (this);
action_group->setExclusive (false);
settings[ShowObjectsAllEnvironments].action = new QAction (i18n ("All Environments"), action_group);
- settings[ShowObjectsContainer].action = new QAction (i18n ("Objects with children"), action_group);
- settings[ShowObjectsVariable].action = new QAction (i18n ("Variables"), action_group);
- settings[ShowObjectsFunction].action = new QAction (i18n ("Functions"), action_group);
settings[ShowObjectsHidden].action = new QAction (i18n ("Hidden Objects"), action_group);
settings[ShowFieldsType].action = new QAction (i18n ("Type"), action_group);
settings[ShowFieldsLabel].action = new QAction (i18n ("Label"), action_group);
@@ -257,6 +266,96 @@ RKObjectListViewSettings::~RKObjectListViewSettings () {
delete show_objects_menu;
}
+QWidget* RKObjectListViewSettings::filterWidget (QWidget *parent) {
+ RK_TRACE (APP);
+
+ if (filter_widget) return filter_widget;
+
+ filter_widget = new QWidget (parent);
+
+ QVBoxLayout *layout = new QVBoxLayout (filter_widget);
+ layout->setContentsMargins (0, 0, 0, 0);
+ QHBoxLayout* hlayout = new QHBoxLayout ();
+ hlayout->setContentsMargins (0, 0, 0, 0);
+ layout->addLayout (hlayout);
+
+ KFilterProxySearchLine* sline = new KFilterProxySearchLine (filter_widget);
+ sline->setProxy (this);
+ hlayout->addWidget (sline);
+ QPushButton* expander = new QPushButton (filter_widget);
+ expander->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionExpandDown));
+ expander->setCheckable (true);
+ hlayout->addWidget (expander);
+
+ filter_widget_expansion = new QWidget (filter_widget);
+ layout->addWidget (filter_widget_expansion);
+ connect (expander, SIGNAL (toggled(bool)), filter_widget_expansion, SLOT (setShown(bool)));
+ filter_widget_expansion->hide ();
+ QVBoxLayout *elayout = new QVBoxLayout (filter_widget_expansion);
+ elayout->setContentsMargins (0, 0, 0, 0);
+
+ QGroupBox *box = new QGroupBox (i18nc ("Fields==columns in tree view", "Fields to search in"), filter_widget_expansion);
+ elayout->addWidget (box);
+ QHBoxLayout *boxlayout = new QHBoxLayout (box);
+ filter_on_name_box = new QCheckBox (i18n ("Name"));
+ boxlayout->addWidget (filter_on_name_box);
+ filter_on_label_box = new QCheckBox (i18n ("Label"));
+ boxlayout->addWidget (filter_on_label_box);
+ filter_on_class_box = new QCheckBox (i18n ("Class"));
+ boxlayout->addWidget (filter_on_class_box);
+
+ connect (filter_on_name_box, SIGNAL(clicked(bool)), this, SLOT (filterSettingsChanged()));
+ connect (filter_on_label_box, SIGNAL(clicked(bool)), this, SLOT (filterSettingsChanged()));
+ connect (filter_on_class_box, SIGNAL(clicked(bool)), this, SLOT (filterSettingsChanged()));
+
+ show_functions_box = new QCheckBox (i18n ("Show Functions"));
+ RKCommonFunctions::setTips (i18n ("Uncheck this to exclude functions from the list"), show_functions_box);
+ elayout->addWidget (show_functions_box);
+ show_variables_box = new QCheckBox (i18n ("Show Vectors"));
+ RKCommonFunctions::setTips (i18n ("Uncheck this to exclude vectors (i.e. most types of data objects) from the list"), show_variables_box);
+ elayout->addWidget (show_variables_box);
+ show_containers_box = new QCheckBox (i18n ("Show Containers"));
+ RKCommonFunctions::setTips (i18n ("Uncheck this to exclude \"container\"-objects such as <i>list</i>s or <i>environment</i>s from the list. Note that containers will continue to be show, if they contain child objects matching the filter settings."), show_containers_box);
+ elayout->addWidget (show_containers_box);
+
+ connect (show_functions_box, SIGNAL(clicked(bool)), this, SLOT (filterSettingsChanged()));
+ connect (show_variables_box, SIGNAL(clicked(bool)), this, SLOT (filterSettingsChanged()));
+ connect (show_containers_box, SIGNAL(clicked(bool)), this, SLOT (filterSettingsChanged()));
+
+ hidden_objects_box = new QCheckBox (i18n ("Show Hidden Objects"));
+ connect (hidden_objects_box, SIGNAL (clicked(bool)), this, SLOT (filterSettingsChanged()));
+ layout->addWidget (hidden_objects_box);
+
+ filter_on_name_box->setChecked (filter_on_name);
+ filter_on_label_box->setChecked (filter_on_label);
+ filter_on_class_box->setChecked (filter_on_class);
+ show_functions_box->setChecked (show_functions);
+ show_variables_box->setChecked (show_variables);
+ show_containers_box->setChecked (show_containers);
+ hidden_objects_box->setChecked (show_hidden_objects);
+
+ return filter_widget;
+}
+
+void RKObjectListViewSettings::filterSettingsChanged () {
+ RK_TRACE (APP);
+
+ if (!filter_widget) {
+ RK_ASSERT (filter_widget);
+ return;
+ }
+
+ filter_on_name = filter_on_name_box->isChecked ();
+ filter_on_label = filter_on_label_box->isChecked ();
+ filter_on_class = filter_on_class_box->isChecked ();
+ show_functions = show_functions_box->isChecked ();
+ show_variables = show_variables_box->isChecked ();
+ show_containers = show_containers_box->isChecked ();
+ show_hidden_objects = hidden_objects_box->isChecked ();
+#warning TODO: It is also a QAction, currently.
+ updateSelf ();
+}
+
void RKObjectListViewSettings::setSetting (Settings setting, bool to) {
RK_TRACE (APP);
@@ -278,7 +377,7 @@ bool RKObjectListViewSettings::filterAcceptsColumn (int source_column, const QMo
return false;
}
-bool RKObjectListViewSettings::filterAcceptsRow (int source_row, const QModelIndex& source_parent) const {
+bool RKObjectListViewSettings::acceptRow (int source_row, const QModelIndex& source_parent) const {
RK_TRACE (APP);
// always show the root item
@@ -291,24 +390,25 @@ bool RKObjectListViewSettings::filterAcceptsRow (int source_row, const QModelInd
// always show global env and search path
if (!object->parentObject ()) return true;
- if (!settings[ShowObjectsHidden].state) {
+ if (!show_hidden_objects) {
if (object->getShortName ().startsWith ('.')) return false;
if (object == reinterpret_cast<RObject*> (RObjectList::getObjectList ()->orphanNamespacesObject ())) return false;
}
- bool base_filter = QSortFilterProxyModel::filterAcceptsRow (source_row, source_parent);
+ if (!show_functions && object->isType (RObject::Function)) return false;
+ if (!show_containers && object->isType (RObject::Container | RObject::Environment)) return false;
+ if (!show_variables && object->isVariable ()) return false;
- if (object->isType (RObject::ToplevelEnv)) {
- return (base_filter && settings[ShowObjectsAllEnvironments].state);
- } else if (object->isType (RObject::Function)) {
- return (base_filter && settings[ShowObjectsFunction].state);
- } else if (object->isType (RObject::Container)) {
- return (base_filter && settings[ShowObjectsContainer].state);
- } else if (object->isVariable ()) {
- return (base_filter && settings[ShowObjectsVariable].state);
+ if (filter_on_name && object->getShortName ().contains (filterRegExp ())) return true;
+ if (filter_on_label && object->getLabel ().contains (filterRegExp ())) return true;
+ if (filter_on_class) {
+ QStringList cnames = object->classNames ();
+ for (int i = cnames.length () - 1; i >= 0; --i) {
+ if (cnames[i].contains (filterRegExp ())) return true;
+ }
}
- return base_filter;
+ return false;
}
bool RKObjectListViewSettings::lessThan (const QModelIndex& left, const QModelIndex& right) const {
@@ -341,9 +441,6 @@ void RKObjectListViewSettings::createContextMenus () {
show_objects_menu = new QMenu (i18n ("Show Objects"), 0);
show_objects_menu->addAction (settings[ShowObjectsAllEnvironments].action);
- show_objects_menu->addAction (settings[ShowObjectsContainer].action);
- show_objects_menu->addAction (settings[ShowObjectsVariable].action);
- show_objects_menu->addAction (settings[ShowObjectsFunction].action);
show_objects_menu->addSeparator ();
show_objects_menu->addAction (settings[ShowObjectsHidden].action);
diff --git a/rkward/misc/rkobjectlistview.h b/rkward/misc/rkobjectlistview.h
index 382b586..a5281ea 100644
--- a/rkward/misc/rkobjectlistview.h
+++ b/rkward/misc/rkobjectlistview.h
@@ -18,7 +18,8 @@
#define RKOBJECTLISTVIEW_H
#include <QTreeView>
-#include <QSortFilterProxyModel>
+
+#include <krecursivefilterproxymodel.h>
#include "../settings/rksettings.h"
#include "../core/robject.h"
@@ -28,6 +29,7 @@ class RKListViewItem;
class RKObjectListViewSettings;
class QActionGroup;
class QTimer;
+class QCheckBox;
/**
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?
@@ -84,7 +86,7 @@ friend class RKObjectListViewRootDelegate;
};
/** Does filtering for an RKObjectListView. Should probably be renamed to RKObjectListViewFilter */
-class RKObjectListViewSettings : public QSortFilterProxyModel {
+class RKObjectListViewSettings : public KRecursiveFilterProxyModel {
Q_OBJECT
public:
/** ctor. copies the default settings from RKSettingsModuleObjectBrowser */
@@ -92,10 +94,7 @@ public:
~RKObjectListViewSettings ();
enum Settings {
- ShowObjectsVariable=0,
ShowObjectsAllEnvironments,
- ShowObjectsFunction,
- ShowObjectsContainer,
ShowObjectsHidden,
ShowFieldsType,
ShowFieldsClass,
@@ -108,14 +107,17 @@ public:
QMenu *showObjectsMenu () const { return show_objects_menu; };
QMenu *showFieldsMenu () const { return show_fields_menu; };
+
+ QWidget* filterWidget (QWidget *parent);
signals:
void settingsChanged ();
public slots:
void globalSettingsChanged (RKSettings::SettingsPage);
+ void filterSettingsChanged ();
void settingToggled (QAction* which);
void updateSelfNow ();
protected:
- bool filterAcceptsRow (int source_row, const QModelIndex& source_parent) const;
+ bool acceptRow (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:
@@ -134,6 +136,23 @@ private:
QMenu *show_objects_menu;
QMenu *show_fields_menu;
+ QWidget *filter_widget;
+ QWidget *filter_widget_expansion;
+ QCheckBox* filter_on_name_box;
+ QCheckBox* filter_on_label_box;
+ QCheckBox* filter_on_class_box;
+ bool filter_on_name;
+ bool filter_on_label;
+ bool filter_on_class;
+ QCheckBox* show_variables_box;
+ QCheckBox* show_containers_box;
+ QCheckBox* show_functions_box;
+ bool show_variables;
+ bool show_containers;
+ bool show_functions;
+ QCheckBox* hidden_objects_box;
+ bool show_hidden_objects;
+
QTimer *update_timer;
};
diff --git a/rkward/settings/rksettingsmoduleobjectbrowser.cpp b/rkward/settings/rksettingsmoduleobjectbrowser.cpp
index 69006db..22215e6 100644
--- a/rkward/settings/rksettingsmoduleobjectbrowser.cpp
+++ b/rkward/settings/rksettingsmoduleobjectbrowser.cpp
@@ -137,10 +137,8 @@ void RKSettingsModuleObjectBrowser::loadSettings (KConfig *config) {
KConfigGroup cg = config->group ("Object Browser");
// The following are _not_ actually configurable defaults in RKWard 0.6.4. These settings here simply serve to define the static default.
+ // TODO: That is just plain wrong. Move them to RObjectListViewSettings, exclusively.
settings[RKObjectListViewSettings::ShowObjectsAllEnvironments] = true;
- settings[RKObjectListViewSettings::ShowObjectsVariable] = true;
- settings[RKObjectListViewSettings::ShowObjectsContainer] = true;
- settings[RKObjectListViewSettings::ShowObjectsFunction] = true;
// These defaults _are_ configurable
settings[RKObjectListViewSettings::ShowObjectsHidden] = cg.readEntry ("show hidden vars", false);
settings[RKObjectListViewSettings::ShowFieldsLabel] = cg.readEntry ("show label field", true);
diff --git a/rkward/windows/robjectbrowser.cpp b/rkward/windows/robjectbrowser.cpp
index fe9221b..0041a48 100644
--- a/rkward/windows/robjectbrowser.cpp
+++ b/rkward/windows/robjectbrowser.cpp
@@ -18,13 +18,9 @@
#include <qlayout.h>
#include <qpushbutton.h>
-#include <qcheckbox.h>
-#include <qradiobutton.h>
-#include <QHBoxLayout>
#include <QFocusEvent>
#include <QVBoxLayout>
#include <QMenu>
-#include <QButtonGroup>
#include <klocale.h>
#include <kinputdialog.h>
@@ -40,6 +36,7 @@
#include "../rbackend/rinterface.h"
#include "../misc/rkobjectlistview.h"
#include "../misc/rkdummypart.h"
+#include "../misc/rkstandardicons.h"
#include "rkworkplace.h"
#include "../dataeditor/rkeditor.h"
@@ -111,7 +108,7 @@ RObjectBrowserInternal::RObjectBrowserInternal (QWidget *parent) : QWidget (pare
vbox->setContentsMargins (0, 0, 0, 0);
list_view = new RKObjectListView (this);
- vbox->addWidget (new RKObjectListViewSettingsWidget (list_view->getSettings (), this));
+ vbox->addWidget (list_view->getSettings ()->filterWidget (this));
vbox->addWidget (list_view);
update_button = new QPushButton (i18n ("Update"), this);
@@ -278,90 +275,4 @@ void RObjectBrowserInternal::doubleClicked (const QModelIndex& index) {
}
}
-
-//////////////////// RKObjectListViewSettingsWidget //////////////////////////
-RKObjectListViewSettingsWidget::RKObjectListViewSettingsWidget (RKObjectListViewSettings *settings, QWidget *parent) : QWidget (parent) {
- RK_TRACE (APP);
-
- RKObjectListViewSettingsWidget::settings = settings;
- connect (settings, SIGNAL (settingsChanged()), this, SLOT (settingsChanged()));
-
- QVBoxLayout *layout = new QVBoxLayout (this);
- layout->setContentsMargins (0, 0, 0, 0);
-
- QButtonGroup *group = new QButtonGroup (this);
- QHBoxLayout *hbox = new QHBoxLayout ();
- hbox->setContentsMargins (0, 0, 0, 0);
- group->addButton (all = new QRadioButton (i18n ("All"), this));
- group->addButton (nonfunctions = new QRadioButton (i18n ("Non-Functions"), this));
- group->addButton (functions = new QRadioButton (i18n ("Functions"), this));
- hbox->addWidget (all);
- hbox->addWidget (nonfunctions);
- hbox->addWidget (functions);
- connect (all, SIGNAL(clicked(bool)), this, SLOT(modeChanged(bool)));
- connect (nonfunctions, SIGNAL(clicked(bool)), this, SLOT(modeChanged(bool)));
- connect (functions, SIGNAL(clicked(bool)), this, SLOT(modeChanged(bool)));
- layout->addLayout (hbox);
-
- hidden_objects = new QCheckBox (i18n ("Show Hidden Objects"), this);
- connect (hidden_objects, SIGNAL (clicked(bool)), this, SLOT (boxChanged(bool)));
- layout->addWidget (hidden_objects);
-
- settingsChanged ();
-}
-
-RKObjectListViewSettingsWidget::~RKObjectListViewSettingsWidget () {
- RK_TRACE (APP);
-}
-
-void RKObjectListViewSettingsWidget::settingsChanged () {
- RK_TRACE (APP);
-
- hidden_objects->setChecked (settings->getSetting (RKObjectListViewSettings::ShowObjectsHidden));
-
- bool functions_shown = settings->getSetting (RKObjectListViewSettings::ShowObjectsFunction);
- bool vars_shown = settings->getSetting (RKObjectListViewSettings::ShowObjectsVariable);
- bool containers_shown = settings->getSetting (RKObjectListViewSettings::ShowObjectsContainer);
-
- if (functions_shown && vars_shown && containers_shown) {
- all->setChecked (true);
- } else if (vars_shown && containers_shown) {
- nonfunctions->setChecked (true);
- } else if (functions_shown && (!(vars_shown || containers_shown))) {
- functions->setChecked (true);
- } else {
- all->setChecked (false);
- nonfunctions->setChecked (false);
- functions->setChecked (false);
- }
-}
-
-void RKObjectListViewSettingsWidget::modeChanged (bool) {
- RK_TRACE (APP);
-
- if (all->isChecked ()) {
- settings->setSetting (RKObjectListViewSettings::ShowObjectsFunction, true);
- settings->setSetting (RKObjectListViewSettings::ShowObjectsVariable, true);
- settings->setSetting (RKObjectListViewSettings::ShowObjectsContainer, true);
- } else if (functions->isChecked ()) {
- settings->setSetting (RKObjectListViewSettings::ShowObjectsFunction, true);
- settings->setSetting (RKObjectListViewSettings::ShowObjectsVariable, false);
- settings->setSetting (RKObjectListViewSettings::ShowObjectsContainer, false);
- } else if (nonfunctions->isChecked ()) {
- settings->setSetting (RKObjectListViewSettings::ShowObjectsFunction, false);
- settings->setSetting (RKObjectListViewSettings::ShowObjectsVariable, true);
- settings->setSetting (RKObjectListViewSettings::ShowObjectsContainer, true);
- } else {
- RK_ASSERT (false);
- }
-}
-
-void RKObjectListViewSettingsWidget::boxChanged (bool) {
- RK_TRACE (APP);
-
- if (sender () == hidden_objects) {
- settings->setSetting (RKObjectListViewSettings::ShowObjectsHidden, hidden_objects->isChecked ());
- }
-}
-
#include "robjectbrowser.moc"
diff --git a/rkward/windows/robjectbrowser.h b/rkward/windows/robjectbrowser.h
index b5125f7..afcadb0 100644
--- a/rkward/windows/robjectbrowser.h
+++ b/rkward/windows/robjectbrowser.h
@@ -25,8 +25,6 @@
class RKObjectListView;
class RKObjectListViewSettings;
class QPushButton;
-class QRadioButton;
-class QCheckBox;
class RObject;
class RObjectBrowserInternal;
class KVBox;
@@ -103,28 +101,4 @@ private:
RKObjectListView *list_view;
};
-/** This class provides a widget to switch quickly between the most important RKObjectListViewSettings */
-class RKObjectListViewSettingsWidget : public QWidget {
- Q_OBJECT
-public:
- RKObjectListViewSettingsWidget (RKObjectListViewSettings *settings, QWidget *parent);
- ~RKObjectListViewSettingsWidget ();
-
- enum Modes {
- All = 0,
- NonFunctions = 1,
- Functions = 2
- };
-public slots:
- void settingsChanged ();
- void modeChanged (bool);
- void boxChanged (bool);
-private:
- QRadioButton *all;
- QRadioButton *nonfunctions;
- QRadioButton *functions;
- QCheckBox *hidden_objects;
- RKObjectListViewSettings *settings;
-};
-
#endif
More information about the rkward-tracker
mailing list