comparison gui/src/backend/OctaveLink.cpp @ 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 eeddf586cf0f
children 6a6733a55982
comparison
equal deleted inserted replaced
14662:6573ba8f094f 14664:664f54233c98
19 19
20 OctaveLink OctaveLink::m_singleton; 20 OctaveLink OctaveLink::m_singleton;
21 21
22 OctaveLink::OctaveLink ():QObject () 22 OctaveLink::OctaveLink ():QObject ()
23 { 23 {
24 m_symbolTableSemaphore = new QSemaphore (1);
25 m_historyModel = new QStringListModel (this); 24 m_historyModel = new QStringListModel (this);
25 m_workspaceModel = new WorkspaceModel (this);
26
27 m_workspaceModel->insertTopLevelItem(0, new TreeItem ("Local"));
28 m_workspaceModel->insertTopLevelItem(1, new TreeItem ("Global"));
29 m_workspaceModel->insertTopLevelItem(2, new TreeItem ("Persistent"));
30 m_workspaceModel->insertTopLevelItem(3, new TreeItem ("Hidden"));
26 } 31 }
27 32
28 OctaveLink::~OctaveLink () 33 OctaveLink::~OctaveLink ()
29 { 34 {
30 }
31
32 QString
33 OctaveLink::octaveValueAsQString (OctaveValue octaveValue)
34 {
35 // Convert single qouted string.
36 if (octaveValue.is_sq_string ())
37 {
38 return QString ("\'%1\'").arg (octaveValue.string_value ().c_str ());
39
40 // Convert double qouted string.
41 }
42 else if (octaveValue.is_dq_string ())
43 {
44 return QString ("\"%1\"").arg (octaveValue.string_value ().c_str ());
45
46 // Convert real scalar.
47 }
48 else if (octaveValue.is_real_scalar ())
49 {
50 return QString ("%1").arg (octaveValue.scalar_value ());
51
52 // Convert complex scalar.
53 }
54 else if (octaveValue.is_complex_scalar ())
55 {
56 return QString ("%1 + %2i").arg (octaveValue.scalar_value ()).
57 arg (octaveValue.complex_value ().imag ());
58
59 // Convert range.
60 }
61 else if (octaveValue.is_range ())
62 {
63 return QString ("%1 : %2 : %3").arg (octaveValue.range_value ().
64 base ()).arg (octaveValue.
65 range_value ().
66 inc ()).
67 arg (octaveValue.range_value ().limit ());
68
69 // Convert real matrix.
70 }
71 else if (octaveValue.is_real_matrix ())
72 {
73 return QString ("%1x%2 matrix")
74 .arg (octaveValue.matrix_value ().rows ())
75 .arg (octaveValue.matrix_value ().cols ());
76
77 // Convert complex matrix.
78 }
79 else if (octaveValue.is_complex_matrix ())
80 {
81 return QString ("%1x%2 complex matrix")
82 .arg (octaveValue.matrix_value ().rows ())
83 .arg (octaveValue.matrix_value ().cols ());
84
85 // If everything else does not fit, we could not recognize the type.
86 }
87 else
88 {
89 return QString ("<Type not recognized>");
90 }
91 } 35 }
92 36
93 void 37 void
94 OctaveLink::launchOctave () 38 OctaveLink::launchOctave ()
95 { 39 {
96 // Create both threads. 40 // Create both threads.
97 m_octaveMainThread = new OctaveMainThread (this); 41 m_octaveMainThread = new OctaveMainThread (this);
98 m_octaveCallbackThread = new OctaveCallbackThread (this); 42 m_octaveCallbackThread = new OctaveCallbackThread (this);
99 43
100 // Launch the second as soon as the first ist ready. 44 // Launch the second as soon as the first ist ready.
101 connect (m_octaveMainThread, SIGNAL(ready()), m_octaveCallbackThread, SLOT(start())); 45 connect (m_octaveMainThread, SIGNAL (ready ()), m_octaveCallbackThread, SLOT (start ()));
102 46
103 // Start the first one. 47 // Start the first one.
104 m_octaveMainThread->start (); 48 m_octaveMainThread->start ();
105 } 49 }
106 50
107 void 51 void
108 OctaveLink::terminateOctave () 52 OctaveLink::terminateOctave ()
109 { 53 {
110 m_octaveCallbackThread->halt(); 54 m_octaveCallbackThread->halt ();
111 m_octaveCallbackThread->wait (); 55 m_octaveCallbackThread->wait ();
112 56
113 m_octaveMainThread->terminate (); 57 m_octaveMainThread->terminate ();
114 //m_octaveMainThread->wait(); 58 //m_octaveMainThread->wait();
115 }
116
117 QList < SymbolRecord > OctaveLink::symbolTable ()
118 {
119 m_symbolTableBuffer.clear ();
120 std::list < SymbolRecord > allVariables = symbol_table::all_variables ();
121 std::list < SymbolRecord >::iterator iterator;
122 for (iterator = allVariables.begin (); iterator != allVariables.end ();
123 iterator++)
124 {
125 SymbolRecord s = iterator->dup (symbol_table::global_scope ());
126 m_symbolTableBuffer.append (s);
127 }
128 return m_symbolTableBuffer;
129 } 59 }
130 60
131 void 61 void
132 OctaveLink::triggerUpdateHistoryModel () 62 OctaveLink::triggerUpdateHistoryModel ()
133 { 63 {
144 m_historyModel->setData (m_historyModel->index (0), QString (command_history::get_entry (i).c_str ())); 74 m_historyModel->setData (m_historyModel->index (0), QString (command_history::get_entry (i).c_str ()));
145 } 75 }
146 } 76 }
147 } 77 }
148 78
79 void
80 OctaveLink::triggerUpdateSymbolTable ()
81 {
82 m_workspaceModel->updateFromSymbolTable();
83 }
84
149 QStringListModel * 85 QStringListModel *
150 OctaveLink::historyModel () 86 OctaveLink::historyModel ()
151 { 87 {
152 return m_historyModel; 88 return m_historyModel;
153 } 89 }
90
91 WorkspaceModel *
92 OctaveLink::workspaceModel ()
93 {
94 return m_workspaceModel;
95 }