Mercurial > hg > octave-nkf
changeset 16462:8c666c7b0e5d
Added context menu to workspace variable display
* libgui/src/workspace-view.h, libgui/src/workspace-view.cc
(workspace_view::workspace_view): Connect signals for context menu.
(workspace_view::contextmenu_requested,
workspace_view::handle_contextmenu_disp,
workspace_view::handle_contextmenu_plot,
workspace_view::handle_contextmenu_stem): New slot functions.
(workspace_view::relay_contextmenu_command): New function.
(workspace_view::command_requested): New signal.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Sun, 07 Apr 2013 15:48:11 -0400 |
parents | 094bd3627ead |
children | 8e2a853cdd7d |
files | libgui/src/workspace-view.cc libgui/src/workspace-view.h |
diffstat | 2 files changed, 80 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/workspace-view.cc +++ b/libgui/src/workspace-view.cc @@ -30,6 +30,7 @@ #include <QHBoxLayout> #include <QVBoxLayout> #include <QPushButton> +#include <QMenu> workspace_view::workspace_view (QWidget *p) : QDockWidget (p) @@ -45,6 +46,7 @@ view->setAnimated (false); // Deactivate animations because of strange glitches. view->setTextElideMode (Qt::ElideRight);// Elide text to the right side of the cells. view->setWordWrap (false); // No wordwrapping in cells. + view->setContextMenuPolicy (Qt::CustomContextMenu); // Set an empty widget, so we can assign a layout to it. setWidget (new QWidget (this)); @@ -81,6 +83,12 @@ connect (view, SIGNAL (doubleClicked (QModelIndex)), this, SLOT (item_double_clicked (QModelIndex))); + connect (view, SIGNAL (customContextMenuRequested(const QPoint&)), + this, SLOT(contextmenu_requested (const QPoint&))); + + connect (this, SIGNAL (command_requested (const QString&)), + p, SLOT (handle_command_double_clicked(const QString&))); + // topLevelChanged is emitted when floating property changes (floating = true) connect (this, SIGNAL (topLevelChanged(bool)), this, SLOT(top_level_changed(bool))); @@ -245,3 +253,66 @@ if (visible && ! isFloating ()) focus (); } + +void +workspace_view::contextmenu_requested (const QPoint& pos) +{ + QMenu menu (this); + + QModelIndex index = view->indexAt (pos); + QAbstractItemModel *m = view->model (); + + // if it isnt Local, Glocal etc, allow the ctx menu + if (index.parent() != QModelIndex()) + { + QMap<int, QVariant> item_data = m->itemData (index); + + QString var_name = item_data[0].toString (); + + menu.addAction ("disp(" + var_name + ")", this, + SLOT (handle_contextmenu_disp ())); + + menu.addAction ("plot(" + var_name + ")", this, + SLOT (handle_contextmenu_plot ())); + + menu.addAction ("stem(" + var_name + ")", this, + SLOT (handle_contextmenu_stem ())); + + menu.exec (view->mapToGlobal (pos)); + } +} + +void +workspace_view::handle_contextmenu_disp (void) +{ + relay_contextmenu_command ("disp"); +} + +void +workspace_view::handle_contextmenu_plot (void) +{ + relay_contextmenu_command("figure;\nplot"); +} + +void +workspace_view::handle_contextmenu_stem (void) +{ + relay_contextmenu_command ("figure;\nstem"); +} + +void +workspace_view::relay_contextmenu_command (const QString& cmdname) +{ + QModelIndex index = view->currentIndex (); + + if (index.parent () != QModelIndex ()) + { + QAbstractItemModel *m = view->model (); + + QMap<int, QVariant> item_data = m->itemData (index); + + QString var_name = item_data[0].toString (); + + emit command_requested (cmdname + "(" + var_name + ")\n"); + } +}
--- a/libgui/src/workspace-view.h +++ b/libgui/src/workspace-view.h @@ -59,6 +59,8 @@ signals: /** Custom signal that tells if a user has clicke away that dock widget. */ void active_changed (bool active); + /** signal that user had requested a command on a variable */ + void command_requested (const QString& cmd); protected: void closeEvent (QCloseEvent *event); @@ -67,8 +69,14 @@ void collapse_requested (QModelIndex index); void expand_requested (QModelIndex index); void item_double_clicked (QModelIndex index); + void contextmenu_requested (const QPoint& pos); + // context menu slots + void handle_contextmenu_disp (); + void handle_contextmenu_plot (); + void handle_contextmenu_stem (); +private: + void relay_contextmenu_command (const QString& cmdname); -private: QTreeView *view; struct