28 #include <QInputDialog>
29 #include <QApplication>
31 #include <QMessageBox>
33 #include <QHeaderView>
34 #include <QHBoxLayout>
35 #include <QVBoxLayout>
36 #include <QPushButton>
48 setObjectName (
"WorkspaceView");
49 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
51 setStatusTip (tr (
"View the variables in the active workspace."));
54 _filter->setToolTip (tr (
"Enter text to filter the workspace"));
57 _filter->setInsertPolicy (QComboBox::NoInsert);
59 QComboBox::AdjustToMinimumContentsLengthWithIcon);
60 QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred);
61 _filter->setSizePolicy (sizePol);
62 _filter->completer ()->setCaseSensitivity (Qt::CaseSensitive);
64 QLabel *filter_label =
new QLabel (tr (
"Filter"));
68 view->setWordWrap (
false);
69 view->setContextMenuPolicy (Qt::CustomContextMenu);
70 view->setShowGrid (
false);
71 (
view->verticalHeader) ()->hide ();
72 view->setAlternatingRowColors (
true);
79 QVBoxLayout *vbox_layout =
new QVBoxLayout ();
80 QHBoxLayout *hbox_layout =
new QHBoxLayout ();
81 hbox_layout->addWidget (filter_label);
83 hbox_layout->addWidget (
_filter);
84 vbox_layout->addLayout (hbox_layout);
85 vbox_layout->addWidget (
view);
86 vbox_layout->setMargin (2);
89 widget ()->setLayout (vbox_layout);
96 view->setSortingEnabled (
true);
98 settings->value (
"workspaceview/sort_by_column",0).toInt (),
99 static_cast<Qt::SortOrder
>
100 (settings->value (
"workspaceview/sort_order", Qt::AscendingOrder).toUInt ())
103 view->horizontalHeader ()->restoreState (
104 settings->value (
"workspaceview/column_state").toByteArray ());
107 _filter->addItems (settings->value (
"workspaceview/mru_list").toStringList ());
110 settings->value (
"workspaceview/filter_active",
false).toBool ();
116 connect (
_filter, SIGNAL (editTextChanged (
const QString&)),
120 connect (
_filter->lineEdit (), SIGNAL (editingFinished ()),
123 connect (
view, SIGNAL (customContextMenuRequested (
const QPoint&)),
127 p, SLOT (execute_command_in_terminal (
const QString&)));
135 settings->setValue (
"workspaceview/column_state",
136 view->horizontalHeader ()->saveState ());
138 int sort_column =
view->horizontalHeader ()->sortIndicatorSection ();
139 Qt::SortOrder sort_order =
view->horizontalHeader ()->sortIndicatorOrder ();
140 settings->setValue (
"workspaceview/sort_by_column", sort_column);
141 settings->setValue (
"workspaceview/sort_order", sort_order);
143 settings->setValue (
"workspaceview/filter_active",
147 for (
int i = 0; i <
_filter->count (); i++)
148 mru.append (
_filter->itemText (i));
149 settings->setValue (
"workspaceview/mru_list", mru);
168 QDockWidget::closeEvent (e);
194 int index =
_filter->findText (text);
206 index = index.sibling (index.row (), 0);
207 QAbstractItemModel *m =
view->model ();
210 return item_data[0].toString ();
218 QModelIndex index =
view->indexAt (qpos);
221 if (index.isValid () && index.column () == 0)
225 menu.addAction (tr (
"Copy name"),
this,
228 menu.addAction (tr (
"Copy value"),
this,
231 QAction *rename = menu.addAction (tr (
"Rename"),
this,
234 QAbstractItemModel *m =
view->model ();
239 rename->setDisabled (
true);
240 rename->setToolTip (tr (
"Only top-level symbols may be renamed."));
243 menu.addSeparator ();
245 menu.addAction (
"disp (" + var_name +
")",
this,
248 menu.addAction (
"plot (" + var_name +
")",
this,
251 menu.addAction (
"stem (" + var_name +
")",
this,
254 menu.exec (
view->mapToGlobal (qpos));
261 QModelIndex index =
view->currentIndex ();
263 if (index.isValid ())
267 QClipboard *clipboard = QApplication::clipboard ();
269 clipboard->setText (var_name);
276 QModelIndex index =
view->currentIndex ();
278 if (index.isValid ())
283 std::ostringstream buf;
286 QClipboard *clipboard = QApplication::clipboard ();
294 QModelIndex index =
view->currentIndex ();
296 if (index.isValid ())
300 QInputDialog* inputDialog =
new QInputDialog ();
302 inputDialog->setOptions (QInputDialog::NoButtons);
307 = inputDialog->getText (0,
"Rename Variable",
"New name:",
308 QLineEdit::Normal, var_name, &ok);
310 if (ok && ! new_name.isEmpty ())
312 QAbstractItemModel *m =
view->model ();
313 m->setData (index, new_name, Qt::EditRole);
339 QModelIndex index =
view->currentIndex ();
341 if (index.isValid ())
355 QFontMetrics fm =
view->fontMetrics ();
356 int row_height = fm.height ();
359 view->setRowHeight (i, row_height);
370 if (!settings->value (
"workspaceview/hide_tool_tips",
false).toBool ())
372 tool_tip = QString (tr (
"View the variables in the active workspace.<br>"));
373 tool_tip += QString (tr (
"Colors for variable attributes:"));
377 QString (
"<div style=\"background-color:%1;color:#000000\">%2</div>")
383 setToolTip (tool_tip);
390 if (
view->hasFocus ())
397 if (
view->hasFocus ())
void filter_activate(bool enable)
QCheckBox * _filter_checkbox
void closeEvent(QCloseEvent *event)
QColor storage_class_color(int s_class)
static uint32_t state[624]
void handle_contextmenu_stem(void)
QString fromStdString(const std::string &s)
void command_requested(const QString &cmd)
signal that user had requested a command on a variable
void filter_update(const QString &expression)
QSortFilterProxyModel _filter_model
static octave_value varval(const std::string &name, scope_id scope=xcurrent_scope, context_id context=xdefault_context)
void handle_contextmenu_rename(void)
workspace_view(QWidget *parent=0)
void setModel(workspace_model *model)
void contextmenu_requested(const QPoint &pos)
void update_filter_history()
void notice_settings(const QSettings *)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
int view_previous_row_count
void handle_model_changed(void)
static QSettings * get_settings(void)
QString get_var_name(QModelIndex index)
void notice_settings(const QSettings *)
void handle_contextmenu_copy(void)
void handle_contextmenu_disp(void)
static QString storage_class_chars(void)
static QStringList storage_class_names(void)
void relay_contextmenu_command(const QString &cmdname)
void handle_contextmenu_copy_value(void)
void handle_contextmenu_plot(void)
bool is_top_level(void) const