annotate libgui/src/workspace-view.cc @ 15196:017f0b2e6933

rename gui directory to libgu * libgui: Rename from gui. * .hgsub (libgui/qterminal): Rename from gui/qterminal. * Makefile.am (GUIDIR): Set to libgui instead of gui if AMCOND_BUILD_GUI is true. * configure.ac (AC_CONFIG_FILES): Update list for directory renaming. * Makefile.am (.NOTPARALLEL): Delete. List octave.html/index.html as the primary HTML target, not octave.html. (octave.html): New target for making the octave.html directory. (octave.pdf): Depend on octave.dvi. * images.awk: In generated rules for png files, depend on octave.html, not octave.html/index.html. * src/Makefile.am (OCTAVE_GUI_CPPFLAGS, OCTAVE_GUI_LIBS): Update for directory renaming. (CLEANFILES): Fix typo. * fntests.m (src_tree): Use libinterp, not src.
author John W. Eaton <jwe@octave.org>
date Sat, 18 Aug 2012 18:10:09 -0400
parents gui/src/workspace-view.cc@bc801a44bb1f
children 359098ad343e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13504
13e3d60aff2d Replaced Quint with OctaveGUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
1 /* OctaveGUI - A graphical user interface for Octave
13674
c0e66d6e3dc8 Updated license headers and moved to AGPLv3.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13577
diff changeset
2 * Copyright (C) 2011 Jacob Dawid (jacob.dawid@googlemail.com)
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
3 *
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
4 * This program is free software: you can redistribute it and/or modify
14290
faece6b2ab90 Corrected license headers in all files to GPL.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14289
diff changeset
5 * it under the terms of the GNU General Public License as
13674
c0e66d6e3dc8 Updated license headers and moved to AGPLv3.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13577
diff changeset
6 * published by the Free Software Foundation, either version 3 of the
c0e66d6e3dc8 Updated license headers and moved to AGPLv3.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13577
diff changeset
7 * License, or (at your option) any later version.
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
8 *
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14290
faece6b2ab90 Corrected license headers in all files to GPL.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14289
diff changeset
12 * GNU General Public License for more details.
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
13 *
14290
faece6b2ab90 Corrected license headers in all files to GPL.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14289
diff changeset
14 * You should have received a copy of the GNU General Public License
13674
c0e66d6e3dc8 Updated license headers and moved to AGPLv3.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13577
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
16 */
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
17
14707
674740c44c09 Changed various files to matche file naming conventions.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14703
diff changeset
18 #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
19 #include "resource-manager.h"
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
20 #include <QHBoxLayout>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
21 #include <QVBoxLayout>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
22 #include <QPushButton>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
23
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
24 workspace_view::workspace_view (QWidget * parent) : QDockWidget
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
25 (parent)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
26 {
13683
25dc40d24a44 Renamed VariablesDockWidget to WorkspaceView and optimized memory footprint for 30%.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13678
diff changeset
27 setObjectName ("WorkspaceView");
13523
103b7bebb38f Moved load/save/clear workspace into main menu.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13506
diff changeset
28 setWindowTitle (tr ("Workspace"));
103b7bebb38f Moved load/save/clear workspace into main menu.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13506
diff changeset
29
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
30 // Create a new workspace model.
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
31 _workspace_model = new workspace_model ();
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
32
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
33 _workspace_tree_view = new QTreeView (this); // Create a new tree view.
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
34 _workspace_tree_view->setHeaderHidden (false); // Do not show header columns.
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
35 _workspace_tree_view->setAlternatingRowColors (true); // Activate alternating row colors.
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
36 _workspace_tree_view->setAnimated (false); // Deactivate animations because of strange glitches.
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
37 _workspace_tree_view->setTextElideMode (Qt::ElideRight);// Elide text to the right side of the cells.
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
38 _workspace_tree_view->setWordWrap (false); // No wordwrapping in cells.
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
39 _workspace_tree_view->setModel (_workspace_model); // Assign model.
13523
103b7bebb38f Moved load/save/clear workspace into main menu.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13506
diff changeset
40
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
41 // 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
42 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
43
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
44 // Create a new layout and add widgets to it.
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
45 QVBoxLayout *layout = new QVBoxLayout ();
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
46 layout->addWidget (_workspace_tree_view);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
47 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
48
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 the empty widget to have our layout.
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
50 widget ()->setLayout (layout);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
51
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
52 // 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
53
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
54 QSettings *settings = resource_manager::get_settings ();
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
55
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
56 // 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
57
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
58 _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
59 _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
60 _explicit_collapse.persistent = settings->value ("workspaceview/persistent_collapsed", false).toBool ();;
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
61 _explicit_collapse.hidden = settings->value ("workspaceview/hidden_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
62
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
63 // Connect signals and slots.
14599
97cb9286919c Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14290
diff changeset
64 connect (this, SIGNAL (visibilityChanged (bool)),
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
65 this, SLOT(handle_visibility_changed (bool)));
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
66
14761
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
67 connect (_workspace_model, SIGNAL (model_changed ()),
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
68 this, SLOT (model_changed ()));
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
69
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
70 connect (_workspace_tree_view, SIGNAL (collapsed (QModelIndex)),
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
71 this, SLOT (collapse_requested (QModelIndex)));
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
72 connect (_workspace_tree_view, SIGNAL (expanded (QModelIndex)),
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
73 this, SLOT (expand_requested (QModelIndex)));
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
74
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
75 connect (_workspace_tree_view, SIGNAL (doubleClicked (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
76 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
77
13541
b48ac9ad8de0 Highly improved separation of model and view classes.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13536
diff changeset
78 }
13577
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
79
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
80 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
81 {
15164
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
82 QSettings *settings = resource_manager::get_settings ();
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
83
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
84 // 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
85
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
86 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
87 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
88 settings->setValue("workspaceview/persistent_collapsed", _explicit_collapse.persistent);
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 14997
diff changeset
89 settings->setValue("workspaceview/hidden_collapsed", _explicit_collapse.hidden);
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
90 }
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
91
13577
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
92 void
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
93 workspace_view::handle_visibility_changed (bool visible)
13577
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
94 {
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
95 if (visible)
14761
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
96 emit active_changed (true);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
97 }
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
98
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
99 void
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
100 workspace_view::model_changed ()
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
101 {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
102 // 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
103 // 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
104 // 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
105 // 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
106 //
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
107 // 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
108 // 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
109 // 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
110 // 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
111 // displayed data as invalid.
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
112 //
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
113 // 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
114 // flags ourselves here.
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
115
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
116 QModelIndex local_model_index = _workspace_model->index (0, 0);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
117 QModelIndex global_model_index = _workspace_model->index (1, 0);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
118 QModelIndex persistent_model_index = _workspace_model->index (2, 0);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
119 QModelIndex hidden_model_index = _workspace_model->index (3, 0);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
120
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
121 if (_explicit_collapse.local) {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
122 _workspace_tree_view->collapse (local_model_index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
123 } else {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
124 _workspace_tree_view->expand (local_model_index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
125 }
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
126
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
127 if (_explicit_collapse.global) {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
128 _workspace_tree_view->collapse (global_model_index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
129 } else {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
130 _workspace_tree_view->expand (global_model_index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
131 }
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
132
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
133 if (_explicit_collapse.persistent) {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
134 _workspace_tree_view->collapse (persistent_model_index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
135 } else {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
136 _workspace_tree_view->expand (persistent_model_index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
137 }
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
138
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
139 if (_explicit_collapse.hidden) {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
140 _workspace_tree_view->collapse (hidden_model_index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
141 } else {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
142 _workspace_tree_view->expand (hidden_model_index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
143 }
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
144 }
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
145
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
146 void
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
147 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
148 {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
149 // 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
150 // 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
151 // 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
152 // 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
153 //
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
154 // 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
155 // 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
156 // 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
157 // 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
158 // displayed data as invalid.
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
159 //
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
160 // 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
161 // flags ourselves here.
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
162 QMap<int, QVariant> item_data
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
163 = _workspace_model->itemData (index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
164
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
165 if (item_data[0] == "Local")
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
166 _explicit_collapse.local = true;
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
167 if (item_data[0] == "Global")
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
168 _explicit_collapse.global = true;
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
169 if (item_data[0] == "Persistent")
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
170 _explicit_collapse.persistent = true;
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
171 if (item_data[0] == "Hidden")
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
172 _explicit_collapse.hidden = true;
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
173 }
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
174
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
175 void
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
176 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
177 {
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
178 // 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
179 // 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
180 // 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
181 // 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
182 //
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
183 // 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
184 // 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
185 // 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
186 // 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
187 // displayed data as invalid.
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
188 //
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
189 // 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
190 // flags ourselves here.
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
191 QMap<int, QVariant> item_data
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
192 = _workspace_model->itemData (index);
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
193
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
194 if (item_data[0] == "Local")
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
195 _explicit_collapse.local = false;
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
196 if (item_data[0] == "Global")
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
197 _explicit_collapse.global = false;
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
198 if (item_data[0] == "Persistent")
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
199 _explicit_collapse.persistent = 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] == "Hidden")
8c4d5029d933 Collapsing/Expanding items now works with a workaround.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
201 _explicit_collapse.hidden = false;
13577
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
202 }
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
203
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
204 void
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
205 workspace_view::item_double_clicked (QModelIndex index)
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
206 {
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
207 Q_UNUSED (index);
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 // 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
209 }
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 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
212 workspace_view::closeEvent (QCloseEvent *event)
13577
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
213 {
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
214 emit active_changed (false);
13577
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
215 QDockWidget::closeEvent (event);
e440b3f32f02 Fixed bug with closing subwindows.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13541
diff changeset
216 }