annotate libgui/src/workspace-model.cc @ 15388:24b5348d38e7

merge event_accepted and event_reject into a single function * history-dockwidget.cc, history-dockwidget.h (history_dock_widget::handle_event): New function from merging history_dock_widget::event_accepted and history_dock_widget::event_reject into single fucntion with argument. * file-editor-tab.cc, file-editor-tab.h (file_editor_tab::handle_event): Likewise. * main-window.cc, main-window.h (main_window::handle_event): Likewise. * octave-event-observer.h (octave_event_observer::handle_event): New pure virtual function. (octave_event_observer::event_accepted, octave_event_observer::event_reject): Delete. * octave_link.cc, octave-link.h (octave_link::handle_event): Likewise. * workspace-model.cc, workspace-model.h (workspace_model::handle_event): Likewise. * octave-link.cc (octave_link::do_process_events): Call octave_event::handle_event with the return value from octave_event::perform instead of calling octave_event::accept and octave_event::reject. * octave-event.h (octave_event:handle_event): New function. (octave_event::accept, octave_event::reject): Delete.
author John W. Eaton <jwe@octave.org>
date Fri, 14 Sep 2012 11:14:27 -0400
parents f9ee3befcd6b
children 7f423c6111c6
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
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 */
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
22
15155
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
23 #ifdef HAVE_CONFIG_H
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
24 #include <config.h>
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
25 #endif
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
26
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
27 #include <QTreeWidget>
14669
7605e7136b50 Discarded initFileEditor, instead put that in the constructor. Speedup for updating the symbol table by lowering complexity from n² to n. Fixed problem with hangup on quit.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14668
diff changeset
28 #include <QTime>
15155
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
29
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
30 #include <list>
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
31
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
32 #include <symtab.h>
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
33
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 14879
diff changeset
34 #include "workspace-model.h"
14707
674740c44c09 Changed various files to matche file naming conventions.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14703
diff changeset
35 #include "octave-link.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
36
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
37 workspace_model::workspace_model(QObject *p)
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
38 : QAbstractItemModel (p), octave_event_observer ()
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
39 {
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
40 QList<QVariant> rootData;
15342
67fabb3d81f4 display class of variables in workspace viewer instead of type
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
41 rootData << tr ("Name") << tr ("Class") << tr("Dimension") << tr ("Value");
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
42 _rootItem = new tree_item(rootData);
14719
89c64340e9ab Extended event based communication model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14712
diff changeset
43
89c64340e9ab Extended event based communication model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14712
diff changeset
44 insert_top_level_item(0, new tree_item ("Local"));
89c64340e9ab Extended event based communication model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14712
diff changeset
45 insert_top_level_item(1, new tree_item ("Global"));
89c64340e9ab Extended event based communication model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14712
diff changeset
46 insert_top_level_item(2, new tree_item ("Persistent"));
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
47
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
48 connect(&_update_workspace_model_timer,
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
49 SIGNAL (timeout ()),
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
50 this,
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
51 SLOT (request_update_workspace()));
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
52
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
53 _update_workspace_model_timer.setInterval (500);
14750
4812bcd524a1 Fixed flooding the event queue by only an event after the last one has been processed.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14720
diff changeset
54 _update_workspace_model_timer.setSingleShot (true);
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
55 _update_workspace_model_timer.start ();
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
56 }
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
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
58 workspace_model::~workspace_model()
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 delete _rootItem;
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 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
62
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
63 void
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
64 workspace_model::request_update_workspace ()
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
65 {
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15368
diff changeset
66 octave_link::post_event (new octave_update_workspace_event (*this));
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
67 }
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
68
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
69 void
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
70 workspace_model::handle_event (octave_event *e, bool accept)
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
71 {
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
72 if (accept)
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
73 {
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
74 if (dynamic_cast <octave_update_workspace_event*> (e))
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
75 {
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
76 std::list < symbol_table::symbol_record > symbolTable = symbol_table::all_variables ();
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
77
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
78 _symbol_information.clear ();
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
79 for (std::list < symbol_table::symbol_record > ::iterator iterator = symbolTable.begin ();
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
80 iterator != symbolTable.end (); iterator++)
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
81 _symbol_information.push_back (symbol_information (*iterator));
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
82
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
83 beginResetModel();
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
84 top_level_item (0)->delete_child_items ();
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
85 top_level_item (1)->delete_child_items ();
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
86 top_level_item (2)->delete_child_items ();
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
87
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
88 foreach (const symbol_information& s, _symbol_information)
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
89 {
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
90 tree_item *child = new tree_item ();
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
91
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
92 child->set_data (0, s.symbol ());
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
93 child->set_data (1, s.class_name ());
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
94 child->set_data (2, s.dimension ());
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
95 child->set_data (3, s.value ());
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
96
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
97 switch (s.scope ())
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
98 {
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
99 case symbol_information::local:
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
100 top_level_item (0)->add_child (child);
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
101 break;
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
102
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
103 case symbol_information::global:
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
104 top_level_item (1)->add_child (child);
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
105 break;
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
106
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
107 case symbol_information::persistent:
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
108 top_level_item (2)->add_child (child);
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
109 break;
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
110
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
111 default:
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
112 break;
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
113 }
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
114 }
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
115
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
116 endResetModel();
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
117 emit model_changed();
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
118 }
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
119
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
120 // Post a new event in a given time.
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
121 // This prevents flooding the event queue when no events are being processed.
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
122 _update_workspace_model_timer.start ();
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
123 }
15388
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
124 else
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
125 {
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
126 // octave_event::perform failed to process event.
24b5348d38e7 merge event_accepted and event_reject into a single function
John W. Eaton <jwe@octave.org>
parents: 15387
diff changeset
127 }
14720
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
128 }
cecc7da96e2a Added update events for the command history model and workspace model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14719
diff changeset
129
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
130 QModelIndex
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
131 workspace_model::index(int row, int column, const QModelIndex &p) 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
132 {
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
133 if (!hasIndex(row, column, 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
134 return QModelIndex();
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
135
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
136 tree_item *parentItem;
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
137
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
138 if (!p.isValid())
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
139 parentItem = _rootItem;
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
140 else
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
141 parentItem = static_cast<tree_item*>(p.internalPointer());
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
142
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
143 tree_item *childItem = parentItem->child(row);
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
144 if (childItem)
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 return createIndex(row, column, childItem);
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 else
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
147 return QModelIndex();
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
148 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
149
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
150 QModelIndex
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
151 workspace_model::parent(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
152 {
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
153 if (!idx.isValid())
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
154 return QModelIndex();
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
155
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
156 tree_item *childItem = static_cast<tree_item*>(idx.internalPointer());
15345
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
157
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
158 if (childItem)
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
159 {
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
160 tree_item *parentItem = childItem->parent();
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
161
15345
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
162 if (! parentItem || parentItem == _rootItem)
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
163 return QModelIndex();
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
164
15345
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
165 return createIndex(parentItem->row(), 0, parentItem);
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
166 }
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
167 else
bd906ac220b6 avoid GUI crash due to null pointer dereference
John W. Eaton <jwe@octave.org>
parents: 15344
diff changeset
168 return QModelIndex ();
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
169 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
170
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
171 int
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
172 workspace_model::rowCount(const QModelIndex &p) 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
173 {
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
174 tree_item *parentItem;
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
175 if (p.column() > 0)
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
176 return 0;
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
177
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
178 if (!p.isValid())
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
179 parentItem = _rootItem;
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
180 else
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
181 parentItem = static_cast<tree_item*>(p.internalPointer());
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
182
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
183 return parentItem->child_count();
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
184 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
185
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
186 int
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
187 workspace_model::columnCount(const QModelIndex &p) 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
188 {
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
189 if (p.isValid())
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
190 return static_cast<tree_item*>(p.internalPointer())->column_count();
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
191 else
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
192 return _rootItem->column_count();
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
193 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
194
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
195 void
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
196 workspace_model::insert_top_level_item(int at, tree_item *treeItem)
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
197 {
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
198 _rootItem->insert_child_item(at, treeItem);
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
199 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
200
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
201 tree_item *
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
202 workspace_model::top_level_item (int at)
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
203 {
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
204 return _rootItem->child(at);
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
205 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
206
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
207 Qt::ItemFlags
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
208 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
209 {
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
210 if (!idx.isValid())
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
211 return 0;
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
212
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
213 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
214 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
215
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
216 QVariant
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
217 workspace_model::headerData(int section, Qt::Orientation orientation, 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
218 {
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
219 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
220 return _rootItem->data(section);
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
221
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
222 return QVariant();
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
223 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
224
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
225 QVariant
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
226 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
227 {
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
228 if (!idx.isValid())
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
229 return QVariant();
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
230
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
231 if (role != Qt::DisplayRole)
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
232 return QVariant();
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
233
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
234 tree_item *item = static_cast<tree_item*>(idx.internalPointer());
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
235
15368
36ececf69385 avoid some GCC warnings in the libgui code
John W. Eaton <jwe@octave.org>
parents: 15367
diff changeset
236 return item->data(idx.column());
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
237 }
664f54233c98 Extracted model code from the WorkspaceView and rearranged it in a new model class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
238