28 #include <QInputDialog>
29 #include <QApplication>
31 #include <QMessageBox>
33 #include <QHeaderView>
34 #include <QHBoxLayout>
35 #include <QVBoxLayout>
36 #include <QPushButton>
45 setObjectName (
"WorkspaceView");
46 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
48 setStatusTip (tr (
"View the variables in the active workspace."));
50 view->setWordWrap (
false);
51 view->setContextMenuPolicy (Qt::CustomContextMenu);
58 QVBoxLayout *vbox_layout =
new QVBoxLayout ();
59 vbox_layout->addWidget (
view);
60 vbox_layout->setMargin (2);
63 widget ()->setLayout (vbox_layout);
71 view->horizontalHeader ()->restoreState (
72 settings->value (
"workspaceview/column_state").toByteArray ());
76 connect (
view, SIGNAL (customContextMenuRequested (
const QPoint&)),
80 p, SLOT (execute_command_in_terminal (
const QString&)));
88 settings->setValue (
"workspaceview/column_state",
89 view->horizontalHeader ()->saveState ());
96 view->setModel (model);
112 QModelIndex index =
view->indexAt (qpos);
113 QAbstractItemModel *m =
view->model ();
116 if (index.isValid () && index.column () == 0)
118 index = index.sibling (index.row (), 0);
122 QString var_name = item_data[0].toString ();
124 menu.addAction (tr (
"Copy"),
this,
127 QAction *rename = menu.addAction (tr (
"Rename"),
this,
134 rename->setDisabled (
true);
135 rename->setToolTip (tr (
"Only top-level symbols may be renamed."));
138 menu.addSeparator ();
140 menu.addAction (
"disp (" + var_name +
")",
this,
143 menu.addAction (
"plot (" + var_name +
")",
this,
146 menu.addAction (
"stem (" + var_name +
")",
this,
149 menu.exec (
view->mapToGlobal (qpos));
156 QModelIndex index =
view->currentIndex ();
158 if (index.isValid ())
160 index = index.sibling (index.row (), 0);
162 QAbstractItemModel *m =
view->model ();
166 QString var_name = item_data[0].toString ();
168 QClipboard *clipboard = QApplication::clipboard ();
170 clipboard->setText (var_name);
177 QModelIndex index =
view->currentIndex ();
179 if (index.isValid ())
181 index = index.sibling (index.row (), 0);
183 QAbstractItemModel *m =
view->model ();
187 QString var_name = item_data[0].toString ();
189 QInputDialog* inputDialog =
new QInputDialog ();
191 inputDialog->setOptions (QInputDialog::NoButtons);
196 = inputDialog->getText (0,
"Rename Variable",
"New name:",
197 QLineEdit::Normal, var_name, &ok);
199 if (ok && ! new_name.isEmpty ())
200 m->setData (index, new_name, Qt::EditRole);
225 QModelIndex index =
view->currentIndex ();
227 if (index.isValid ())
229 index = index.sibling (index.row (), 0);
231 QAbstractItemModel *m =
view->model ();
235 QString var_name = item_data[0].toString ();
246 QFontMetrics fm =
view->fontMetrics ();
247 int row_height = fm.height ();
248 int new_row_count =
view->model ()->rowCount ();
250 view->setRowHeight (i, row_height);
260 tool_tip = QString (tr (
"View the variables in the active workspace.<br>"));
261 tool_tip += QString (tr (
"Colors for the storage class:"));
265 QString (
"<div style=\"background-color:%1;color:#000000\">%2</div>")
269 setToolTip (tool_tip);
275 if (
view->hasFocus ())