comparison gui/src/WorkspaceModel.h @ 14664:664f54233c98 gui

Extracted model code from the WorkspaceView and rearranged it in a new model class. * WorkspaceModel.cpp/.h (new class): Model class for the workspace. * WorkspaceView.cpp/.h: Replaced QTreeWidget with QTreeView and removed model code. * OctaveLink.cpp/.h: Removed symbol table semaphore and methods to access the copy of the symbol table, removed copying the symbol table. * src.pro: Added new files to Qt project.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Sun, 20 May 2012 22:05:49 +0200
parents
children 6a6733a55982
comparison
equal deleted inserted replaced
14662:6573ba8f094f 14664:664f54233c98
1 /* OctaveGUI - A graphical user interface for Octave
2 * Copyright (C) 2011 Jacob Dawid (jacob.dawid@googlemail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef WORKSPACEMODEL_H
19 #define WORKSPACEMODEL_H
20
21 // Octave includes
22 #undef PACKAGE_BUGREPORT
23 #undef PACKAGE_NAME
24 #undef PACKAGE_STRING
25 #undef PACKAGE_TARNAME
26 #undef PACKAGE_VERSION
27 #undef PACKAGE_URL
28 #include "octave/config.h"
29 #include "octave/cmd-edit.h"
30 #include "octave/error.h"
31 #include "octave/file-io.h"
32 #include "octave/input.h"
33 #include "octave/lex.h"
34 #include "octave/load-path.h"
35 #include "octave/octave.h"
36 #include "octave/oct-hist.h"
37 #include "octave/oct-map.h"
38 #include "octave/oct-obj.h"
39 #include "octave/ops.h"
40 #include "octave/ov.h"
41 #include "octave/ov-usr-fcn.h"
42 #include "octave/symtab.h"
43 #include "octave/pt.h"
44 #include "octave/pt-eval.h"
45 #include "octave/config.h"
46 #include "octave/Range.h"
47 #include "octave/toplev.h"
48 #include "octave/procstream.h"
49 #include "octave/sighandlers.h"
50 #include "octave/debug.h"
51 #include "octave/sysdep.h"
52 #include "octave/ov.h"
53 #include "octave/unwind-prot.h"
54 #include "octave/utils.h"
55 #include "octave/variables.h"
56
57 // Qt includes
58 #include <QAbstractItemModel>
59
60 class TreeItem
61 {
62 public:
63 TreeItem(const QList<QVariant> &data, TreeItem *parent = 0) {
64 _parentItem = parent;
65 _itemData = data;
66 }
67
68 TreeItem(QVariant data = QVariant(), TreeItem *parent = 0) {
69 QList<QVariant> variantList;
70 variantList << data << QVariant() << QVariant();
71 _parentItem = parent;
72 _itemData = variantList;
73 }
74
75 ~TreeItem() {
76 qDeleteAll(_childItems);
77 }
78
79 void insertChildItem(int at, TreeItem *item) {
80 item->_parentItem = this;
81 _childItems.insert(at, item);
82 }
83
84 void addChild(TreeItem *item) {
85 item->_parentItem = this;
86 _childItems.append(item);
87 }
88
89 void removeChild(TreeItem *item) {
90 _childItems.removeAll(item);
91 }
92
93 QVariant data(int column) const
94 {
95 return _itemData.value(column);
96 }
97
98 void setData(int column, QVariant data)
99 {
100 _itemData[column] = data;
101 }
102
103 TreeItem *child(int row) {
104 return _childItems.value(row);
105 }
106
107 int childCount() const {
108 return _childItems.count();
109 }
110
111 int columnCount() const
112 {
113 return _itemData.count();
114 }
115
116 int row() const {
117 if (_parentItem)
118 return _parentItem->_childItems.indexOf(const_cast<TreeItem*>(this));
119
120 return 0;
121 }
122
123 TreeItem *parent()
124 {
125 return _parentItem;
126 }
127
128 private:
129 QList<TreeItem*> _childItems;
130 QList<QVariant> _itemData;
131 TreeItem *_parentItem;
132 };
133
134 class WorkspaceModel : public QAbstractItemModel
135 {
136 Q_OBJECT
137
138 public:
139 WorkspaceModel(QObject *parent = 0);
140 ~WorkspaceModel();
141
142 QVariant data(const QModelIndex &index, int role) const;
143 Qt::ItemFlags flags(const QModelIndex &index) const;
144 QVariant headerData(int section, Qt::Orientation orientation,
145 int role = Qt::DisplayRole) const;
146 QModelIndex index(int row, int column,
147 const QModelIndex &parent = QModelIndex()) const;
148 QModelIndex parent(const QModelIndex &index) const;
149 int rowCount(const QModelIndex &parent = QModelIndex()) const;
150 int columnCount(const QModelIndex &parent = QModelIndex()) const;
151
152 void insertTopLevelItem (int at, TreeItem *treeItem);
153 TreeItem *topLevelItem (int at);
154
155 void updateFromSymbolTable ();
156 void updateTreeEntry (TreeItem * treeItem, symbol_table::symbol_record symbolRecord);
157 void updateCategory (int topLevelItemIndex, QList < symbol_table::symbol_record > symbolTable);
158 QString octaveValueAsQString (octave_value octaveValue);
159
160 private:
161 TreeItem *_rootItem;
162 };
163
164 #endif // WORKSPACEMODEL_H