1 | /* $Id: UIVMActivityOverviewModelView.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVMActivityOverviewModelView class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2024 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_activity_overview_UIVMActivityOverviewModelView_h
|
---|
29 | #define FEQT_INCLUDED_SRC_activity_overview_UIVMActivityOverviewModelView_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QAbstractTableModel>
|
---|
36 | #include <QSortFilterProxyModel>
|
---|
37 | #include <QUuid>
|
---|
38 |
|
---|
39 | /* GUI includes: */
|
---|
40 | #include "QITableView.h"
|
---|
41 |
|
---|
42 | /* COM includes: */
|
---|
43 | #include "CPerformanceMetric.h"
|
---|
44 | #include "CPerformanceCollector.h"
|
---|
45 | #include "KMachineState.h"
|
---|
46 |
|
---|
47 |
|
---|
48 | class QTimer;
|
---|
49 | class UIVMActivityOverviewCell;
|
---|
50 | class UIVMActivityOverviewRow;
|
---|
51 | class UIVMActivityOverviewRowCloud;
|
---|
52 | class UIVirtualMachineItemCloud;
|
---|
53 |
|
---|
54 | /** A simple container to store host related performance values. */
|
---|
55 | class UIVMActivityOverviewHostStats
|
---|
56 | {
|
---|
57 |
|
---|
58 | public:
|
---|
59 |
|
---|
60 | UIVMActivityOverviewHostStats();
|
---|
61 | quint64 m_iCPUUserLoad;
|
---|
62 | quint64 m_iCPUKernelLoad;
|
---|
63 | quint64 m_iCPUFreq;
|
---|
64 | quint64 m_iRAMTotal;
|
---|
65 | quint64 m_iRAMFree;
|
---|
66 | quint64 m_iFSTotal;
|
---|
67 | quint64 m_iFSFree;
|
---|
68 | };
|
---|
69 |
|
---|
70 |
|
---|
71 | class UIVMActivityOverviewTableView : public QITableView
|
---|
72 | {
|
---|
73 | Q_OBJECT;
|
---|
74 |
|
---|
75 | signals:
|
---|
76 |
|
---|
77 | void sigSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
---|
78 |
|
---|
79 | public:
|
---|
80 |
|
---|
81 | UIVMActivityOverviewTableView(QWidget *pParent);
|
---|
82 | void setMinimumColumnWidths(const QMap<int, int>& widths);
|
---|
83 | void updateColumVisibility();
|
---|
84 | int selectedItemIndex() const;
|
---|
85 | bool hasSelection() const;
|
---|
86 |
|
---|
87 | private:
|
---|
88 |
|
---|
89 | virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE;
|
---|
90 | virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) RT_OVERRIDE;
|
---|
91 | virtual void mousePressEvent(QMouseEvent *pEvent) RT_OVERRIDE;
|
---|
92 | /** Resizes all the columns in response to resizeEvent. Columns cannot be narrower than m_minimumColumnWidths values. */
|
---|
93 | void resizeHeaders();
|
---|
94 | /** Value is in pixels. Columns cannot be narrower than this width. */
|
---|
95 | QMap<int, int> m_minimumColumnWidths;
|
---|
96 | };
|
---|
97 |
|
---|
98 | class UIVMActivityOverviewProxyModel : public QSortFilterProxyModel
|
---|
99 | {
|
---|
100 |
|
---|
101 | Q_OBJECT;
|
---|
102 |
|
---|
103 | public:
|
---|
104 |
|
---|
105 | UIVMActivityOverviewProxyModel(QObject *parent = 0);
|
---|
106 | void dataUpdate();
|
---|
107 | void setNotRunningVMVisibility(bool fShow);
|
---|
108 | void setCloudVMVisibility(bool fShow);
|
---|
109 |
|
---|
110 | protected:
|
---|
111 |
|
---|
112 | virtual bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const RT_OVERRIDE;
|
---|
113 | virtual bool filterAcceptsRow(int iSourceRow, const QModelIndex &sourceParent) const RT_OVERRIDE RT_FINAL;
|
---|
114 |
|
---|
115 | private:
|
---|
116 |
|
---|
117 | bool m_fShowNotRunningVMs;
|
---|
118 | bool m_fShowCloudVMs;
|
---|
119 | };
|
---|
120 |
|
---|
121 | class UIVMActivityOverviewModel : public QAbstractTableModel
|
---|
122 | {
|
---|
123 | Q_OBJECT;
|
---|
124 |
|
---|
125 | signals:
|
---|
126 |
|
---|
127 | void sigDataUpdate();
|
---|
128 | void sigHostStatsUpdate(const UIVMActivityOverviewHostStats &stats);
|
---|
129 |
|
---|
130 | public:
|
---|
131 |
|
---|
132 | ~UIVMActivityOverviewModel();
|
---|
133 | UIVMActivityOverviewModel(QObject *pParent, QITableView *pView);
|
---|
134 | QModelIndex index(int iRow, int iColumn, const QModelIndex &parentIdx = QModelIndex()) const RT_OVERRIDE RT_FINAL;
|
---|
135 | int rowCount(const QModelIndex &parent = QModelIndex()) const RT_OVERRIDE RT_FINAL;
|
---|
136 | int columnCount(const QModelIndex &parent = QModelIndex()) const RT_OVERRIDE RT_FINAL;
|
---|
137 | QVariant data(const QModelIndex &index, int role) const RT_OVERRIDE RT_FINAL;
|
---|
138 | QVariant headerData(int section, Qt::Orientation orientation, int role) const RT_OVERRIDE RT_FINAL;
|
---|
139 | void setColumnCaptions(const QMap<int, QString>& captions);
|
---|
140 | int itemIndex(const QUuid &uid);
|
---|
141 | void setShouldUpdate(bool fShouldUpdate);
|
---|
142 | void clearData();
|
---|
143 | bool isVMRunning(int rowIndex) const;
|
---|
144 | bool isCloudVM(int rowIndex) const;
|
---|
145 | void setColumnVisible(const QMap<int, bool>& columnVisible);
|
---|
146 | bool columnVisible(int iColumnId) const;
|
---|
147 | void setCloudMachineItems(const QList<UIVirtualMachineItemCloud*> &cloudItems);
|
---|
148 | QUuid itemUid(int iIndex);
|
---|
149 | const QMap<int, int> dataLengths() const;
|
---|
150 |
|
---|
151 | private slots:
|
---|
152 |
|
---|
153 | void sltMachineStateChanged(const QUuid &uId, const KMachineState state);
|
---|
154 | void sltMachineRegistered(const QUuid &uId, bool fRegistered);
|
---|
155 | void sltLocalVMUpdateTimeout();
|
---|
156 |
|
---|
157 | private:
|
---|
158 |
|
---|
159 | void initialize();
|
---|
160 | void addRow(const QUuid& uMachineId, const QString& strMachineName, KMachineState enmState);
|
---|
161 | void removeRow(const QUuid& uMachineId);
|
---|
162 | void setupPerformanceCollector();
|
---|
163 | void queryPerformanceCollector();
|
---|
164 | void getHostRAMStats();
|
---|
165 | QVector<UIVMActivityOverviewRow*> m_rows;
|
---|
166 | QITableView *m_pTableView;
|
---|
167 | QMap<int, QString> m_columnTitles;
|
---|
168 | QMap<int, bool> m_columnVisible;
|
---|
169 | QTimer *m_pLocalVMUpdateTimer;
|
---|
170 | /** Maximum length of string length of data displayed in column. Updated in UIVMActivityOverviewModel::data(..). */
|
---|
171 | mutable QMap<int, int> m_columnDataMaxLength;
|
---|
172 | CPerformanceCollector m_performanceCollector;
|
---|
173 | /** @name The following are used during UIPerformanceCollector::QueryMetricsData(..)
|
---|
174 | * @{ */
|
---|
175 | QVector<QString> m_nameList;
|
---|
176 | QVector<CUnknown> m_objectList;
|
---|
177 | /** @} */
|
---|
178 | UIVMActivityOverviewHostStats m_hostStats;
|
---|
179 | };
|
---|
180 |
|
---|
181 |
|
---|
182 | #endif /* !FEQT_INCLUDED_SRC_activity_overview_UIVMActivityOverviewModelView_h */
|
---|