VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h@ 103538

Last change on this file since 103538 was 102111, checked in by vboxsync, 7 months ago

FE/Qt: bugref:10513: VBox Manager: Make sure Chooser pane let Tool menu know which machine item (if any) caused popup-menu to be shown; That is useful as a hint to determine machine status while updating machine Tool popup-menu.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.6 KB
Line 
1/* $Id: UIChooserModel.h 102111 2023-11-15 16:01:07Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIChooserModel class declaration.
4 */
5
6/*
7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef FEQT_INCLUDED_SRC_manager_chooser_UIChooserModel_h
29#define FEQT_INCLUDED_SRC_manager_chooser_UIChooserModel_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QPointer>
36
37/* GUI includes: */
38#include "UIChooserAbstractModel.h"
39#include "UIExtraDataDefs.h"
40
41/* COM includes: */
42#include "COMEnums.h"
43#include "CCloudMachine.h"
44#include "CMachine.h"
45
46/* Forward declaration: */
47class QDrag;
48class UIActionPool;
49class UIChooser;
50class UIChooserHandlerMouse;
51class UIChooserHandlerKeyboard;
52class UIChooserItem;
53class UIChooserItemMachine;
54class UIChooserNode;
55class UIChooserView;
56class UIVirtualMachineItem;
57
58/** UIChooserAbstractModel extension used as VM Chooser-pane model.
59 * This class is used to operate on tree of visible tree items
60 * representing VMs and their groups. */
61class UIChooserModel : public UIChooserAbstractModel
62{
63 Q_OBJECT;
64
65signals:
66
67 /** @name Tool stuff.
68 * @{ */
69 /** Notifies listeners about tool popup-menu request for certain @a position and optionally machine @a pItem. */
70 void sigToolMenuRequested(const QPoint &position, UIVirtualMachineItem *pItem);
71 /** @} */
72
73 /** @name Selection stuff.
74 * @{ */
75 /** Notifies listeners about selection changed. */
76 void sigSelectionChanged();
77 /** Notifies listeners about selection invalidated. */
78 void sigSelectionInvalidated();
79
80 /** Notifies listeners about group toggling started. */
81 void sigToggleStarted();
82 /** Notifies listeners about group toggling finished. */
83 void sigToggleFinished();
84 /** @} */
85
86 /** @name Layout stuff.
87 * @{ */
88 /** Notifies listeners about root item minimum width @a iHint changed. */
89 void sigRootItemMinimumWidthHintChanged(int iHint);
90 /** @} */
91
92 /** @name Action stuff.
93 * @{ */
94 /** Notifies listeners about start or show request. */
95 void sigStartOrShowRequest();
96 /** @} */
97
98public:
99
100 /** Constructs Chooser-model passing @a pParent to the base-class. */
101 UIChooserModel(UIChooser *pParent, UIActionPool *pActionPool);
102 /** Destructs Chooser-model. */
103 virtual ~UIChooserModel() RT_OVERRIDE;
104
105 /** @name General stuff.
106 * @{ */
107 /** Inits model. */
108 virtual void init() RT_OVERRIDE;
109
110 /** Returns the action-pool reference. */
111 UIActionPool *actionPool() const;
112 /** Returns the scene reference. */
113 QGraphicsScene *scene() const;
114 /** Returns the reference of the first view of the scene(). */
115 UIChooserView *view() const;
116 /** Returns the paint device reference. */
117 QPaintDevice *paintDevice() const;
118
119 /** Returns item at @a position, taking into account possible @a deviceTransform. */
120 QGraphicsItem *itemAt(const QPointF &position, const QTransform &deviceTransform = QTransform()) const;
121
122 /** Handles tool button click for certain @a pItem. */
123 void handleToolButtonClick(UIChooserItem *pItem);
124 /** Handles pin button click for certain @a pItem. */
125 void handlePinButtonClick(UIChooserItem *pItem);
126 /** @} */
127
128 /** @name Selection stuff.
129 * @{ */
130 /** Sets a list of selected @a items. */
131 void setSelectedItems(const QList<UIChooserItem*> &items);
132 /** Defines selected @a pItem. */
133 void setSelectedItem(UIChooserItem *pItem);
134 /** Defines selected-item by @a definition. */
135 void setSelectedItem(const QString &strDefinition);
136 /** Clear selected-items list. */
137 void clearSelectedItems();
138
139 /** Returns a list of selected-items. */
140 const QList<UIChooserItem*> &selectedItems() const;
141
142 /** Adds @a pItem to list of selected. */
143 void addToSelectedItems(UIChooserItem *pItem);
144 /** Removes @a pItem from list of selected. */
145 void removeFromSelectedItems(UIChooserItem *pItem);
146
147 /** Returns first selected-item. */
148 UIChooserItem *firstSelectedItem() const;
149 /** Returns first selected machine item. */
150 UIVirtualMachineItem *firstSelectedMachineItem() const;
151 /** Returns a list of selected machine items. */
152 QList<UIVirtualMachineItem*> selectedMachineItems() const;
153
154 /** Returns whether group item is selected. */
155 bool isGroupItemSelected() const;
156 /** Returns whether global item is selected. */
157 bool isGlobalItemSelected() const;
158 /** Returns whether machine item is selected. */
159 bool isMachineItemSelected() const;
160 /** Returns whether local machine item is selected. */
161 bool isLocalMachineItemSelected() const;
162 /** Returns whether cloud machine item is selected. */
163 bool isCloudMachineItemSelected() const;
164
165 /** Returns whether single group is selected. */
166 bool isSingleGroupSelected() const;
167 /** Returns whether single local group is selected. */
168 bool isSingleLocalGroupSelected() const;
169 /** Returns whether single cloud provider group is selected. */
170 bool isSingleCloudProviderGroupSelected() const;
171 /** Returns whether single cloud profile group is selected. */
172 bool isSingleCloudProfileGroupSelected() const;
173 /** Returns whether all machine items of one group is selected. */
174 bool isAllItemsOfOneGroupSelected() const;
175
176 /** Returns full name of currently selected group. */
177 QString fullGroupName() const;
178
179 /** Finds closest non-selected-item. */
180 UIChooserItem *findClosestUnselectedItem() const;
181 /** Makes sure selection doesn't contain item with certain @a uId. */
182 void makeSureNoItemWithCertainIdSelected(const QUuid &uId);
183 /** Makes sure at least one item selected. */
184 void makeSureAtLeastOneItemSelected();
185
186 /** Defines current @a pItem. */
187 void setCurrentItem(UIChooserItem *pItem);
188 /** Returns current-item. */
189 UIChooserItem *currentItem() const;
190 /** @} */
191
192 /** @name Navigation stuff.
193 * @{ */
194 /** Returns a list of navigation-items. */
195 const QList<UIChooserItem*> &navigationItems() const;
196 /** Removes @a pItem from navigation list. */
197 void removeFromNavigationItems(UIChooserItem *pItem);
198 /** Updates navigation list. */
199 void updateNavigationItemList();
200 /** @} */
201
202 /** @name Search stuff.
203 * @{ */
204 /** Performs a search for an item matching @a strDefinition. */
205 UIChooserItem *searchItemByDefinition(const QString &strDefinition) const;
206
207 /** Performs a search using @a strSearchTerm and @a iSearchFlags specified. */
208 virtual void performSearch(const QString &strSearchTerm, int iSearchFlags) RT_OVERRIDE;
209 /** Resets the search result data members and disables item's visual effects.
210 * Also returns a list of all nodes which may be utilized by the calling code. */
211 virtual QList<UIChooserNode*> resetSearch() RT_OVERRIDE;
212
213 /** Selects next/prev (wrt. @a fIsNext) search result. */
214 void selectSearchResult(bool fIsNext);
215 /** Shows/hides machine search widget. */
216 void setSearchWidgetVisible(bool fVisible);
217 /** @} */
218
219 /** @name Children stuff.
220 * @{ */
221 /** Returns the root instance. */
222 UIChooserItem *root() const;
223
224 /** Starts editing selected group item name. */
225 void startEditingSelectedGroupItemName();
226 /** Disbands selected group item. */
227 void disbandSelectedGroupItem();
228 /** Removes selected machine items. */
229 void removeSelectedMachineItems();
230 /** Moves selected machine items to group item.
231 * @param strName Holds the group item name to move items to, if
232 * that name isn't specified, new top-level group
233 * item will be created. */
234 void moveSelectedMachineItemsToGroupItem(const QString &strName);
235 /** Starts or shows selected items. */
236 void startOrShowSelectedItems();
237 /** Refreshes selected machine items. */
238 void refreshSelectedMachineItems();
239 /** Sorts selected [parent] group item. */
240 void sortSelectedGroupItem();
241 /** Changes current machine item to the one with certain @a uId. */
242 void setCurrentMachineItem(const QUuid &uId);
243 /** Sets global tools item to be the current one. */
244 void setCurrentGlobalItem();
245
246 /** Defines current @a pDragObject. */
247 void setCurrentDragObject(QDrag *pDragObject);
248
249 /** Looks for item with certain @a strLookupText. */
250 void lookFor(const QString &strLookupText);
251 /** @} */
252
253 /** @name Layout stuff.
254 * @{ */
255 /** Updates layout. */
256 void updateLayout();
257
258 /** Defines global item height @a iHint. */
259 void setGlobalItemHeightHint(int iHint);
260 /** @} */
261
262public slots:
263
264 /** @name General stuff.
265 * @{ */
266 /** Handles Chooser-view resize. */
267 void sltHandleViewResized();
268 /** @} */
269
270protected:
271
272 /** @name Event handling stuff.
273 * @{ */
274 /** Preprocesses Qt @a pEvent for passed @a pObject. */
275 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
276 /** @} */
277
278protected slots:
279
280 /** @name Main event handling stuff.
281 * @{ */
282 /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
283 virtual void sltLocalMachineRegistrationChanged(const QUuid &uMachineId, const bool fRegistered) RT_OVERRIDE;
284
285 /** Handles event about cloud provider with @a uProviderId being uninstalled. */
286 virtual void sltHandleCloudProviderUninstall(const QUuid &uProviderId) RT_OVERRIDE;
287 /** @} */
288
289 /** @name Children stuff.
290 * @{ */
291 /** Handles reload machine with certain @a uMachineId request. */
292 virtual void sltReloadMachine(const QUuid &uMachineId) RT_OVERRIDE;
293
294 /** Handles command to detach COM. */
295 virtual void sltDetachCOM() RT_OVERRIDE;
296 /** @} */
297
298 /** @name Cloud stuff.
299 * @{ */
300 /** Handles cloud machine unregistering for @a uId.
301 * @param strProviderShortName Brings provider short name.
302 * @param strProfileName Brings profile name. */
303 virtual void sltCloudMachineUnregistered(const QString &strProviderShortName,
304 const QString &strProfileName,
305 const QUuid &uId) RT_OVERRIDE;
306 /** Handles cloud machine unregistering for a list of @a ids.
307 * @param strProviderShortName Brings provider short name.
308 * @param strProfileName Brings profile name. */
309 virtual void sltCloudMachinesUnregistered(const QString &strProviderShortName,
310 const QString &strProfileName,
311 const QList<QUuid> &ids) RT_OVERRIDE;
312 /** Handles cloud machine registering for @a comMachine.
313 * @param strProviderShortName Brings provider short name.
314 * @param strProfileName Brings profile name. */
315 virtual void sltCloudMachineRegistered(const QString &strProviderShortName,
316 const QString &strProfileName,
317 const CCloudMachine &comMachine) RT_OVERRIDE;
318 /** Handles cloud machine registering for a list of @a machines.
319 * @param strProviderShortName Brings provider short name.
320 * @param strProfileName Brings profile name. */
321 virtual void sltCloudMachinesRegistered(const QString &strProviderShortName,
322 const QString &strProfileName,
323 const QVector<CCloudMachine> &machines) RT_OVERRIDE;
324
325 /** Handles read cloud machine list task complete signal. */
326 virtual void sltHandleReadCloudMachineListTaskComplete() RT_OVERRIDE;
327
328 /** Handles Cloud Profile Manager cumulative changes. */
329 virtual void sltHandleCloudProfileManagerCumulativeChange() RT_OVERRIDE;
330 /** @} */
331
332private slots:
333
334 /** @name Selection stuff.
335 * @{ */
336 /** Makes sure current item is visible. */
337 void sltMakeSureCurrentItemVisible();
338
339 /** Handles current-item destruction. */
340 void sltCurrentItemDestroyed();
341 /** @} */
342
343 /** @name Children stuff.
344 * @{ */
345 /** Handles D&D scrolling. */
346 void sltStartScrolling();
347 /** Handles D&D object destruction. */
348 void sltCurrentDragObjectDestroyed();
349 /** @} */
350
351 /** @name Cloud stuff.
352 * @{ */
353 /** Handles cloud machine removal.
354 * @param strProviderShortName Brings the provider short name.
355 * @param strProfileName Brings the profile name.
356 * @param strName Brings the machine name. */
357 void sltHandleCloudMachineRemoved(const QString &strProviderShortName,
358 const QString &strProfileName,
359 const QString &strName);
360
361 /** Updates selected cloud profiles. */
362 void sltUpdateSelectedCloudProfiles();
363 /** @} */
364
365private:
366
367 /** @name Prepare/Cleanup cascade.
368 * @{ */
369 /** Prepares all. */
370 void prepare();
371 /** Prepares scene. */
372 void prepareScene();
373 /** Prepares context-menu. */
374 void prepareContextMenu();
375 /** Prepares handlers. */
376 void prepareHandlers();
377 /** Prepares cloud update timer. */
378 void prepareCloudUpdateTimer();
379 /** Prepares connections. */
380 void prepareConnections();
381 /** Loads settings. */
382 void loadSettings();
383
384 /** Cleanups connections. */
385 void cleanupConnections();
386 /** Cleanups cloud update timer.*/
387 void cleanupCloudUpdateTimer();
388 /** Cleanups handlers. */
389 void cleanupHandlers();
390 /** Cleanups context-menu. */
391 void cleanupContextMenu();
392 /** Cleanups scene. */
393 void cleanupScene();
394 /** Cleanups all. */
395 void cleanup();
396 /** @} */
397
398 /** @name General stuff.
399 * @{ */
400 /** Handles context-menu @a pEvent. */
401 bool processContextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent);
402 /** @} */
403
404 /** @name Selection stuff.
405 * @{ */
406 /** Clears real focus. */
407 void clearRealFocus();
408 /** @} */
409
410 /** @name Navigation stuff.
411 * @{ */
412 /** Creates navigation list for passed root @a pItem. */
413 QList<UIChooserItem*> createNavigationItemList(UIChooserItem *pItem);
414 /** @} */
415
416 /** @name Children stuff.
417 * @{ */
418 /** Clears tree for main root. */
419 void clearTreeForMainRoot();
420 /** [Re]builds tree for main root, preserves selection if requested. */
421 void buildTreeForMainRoot(bool fPreserveSelection = false);
422 /** Update tree for main root. */
423 void updateTreeForMainRoot();
424
425 /** Removes a list of local virtual @a machineItems. */
426 void removeLocalMachineItems(const QList<UIChooserItemMachine*> &machineItems);
427 /** Unregisters a list of local virtual @a machines. */
428 void unregisterLocalMachines(const QList<CMachine> &machines);
429 /** Unregisters a list of cloud virtual @a machineItems. */
430 void unregisterCloudMachineItems(const QList<UIChooserItemMachine*> &machineItems);
431
432 /** Processes drag move @a pEvent. */
433 bool processDragMoveEvent(QGraphicsSceneDragDropEvent *pEvent);
434 /** Processes drag leave @a pEvent. */
435 bool processDragLeaveEvent(QGraphicsSceneDragDropEvent *pEvent);
436
437 /** Applies the global item height hint. */
438 void applyGlobalItemHeightHint();
439 /** @} */
440
441 /** @name General stuff.
442 * @{ */
443 /** Holds the action-pool reference. */
444 UIActionPool *m_pActionPool;
445
446 /** Holds the scene reference. */
447 QGraphicsScene *m_pScene;
448
449 /** Holds the mouse handler instance. */
450 UIChooserHandlerMouse *m_pMouseHandler;
451 /** Holds the keyboard handler instance. */
452 UIChooserHandlerKeyboard *m_pKeyboardHandler;
453
454 /** Holds the map of local context-menu instances. */
455 QMap<UIChooserNodeType, QMenu*> m_localMenus;
456 /** Holds the map of cloud context-menu instances. */
457 QMap<UIChooserNodeType, QMenu*> m_cloudMenus;
458 /** @} */
459
460 /** @name Selection stuff.
461 * @{ */
462 /** Holds the current-item reference. */
463 QPointer<UIChooserItem> m_pCurrentItem;
464
465 /** Holds whether selection save allowed. */
466 bool m_fSelectionSaveAllowed;
467 /** @} */
468
469 /** @name Search stuff.
470 * @{ */
471 /** Stores the index (within the m_searchResults) of the currently selected found item. */
472 int m_iCurrentSearchResultIndex;
473 /** @} */
474
475 /** @name Children stuff.
476 * @{ */
477 /** Holds the root instance. */
478 QPointer<UIChooserItem> m_pRoot;
479
480 /** Holds the navigation-items. */
481 QList<UIChooserItem*> m_navigationItems;
482 /** Holds the selected-items. */
483 QList<UIChooserItem*> m_selectedItems;
484
485 /** Holds the current drag object instance. */
486 QPointer<QDrag> m_pCurrentDragObject;
487 /** Holds the drag scrolling token size. */
488 int m_iScrollingTokenSize;
489 /** Holds whether drag scrolling is in progress. */
490 bool m_fIsScrollingInProgress;
491
492 /** Holds the global item height hint. */
493 int m_iGlobalItemHeightHint;
494 /** @} */
495
496 /** @name Cloud stuff.
497 * @{ */
498 /** Holds cloud profile update timer instance. */
499 QTimer *m_pTimerCloudProfileUpdate;
500 /** @} */
501};
502
503#endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserModel_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use