Mercurial > octave
comparison libgui/src/set-path-model.cc @ 31648:29d734430e5f stable
maint: Re-indent code after switch to using namespace macros.
* BaseControl.cc, BaseControl.h, ButtonControl.cc, ButtonControl.h,
ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h,
CheckBoxControl.cc, CheckBoxControl.h, Container.cc, Container.h,
ContextMenu.cc, ContextMenu.h, EditControl.cc, EditControl.h,
Figure.cc, Figure.h, FigureWindow.cc, FigureWindow.h, GLCanvas.cc,
GLCanvas.h, GenericEventNotify.h, KeyMap.cc, KeyMap.h,
ListBoxControl.cc, ListBoxControl.h, Logger.cc, Logger.h, Menu.cc,
Menu.h, MenuContainer.h, Object.cc, Object.h, ObjectProxy.cc,
ObjectProxy.h, Panel.cc, Panel.h, PopupMenuControl.cc,
PopupMenuControl.h, PushButtonControl.cc, PushButtonControl.h,
PushTool.cc, PushTool.h, QtHandlesUtils.cc, QtHandlesUtils.h,
RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc,
SliderControl.h, Table.cc, Table.h, TextControl.cc, TextControl.h,
TextEdit.cc, TextEdit.h, ToggleButtonControl.cc,
ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h, ToolBar.cc,
ToolBar.h, ToolBarButton.cc, ToolBarButton.h, annotation-dialog.cc,
annotation-dialog.h, gl-select.cc, gl-select.h, qopengl-functions.h,
qt-graphics-toolkit.cc, qt-graphics-toolkit.h, module.mk, QTerminal.h,
color-picker.cc, color-picker.h, command-widget.cc, command-widget.h,
community-news.cc, community-news.h, dialog.cc, dialog.h,
documentation-bookmarks.cc, documentation-bookmarks.h,
documentation-dock-widget.cc, documentation-dock-widget.h,
documentation.cc, documentation.h, dw-main-window.cc,
dw-main-window.h, external-editor-interface.cc,
external-editor-interface.h, files-dock-widget.cc,
files-dock-widget.h, find-files-dialog.cc, find-files-dialog.h,
find-files-model.cc, find-files-model.h, graphics-init.cc,
graphics-init.h, gui-settings.cc, gui-settings.h, gui-utils.cc,
gui-utils.h, history-dock-widget.cc, history-dock-widget.h,
interpreter-qobject.cc, interpreter-qobject.h, led-indicator.cc,
led-indicator.h, file-editor-interface.h, file-editor-tab.cc,
file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc,
find-dialog.h, marker.cc, marker.h, octave-qscintilla.cc,
octave-qscintilla.h, octave-txt-lexer.cc, octave-txt-lexer.h,
main-window.cc, main-window.h, news-reader.cc, news-reader.h,
octave-dock-widget.cc, octave-dock-widget.h, octave-qobject.cc,
octave-qobject.h, qt-application.cc, qt-application.h,
qt-interpreter-events.cc, qt-interpreter-events.h, qt-utils.h,
release-notes.cc, release-notes.h, resource-manager.cc,
resource-manager.h, set-path-dialog.cc, set-path-dialog.h,
set-path-model.cc, set-path-model.h, settings-dialog.cc,
settings-dialog.h, shortcut-manager.cc, shortcut-manager.h,
tab-bar.cc, tab-bar.h, terminal-dock-widget.cc,
terminal-dock-widget.h, variable-editor-model.cc,
variable-editor-model.h, variable-editor.cc, variable-editor.h,
welcome-wizard.cc, welcome-wizard.h, workspace-model.cc,
workspace-model.h, workspace-view.cc, workspace-view.h:
Re-indent code after switch to using namespace macros.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Dec 2022 14:53:00 -0500 |
parents | c6d54dd31a7e |
children | 597f3ee61a48 |
comparison
equal
deleted
inserted
replaced
31646:c6d54dd31a7e | 31648:29d734430e5f |
---|---|
42 #include "interpreter.h" | 42 #include "interpreter.h" |
43 #include "load-path.h" | 43 #include "load-path.h" |
44 | 44 |
45 OCTAVE_BEGIN_NAMESPACE(octave) | 45 OCTAVE_BEGIN_NAMESPACE(octave) |
46 | 46 |
47 set_path_model::set_path_model (QObject *p) | 47 set_path_model::set_path_model (QObject *p) |
48 : QAbstractListModel (p) | 48 : QAbstractListModel (p) |
49 { | 49 { |
50 connect (this, &set_path_model::update_data_signal, | 50 connect (this, &set_path_model::update_data_signal, |
51 this, &set_path_model::update_data); | 51 this, &set_path_model::update_data); |
52 | 52 |
53 m_revertible = false; | 53 m_revertible = false; |
54 } | 54 } |
55 | 55 |
56 std::string set_path_model::to_string (void) | 56 std::string set_path_model::to_string (void) |
57 { | 57 { |
58 std::string path_sep = directory_path::path_sep_str (); | 58 std::string path_sep = directory_path::path_sep_str (); |
59 | 59 |
60 std::string path_str; | 60 std::string path_str; |
61 | 61 |
62 QStringList::iterator it = m_dirs.begin (); | 62 QStringList::iterator it = m_dirs.begin (); |
63 | 63 |
64 while (it < m_dirs.end ()) | 64 while (it < m_dirs.end ()) |
65 { | 65 { |
66 if (it != m_dirs.begin ()) | 66 if (it != m_dirs.begin ()) |
67 path_str += path_sep; | 67 path_str += path_sep; |
68 path_str += it->toStdString (); | 68 path_str += it->toStdString (); |
69 ++it; | 69 ++it; |
70 } | 70 } |
71 | 71 |
72 return path_str; | 72 return path_str; |
73 } | 73 } |
74 | 74 |
75 void set_path_model::model_to_path (void) | 75 void set_path_model::model_to_path (void) |
76 { | 76 { |
77 std::string path_str = to_string (); | 77 std::string path_str = to_string (); |
78 | 78 |
79 emit interpreter_event | 79 emit interpreter_event |
80 ([=] (interpreter& interp) | 80 ([=] (interpreter& interp) |
81 { | 81 { |
82 // INTERPRETER THREAD | 82 // INTERPRETER THREAD |
83 | 83 |
84 load_path& lp = interp.get_load_path (); | 84 load_path& lp = interp.get_load_path (); |
85 | 85 |
86 lp.set (path_str); | 86 lp.set (path_str); |
87 }); | 87 }); |
88 } | 88 } |
89 | 89 |
90 void set_path_model::clear (void) | 90 void set_path_model::clear (void) |
91 { | 91 { |
92 beginResetModel (); | 92 beginResetModel (); |
93 | 93 |
94 m_dirs.clear (); | 94 m_dirs.clear (); |
95 | 95 |
96 endResetModel (); | 96 endResetModel (); |
97 } | 97 } |
98 | 98 |
99 void set_path_model::save (void) | 99 void set_path_model::save (void) |
100 { | 100 { |
101 model_to_path (); | 101 model_to_path (); |
102 | 102 |
103 emit interpreter_event | 103 emit interpreter_event |
104 ([] (interpreter& interp) | 104 ([] (interpreter& interp) |
105 { | 105 { |
106 // INTERPRETER THREAD | 106 // INTERPRETER THREAD |
107 | 107 |
108 interp.feval ("savepath"); | 108 interp.feval ("savepath"); |
109 }); | 109 }); |
110 } | 110 } |
111 | 111 |
112 void set_path_model::revert (void) | 112 void set_path_model::revert (void) |
113 { | 113 { |
114 clear (); | 114 clear (); |
115 | 115 |
116 beginInsertRows (QModelIndex (), 0, m_orig_dirs.size () - 1); | 116 beginInsertRows (QModelIndex (), 0, m_orig_dirs.size () - 1); |
117 m_dirs = m_orig_dirs; | 117 m_dirs = m_orig_dirs; |
118 endInsertRows (); | 118 endInsertRows (); |
119 | 119 |
120 model_to_path (); | 120 model_to_path (); |
121 } | 121 } |
122 | 122 |
123 void set_path_model::revert_last (void) | 123 void set_path_model::revert_last (void) |
124 { | 124 { |
125 clear (); | 125 clear (); |
126 | 126 |
127 beginInsertRows (QModelIndex (), 0, m_last_dirs.size () - 1); | 127 beginInsertRows (QModelIndex (), 0, m_last_dirs.size () - 1); |
128 m_dirs = m_last_dirs; | 128 m_dirs = m_last_dirs; |
129 endInsertRows (); | 129 endInsertRows (); |
130 | 130 |
131 model_to_path (); | 131 model_to_path (); |
132 } | 132 } |
133 | 133 |
134 void set_path_model::add_dir (const QString& p) | 134 void set_path_model::add_dir (const QString& p) |
135 { | 135 { |
136 m_last_dirs = m_dirs; | 136 m_last_dirs = m_dirs; |
137 | 137 |
138 beginInsertRows (QModelIndex (), m_dirs.size (), m_dirs.size ()); | 138 beginInsertRows (QModelIndex (), m_dirs.size (), m_dirs.size ()); |
139 | 139 |
140 QList<QString>::Iterator it = m_dirs.begin(); | 140 QList<QString>::Iterator it = m_dirs.begin(); |
141 | 141 |
142 m_dirs.insert (it, p); | 142 m_dirs.insert (it, p); |
143 | 143 |
144 endInsertRows (); | 144 endInsertRows (); |
145 | 145 |
146 model_to_path (); | 146 model_to_path (); |
147 } | 147 } |
148 | 148 |
149 void set_path_model::rm_dir (const QModelIndexList& indices) | 149 void set_path_model::rm_dir (const QModelIndexList& indices) |
150 { | 150 { |
151 m_last_dirs = m_dirs; | 151 m_last_dirs = m_dirs; |
152 | 152 |
153 for (int i = indices.size () - 1; i >= 0; i--) | 153 for (int i = indices.size () - 1; i >= 0; i--) |
154 { | 154 { |
155 const QModelIndex& idx = indices.at (i); | 155 const QModelIndex& idx = indices.at (i); |
156 | 156 |
157 beginRemoveRows (idx, idx.row (), idx.row ()); | 157 beginRemoveRows (idx, idx.row (), idx.row ()); |
158 m_dirs.removeAt (idx.row ()); | 158 m_dirs.removeAt (idx.row ()); |
159 endRemoveRows (); | 159 endRemoveRows (); |
160 } | 160 } |
161 | 161 |
162 model_to_path (); | 162 model_to_path (); |
163 } | 163 } |
164 | 164 |
165 void set_path_model::move_dir_up (const QModelIndexList& indices) | 165 void set_path_model::move_dir_up (const QModelIndexList& indices) |
166 { | 166 { |
167 m_last_dirs = m_dirs; | 167 m_last_dirs = m_dirs; |
168 | 168 |
169 for (int i = 0; i < indices.size (); i++) | 169 for (int i = 0; i < indices.size (); i++) |
170 { | 170 { |
171 const QModelIndex& idx = indices.at (i); | 171 const QModelIndex& idx = indices.at (i); |
172 | 172 |
173 if (idx.row () == 0 ) | 173 if (idx.row () == 0 ) |
174 continue; // already at top position | 174 continue; // already at top position |
175 | 175 |
176 beginMoveRows (idx, idx.row (), idx.row (), | 176 beginMoveRows (idx, idx.row (), idx.row (), |
177 this->index (idx.row () - 1), idx.row () - 1); | 177 this->index (idx.row () - 1), idx.row () - 1); |
178 | 178 |
179 m_dirs.move (idx.row (), idx.row () - 1); | 179 m_dirs.move (idx.row (), idx.row () - 1); |
180 | 180 |
181 endMoveRows (); | 181 endMoveRows (); |
182 } | 182 } |
183 | 183 |
184 model_to_path (); | 184 model_to_path (); |
185 } | 185 } |
186 | 186 |
187 void set_path_model::move_dir_down (const QModelIndexList& indices) | 187 void set_path_model::move_dir_down (const QModelIndexList& indices) |
188 { | 188 { |
189 m_last_dirs = m_dirs; | 189 m_last_dirs = m_dirs; |
190 | 190 |
191 for (int i = indices.size () - 1; i >= 0; i--) | 191 for (int i = indices.size () - 1; i >= 0; i--) |
192 { | 192 { |
193 const QModelIndex& idx = indices.at (i); | 193 const QModelIndex& idx = indices.at (i); |
194 int bottom = m_dirs.size () - 1; | 194 int bottom = m_dirs.size () - 1; |
195 | 195 |
196 if (idx.row () >= bottom) | 196 if (idx.row () >= bottom) |
197 continue; // already at bottom position | 197 continue; // already at bottom position |
198 | 198 |
199 beginMoveRows (idx, idx.row (), idx.row (), | 199 beginMoveRows (idx, idx.row (), idx.row (), |
200 this->index (idx.row () + 1), idx.row () + 1); | 200 this->index (idx.row () + 1), idx.row () + 1); |
201 | 201 |
202 m_dirs.move (idx.row (), idx.row () + 1); | 202 m_dirs.move (idx.row (), idx.row () + 1); |
203 | 203 |
204 endMoveRows (); | 204 endMoveRows (); |
205 } | 205 } |
206 | 206 |
207 model_to_path (); | 207 model_to_path (); |
208 } | 208 } |
209 | 209 |
210 void set_path_model::move_dir_top (const QModelIndexList& indices) | 210 void set_path_model::move_dir_top (const QModelIndexList& indices) |
211 { | 211 { |
212 m_last_dirs = m_dirs; | 212 m_last_dirs = m_dirs; |
213 | 213 |
214 for (int i = 0; i < indices.size (); i++) | 214 for (int i = 0; i < indices.size (); i++) |
215 { | 215 { |
216 const QModelIndex& idx = indices.at (i); | 216 const QModelIndex& idx = indices.at (i); |
217 | 217 |
218 if (idx.row () == i) | 218 if (idx.row () == i) |
219 continue; // already at target position | 219 continue; // already at target position |
220 | 220 |
221 beginMoveRows (idx, idx.row (), idx.row (), this->index (i), i); | 221 beginMoveRows (idx, idx.row (), idx.row (), this->index (i), i); |
222 | 222 |
223 m_dirs.move (idx.row (), i); | 223 m_dirs.move (idx.row (), i); |
224 | 224 |
225 endMoveRows (); | 225 endMoveRows (); |
226 } | 226 } |
227 | 227 |
228 model_to_path (); | 228 model_to_path (); |
229 } | 229 } |
230 | 230 |
231 void set_path_model::move_dir_bottom (const QModelIndexList& indices) | 231 void set_path_model::move_dir_bottom (const QModelIndexList& indices) |
232 { | 232 { |
233 m_last_dirs = m_dirs; | 233 m_last_dirs = m_dirs; |
234 | 234 |
235 for (int i = 0; i < indices.size (); i++) | 235 for (int i = 0; i < indices.size (); i++) |
236 { | 236 { |
237 const QModelIndex& idx = indices.at (i); | 237 const QModelIndex& idx = indices.at (i); |
238 int target = m_dirs.size () - 1 - i; | 238 int target = m_dirs.size () - 1 - i; |
239 | 239 |
240 if (idx.row () == target) | 240 if (idx.row () == target) |
241 continue; // already at target position | 241 continue; // already at target position |
242 | 242 |
243 beginMoveRows (idx, idx.row (), idx.row (), | 243 beginMoveRows (idx, idx.row (), idx.row (), |
244 this->index (target), target); | 244 this->index (target), target); |
245 | 245 |
246 m_dirs.move (idx.row (), target); | 246 m_dirs.move (idx.row (), target); |
247 | 247 |
248 endMoveRows (); | 248 endMoveRows (); |
249 } | 249 } |
250 | 250 |
251 model_to_path (); | 251 model_to_path (); |
252 } | 252 } |
253 | 253 |
254 int set_path_model::rowCount (const QModelIndex&) const | 254 int set_path_model::rowCount (const QModelIndex&) const |
255 { | 255 { |
256 return m_dirs.size (); | 256 return m_dirs.size (); |
257 } | 257 } |
258 | 258 |
259 QVariant set_path_model::data (const QModelIndex& idx, int role) const | 259 QVariant set_path_model::data (const QModelIndex& idx, int role) const |
260 { | 260 { |
261 QVariant retval; | 261 QVariant retval; |
262 if (idx.isValid ()) | 262 if (idx.isValid ()) |
263 { | 263 { |
264 switch (role) | 264 switch (role) |
265 { | 265 { |
266 case Qt::DisplayRole: | 266 case Qt::DisplayRole: |
267 retval = QVariant (m_dirs[idx.row ()]); | 267 retval = QVariant (m_dirs[idx.row ()]); |
268 break; | 268 break; |
269 | 269 |
270 case Qt::DecorationRole: | 270 case Qt::DecorationRole: |
271 retval = QVariant (QIcon ()); | 271 retval = QVariant (QIcon ()); |
272 break; | 272 break; |
273 | 273 |
274 case Qt::SizeHintRole: | 274 case Qt::SizeHintRole: |
275 retval = QVariant (QSize (10, 20)); | 275 retval = QVariant (QSize (10, 20)); |
276 break; | 276 break; |
277 } | 277 } |
278 } | 278 } |
279 | 279 |
280 return retval; | 280 return retval; |
281 } | 281 } |
282 | 282 |
283 void set_path_model::path_to_model (void) | 283 void set_path_model::path_to_model (void) |
284 { | 284 { |
285 emit interpreter_event | 285 emit interpreter_event |
286 ([=] (interpreter& interp) | 286 ([=] (interpreter& interp) |
287 { | 287 { |
288 // INTERPRETER THREAD | 288 // INTERPRETER THREAD |
289 | 289 |
290 load_path& lp = interp.get_load_path (); | 290 load_path& lp = interp.get_load_path (); |
291 | 291 |
292 std::list<std::string> dir_list = lp.dir_list (); | 292 std::list<std::string> dir_list = lp.dir_list (); |
293 | 293 |
294 QStringList qs_dir_list; | 294 QStringList qs_dir_list; |
295 | 295 |
296 for (const auto& dir : dir_list) | 296 for (const auto& dir : dir_list) |
297 qs_dir_list << QString::fromStdString (dir); | 297 qs_dir_list << QString::fromStdString (dir); |
298 | 298 |
299 emit update_data_signal (qs_dir_list); | 299 emit update_data_signal (qs_dir_list); |
300 }); | 300 }); |
301 | 301 |
302 m_revertible = false; | 302 m_revertible = false; |
303 } | 303 } |
304 | 304 |
305 void set_path_model::update_data (const QStringList& dirs) | 305 void set_path_model::update_data (const QStringList& dirs) |
306 { | 306 { |
307 m_dirs = dirs; | 307 m_dirs = dirs; |
308 | 308 |
309 m_dirs.removeAll ("."); | 309 m_dirs.removeAll ("."); |
310 | 310 |
311 if (! m_revertible) | 311 if (! m_revertible) |
312 { | 312 { |
313 // first time update | 313 // first time update |
314 m_orig_dirs = m_dirs; | 314 m_orig_dirs = m_dirs; |
315 m_last_dirs = m_dirs; | 315 m_last_dirs = m_dirs; |
316 | 316 |
317 m_revertible = true; | 317 m_revertible = true; |
318 } | 318 } |
319 | 319 |
320 int numel = m_dirs.size (); | 320 int numel = m_dirs.size (); |
321 | 321 |
322 emit dataChanged (QAbstractListModel::index (0, 0), | 322 emit dataChanged (QAbstractListModel::index (0, 0), |
323 QAbstractListModel::index (numel-1, 0)); | 323 QAbstractListModel::index (numel-1, 0)); |
324 } | 324 } |
325 | 325 |
326 OCTAVE_END_NAMESPACE(octave) | 326 OCTAVE_END_NAMESPACE(octave) |