annotate libgui/src/workspace-model.cc @ 16610:a1f613e5066d

workspace view colors based upon variable scope (derived from Dan's patch #8013) * resource-manager.cc/.h(storage_class_names): function returning scope names (storage_class_colors): function returning default colors for scopes (storage_class_chars): function returning the ident. characters of the scopes * color-picker.cc(constructor): prevent focus for the colored pushbutton * settings-dialog.cc/.h(read_workspace_colors): function reading the colors from the setitngs and creating a table with color-pickers in the settings dialog (write_wirkspace_colors): function getting the states of the color-pickers and writing them into the settings files * settings-dialog.cc(constructor): call read_workspace_colors (write_changed_settings): call write_workspace_colors * settings-dialog.ui: new tab for workspace settings with a box for the colors * workspace_model.cc/.h(notice_settings): reading colors from the settings * workspace-model.cc(constructor): initialize list of colors (data): reorganize determining the appropriate data and take background color role into consideration * workspace-model.h(storage_class_color): returns the color for a specific scope * workspace-view.cc/.h(notice_settings): create tool tip with color key (setModel): not inline anymore, actual model is stored in _model
author Torsten <ttl@justmail.de>
date Sat, 04 May 2013 09:37:28 +0200
parents 8701792e16ec
children 64f9a3e301d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
1 /*
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
2
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
3 Copyright (C) 2013 John W. Eaton
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
4 Copyright (C) 2011-2012 Jacob Dawid
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
5
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
6 This file is part of Octave.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
7
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
9 under the terms of the GNU General Public License as published by the
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
11 option) any later version.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
12
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
16 for more details.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
17
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
18 You should have received a copy of the GNU General Public License
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
19 along with Octave; see the file COPYING. If not, see
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
20 <http://www.gnu.org/licenses/>.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
21
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
22 */
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
23
15155
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
24 #ifdef HAVE_CONFIG_H
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
25 #include <config.h>
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
26 #endif
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
27
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
28 #include <QTreeWidget>
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
29 #include <QSettings>
15155
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
30
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
31 #include "utils.h"
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
32 #include "resource-manager.h"
15155
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
33 #include "workspace-model.h"
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
34
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
35 workspace_model::workspace_model (QObject *p)
16477
64727ed135cb use QTableView instead of QTreeView to display workspace
John Donoghue <john.donoghue@ieee.org>
parents: 16468
diff changeset
36 : QAbstractTableModel (p)
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
37 {
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
38 _columnNames.append (tr ("Name"));
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
39 _columnNames.append (tr ("Class"));
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
40 _columnNames.append (tr ("Dimension"));
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
41 _columnNames.append (tr ("Value"));
16527
8701792e16ec include column in workspace viewer for storage class
John W. Eaton <jwe@octave.org>
parents: 16521
diff changeset
42 _columnNames.append (tr ("Storage Class"));
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
43
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
44 for (int i = 0; i < resource_manager::storage_class_chars ().length (); i++)
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
45 _storage_class_colors.append (QColor (Qt::white));
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
46
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
47 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
48
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
49 int
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
50 workspace_model::rowCount (const QModelIndex&) const
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
51 {
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
52 return _symbols.size ();
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
53 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
54
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
55 int
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
56 workspace_model::columnCount (const QModelIndex&) const
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
57 {
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
58 return _columnNames.size ();
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
59 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
60
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
61 Qt::ItemFlags
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
62 workspace_model::flags (const QModelIndex& idx) const
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
63 {
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
64 Qt::ItemFlags retval = 0;
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
65
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
66 if (idx.isValid ())
16521
dbc7018be4be use context menu for workspace viewer rename and copy to clipboard operations
John W. Eaton <jwe@octave.org>
parents: 16502
diff changeset
67 {
dbc7018be4be use context menu for workspace viewer rename and copy to clipboard operations
John W. Eaton <jwe@octave.org>
parents: 16502
diff changeset
68 retval |= Qt::ItemIsEnabled;
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
69
16521
dbc7018be4be use context menu for workspace viewer rename and copy to clipboard operations
John W. Eaton <jwe@octave.org>
parents: 16502
diff changeset
70 if (_top_level && idx.column () == 0)
dbc7018be4be use context menu for workspace viewer rename and copy to clipboard operations
John W. Eaton <jwe@octave.org>
parents: 16502
diff changeset
71 retval |= Qt::ItemIsSelectable;
dbc7018be4be use context menu for workspace viewer rename and copy to clipboard operations
John W. Eaton <jwe@octave.org>
parents: 16502
diff changeset
72 }
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
73
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
74 return retval;
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
75 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
76
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
77 QVariant
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
78 workspace_model::headerData (int section, Qt::Orientation orientation,
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
79 int role) const
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
80 {
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
81 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
82 return _columnNames[section];
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
83 else
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
84 return QVariant();
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
85 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
86
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
87 QVariant
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
88 workspace_model::data (const QModelIndex& idx, int role) const
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
89 {
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
90 QVariant retval;
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
91
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
92 if (idx.isValid ())
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
93 {
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
94 if (role == Qt::BackgroundColorRole)
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
95 {
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
96 QString class_chars = resource_manager::storage_class_chars ();
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
97 int actual_class = class_chars.indexOf (_scopes[idx.row()].toAscii ());
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
98 if (actual_class >= 0)
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
99 return QVariant (_storage_class_colors.at (actual_class));
16521
dbc7018be4be use context menu for workspace viewer rename and copy to clipboard operations
John W. Eaton <jwe@octave.org>
parents: 16502
diff changeset
100 else
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
101 return retval;
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
102 }
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
103
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
104 if (role == Qt::DisplayRole
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
105 || (idx.column () == 0 && role == Qt::EditRole)
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
106 || (idx.column () == 0 && role == Qt::ToolTipRole) )
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
107 {
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
108 switch (idx.column ())
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
109 {
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
110 case 0:
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
111 if (role == Qt::ToolTipRole)
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
112 retval = QVariant (tr ("Right click to copy, rename, or display"));
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
113 else
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
114 retval = QVariant (_symbols[idx.row()]);
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
115 break;
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
116
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
117 case 1:
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
118 retval = QVariant (_class_names[idx.row()]);
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
119 break;
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
120
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
121 case 2:
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
122 retval = QVariant (_dimensions[idx.row()]);
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
123 break;
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
124
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
125 case 3:
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
126 retval = QVariant (_values[idx.row()]);
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
127 break;
16527
8701792e16ec include column in workspace viewer for storage class
John W. Eaton <jwe@octave.org>
parents: 16521
diff changeset
128
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
129 case 4:
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
130 retval = QVariant ();
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
131 QString class_chars = resource_manager::storage_class_chars ();
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
132 int actual_class = class_chars.indexOf (_scopes[idx.row()].toAscii ());
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
133 if (actual_class >= 0)
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
134 {
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
135 QStringList class_names = resource_manager::storage_class_names ();
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
136 retval = QVariant (class_names.at (actual_class));
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
137 }
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
138 break;
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
139
16527
8701792e16ec include column in workspace viewer for storage class
John W. Eaton <jwe@octave.org>
parents: 16521
diff changeset
140 }
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
141 }
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
142 }
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
143
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
144 return retval;
14664
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
145 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
146
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
147 bool
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
148 workspace_model::setData (const QModelIndex& idx, const QVariant& value,
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
149 int role)
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
150 {
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
151 bool retval = false;
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
152
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
153 if (idx.column () == 0 && role == Qt::EditRole)
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
154 {
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
155 QString qold_name = _symbols[idx.row()];
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
156
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
157 QString qnew_name = value.toString ();
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
158
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
159 std::string new_name = qnew_name.toStdString ();
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
160
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
161 if (valid_identifier (new_name))
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
162 {
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
163 emit rename_variable (qold_name, qnew_name);
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
164
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
165 retval = true;
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
166 }
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
167 }
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
168
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
169 return retval;
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
170 }
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
171
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
172
15402
7f423c6111c6 refactor GUI event handling to use new event_queue class
John W. Eaton <jwe@octave.org>
parents: 15388
diff changeset
173 void
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
174 workspace_model::set_workspace (bool top_level,
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
175 const QString& scopes,
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
176 const QStringList& symbols,
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
177 const QStringList& class_names,
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
178 const QStringList& dimensions,
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
179 const QStringList& values)
15402
7f423c6111c6 refactor GUI event handling to use new event_queue class
John W. Eaton <jwe@octave.org>
parents: 15388
diff changeset
180 {
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
181 _top_level = top_level;
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
182 _scopes = scopes;
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
183 _symbols = symbols;
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
184 _class_names = class_names;
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
185 _dimensions = dimensions;
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
186 _values = values;
15402
7f423c6111c6 refactor GUI event handling to use new event_queue class
John W. Eaton <jwe@octave.org>
parents: 15388
diff changeset
187
16477
64727ed135cb use QTableView instead of QTreeView to display workspace
John Donoghue <john.donoghue@ieee.org>
parents: 16468
diff changeset
188 update_table ();
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
189
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
190 emit model_changed ();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
191 }
15402
7f423c6111c6 refactor GUI event handling to use new event_queue class
John W. Eaton <jwe@octave.org>
parents: 15388
diff changeset
192
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
193 void
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
194 workspace_model::clear_workspace (void)
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
195 {
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
196 clear_data ();
16477
64727ed135cb use QTableView instead of QTreeView to display workspace
John Donoghue <john.donoghue@ieee.org>
parents: 16468
diff changeset
197 update_table ();
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
198
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
199 emit model_changed ();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
200 }
15402
7f423c6111c6 refactor GUI event handling to use new event_queue class
John W. Eaton <jwe@octave.org>
parents: 15388
diff changeset
201
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
202 void
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
203 workspace_model::clear_data (void)
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
204 {
16502
45ae1038ee89 allow renaming of variables in workspace viewer
John W. Eaton <jwe@octave.org>
parents: 16478
diff changeset
205 _top_level = false;
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
206 _scopes = QString ();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
207 _symbols = QStringList ();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
208 _class_names = QStringList ();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
209 _dimensions = QStringList ();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
210 _values = QStringList ();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
211 }
15402
7f423c6111c6 refactor GUI event handling to use new event_queue class
John W. Eaton <jwe@octave.org>
parents: 15388
diff changeset
212
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
213 void
16477
64727ed135cb use QTableView instead of QTreeView to display workspace
John Donoghue <john.donoghue@ieee.org>
parents: 16468
diff changeset
214 workspace_model::update_table (void)
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
215 {
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
216 beginResetModel();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
217
16478
079ec7ce60e0 delete useless connection; style fixes
John W. Eaton <jwe@octave.org>
parents: 16477
diff changeset
218 // Nothing to do except tell the world to recalc.
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
219
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
220 endResetModel ();
15402
7f423c6111c6 refactor GUI event handling to use new event_queue class
John W. Eaton <jwe@octave.org>
parents: 15388
diff changeset
221
16468
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
222 emit model_changed ();
0f143f68078d use signal/slot for updating workspace instead of using event listener
John W. Eaton <jwe@octave.org>
parents: 16444
diff changeset
223 }
16610
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
224
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
225 void
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
226 workspace_model::notice_settings (const QSettings *settings)
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
227 {
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
228 QList<QColor> default_colors = resource_manager::storage_class_default_colors ();
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
229 QString class_chars = resource_manager::storage_class_chars ();
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
230
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
231 for (int i = 0; i < class_chars.length (); i++)
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
232 {
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
233 QVariant default_var = default_colors.at (i);
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
234 QColor setting_color = settings->value ("workspaceview/color_"+class_chars.mid (i,1),
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
235 default_var).value<QColor> ();
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
236 _storage_class_colors.replace (i,setting_color);
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
237 }
a1f613e5066d workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents: 16527
diff changeset
238 }