Changeset 102273 in vbox
- Timestamp:
- Nov 23, 2023 11:11:35 AM (12 months ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.cpp
r102266 r102273 551 551 int iAverageFontWidth = fontMetrics.averageCharWidth(); 552 552 553 /* Draw a straight line per data series: */ 554 if (iMaximum == 0) 555 { 556 for (int k = 0; k < DATA_SERIES_SIZE; ++k) 553 /* Draw the data lines: */ 554 float fBarWidth = m_lineChartRect.width() / (float) (m_iMaximumQueueSize - 1); 555 float fH = iMaximum == 0 ? 0 : m_lineChartRect.height() / (float)iMaximum; 556 for (int k = 0; k < DATA_SERIES_SIZE; ++k) 557 { 558 if (m_fUseGradientLineColor) 557 559 { 558 QLineF bar(0 + m_iMarginLeft, height() - m_iMarginBottom, 559 width() - m_iMarginRight, height() - m_iMarginBottom); 560 painter.drawLine(bar); 560 QLinearGradient gradient(0, 0, 0, m_lineChartRect.height()); 561 gradient.setColorAt(0, Qt::black); 562 gradient.setColorAt(1, m_dataSeriesColor[k]); 563 painter.setPen(QPen(gradient, 2.5)); 564 } 565 const QQueue<quint64> *data = m_pMetric->data(k); 566 if (!m_fUseGradientLineColor) 561 567 painter.setPen(QPen(m_dataSeriesColor[k], 2.5)); 568 if (m_fUseAreaChart && m_fIsAreaChartAllowed) 569 { 570 QVector<QPointF> points; 571 for (int i = 0; i < data->size(); ++i) 572 { 573 float fHeight = fH * data->at(i); 574 if (k == 0) 575 { 576 if (m_pMetric->data(1) && m_pMetric->data(1)->size() > i) 577 fHeight += fH * m_pMetric->data(1)->at(i); 578 } 579 float fX = (width() - m_iMarginRight) - ((data->size() - i - 1) * fBarWidth); 580 if (i == 0) 581 points << QPointF(fX, height() - m_iMarginBottom); 582 points << QPointF(fX, height() - (fHeight + m_iMarginBottom)); 583 if (i == data->size() - 1) 584 points << QPointF(fX, height() - + m_iMarginBottom); 585 } 586 painter.setPen(Qt::NoPen); 562 587 painter.setBrush(m_dataSeriesColor[k]); 588 painter.drawPolygon(points, Qt::WindingFill); 563 589 } 564 } 565 else 566 { 567 /* Draw the data lines: */ 568 float fBarWidth = m_lineChartRect.width() / (float) (m_iMaximumQueueSize - 1); 569 float fH = m_lineChartRect.height() / (float)iMaximum; 570 for (int k = 0; k < DATA_SERIES_SIZE; ++k) 590 else 571 591 { 572 if (m_fUseGradientLineColor)592 for (int i = 0; i < data->size() - 1; ++i) 573 593 { 574 QLinearGradient gradient(0, 0, 0, m_lineChartRect.height()); 575 gradient.setColorAt(0, Qt::black); 576 gradient.setColorAt(1, m_dataSeriesColor[k]); 577 painter.setPen(QPen(gradient, 2.5)); 578 } 579 const QQueue<quint64> *data = m_pMetric->data(k); 580 if (!m_fUseGradientLineColor) 581 painter.setPen(QPen(m_dataSeriesColor[k], 2.5)); 582 if (m_fUseAreaChart && m_fIsAreaChartAllowed) 583 { 584 QVector<QPointF> points; 585 for (int i = 0; i < data->size(); ++i) 586 { 587 float fHeight = fH * data->at(i); 588 if (k == 0) 589 { 590 if (m_pMetric->data(1) && m_pMetric->data(1)->size() > i) 591 fHeight += fH * m_pMetric->data(1)->at(i); 592 } 593 float fX = (width() - m_iMarginRight) - ((data->size() - i - 1) * fBarWidth); 594 if (i == 0) 595 points << QPointF(fX, height() - m_iMarginBottom); 596 points << QPointF(fX, height() - (fHeight + m_iMarginBottom)); 597 if (i == data->size() - 1) 598 points << QPointF(fX, height() - + m_iMarginBottom); 599 } 600 painter.setPen(Qt::NoPen); 601 painter.setBrush(m_dataSeriesColor[k]); 602 painter.drawPolygon(points, Qt::WindingFill); 603 } 604 else 605 { 606 for (int i = 0; i < data->size() - 1; ++i) 607 { 608 int j = i + 1; 609 float fHeight = fH * data->at(i); 610 float fX = (width() - m_iMarginRight) - ((data->size() -i - 1) * fBarWidth); 611 float fHeight2 = fH * data->at(j); 612 float fX2 = (width() - m_iMarginRight) - ((data->size() -j - 1) * fBarWidth); 613 QLineF bar(fX, height() - (fHeight + m_iMarginBottom), fX2, height() - (fHeight2 + m_iMarginBottom)); 614 painter.drawLine(bar); 615 } 616 } 617 /* Draw a horizontal and vertical line on data point under the mouse cursor 618 * and draw the value on the left hand side of the chart: */ 619 if (m_fDrawCurenValueIndicators && m_iDataIndexUnderCursor >= 0 && m_iDataIndexUnderCursor < data->size()) 620 { 621 painter.setPen(QPen(m_dataSeriesColor[k], 0.5)); 622 float fHeight = fH * data->at(data->size() - m_iDataIndexUnderCursor); 623 if (fHeight > 0) 624 { 625 painter.drawLine(m_iMarginLeft, height() - (fHeight + m_iMarginBottom), 626 width() - m_iMarginRight, height() - (fHeight + m_iMarginBottom)); 627 QPoint cursorPosition = mapFromGlobal(cursor().pos()); 628 painter.setPen(mainAxisColor); 629 painter.drawLine(cursorPosition.x(), 0, 630 cursorPosition.x(), height() - m_iMarginBottom); 631 QString strValue = QString::number(data->at(data->size() - m_iDataIndexUnderCursor)); 632 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) 633 painter.drawText(m_iMarginLeft - fontMetrics.horizontalAdvance(strValue) - iAverageFontWidth, 634 height() - (fHeight + m_iMarginBottom) + 0.5 * iFontHeight, strValue); 635 #else 636 painter.drawText(m_iMarginLeft - fontMetrics.width(strValue) - iAverageFontWidth, 637 height() - (fHeight + m_iMarginBottom) + 0.5 * iFontHeight, strValue); 638 #endif 639 640 } 594 int j = i + 1; 595 float fHeight = fH * data->at(i); 596 float fX = (width() - m_iMarginRight) - ((data->size() -i - 1) * fBarWidth); 597 float fHeight2 = fH * data->at(j); 598 float fX2 = (width() - m_iMarginRight) - ((data->size() -j - 1) * fBarWidth); 599 QLineF bar(fX, height() - (fHeight + m_iMarginBottom), fX2, height() - (fHeight2 + m_iMarginBottom)); 600 painter.drawLine(bar); 641 601 } 642 602 } 643 }// else of if (iMaximum == 0) 603 /* Draw a horizontal and vertical line on data point under the mouse cursor 604 * and draw the value on the left hand side of the chart: */ 605 if (m_fDrawCurenValueIndicators && m_iDataIndexUnderCursor >= 0 && m_iDataIndexUnderCursor < data->size()) 606 { 607 painter.setPen(QPen(m_dataSeriesColor[k], 0.5)); 608 float fHeight = fH * data->at(data->size() - m_iDataIndexUnderCursor); 609 if (fHeight > 0) 610 { 611 painter.drawLine(m_iMarginLeft, height() - (fHeight + m_iMarginBottom), 612 width() - m_iMarginRight, height() - (fHeight + m_iMarginBottom)); 613 QPoint cursorPosition = mapFromGlobal(cursor().pos()); 614 painter.setPen(mainAxisColor); 615 painter.drawLine(cursorPosition.x(), 0, 616 cursorPosition.x(), height() - m_iMarginBottom); 617 QString strValue = QString::number(data->at(data->size() - m_iDataIndexUnderCursor)); 618 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) 619 painter.drawText(m_iMarginLeft - fontMetrics.horizontalAdvance(strValue) - iAverageFontWidth, 620 height() - (fHeight + m_iMarginBottom) + 0.5 * iFontHeight, strValue); 621 #else 622 painter.drawText(m_iMarginLeft - fontMetrics.width(strValue) - iAverageFontWidth, 623 height() - (fHeight + m_iMarginBottom) + 0.5 * iFontHeight, strValue); 624 #endif 625 626 } 627 } 628 } 644 629 645 630 /* Draw YAxis tick labels: */ … … 1209 1194 } 1210 1195 1211 void UIVMActivityMonitor ::resetCPUInfoLabel()1196 void UIVMActivityMonitorLocal::resetCPUInfoLabel() 1212 1197 { 1213 1198 if (m_infoLabels.contains(m_strCPUMetricName) && m_infoLabels[m_strCPUMetricName]) … … 1271 1256 } 1272 1257 1273 void UIVMActivityMonitorLocal::start() 1274 { 1275 if (m_comMachine.isNull() || m_comMachine.GetState() != KMachineState_Running) 1276 return; 1277 1278 m_fGuestAdditionsAvailable = guestAdditionsAvailable("6.1"); 1279 enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable); 1280 if (m_pTimer) 1281 m_pTimer->start(1000 * g_iPeriod); 1282 } 1283 1284 UIVMActivityMonitorLocal::UIVMActivityMonitorLocal(EmbedTo enmEmbedding, QWidget *pParent, const CMachine &machine) 1285 :UIVMActivityMonitor(enmEmbedding, pParent, 120 /* iMaximumQueueSize */) 1286 , m_fGuestAdditionsAvailable(false) 1287 { 1288 prepareMetrics(); 1289 prepareWidgets(); 1290 retranslateUi(); 1291 prepareActions(); 1292 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange, this, &UIVMActivityMonitorLocal::sltMachineStateChange); 1293 connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UIVMActivityMonitorLocal::sltClearCOMData); 1294 setMachine(machine); 1295 } 1296 1297 UIVMActivityMonitorLocal::~UIVMActivityMonitorLocal() 1298 { 1299 sltClearCOMData(); 1300 } 1301 1302 QUuid UIVMActivityMonitorLocal::machineId() const 1303 { 1304 if (m_comMachine.isNull()) 1305 return QUuid(); 1306 return m_comMachine.GetId(); 1307 } 1308 1309 void UIVMActivityMonitorLocal::retranslateUi() 1310 { 1311 UIVMActivityMonitor::retranslateUi(); 1312 1313 foreach (UIChart *pChart, m_charts) 1314 pChart->setXAxisLabel(QApplication::translate("UIVMInformationDialog", "Sec.")); 1315 1316 m_strVMExitInfoLabelTitle = QApplication::translate("UIVMInformationDialog", "VM Exits"); 1317 m_iMaximumLabelLength = qMax(m_iMaximumLabelLength, m_strVMExitInfoLabelTitle.length()); 1318 m_strVMExitLabelCurrent = QApplication::translate("UIVMInformationDialog", "Current"); 1319 m_iMaximumLabelLength = qMax(m_iMaximumLabelLength, m_strVMExitLabelCurrent.length()); 1320 m_strVMExitLabelTotal = QApplication::translate("UIVMInformationDialog", "Total"); 1321 m_iMaximumLabelLength = qMax(m_iMaximumLabelLength, m_strVMExitLabelTotal.length()); 1322 1258 void UIVMActivityMonitor::setInfoLabelWidth() 1259 { 1323 1260 /* Compute the maximum label string length and set it as a fixed width to labels to prevent always changing widths: */ 1324 1261 /* Add m_iDecimalCount plus 4 characters for the number and 3 for unit string: */ … … 1339 1276 } 1340 1277 } 1278 } 1279 1280 /********************************************************************************************************************************* 1281 * UIVMActivityMonitorLocal definition. * 1282 *********************************************************************************************************************************/ 1283 1284 UIVMActivityMonitorLocal::UIVMActivityMonitorLocal(EmbedTo enmEmbedding, QWidget *pParent, const CMachine &machine) 1285 :UIVMActivityMonitor(enmEmbedding, pParent, 120 /* iMaximumQueueSize */) 1286 , m_fGuestAdditionsAvailable(false) 1287 { 1288 prepareMetrics(); 1289 prepareWidgets(); 1290 retranslateUi(); 1291 prepareActions(); 1292 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineStateChange, this, &UIVMActivityMonitorLocal::sltMachineStateChange); 1293 connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UIVMActivityMonitorLocal::sltClearCOMData); 1294 setMachine(machine); 1295 } 1296 1297 void UIVMActivityMonitorLocal::start() 1298 { 1299 if (m_comMachine.isNull() || m_comMachine.GetState() != KMachineState_Running) 1300 return; 1301 1302 m_fGuestAdditionsAvailable = guestAdditionsAvailable("6.1"); 1303 enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable); 1304 if (m_pTimer) 1305 m_pTimer->start(1000 * g_iPeriod); 1306 } 1307 1308 UIVMActivityMonitorLocal::~UIVMActivityMonitorLocal() 1309 { 1310 sltClearCOMData(); 1311 } 1312 1313 QUuid UIVMActivityMonitorLocal::machineId() const 1314 { 1315 if (m_comMachine.isNull()) 1316 return QUuid(); 1317 return m_comMachine.GetId(); 1318 } 1319 1320 void UIVMActivityMonitorLocal::retranslateUi() 1321 { 1322 UIVMActivityMonitor::retranslateUi(); 1323 1324 foreach (UIChart *pChart, m_charts) 1325 pChart->setXAxisLabel(QApplication::translate("UIVMInformationDialog", "Sec.")); 1326 1327 m_strVMExitInfoLabelTitle = QApplication::translate("UIVMInformationDialog", "VM Exits"); 1328 m_iMaximumLabelLength = qMax(m_iMaximumLabelLength, m_strVMExitInfoLabelTitle.length()); 1329 m_strVMExitLabelCurrent = QApplication::translate("UIVMInformationDialog", "Current"); 1330 m_iMaximumLabelLength = qMax(m_iMaximumLabelLength, m_strVMExitLabelCurrent.length()); 1331 m_strVMExitLabelTotal = QApplication::translate("UIVMInformationDialog", "Total"); 1332 m_iMaximumLabelLength = qMax(m_iMaximumLabelLength, m_strVMExitLabelTotal.length()); 1333 1334 setInfoLabelWidth(); 1341 1335 } 1342 1336 … … 1748 1742 } 1749 1743 1744 /********************************************************************************************************************************* 1745 * UIVMActivityMonitorCloud definition. * 1746 *********************************************************************************************************************************/ 1747 1750 1748 UIVMActivityMonitorCloud::UIVMActivityMonitorCloud(EmbedTo enmEmbedding, QWidget *pParent, const CCloudMachine &machine) 1751 1749 :UIVMActivityMonitor(enmEmbedding, pParent, 60 /* iMaximumQueueSize */) … … 1763 1761 prepareActions(); 1764 1762 setMachine(machine); 1763 resetCPUInfoLabel(); 1765 1764 } 1766 1765 … … 1827 1826 foreach (UIChart *pChart, m_charts) 1828 1827 pChart->setXAxisLabel(QApplication::translate("UIVMInformationDialog", "Min.")); 1828 setInfoLabelWidth(); 1829 1829 } 1830 1830 … … 1886 1886 m_charts[m_strCPUMetricName]->update(); 1887 1887 } 1888 1888 1889 void UIVMActivityMonitorCloud::updateRAMGraphsAndMetric(quint64 /*iTotalRAM*/, quint64 /*iFreeRAM*/){} 1889 1890 void UIVMActivityMonitorCloud::updateNetworkGraphsAndMetric(quint64 /*iReceiveTotal*/, quint64 /*iTransmitTotal*/){} … … 1945 1946 m_charts[m_strCPUMetricName]->setShowPieChart(false); 1946 1947 } 1948 1949 void UIVMActivityMonitorCloud::resetCPUInfoLabel() 1950 { 1951 if (m_infoLabels.contains(m_strCPUMetricName) && m_infoLabels[m_strCPUMetricName]) 1952 { 1953 QString strInfo; 1954 1955 strInfo = QString("<b>%1</b></b><br/><font color=\"%2\">%3: %4</font>") 1956 .arg(m_strCPUInfoLabelTitle) 1957 .arg(dataColorString(m_strCPUMetricName, 0)) 1958 .arg(m_strCPUInfoLabelGuest).arg("---"); 1959 1960 m_infoLabels[m_strCPUMetricName]->setText(strInfo); 1961 } 1962 } 1963 1947 1964 #include "UIVMActivityMonitor.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.h
r102266 r102273 166 166 /** @name The following functions reset corresponding info labels 167 167 * @{ */ 168 v oid resetCPUInfoLabel();168 virtual void resetCPUInfoLabel() = 0; 169 169 void resetRAMInfoLabel(); 170 170 void resetNetworkInfoLabel(); … … 174 174 virtual void prepareWidgets(); 175 175 void prepareActions(); 176 176 void setInfoLabelWidth(); 177 177 QTimer *m_pTimer; 178 178 quint64 m_iTimeStep; … … 289 289 void updateVMExitMetric(quint64 uTotalVMExits); 290 290 void resetVMExitInfoLabel(); 291 291 virtual void resetCPUInfoLabel(); 292 292 bool m_fGuestAdditionsAvailable; 293 293 CMachine m_comMachine; … … 335 335 virtual void updateDiskIOGraphsAndMetric(quint64 uDiskIOTotalWritten, quint64 uDiskIOTotalRead) RT_OVERRIDE; 336 336 /** @} */ 337 virtual void resetCPUInfoLabel(); 337 338 bool findMetric(KMetricType enmMetricType, UIMetric &metric, int &iDataSeriesIndex) const; 338 339 void prepareMetrics();
Note:
See TracChangeset
for help on using the changeset viewer.