儲存庫 vbox 的更動 83600
- 時間撮記:
- 2020-4-7 上午08:10:53 (5 年 以前)
- 位置:
- trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource
- 檔案:
-
- 修改 2 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.cpp
r83518 r83600 178 178 179 179 UIVMResourceMonitorTableView(QWidget *pParent = 0); 180 void setMinimumColumnWidths(const Q Vector<int>& widths);180 void setMinimumColumnWidths(const QMap<int, int>& widths); 181 181 void updateColumVisibility(); 182 182 … … 192 192 193 193 void resizeHeader(); 194 QVector<int> m_minimumColumnWidths; 194 /** Value is in pixels. Columns cannot be narrower than this width. */ 195 QMap<int, int> m_minimumColumnWidths; 195 196 }; 196 197 … … 231 232 232 233 CMachineDebugger m_comDebugger; 233 mutable CGuest m_comGuest; 234 mutable CGuest m_comGuest; 235 /** The strings of each column for the item. We update this during performance query 236 * instead of model's data function to know the string length earlier. */ 237 QMap<int, QString> m_columnData; 238 234 239 private: 235 240 236 241 void setupPerformanceCollector(); 237 238 242 }; 239 243 … … 303 307 QVariant data(const QModelIndex &index, int role) const /* override */; 304 308 QVariant headerData(int section, Qt::Orientation orientation, int role) const; 305 void setColumnCaptions(const Q Vector<QString>& captions);309 void setColumnCaptions(const QMap<int, QString>& captions); 306 310 void setColumnVisible(const QMap<int, bool>& columnVisible); 307 311 bool columnVisible(int iColumnId) const; 308 312 void setShouldUpdate(bool fShouldUpdate); 313 const QMap<int, int> dataLengths() const; 309 314 310 315 private slots: … … 315 320 private: 316 321 322 void initialize(); 317 323 void initializeItems(); 318 324 void setupPerformanceCollector(); … … 325 331 /* Used to find machines by uid. key is the machine uid and int is the index to m_itemList */ 326 332 QMap<QUuid, int> m_itemMap; 327 Q Vector<QString>m_columnCaptions;333 QMap<int, QString> m_columnCaptions; 328 334 QTimer *m_pTimer; 329 335 /** @name The following are used during UIPerformanceCollector::QueryMetricsData(..) … … 338 344 bool m_fShouldUpdate; 339 345 UIVMResourceMonitorHostStats m_hostStats; 346 /** Maximum length of string length of data displayed in column. Updated in UIResourceMonitorModel::data(..). */ 347 mutable QMap<int, int> m_columnDataMaxLength; 340 348 }; 341 349 … … 667 675 UIVMResourceMonitorTableView::UIVMResourceMonitorTableView(QWidget *pParent /* = 0 */) 668 676 :QTableView(pParent) 669 , m_minimumColumnWidths(QVector<int>((int)VMResourceMonitorColumn_Max, 0)) 670 { 671 } 672 673 void UIVMResourceMonitorTableView::setMinimumColumnWidths(const QVector<int>& widths) 677 { 678 } 679 680 void UIVMResourceMonitorTableView::setMinimumColumnWidths(const QMap<int, int>& widths) 674 681 { 675 682 m_minimumColumnWidths = widths; 683 resizeHeader(); 676 684 } 677 685 … … 710 718 int iHiddenSectionCount = pHeader->hiddenSectionCount(); 711 719 int iWidth = width() / (iSectionCount - iHiddenSectionCount); 712 for (int i = 0; i < iSectionCount && i < m_minimumColumnWidths.size(); ++i)720 for (int i = 0; i < iSectionCount; ++i) 713 721 { 714 722 if (pHeader->isSectionHidden(i)) 715 723 continue; 716 pHeader->resizeSection(i, iWidth < m_minimumColumnWidths[i] ? m_minimumColumnWidths[i] : iWidth); 724 int iMinWidth = m_minimumColumnWidths.value((VMResourceMonitorColumn)i, 0); 725 pHeader->resizeSection(i, iWidth < iMinWidth ? iMinWidth : iWidth); 717 726 } 718 727 } … … 885 894 , m_fShouldUpdate(true) 886 895 { 896 initialize(); 897 } 898 899 void UIResourceMonitorModel::initialize() 900 { 901 for (int i = 0; i < (int)VMResourceMonitorColumn_Max; ++i) 902 m_columnDataMaxLength[i] = 0; 903 887 904 initializeItems(); 888 905 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange, … … 913 930 } 914 931 932 const QMap<int, int> UIResourceMonitorModel::dataLengths() const 933 { 934 return m_columnDataMaxLength; 935 } 936 915 937 QVariant UIResourceMonitorModel::data(const QModelIndex &index, int role) const 916 938 { 917 int iDecimalCount = 2;918 939 if (!index.isValid() || role != Qt::DisplayRole || index.row() >= rowCount()) 919 940 return QVariant(); 920 921 switch (index.column()) 922 { 923 case VMResourceMonitorColumn_Name: 924 return m_itemList[index.row()].m_strVMName; 925 break; 926 case VMResourceMonitorColumn_CPUGuestLoad: 927 return QString("%1%").arg(QString::number(m_itemList[index.row()].m_uCPUGuestLoad)); 928 break; 929 case VMResourceMonitorColumn_CPUVMMLoad: 930 return QString("%1%").arg(QString::number(m_itemList[index.row()].m_uCPUVMMLoad)); 931 break; 932 case VMResourceMonitorColumn_RAMUsedAndTotal: 933 if (m_itemList[index.row()].isWithGuestAdditions()) 934 return QString("%1/%2").arg(uiCommon().formatSize(_1K * m_itemList[index.row()].m_uUsedRAM, iDecimalCount)). 935 arg(uiCommon().formatSize(_1K * m_itemList[index.row()].m_uTotalRAM, iDecimalCount)); 936 else 937 return tr("N/A"); 938 break; 939 case VMResourceMonitorColumn_RAMUsedPercentage: 940 if (m_itemList[index.row()].isWithGuestAdditions()) 941 return QString("%1%").arg(QString::number(m_itemList[index.row()].m_fRAMUsagePercentage, 'f', 2)); 942 else 943 return tr("N/A"); 944 break; 945 case VMResourceMonitorColumn_NetworkUpRate: 946 return QString("%1").arg(uiCommon().formatSize(m_itemList[index.row()].m_uNetworkUpRate, iDecimalCount)); 947 break; 948 case VMResourceMonitorColumn_NetworkDownRate: 949 return QString("%1").arg(uiCommon().formatSize(m_itemList[index.row()].m_uNetworkDownRate, iDecimalCount)); 950 break; 951 case VMResourceMonitorColumn_NetworkUpTotal: 952 return QString("%1").arg(uiCommon().formatSize(m_itemList[index.row()].m_uNetworkUpTotal, iDecimalCount)); 953 break; 954 case VMResourceMonitorColumn_NetworkDownTotal: 955 return QString("%1").arg(uiCommon().formatSize(m_itemList[index.row()].m_uNetworkDownTotal, iDecimalCount)); 956 break; 957 case VMResourceMonitorColumn_DiskIOReadRate: 958 return QString("%1").arg(uiCommon().formatSize(m_itemList[index.row()].m_uDiskReadRate, iDecimalCount)); 959 break; 960 case VMResourceMonitorColumn_DiskIOWriteRate: 961 return QString("%1").arg(uiCommon().formatSize(m_itemList[index.row()].m_uDiskWriteRate, iDecimalCount)); 962 break; 963 case VMResourceMonitorColumn_DiskIOReadTotal: 964 return QString("%1").arg(uiCommon().formatSize(m_itemList[index.row()].m_uDiskReadTotal, iDecimalCount)); 965 break; 966 case VMResourceMonitorColumn_DiskIOWriteTotal: 967 return QString("%1").arg(uiCommon().formatSize(m_itemList[index.row()].m_uDiskWriteTotal, iDecimalCount)); 968 break; 969 case VMResourceMonitorColumn_VMExits: 970 return QString("%1/%2").arg(UICommon::addMetricSuffixToNumber(m_itemList[index.row()].m_uVMExitRate)). 971 arg(UICommon::addMetricSuffixToNumber(m_itemList[index.row()].m_uVMExitTotal)); 972 break; 973 default: 974 break; 975 } 941 return m_itemList[index.row()].m_columnData[index.column()]; 942 } 943 944 QVariant UIResourceMonitorModel::headerData(int section, Qt::Orientation orientation, int role) const 945 { 946 if (role == Qt::DisplayRole && orientation == Qt::Horizontal) 947 return m_columnCaptions.value((VMResourceMonitorColumn)section, QString());; 976 948 return QVariant(); 977 949 } 978 950 979 QVariant UIResourceMonitorModel::headerData(int section, Qt::Orientation orientation, int role) const 980 { 981 if (role == Qt::DisplayRole && orientation == Qt::Horizontal && section < m_columnCaptions.size()) 982 return m_columnCaptions[section]; 983 return QVariant(); 984 } 985 986 void UIResourceMonitorModel::setColumnCaptions(const QVector<QString>& captions) 951 void UIResourceMonitorModel::setColumnCaptions(const QMap<int, QString>& captions) 987 952 { 988 953 m_columnCaptions = captions; … … 1098 1063 } 1099 1064 } 1065 } 1066 int iDecimalCount = 2; 1067 for (int i = 0; i < m_itemList.size(); ++i) 1068 { 1069 m_itemList[i].m_columnData[VMResourceMonitorColumn_Name] = m_itemList[i].m_strVMName; 1070 m_itemList[i].m_columnData[VMResourceMonitorColumn_CPUGuestLoad] = 1071 QString("%1%").arg(QString::number(m_itemList[i].m_uCPUGuestLoad)); 1072 m_itemList[i].m_columnData[VMResourceMonitorColumn_CPUVMMLoad] = 1073 QString("%1%").arg(QString::number(m_itemList[i].m_uCPUVMMLoad)); 1074 1075 if (m_itemList[i].isWithGuestAdditions()) 1076 m_itemList[i].m_columnData[VMResourceMonitorColumn_RAMUsedAndTotal] = 1077 QString("%1/%2").arg(uiCommon().formatSize(_1K * m_itemList[i].m_uUsedRAM, iDecimalCount)). 1078 arg(uiCommon().formatSize(_1K * m_itemList[i].m_uTotalRAM, iDecimalCount)); 1079 else 1080 m_itemList[i].m_columnData[VMResourceMonitorColumn_RAMUsedAndTotal] = tr("N/A"); 1081 1082 if (m_itemList[i].isWithGuestAdditions()) 1083 m_itemList[i].m_columnData[VMResourceMonitorColumn_RAMUsedPercentage] = 1084 QString("%1%").arg(QString::number(m_itemList[i].m_fRAMUsagePercentage, 'f', 2)); 1085 else 1086 m_itemList[i].m_columnData[VMResourceMonitorColumn_RAMUsedPercentage] = tr("N/A"); 1087 1088 m_itemList[i].m_columnData[VMResourceMonitorColumn_NetworkUpRate] = 1089 QString("%1").arg(uiCommon().formatSize(m_itemList[i].m_uNetworkUpRate, iDecimalCount)); 1090 1091 m_itemList[i].m_columnData[VMResourceMonitorColumn_NetworkDownRate] = 1092 QString("%1").arg(uiCommon().formatSize(m_itemList[i].m_uNetworkDownRate, iDecimalCount)); 1093 1094 m_itemList[i].m_columnData[VMResourceMonitorColumn_NetworkUpTotal] = 1095 QString("%1").arg(uiCommon().formatSize(m_itemList[i].m_uNetworkUpTotal, iDecimalCount)); 1096 1097 m_itemList[i].m_columnData[VMResourceMonitorColumn_NetworkDownTotal] = 1098 QString("%1").arg(uiCommon().formatSize(m_itemList[i].m_uNetworkDownTotal, iDecimalCount)); 1099 1100 m_itemList[i].m_columnData[VMResourceMonitorColumn_DiskIOReadRate] = 1101 QString("%1").arg(uiCommon().formatSize(m_itemList[i].m_uDiskReadRate, iDecimalCount)); 1102 1103 m_itemList[i].m_columnData[VMResourceMonitorColumn_DiskIOWriteRate] = 1104 QString("%1").arg(uiCommon().formatSize(m_itemList[i].m_uDiskWriteRate, iDecimalCount)); 1105 1106 m_itemList[i].m_columnData[VMResourceMonitorColumn_DiskIOReadTotal] = 1107 QString("%1").arg(uiCommon().formatSize(m_itemList[i].m_uDiskReadTotal, iDecimalCount)); 1108 1109 m_itemList[i].m_columnData[VMResourceMonitorColumn_DiskIOWriteTotal] = 1110 QString("%1").arg(uiCommon().formatSize(m_itemList[i].m_uDiskWriteTotal, iDecimalCount)); 1111 1112 m_itemList[i].m_columnData[VMResourceMonitorColumn_VMExits] = 1113 QString("%1/%2").arg(UICommon::addMetricSuffixToNumber(m_itemList[i].m_uVMExitRate)). 1114 arg(UICommon::addMetricSuffixToNumber(m_itemList[i].m_uVMExitTotal)); 1115 } 1116 1117 for (int i = 0; i < (int)VMResourceMonitorColumn_Max; ++i) 1118 { 1119 for (int j = 0; j < m_itemList.size(); ++j) 1120 if (m_columnDataMaxLength.value(i, 0) < m_itemList[j].m_columnData[i]) 1121 m_columnDataMaxLength[i] = m_itemList[j].m_columnData[i].length(); 1100 1122 } 1101 1123 emit sigDataUpdate(); … … 1281 1303 void UIResourceMonitorWidget::retranslateUi() 1282 1304 { 1283 m_columnCaptions.resize(VMResourceMonitorColumn_Max);1284 1305 m_columnCaptions[VMResourceMonitorColumn_Name] = tr("VM Name"); 1285 1306 m_columnCaptions[VMResourceMonitorColumn_CPUGuestLoad] = tr("CPU Guest"); … … 1298 1319 if (m_pModel) 1299 1320 m_pModel->setColumnCaptions(m_columnCaptions); 1300 if (m_pTableView) 1301 { 1302 QFontMetrics fontMetrics(m_pTableView->font()); 1303 QVector<int> columnWidths; 1304 foreach (const QString strCaption, m_columnCaptions) 1305 { 1306 columnWidths << fontMetrics.width(strCaption) + 1307 QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin) + 1308 QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin); 1309 } 1310 m_pTableView->setMinimumColumnWidths(columnWidths); 1311 } 1321 computeMinimumColumnWidths(); 1312 1322 } 1313 1323 … … 1404 1414 { 1405 1415 UIVMResourceMonitorCheckBox* pCheckBox = new UIVMResourceMonitorCheckBox; 1406 pCheckBox->setText(m_columnCaptions[i]); 1407 iLength = m_columnCaptions[i].length() > iLength ? m_columnCaptions[i].length() : iLength; 1416 QString strCaption = m_columnCaptions.value((VMResourceMonitorColumn)i, QString()); 1417 pCheckBox->setText(strCaption); 1418 iLength = strCaption.length() > iLength ? strCaption.length() : iLength; 1408 1419 if (!pCheckBox) 1409 1420 continue; … … 1507 1518 void UIResourceMonitorWidget::sltHandleDataUpdate() 1508 1519 { 1520 computeMinimumColumnWidths(); 1509 1521 if (m_pProxyModel) 1510 1522 m_pProxyModel->dataUpdate(); … … 1526 1538 if (m_pTableView) 1527 1539 m_pTableView->updateColumVisibility(); 1540 } 1541 1542 void UIResourceMonitorWidget::computeMinimumColumnWidths() 1543 { 1544 if (!m_pTableView || !m_pModel) 1545 return; 1546 QFontMetrics fontMetrics(m_pTableView->font()); 1547 const QMap<int, int> &columnDataStringLengths = m_pModel->dataLengths(); 1548 1549 QMap<int, int> columnWidthsInPixels; 1550 for (int i = 0; i < (int)VMResourceMonitorColumn_Max; ++i) 1551 { 1552 int iColumnStringWidth = columnDataStringLengths.value(i, 0); 1553 int iColumnTitleWidth = m_columnCaptions.value(i, QString()).length(); 1554 int iMax = iColumnStringWidth > iColumnTitleWidth ? iColumnStringWidth : iColumnTitleWidth; 1555 columnWidthsInPixels[i] = iMax * fontMetrics.width('x') + 1556 QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin) + 1557 QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin); 1558 } 1559 m_pTableView->setMinimumColumnWidths(columnWidthsInPixels); 1528 1560 } 1529 1561 -
trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.h
r83509 r83600 88 88 bool columnVisible(int iColumnId) const; 89 89 void updateModelColumVisibilityCache(); 90 void computeMinimumColumnWidths(); 90 91 91 92 /** @name Prepare/cleanup cascade. … … 114 115 UIResourceMonitorProxyModel *m_pProxyModel; 115 116 UIResourceMonitorModel *m_pModel; 116 QVector<QString> m_columnCaptions; 117 /* The key is the column id (VMResourceMonitorColumn) and value is column title. */ 118 QMap<int, QString> m_columnCaptions; 117 119 /* The key is the column id (VMResourceMonitorColumn) and value is true if the column is visible. */ 118 120 QMap<int, bool> m_columnVisible;
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器