[rkward/work/workspace_browser_redesign] rkward: Style the two root level items to look like accordion captions in the workspace browser.
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Fri Nov 6 09:59:34 UTC 2015
Git commit 26e98cfe5bbe82a12abb1d36a2a13c52d51f6ce8 by Thomas Friedrichsmeier.
Committed on 06/11/2015 at 09:54.
Pushed by tfry into branch 'work/workspace_browser_redesign'.
Style the two root level items to look like accordion captions in the workspace browser.
M +7 -0 rkward/core/renvironmentobject.cpp
M +2 -1 rkward/core/renvironmentobject.h
M +1 -1 rkward/core/robject.h
M +4 -5 rkward/misc/rkaccordiontable.cpp
M +64 -4 rkward/misc/rkobjectlistview.cpp
M +5 -4 rkward/misc/rkobjectlistview.h
M +3 -0 rkward/misc/rkstandardicons.cpp
M +3 -0 rkward/misc/rkstandardicons.h
http://commits.kde.org/rkward/26e98cfe5bbe82a12abb1d36a2a13c52d51f6ce8
diff --git a/rkward/core/renvironmentobject.cpp b/rkward/core/renvironmentobject.cpp
index ac97171..2ee3937 100644
--- a/rkward/core/renvironmentobject.cpp
+++ b/rkward/core/renvironmentobject.cpp
@@ -48,6 +48,13 @@ REnvironmentObject::~REnvironmentObject () {
RK_TRACE (OBJECTS);
}
+QString REnvironmentObject::getObjectDescription () const {
+ if (isType (GlobalEnv)) {
+ return i18n ("This section contains data in your \"workspace\". This is data that you created or imported, in contrast to data contained in a loaded R package. Technically, this corresponds to the <i>.GlobalEnv</i> environment.");
+ }
+ return RContainerObject::getObjectDescription ();
+}
+
QString REnvironmentObject::packageName () const {
RK_ASSERT (isType (PackageEnv));
if (!isType (PackageEnv)) RK_DEBUG (OBJECTS, DL_WARNING, "%s", qPrintable (name));
diff --git a/rkward/core/renvironmentobject.h b/rkward/core/renvironmentobject.h
index 49d190f..5125c02 100644
--- a/rkward/core/renvironmentobject.h
+++ b/rkward/core/renvironmentobject.h
@@ -2,7 +2,7 @@
renvironmentobject - description
-------------------
begin : Wed Sep 27 2006
- copyright : (C) 2006, 2009, 2011 by Thomas Friedrichsmeier
+ copyright : (C) 2006, 2009, 2011, 2015 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -42,6 +42,7 @@ public:
/** reimplemented from RContainerObject: If this is an environment var, call RContainerObject::writeMetaData (). Else, do nothing. An environment has no meta data. */
void writeMetaData (RCommandChain *chain);
QString packageName () const;
+ QString getObjectDescription () const;
protected:
bool updateStructure (RData *new_data);
/// reimplemented from RContainerObject to call "remove (objectname)" instead of "objectname <- NULL"
diff --git a/rkward/core/robject.h b/rkward/core/robject.h
index ace64d5..239bc10 100644
--- a/rkward/core/robject.h
+++ b/rkward/core/robject.h
@@ -197,7 +197,7 @@ public:
static RDataType textToType (const QString &text);
/** Returns the given string in quotes, taking care of escaping quotation marks inside the string. */
static QString rQuote (const QString &string);
-/** Returns a pretty description of the object, and its most important properties. TODO should this be virtual or not? I suppose, it's a close call. For now, we do all work here with casts */
+/** Returns a pretty description of the object, and its most important properties. */
virtual QString getObjectDescription () const;
/** Parses an object path (such as package::name[["a"]]$b at slot) into its components, returning them as a list (in this case 'package', '::' 'name', '$', 'a', '$', 'b', '@', 'slot'). */
static QStringList parseObjectPath (const QString &path);
diff --git a/rkward/misc/rkaccordiontable.cpp b/rkward/misc/rkaccordiontable.cpp
index 6627c6b..d374451 100644
--- a/rkward/misc/rkaccordiontable.cpp
+++ b/rkward/misc/rkaccordiontable.cpp
@@ -217,14 +217,13 @@ private:
#include <QStyledItemDelegate>
#include <QPainter>
-#include <kicon.h>
/** Responsible for drawing expand / collapse indicators in first column */
class RKAccordionDelegate : public QStyledItemDelegate {
public:
RKAccordionDelegate (RKAccordionTable* parent) : QStyledItemDelegate (parent) {
table = parent;
- expanded = KIcon ("arrow-up");
- collapsed = KIcon ("arrow-down");
+ expanded = RKStandardIcons::getIcon (RKStandardIcons::ActionCollapseUp);
+ collapsed = RKStandardIcons::getIcon (RKStandardIcons::ActionExpandDown);
}
void initStyleOption (QStyleOptionViewItem* option, const QModelIndex& index) const {
QStyledItemDelegate::initStyleOption (option, index);
@@ -240,8 +239,8 @@ public:
}
RKAccordionDummyModel *pmodel;
RKAccordionTable* table;
- KIcon expanded;
- KIcon collapsed;
+ QIcon expanded;
+ QIcon collapsed;
};
#include <QPainter>
diff --git a/rkward/misc/rkobjectlistview.cpp b/rkward/misc/rkobjectlistview.cpp
index 3dc8b8a..43f8361 100644
--- a/rkward/misc/rkobjectlistview.cpp
+++ b/rkward/misc/rkobjectlistview.cpp
@@ -21,32 +21,87 @@
#include <QContextMenuEvent>
#include <QMenu>
#include <QTimer>
+#include <QStyledItemDelegate>
#include "../rkglobals.h"
#include "../core/robjectlist.h"
#include "../core/renvironmentobject.h"
#include "../core/rkmodificationtracker.h"
+#include "rkstandardicons.h"
#include "../settings/rksettingsmoduleobjectbrowser.h"
#include "../debug.h"
+/** Responsible for drawing the root level items "My Objects" and "Other Environments" */
+class RKObjectListViewRootDelegate : public QStyledItemDelegate {
+public:
+ RKObjectListViewRootDelegate (RKObjectListView* parent) : QStyledItemDelegate (parent) {
+ tree = parent;
+ expanded = RKStandardIcons::getIcon (RKStandardIcons::ActionCollapseUp);
+ collapsed = RKStandardIcons::getIcon (RKStandardIcons::ActionExpandDown);
+ }
+ void initStyleOption (QStyleOptionViewItem* option, const QModelIndex& index) const {
+ QStyledItemDelegate::initStyleOption (option, index);
+ if (!index.parent ().isValid ()) {
+ QStyleOptionViewItemV4 *v4 = qstyleoption_cast<QStyleOptionViewItemV4 *> (option);
+ if (!v4) {
+ RK_ASSERT (false);
+ return;
+ }
+ v4->icon = tree->isExpanded (index) ? expanded : collapsed;
+ //v4->decorationPosition = QStyleOptionViewItemV4::Right; // easily gets out of the picture, thus using left-align
+ v4->features |= QStyleOptionViewItemV2::HasDecoration;
+
+ RObject* object = static_cast<RObject*> (tree->settings->mapToSource (index).internalPointer ());
+ v4->font.setBold (true);
+ v4->backgroundBrush = tree->palette ().mid ();
+ if (object == RObjectList::getObjectList ()) {
+ v4->text = i18n ("Other Environments");
+ } else {
+ if (tree->model ()->hasChildren (index)) v4->text = i18n ("My Workspace");
+ else v4->text = i18n ("My Workspace (no objects matching filter)");
+ }
+ }
+ }
+ RKObjectListView* tree;
+ QIcon expanded;
+ QIcon collapsed;
+};
+
RKObjectListView::RKObjectListView (QWidget *parent) : QTreeView (parent) {
RK_TRACE (APP);
root_object = 0;
+ rkdelegate = new RKObjectListViewRootDelegate (this);
settings = new RKObjectListViewSettings (this);
setSortingEnabled (true);
+ sortByColumn (0, Qt::AscendingOrder);
menu = new QMenu (this);
menu->addMenu (settings->showObjectsMenu ());
menu->addMenu (settings->showFieldsMenu ());
menu->addAction (i18n ("Configure Defaults"), this, SLOT (popupConfigure()));
+
+ connect (this, SIGNAL(clicked(QModelIndex)), this, SLOT(itemClicked(QModelIndex)));
}
RKObjectListView::~RKObjectListView () {
RK_TRACE (APP);
}
+void RKObjectListView::itemClicked (const QModelIndex& index) {
+ RK_TRACE (APP);
+
+ if (!index.parent ().isValid ()) { // root level (pseudo) items expand on click
+ QModelIndex fixed_index = model ()->index (index.row (), 0, index.parent ());;
+ if (!isExpanded (fixed_index)) {
+ expand (fixed_index);
+ resizeColumnToContents (0);
+ }
+ else collapse (fixed_index);
+ }
+}
+
void RKObjectListView::setObjectCurrent (RObject *object, bool only_if_none_current) {
RK_TRACE (APP);
@@ -73,6 +128,7 @@ void RKObjectListView::setRootObject (RObject *root) {
setRootIndex (index);
settingsChanged (); // Updates column sizes. Note: Recurses into this function, but with index == rootIndex()
}
+ setRootIsDecorated (index.isValid ());
}
RObject* RKObjectListView::objectAtIndex (const QModelIndex& index) const {
@@ -101,8 +157,6 @@ RObject::ObjectList RKObjectListView::selectedObjects () const {
return list;
}
-// KDE4 TODO: does this really need to be virtual?
-//virtual
void RKObjectListView::popupConfigure () {
RK_TRACE (APP);
RKSettings::configureSettings (RKSettings::PageObjectBrowser, this);
@@ -157,7 +211,9 @@ void RKObjectListView::settingsChanged () {
setRootObject (root_object);
if (!root_object) {
setFirstColumnSpanned (0, QModelIndex (), true);
+ setItemDelegateForRow (0, rkdelegate);
setFirstColumnSpanned (1, QModelIndex (), true);
+ setItemDelegateForRow (1, rkdelegate);
}
resizeColumnToContents (0);
}
@@ -233,8 +289,8 @@ bool RKObjectListViewSettings::filterAcceptsRow (int source_row, const QModelInd
object = object->findChildByObjectModelIndex (source_row);
RK_ASSERT (object);
- // always show the global env
- if (object->isType (RObject::GlobalEnv)) return true;
+ // always show global env and search path
+ if (!object->parentObject ()) return true;
if (!settings[ShowObjectsHidden]) {
if (object->getShortName ().startsWith ('.')) return false;
@@ -273,6 +329,10 @@ bool RKObjectListViewSettings::lessThan (const QModelIndex& left, const QModelIn
return (left_parent->getObjectModelIndexOf (left_object) < right_parent->getObjectModelIndexOf (right_object));
} else if (left_object->isPseudoObject ()) return false;
else if (right_object->isPseudoObject ()) return true;
+ else if (!left.parent ().isValid ()) {
+ // For the two root items, _always_ sort .GlobalEnv on top, irrespective of sort order
+ return ((static_cast<RObject*> (left.internalPointer ()) == RObjectList::getGlobalEnv ()) == (sortOrder () == Qt::AscendingOrder));
+ }
return (QSortFilterProxyModel::lessThan (left, right));
}
diff --git a/rkward/misc/rkobjectlistview.h b/rkward/misc/rkobjectlistview.h
index fec3c9b..a5b2a19 100644
--- a/rkward/misc/rkobjectlistview.h
+++ b/rkward/misc/rkobjectlistview.h
@@ -2,7 +2,7 @@
rkobjectlistview - description
-------------------
begin : Wed Sep 1 2004
- copyright : (C) 2004, 2006, 2007, 2010, 2011 by Thomas Friedrichsmeier
+ copyright : (C) 2004-2015 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -70,15 +70,16 @@ public slots:
void updateStarted ();
void selectionChanged (const QItemSelection & selected, const QItemSelection & deselected);
void settingsChanged ();
-
- virtual void popupConfigure ();
+ void popupConfigure ();
+ void itemClicked (const QModelIndex& index);
protected:
void contextMenuEvent (QContextMenuEvent* event);
private:
QMenu *menu;
RObject *menu_object;
RObject *root_object;
-
+friend class RKObjectListViewRootDelegate;
+ QAbstractItemDelegate *rkdelegate;
RKObjectListViewSettings *settings;
};
diff --git a/rkward/misc/rkstandardicons.cpp b/rkward/misc/rkstandardicons.cpp
index 6edf45f..6234330 100644
--- a/rkward/misc/rkstandardicons.cpp
+++ b/rkward/misc/rkstandardicons.cpp
@@ -63,6 +63,9 @@ void RKStandardIcons::initIcons () {
icons[ActionMoveUp] = KIcon ("go-up");
icons[ActionMoveDown] = KIcon ("go-down");
+ icons[ActionExpandDown] = KIcon ("arrow-down");
+ icons[ActionCollapseUp] = KIcon ("arrow-up");
+
icons[ActionDocumentInfo] = KIcon ("documentinfo.png");
icons[ActionFlagGreen] = KIcon ("flag-green.png");
icons[ActionSnapshot] = KIcon ("list-add.png");
diff --git a/rkward/misc/rkstandardicons.h b/rkward/misc/rkstandardicons.h
index 9639587..644b07b 100644
--- a/rkward/misc/rkstandardicons.h
+++ b/rkward/misc/rkstandardicons.h
@@ -63,6 +63,9 @@ public:
ActionMoveUp,
ActionMoveDown,
+ ActionExpandDown,
+ ActionCollapseUp,
+
ActionDocumentInfo,
ActionFlagGreen,
ActionSnapshot,
More information about the rkward-tracker
mailing list