Mercurial > octave
annotate libgui/src/workspace-view.cc @ 16459:cbc39a3d0c42
improve encapsulation of workspace window object
* workspace-view.h, workspace-view.cc
(workspace_view::handle_visibility_changed): Delete.
(workspace_view::workspace_view): Set status tip.
Don't connect workspace_view::visibilityChanged signal to
workspace_view::handle_visibility_changed.
(workspace_view::connect_visibility_changed, workspace_view::focus,
workspace_view::handle_visibility): New functions.
* main-window.h, main-window.cc (main_window::workspace_window):
Rename from _workspace_view. Change all uses.
(main_window::main_window): Initialize it.
(main_window::focus_workspace, main_window::handle_workspace_visible):
Delete.
(main_window::connect_visibility_changed):
Call workspace_window->connect_visibility_changed.
(main_window::construct): Don't create _workspace_view.
Connect workspace_action::triggered directly to workspace_window::focus.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 07 Apr 2013 11:52:09 -0400 |
parents | 3f8d3fc907af |
children | 8c666c7b0e5d |
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 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
3 Copyright (C) 2011-2012 Jacob Dawid |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
4 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
5 This file is part of Octave. |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
6 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
7 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
|
8 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
|
9 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
|
10 option) any later version. |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
11 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
12 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
|
13 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
|
14 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
|
15 for more details. |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
16 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
17 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
|
18 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
|
19 <http://www.gnu.org/licenses/>. |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
20 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
21 */ |
13501 | 22 |
15286
ae9079bbc627
Add '#include <config.h>' to C++ files in libgui/src
Rik <rik@octave.org>
parents:
15204
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
ae9079bbc627
Add '#include <config.h>' to C++ files in libgui/src
Rik <rik@octave.org>
parents:
15204
diff
changeset
|
24 #include <config.h> |
ae9079bbc627
Add '#include <config.h>' to C++ files in libgui/src
Rik <rik@octave.org>
parents:
15204
diff
changeset
|
25 #endif |
ae9079bbc627
Add '#include <config.h>' to C++ files in libgui/src
Rik <rik@octave.org>
parents:
15204
diff
changeset
|
26 |
14707
674740c44c09
Changed various files to matche file naming conventions.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14703
diff
changeset
|
27 #include "workspace-view.h" |
14997
2d6766e93f7b
The GUI now remembers when categories in the workspace view have been closed. Bug #36885
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14874
diff
changeset
|
28 #include "resource-manager.h" |
15460
7f36f7dc25b2
save and restore the columns order and width of the workspace-view
Torsten <ttl@justmail.de>
parents:
15389
diff
changeset
|
29 #include <QHeaderView> |
13501 | 30 #include <QHBoxLayout> |
31 #include <QVBoxLayout> | |
32 #include <QPushButton> | |
33 | |
15368
36ececf69385
avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents:
15367
diff
changeset
|
34 workspace_view::workspace_view (QWidget *p) |
36ececf69385
avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents:
15367
diff
changeset
|
35 : QDockWidget (p) |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
36 { |
13683
25dc40d24a44
Renamed VariablesDockWidget to WorkspaceView and optimized memory footprint for 30%.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13678
diff
changeset
|
37 setObjectName ("WorkspaceView"); |
15552
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
38 setWindowIcon (QIcon(":/actions/icons/logo.png")); |
13523
103b7bebb38f
Moved load/save/clear workspace into main menu.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13506
diff
changeset
|
39 setWindowTitle (tr ("Workspace")); |
16459
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
40 setStatusTip (tr ("View the variables in the active workspace.")); |
13523
103b7bebb38f
Moved load/save/clear workspace into main menu.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13506
diff
changeset
|
41 |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
42 view = new QTreeView (this); // Create a new tree view. |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
43 view->setHeaderHidden (false); // Do not show header columns. |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
44 view->setAlternatingRowColors (true); // Activate alternating row colors. |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
45 view->setAnimated (false); // Deactivate animations because of strange glitches. |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
46 view->setTextElideMode (Qt::ElideRight);// Elide text to the right side of the cells. |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
47 view->setWordWrap (false); // No wordwrapping in cells. |
13523
103b7bebb38f
Moved load/save/clear workspace into main menu.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13506
diff
changeset
|
48 |
14874
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
49 // Set an empty widget, so we can assign a layout to it. |
13523
103b7bebb38f
Moved load/save/clear workspace into main menu.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13506
diff
changeset
|
50 setWidget (new QWidget (this)); |
14874
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
51 |
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
52 // Create a new layout and add widgets to it. |
15368
36ececf69385
avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents:
15367
diff
changeset
|
53 QVBoxLayout *vbox_layout = new QVBoxLayout (); |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
54 vbox_layout->addWidget (view); |
15368
36ececf69385
avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents:
15367
diff
changeset
|
55 vbox_layout->setMargin (2); |
14874
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
56 |
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
57 // Set the empty widget to have our layout. |
15368
36ececf69385
avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents:
15367
diff
changeset
|
58 widget ()->setLayout (vbox_layout); |
13501 | 59 |
14874
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
60 // Initialize collapse/expand state of the workspace subcategories. |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
61 |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
62 QSettings *settings = resource_manager::get_settings (); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
63 |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
64 // FIXME -- what should happen if settings is 0? |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
65 |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
66 _explicit_collapse.local = settings->value ("workspaceview/local_collapsed", false).toBool (); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
67 _explicit_collapse.global = settings->value ("workspaceview/global_collapsed", false).toBool ();; |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
68 _explicit_collapse.persistent = settings->value ("workspaceview/persistent_collapsed", false).toBool ();; |
14874
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
69 |
15460
7f36f7dc25b2
save and restore the columns order and width of the workspace-view
Torsten <ttl@justmail.de>
parents:
15389
diff
changeset
|
70 // Initialize column order and width of the workspace |
7f36f7dc25b2
save and restore the columns order and width of the workspace-view
Torsten <ttl@justmail.de>
parents:
15389
diff
changeset
|
71 |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
72 view->header ()->restoreState (settings->value("workspaceview/column_state").toByteArray ()); |
15460
7f36f7dc25b2
save and restore the columns order and width of the workspace-view
Torsten <ttl@justmail.de>
parents:
15389
diff
changeset
|
73 |
14874
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
74 // Connect signals and slots. |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
75 connect (view, SIGNAL (collapsed (QModelIndex)), |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
76 this, SLOT (collapse_requested (QModelIndex))); |
16459
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
77 |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
78 connect (view, SIGNAL (expanded (QModelIndex)), |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
79 this, SLOT (expand_requested (QModelIndex))); |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
80 |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
81 connect (view, SIGNAL (doubleClicked (QModelIndex)), |
14874
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
82 this, SLOT (item_double_clicked (QModelIndex))); |
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
83 |
15552
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
84 // topLevelChanged is emitted when floating property changes (floating = true) |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
85 connect (this, SIGNAL (topLevelChanged(bool)), this, SLOT(top_level_changed(bool))); |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
86 |
13541
b48ac9ad8de0
Highly improved separation of model and view classes.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13536
diff
changeset
|
87 } |
13577
e440b3f32f02
Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13541
diff
changeset
|
88 |
14997
2d6766e93f7b
The GUI now remembers when categories in the workspace view have been closed. Bug #36885
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14874
diff
changeset
|
89 workspace_view::~workspace_view () |
2d6766e93f7b
The GUI now remembers when categories in the workspace view have been closed. Bug #36885
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14874
diff
changeset
|
90 { |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
91 QSettings *settings = resource_manager::get_settings (); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
92 settings->setValue("workspaceview/local_collapsed", _explicit_collapse.local); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
93 settings->setValue("workspaceview/global_collapsed", _explicit_collapse.global); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
14997
diff
changeset
|
94 settings->setValue("workspaceview/persistent_collapsed", _explicit_collapse.persistent); |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
95 settings->setValue("workspaceview/column_state", view->header ()->saveState ()); |
16175
6f83158c714c
gui: make sure settings are really written into the settings file
Torsten <ttl@justmail.de>
parents:
15552
diff
changeset
|
96 settings->sync (); |
14997
2d6766e93f7b
The GUI now remembers when categories in the workspace view have been closed. Bug #36885
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14874
diff
changeset
|
97 } |
2d6766e93f7b
The GUI now remembers when categories in the workspace view have been closed. Bug #36885
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14874
diff
changeset
|
98 |
13577
e440b3f32f02
Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13541
diff
changeset
|
99 void |
16459
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
100 workspace_view::connect_visibility_changed (void) |
13577
e440b3f32f02
Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13541
diff
changeset
|
101 { |
16459
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
102 connect (this, SIGNAL (visibilityChanged (bool)), |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
103 this, SLOT (handle_visibility (bool))); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
104 } |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
105 |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
106 void |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
107 workspace_view::model_changed () |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
108 { |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
109 QAbstractItemModel *m = view->model (); |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
110 |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
111 dynamic_cast<workspace_model *> (m)->update_workspace_callback (); |
16444
6cd66a5a76e8
undo unintended changes in changeset 302157614308
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
112 |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
113 // This code is very quirky and requires some explanation. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
114 // Usually, we should not deal with collapsing or expanding ourselves, |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
115 // because the view itself determines (based on the model) whether it |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
116 // is appropriate to collapse or expand items. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
117 // |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
118 // Now, the logic requires that we update our model item by item, which |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
119 // would make it work correctly, but this is extremely slow and scales |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
120 // very bad (O(n^2)). That's why we throw away our model and rebuild it |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
121 // completely from scratch (O(n)), which is why the view renders all |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
122 // displayed data as invalid. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
123 // |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
124 // In order to make collapsing/expanding work again, we need to set |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
125 // flags ourselves here. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
126 |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
127 QModelIndex local_model_index = m->index (0, 0); |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
128 QModelIndex global_model_index = m->index (1, 0); |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
129 QModelIndex persistent_model_index = m->index (2, 0); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
130 |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
131 if (_explicit_collapse.local) { |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
132 view->collapse (local_model_index); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
133 } else { |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
134 view->expand (local_model_index); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
135 } |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
136 |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
137 if (_explicit_collapse.global) { |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
138 view->collapse (global_model_index); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
139 } else { |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
140 view->expand (global_model_index); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
141 } |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
142 |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
143 if (_explicit_collapse.persistent) { |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
144 view->collapse (persistent_model_index); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
145 } else { |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
146 view->expand (persistent_model_index); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
147 } |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
148 } |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
149 |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
150 void |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
151 workspace_view::collapse_requested (QModelIndex index) |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
152 { |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
153 // This code is very quirky and requires some explanation. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
154 // Usually, we should not deal with collapsing or expanding ourselves, |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
155 // because the view itself determines (based on the model) whether it |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
156 // is appropriate to collapse or expand items. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
157 // |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
158 // Now, the logic requires that we update our model item by item, which |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
159 // would make it work correctly, but this is extremely slow and scales |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
160 // very bad (O(n^2)). That's why we throw away our model and rebuild it |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
161 // completely from scratch (O(n)), which is why the view renders all |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
162 // displayed data as invalid. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
163 // |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
164 // In order to make collapsing/expanding work again, we need to set |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
165 // flags ourselves here. |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
166 QAbstractItemModel *m = view->model (); |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
167 |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
168 QMap<int, QVariant> item_data = m->itemData (index); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
169 |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
170 if (item_data[0] == "Local") |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
171 _explicit_collapse.local = true; |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
172 if (item_data[0] == "Global") |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
173 _explicit_collapse.global = true; |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
174 if (item_data[0] == "Persistent") |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
175 _explicit_collapse.persistent = true; |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
176 } |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
177 |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
178 void |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
179 workspace_view::expand_requested (QModelIndex index) |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
180 { |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
181 // This code is very quirky and requires some explanation. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
182 // Usually, we should not deal with collapsing or expanding ourselves, |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
183 // because the view itself determines (based on the model) whether it |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
184 // is appropriate to collapse or expand items. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
185 // |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
186 // Now, the logic requires that we update our model item by item, which |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
187 // would make it work correctly, but this is extremely slow and scales |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
188 // very bad (O(n^2)). That's why we throw away our model and rebuild it |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
189 // completely from scratch (O(n)), which is why the view renders all |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
190 // displayed data as invalid. |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
191 // |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
192 // In order to make collapsing/expanding work again, we need to do set |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
193 // flags ourselves here. |
16445
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
194 QAbstractItemModel *m = view->model (); |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
195 |
3f8d3fc907af
store workspace model in main_window, not in workspace view
John W. Eaton <jwe@octave.org>
parents:
16444
diff
changeset
|
196 QMap<int, QVariant> item_data = m->itemData (index); |
14761
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
197 |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
198 if (item_data[0] == "Local") |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
199 _explicit_collapse.local = false; |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
200 if (item_data[0] == "Global") |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
201 _explicit_collapse.global = false; |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
202 if (item_data[0] == "Persistent") |
8c4d5029d933
Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14720
diff
changeset
|
203 _explicit_collapse.persistent = false; |
13577
e440b3f32f02
Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13541
diff
changeset
|
204 } |
e440b3f32f02
Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13541
diff
changeset
|
205 |
e440b3f32f02
Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13541
diff
changeset
|
206 void |
15389
f918db8102d5
eliminate use of Q_UNUSED macro
John W. Eaton <jwe@octave.org>
parents:
15368
diff
changeset
|
207 workspace_view::item_double_clicked (QModelIndex) |
14874
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
208 { |
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
209 // TODO: Implement opening a dialog that allows the user to change a variable in the workspace. |
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
210 } |
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
211 |
5d74d8b982a5
Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14783
diff
changeset
|
212 void |
15368
36ececf69385
avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents:
15367
diff
changeset
|
213 workspace_view::closeEvent (QCloseEvent *e) |
13577
e440b3f32f02
Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13541
diff
changeset
|
214 { |
14712
5cb54cca8a06
Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14709
diff
changeset
|
215 emit active_changed (false); |
15368
36ececf69385
avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents:
15367
diff
changeset
|
216 QDockWidget::closeEvent (e); |
13577
e440b3f32f02
Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13541
diff
changeset
|
217 } |
15552
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
218 |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
219 // slot for signal that is emitted when floating property changes |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
220 void |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
221 workspace_view::top_level_changed (bool floating) |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
222 { |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
223 if(floating) |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
224 { |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
225 setWindowFlags(Qt::Window); // make a window from the widget when floating |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
226 show(); // make it visible again since setWindowFlags hides it |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
227 } |
bbbb89cc338f
make a floating widget behave like a normal window (bug #37190)
Torsten <ttl@justmail.de>
parents:
15460
diff
changeset
|
228 } |
16459
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
229 |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
230 void |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
231 workspace_view::focus (void) |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
232 { |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
233 if (! isVisible ()) |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
234 setVisible (true); |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
235 |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
236 setFocus (); |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
237 activateWindow (); |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
238 raise (); |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
239 } |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
240 |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
241 void |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
242 workspace_view::handle_visibility (bool visible) |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
243 { |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
244 // if changed to visible and widget is not floating |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
245 if (visible && ! isFloating ()) |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
246 focus (); |
cbc39a3d0c42
improve encapsulation of workspace window object
John W. Eaton <jwe@octave.org>
parents:
16445
diff
changeset
|
247 } |