26 #if defined (HAVE_CONFIG_H)
30 #include <QApplication>
33 #include <QHBoxLayout>
34 #include <QHeaderView>
35 #include <QInputDialog>
39 #include <QMessageBox>
40 #include <QPushButton>
41 #include <QSignalMapper>
42 #include <QVBoxLayout>
57 m_filter_checkbox (new QCheckBox ()),
58 m_filter (new QComboBox (this)),
59 m_filter_widget (new
QWidget (this))
61 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
63 setStatusTip (tr (
"View the variables in the active workspace."));
65 m_filter->setToolTip (tr (
"Enter text to filter the workspace"));
68 m_filter->setInsertPolicy (QComboBox::NoInsert);
69 m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon);
70 QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred);
72 m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive);
74 QLabel *filter_label =
new QLabel (tr (
"Filter"));
76 m_view->setWordWrap (
false);
77 m_view->setContextMenuPolicy (Qt::CustomContextMenu);
78 m_view->setShowGrid (
false);
79 (
m_view->verticalHeader) ()->hide ();
80 m_view->setAlternatingRowColors (
true);
87 QHBoxLayout *filter_layout =
new QHBoxLayout ();
89 filter_layout->addWidget (filter_label);
92 filter_layout->setMargin (0);
96 QVBoxLayout *ws_layout =
new QVBoxLayout ();
98 ws_layout->addWidget (
m_view);
99 ws_layout->setSpacing (0);
109 ws_layout->setMargin (2);
112 widget ()->setLayout (ws_layout);
117 m_view->setSortingEnabled (
true);
119 m_view->horizontalHeader ()->restoreState
123 #if defined (HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE)
124 m_view->horizontalHeader ()->setSectionsClickable (
true);
126 m_view->horizontalHeader ()->setClickable (
true);
128 #if defined (HAVE_QHEADERVIEW_SETSECTIONSMOVABLE)
129 m_view->horizontalHeader ()->setSectionsMovable (
true);
131 m_view->horizontalHeader ()->setMovable (
true);
133 m_view->horizontalHeader ()->setSortIndicator (
139 m_view->horizontalHeader ()->setSortIndicatorShown (
true);
141 m_view->horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu);
142 connect (
m_view->horizontalHeader (),
143 SIGNAL (customContextMenuRequested (
const QPoint &)),
157 connect (
m_filter, SIGNAL (editTextChanged (
const QString&)),
161 connect (
m_filter->lineEdit (), SIGNAL (editingFinished ()),
164 connect (
m_view, SIGNAL (customContextMenuRequested (
const QPoint&)),
167 connect (
m_view, SIGNAL (activated (QModelIndex)),
171 p, SLOT (execute_command_in_terminal (
const QString&)));
175 p, SLOT (edit_variable (
const QString&,
const octave_value&)));
210 tool_tip = QString (tr (
"View the variables in the active workspace.<br>"));
211 tool_tip += QString (tr (
"Colors for variable attributes:"));
216 QString (R
"(<div style="background-color:%1;color:%2">%3</div>)")
224 setToolTip (tool_tip);
237 m_view->horizontalHeader ()->saveState ());
239 int sort_column =
m_view->horizontalHeader ()->sortIndicatorSection ();
240 Qt::SortOrder sort_order =
m_view->horizontalHeader ()->sortIndicatorOrder ();
248 for (
int i = 0; i <
m_filter->count (); i++)
249 mru.append (
m_filter->itemText (i));
293 QSignalMapper sig_mapper (
this);
302 &sig_mapper, SLOT (map ()));
303 sig_mapper.setMapping (action, i);
304 action->setCheckable (
true);
308 connect (&sig_mapper, SIGNAL (mapped (
int)),
311 menu.exec (
m_view->mapToGlobal (mpos));
321 bool shown =
settings->value (key,
true).toBool ();
323 m_view->setColumnHidden (col + 1, shown);
336 QModelIndex index =
m_view->indexAt (qpos);
339 if (index.isValid () && index.column () == 0)
343 menu.addAction (tr (
"Open in Variable Editor"),
this,
346 menu.addAction (tr (
"Copy name"),
this,
349 menu.addAction (tr (
"Copy value"),
this,
352 QAction *
rename = menu.addAction (tr (
"Rename"),
this,
359 rename->setDisabled (
true);
360 rename->setToolTip (tr (
"Only top-level symbols may be renamed"));
363 menu.addAction (
"Clear " + var_name,
this,
366 menu.addSeparator ();
368 menu.addAction (
"disp (" + var_name +
')',
this,
371 menu.addAction (
"plot (" + var_name +
')',
this,
374 menu.addAction (
"stem (" + var_name +
')',
this,
377 menu.addSeparator ();
382 menu.addAction (tr (
"Hide filter"),
this,
385 menu.addAction (tr (
"Show filter"),
this,
388 menu.exec (
m_view->mapToGlobal (qpos));
394 QModelIndex index =
m_view->currentIndex ();
396 if (index.isValid ())
400 QClipboard *clipboard = QApplication::clipboard ();
402 clipboard->setText (var_name);
409 QModelIndex index =
m_view->currentIndex ();
411 if (index.isValid ())
425 std::ostringstream buf;
431 QClipboard *clipboard = QApplication::clipboard ();
440 QModelIndex index =
m_view->currentIndex ();
442 if (index.isValid ())
446 QInputDialog *inputDialog =
new QInputDialog ();
448 inputDialog->setOptions (QInputDialog::NoButtons);
453 = inputDialog->getText (
nullptr,
"Rename Variable",
"New name:",
454 QLineEdit::Normal, var_name, &ok);
456 if (ok && ! new_name.isEmpty ())
464 QModelIndex index =
m_view->currentIndex ();
466 if (index.isValid ())
514 QFontMetrics fm =
m_view->fontMetrics ();
515 int row_height = fm.height ();
518 m_view->setRowHeight (i, row_height);
539 QModelIndex index =
m_view->currentIndex ();
541 if (index.isValid ())
560 QAbstractItemModel *
m =
m_view->model ();
563 =
m->itemData (index.sibling (index.row (), 0));
565 return item_data[0].toString ();
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
octave_value varval(const std::string &name) const
gui_settings * get_settings(void) const
octave_value varval(const std::string &name) const
bool is_top_level(void) const
QColor storage_class_color(int s_class)
void notice_settings(const gui_settings *)
symbol_info_list get_symbol_info(void) const
int m_view_previous_row_count
void handle_contextmenu_stem(void)
void toggle_header(int column)
void rename_variable_signal(const QString &, const QString &)
Signal that user wants to rename a variable.
void header_contextmenu_requested(const QPoint &mpos)
void relay_contextmenu_command(const QString &cmdname, bool str=false)
void handle_contextmenu_filter(void)
void handle_contextmenu_edit(void)
void contextmenu_requested(const QPoint &pos)
void filter_activate(bool enable)
void edit_variable_signal(const QString &, const octave_value &)
Signal that user wants to edit a variable.
void handle_contextmenu_plot(void)
workspace_model * m_model
void notice_settings(const gui_settings *)
void update_filter_history(void)
void command_requested(const QString &cmd)
Signal that user had requested a command on a variable.
void handle_model_changed(void)
QCheckBox * m_filter_checkbox
void handle_contextmenu_copy_value(void)
void setModel(workspace_model *model)
void handle_contextmenu_clear(void)
void handle_contextmenu_rename(void)
void handle_contextmenu_disp(void)
void filter_update(const QString &expression)
QWidget * m_filter_widget
workspace_view(QWidget *parent, base_qobject &oct_qobj)
QString get_var_name(const QModelIndex &index)
QSortFilterProxyModel m_filter_model
void handle_contextmenu_copy(void)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool is_undefined(void) const
void translate(Matrix &m, double x, double y, double z)
const QStringList ws_columns_shown(QStringList()<< QT_TRANSLATE_NOOP("octave::workspace_view", "Class")<< QT_TRANSLATE_NOOP("octave::workspace_view", "Dimension")<< QT_TRANSLATE_NOOP("octave::workspace_view", "Value")<< QT_TRANSLATE_NOOP("octave::workspace_view", "Attribute"))
const gui_pref ws_column_state("workspaceview/column_state", QVariant())
const gui_pref ws_sort_order("workspaceview/sort_order", QVariant(Qt::AscendingOrder))
const gui_pref ws_filter_shown("workspaceview/filter_shown", QVariant(true))
const QStringList ws_color_names(QStringList()<< QT_TRANSLATE_NOOP("octave::settings_dialog", "argument")<< QT_TRANSLATE_NOOP("octave::settings_dialog", "global")<< QT_TRANSLATE_NOOP("octave::settings_dialog", "persistent"))
const gui_pref ws_mru_list("workspaceview/mru_list", QVariant())
const QStringList ws_columns_shown_keys(QStringList()<< "workspaceview/show_class"<< "workspaceview/show_dimension"<< "workspaceview/show_value"<< "workspaceview/show_attribute")
const gui_pref ws_sort_column("workspaceview/sort_by_column", QVariant(0))
const gui_pref ws_enable_colors("workspaceview/enable_colors", QVariant(false))
const gui_pref ws_max_filter_history("workspaceview/max_filter_history", QVariant(10))
const gui_pref ws_filter_active("workspaceview/filter_active", QVariant(false))
const gui_pref ws_hide_tool_tips("workspaceview/hide_tools_tips", QVariant(false))
const int ws_colors_count
QString fromStdString(const std::string &s)
int rename(const std::string &from, const std::string &to)
static uint32_t state[624]