VirtualBox

Changeset 80162 in vbox for trunk/src


Ignore:
Timestamp:
Aug 6, 2019 6:50:03 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref: 9510: Disabling/enabling graphs depending on the existence of GAs (only the corresponding metric requires GAs)

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIPerformanceMonitor.cpp

    r80158 r80162  
    145145{
    146146    Q_UNUSED(pEvent);
    147 
    148147    QPainter painter(this);
    149148
     
    163162        painter.drawLine(m_iMargin + i * fChartWidth / (float)iXParts, m_iMargin, m_iMargin + i * fChartWidth / (float)iXParts, height() - m_iMargin);
    164163
    165     painter.setRenderHint(QPainter::Antialiasing);// | QPainter::TextAntialiasing);
     164    painter.setRenderHint(QPainter::Antialiasing);
    166165    if (!m_pSubMetric)
    167166        return;
     
    170169    if (data.isEmpty() || iMaximumQueueSize == 0)
    171170        return;
    172     float fBarWidth = fChartWidth / (float) iMaximumQueueSize;
    173171
    174172    float fMaximum = m_pSubMetric->maximum();
    175173    if (m_pSubMetric->isPercentage())
    176174        fMaximum = 100.f;
    177 
    178     float fH = 0;
    179     if (fMaximum != 0)
    180         fH = fChartHeight / fMaximum;
    181 
    182     QLinearGradient gradient(0, 0, 0, fChartHeight);
    183     gradient.setColorAt(1.0, Qt::green);
    184     gradient.setColorAt(0.0, Qt::red);
    185     painter.setPen(QPen(gradient, 2.5));
    186 
    187     for (int i = 0; i < data.size() - 1; ++i)
    188     {
    189         int j = i + 1;
    190 
    191         float fHeight = fH * data[i];
    192         float fX = width() - ((data.size() -i) * fBarWidth);
    193 
    194         float fHeight2 = fH * data[j];
    195         float fX2 = width() - ((data.size() -j) * fBarWidth);
    196 
    197 
    198         QLineF bar(fX, height() - (fHeight + m_iMargin), fX2, height() - (fHeight2 + m_iMargin));
    199         painter.drawLine(bar);
    200     }
    201 
     175    if (fMaximum == 0)
     176        return;
     177
     178    if (isEnabled())
     179    {
     180        float fBarWidth = fChartWidth / (float) iMaximumQueueSize;
     181
     182        float fH = fChartHeight / fMaximum;
     183
     184        QLinearGradient gradient(0, 0, 0, fChartHeight);
     185        gradient.setColorAt(1.0, Qt::green);
     186        gradient.setColorAt(0.0, Qt::red);
     187        painter.setPen(QPen(gradient, 2.5));
     188
     189        for (int i = 0; i < data.size() - 1; ++i)
     190        {
     191            int j = i + 1;
     192
     193            float fHeight = fH * data[i];
     194            float fX = width() - ((data.size() -i) * fBarWidth);
     195
     196            float fHeight2 = fH * data[j];
     197            float fX2 = width() - ((data.size() -j) * fBarWidth);
     198
     199
     200            QLineF bar(fX, height() - (fHeight + m_iMargin), fX2, height() - (fHeight2 + m_iMargin));
     201            painter.drawLine(bar);
     202        }
     203    }
    202204
    203205    /* Draw a whole non-filled circle: */
     
    207209    QPointF center(m_pieChartRect.center());
    208210    QPainterPath fillPath;
    209     QPainterPath dataPath;
    210     dataPath.moveTo(center);
    211211    fillPath.moveTo(center);
    212     float fAngle = 360.f * data.back() / fMaximum;
    213     dataPath.arcTo(m_pieChartRect, 90/*startAngle*/,
    214                  -1 * fAngle /*sweepLength*/);
     212
    215213    fillPath.arcTo(m_pieChartRect, 90/*startAngle*/,
    216214                 -1 * 360 /*sweepLength*/);
     
    226224    painter.setBrush(Qt::white);
    227225    painter.drawPath(fillPath);
    228     painter.setBrush(pieGradient);
    229     painter.drawPath(dataPath);
     226
     227    if (isEnabled())
     228    {
     229        QPainterPath dataPath;
     230        dataPath.moveTo(center);
     231        float fAngle = 360.f * data.back() / fMaximum;
     232        dataPath.arcTo(m_pieChartRect, 90/*startAngle*/,
     233                       -1 * fAngle /*sweepLength*/);
     234        painter.setBrush(pieGradient);
     235        painter.drawPath(dataPath);
     236    }
     237    else
     238    {
     239        painter.setPen(Qt::NoPen);
     240        painter.setBrush(QColor(60, 60, 60, 50));
     241        painter.drawRect(QRect(0, 0, width(), height()));
     242    }
    230243}
    231244
     
    238251    , m_strUnit(strUnit)
    239252    , m_iMaximumQueueSize(iMaximumQueueSize)
     253    , m_fRequiresGuestAdditions(false)
    240254{
    241255    if (isPercentage())
     
    310324}
    311325
     326bool UISubMetric::requiresGuestAdditions() const
     327{
     328    return m_fRequiresGuestAdditions;
     329}
     330
     331void UISubMetric::setRequiresGuestAdditions(bool fRequiresGAs)
     332{
     333    m_fRequiresGuestAdditions = fRequiresGAs;
     334}
    312335
    313336/*********************************************************************************************************************************
     
    315338*********************************************************************************************************************************/
    316339
    317 UIPerformanceMonitor::UIPerformanceMonitor(QWidget *pParent, const CMachine &machine, const CConsole &console)
     340UIPerformanceMonitor::UIPerformanceMonitor(QWidget *pParent, const CMachine &machine, const CConsole &console, const UISession *pSession)
    318341    : QWidget(pParent)
    319342    , m_fGuestAdditionsAvailable(false)
     
    325348    , m_strRAMMetricName("RAM Usage")
    326349{
    327     // bool fGuestAdditionsStatus = comGuest.GetAdditionsStatus(comGuest.GetAdditionsRunLevel());
    328     // if (fGuestAdditionsStatus)
    329     // {
    330     //     QStringList versionStrings = comGuest.GetAdditionsVersion().split('.', QString::SkipEmptyParts);
    331     //     if (!versionStrings.isEmpty())
    332     //     {
    333     //         bool fConvert = false;
    334     //         int iMajorVersion = versionStrings[0].toInt(&fConvert);
    335     //         if (fConvert && iMajorVersion >= 6)
    336     //             m_fGuestAdditionsAvailable = true;
    337     //     }
    338     // }
    339     // printf("m_fGuestAdditionsAvailable %d\n", m_fGuestAdditionsAvailable);
    340 
     350    if (!m_console.isNull())
     351        m_comGuest = m_console.GetGuest();
     352    m_fGuestAdditionsAvailable = guestAdditionsAvailable(6 /* minimum major version */);
     353
     354    connect(pSession, &UISession::sigAdditionsStateChange, this, &UIPerformanceMonitor::sltGuestAdditionsStateChange);
    341355    preparePerformaceCollector();
    342356    prepareObjects();
     357    enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable);
    343358}
    344359
     
    463478        CPUMetric.addData(aPctExecuting);
    464479        QList<UIChart*> charts = m_charts.values(m_strCPUMetricName);
    465         QString strInfo = QString("%1\n%2%3").arg("CPU Load").arg(QString::number(aPctExecuting)).arg("%");
    466         if (m_infoLabels.contains(m_strCPUMetricName))
    467             m_infoLabels[m_strCPUMetricName]->setText(strInfo);
     480
     481        if (m_infoLabels.contains(m_strCPUMetricName) && m_infoLabels[m_strCPUMetricName])
     482        {
     483            if (m_infoLabels[m_strCPUMetricName]->isEnabled())
     484            {
     485                QString strInfo = QString("%1\n%2%3").arg("CPU Load").arg(QString::number(aPctExecuting)).arg("%");
     486                m_infoLabels[m_strCPUMetricName]->setText(strInfo);
     487            }
     488            else
     489            {
     490                QString strInfo = QString("%1\n%2%3").arg("CPU Load").arg("--").arg("%");
     491                m_infoLabels[m_strCPUMetricName]->setText(strInfo);
     492            }
     493        }
    468494        if (m_charts.contains(m_strCPUMetricName))
    469495            m_charts[m_strCPUMetricName]->update();
     
    475501        RAMMetric.setMaximum(iTotalRAM);
    476502        RAMMetric.addData(iTotalRAM - iFreeRAM);
    477         QString strInfo = QString("%1\n%2: %3\n%4: %5\n%6: %7").arg("RAM Usage").arg("Total").arg(uiCommon().formatSize(_1K * iTotalRAM)).arg("Free:").arg(uiCommon().formatSize(_1K * (iFreeRAM))).arg("Used:").arg(uiCommon().formatSize(_1K * (iTotalRAM - iFreeRAM)));
    478         if (m_infoLabels.contains(m_strRAMMetricName))
    479             m_infoLabels[m_strRAMMetricName]->setText(strInfo);
    480 
     503
     504        if (m_infoLabels.contains(m_strRAMMetricName)  && m_infoLabels[m_strRAMMetricName])
     505        {
     506            if (m_infoLabels[m_strRAMMetricName]->isEnabled())
     507            {
     508                QString strInfo = QString("%1\n%2: %3\n%4: %5\n%6: %7").arg("RAM Usage").arg("Total").arg(uiCommon().formatSize(_1K * iTotalRAM)).arg("Free:").arg(uiCommon().formatSize(_1K * (iFreeRAM))).arg("Used:").arg(uiCommon().formatSize(_1K * (iTotalRAM - iFreeRAM)));
     509                m_infoLabels[m_strRAMMetricName]->setText(strInfo);
     510            }
     511            else
     512            {
     513                QString strInfo = QString("%1\n%2: %3\n%4: %5\n%6: %7").arg("RAM Usage").arg("Total").arg("---").arg("Free").arg("---").arg("Used").arg("---");
     514                m_infoLabels[m_strRAMMetricName]->setText(strInfo);
     515            }
     516        }
    481517        if (m_charts.contains(m_strRAMMetricName))
    482518        {
     
    484520        }
    485521    }
    486 
    487     /* Try to compute a global font size so that all texts fit to widgets: */
    488     // int iMinimumFontSize = 24;
    489     // foreach (UIChart *pChart, m_charts)
    490     // {
    491     //     if (!qobject_cast<UIPieChart*>(pChart))
    492     //         continue;
    493     //             iMinimumFontSize = qMin(pChart->fontSize(), iMinimumFontSize);
    494     // }
    495 
    496     // foreach (UIChart *pChart, m_charts)
    497     // {
    498     //     if (!pChart)
    499     //         continue;
    500     //     pChart->setFontSize(iMinimumFontSize);
    501     //     pChart->update();
    502     // }
    503 
    504 
    505     // int iMaxLineNumber = 0;
    506     // int iMaxLineLength = 0;
    507     // foreach (UIChart *pChart, m_charts)
    508     // {
    509     //     if (!pChart)
    510     //         continue;
    511     //     const QStringList &list = pChart->textList();
    512     //     iMaxLineNumber = qMax(iMaxLineNumber, list.size());
    513     //     foreach (const QString &strLine, list)
    514     //         iMaxLineLength = qMax(iMaxLineLength, strLine.length());
    515     // }
    516 
    517     // foreach (UIChart *pChart, m_charts)
    518     // {
    519     //     /* Currently we only care about the pie charts since they are the smallest of charts: */
    520     //     if (qobject_cast<UIPieChart*>(pChart))
    521     //         continue;
    522 
    523     // }
     522}
     523
     524void UIPerformanceMonitor::sltGuestAdditionsStateChange()
     525{
     526    bool fGuestAdditionsAvailable = guestAdditionsAvailable(6 /* minimum major version */);
     527    if (m_fGuestAdditionsAvailable == fGuestAdditionsAvailable)
     528        return;
     529    m_fGuestAdditionsAvailable = fGuestAdditionsAvailable;
     530    enableDisableGuestAdditionDependedWidgets(m_fGuestAdditionsAvailable);
    524531}
    525532
     
    549556                {
    550557                    QString strRAMMetricName(m_strRAMMetricName);
    551                     m_subMetrics.insert(strRAMMetricName, UISubMetric(strRAMMetricName, metrics[i].GetUnit(), iMaximumQueueSize));
     558                    UISubMetric newMetric(strRAMMetricName, metrics[i].GetUnit(), iMaximumQueueSize);
     559                    newMetric.setRequiresGuestAdditions(true);
     560                    m_subMetrics.insert(strRAMMetricName, newMetric);
    552561                }
    553562            }
     
    557566}
    558567
     568bool UIPerformanceMonitor::guestAdditionsAvailable(int iMinimumMajorVersion)
     569{
     570    if (m_comGuest.isNull())
     571        return false;
     572    bool fGuestAdditionsStatus = m_comGuest.GetAdditionsStatus(m_comGuest.GetAdditionsRunLevel());
     573    if (fGuestAdditionsStatus)
     574    {
     575        QStringList versionStrings = m_comGuest.GetAdditionsVersion().split('.', QString::SkipEmptyParts);
     576        if (!versionStrings.isEmpty())
     577        {
     578            bool fConvert = false;
     579            int iMajorVersion = versionStrings[0].toInt(&fConvert);
     580            if (fConvert && iMajorVersion >= iMinimumMajorVersion)
     581                return true;
     582        }
     583    }
     584    return false;
     585}
     586
     587void UIPerformanceMonitor::enableDisableGuestAdditionDependedWidgets(bool fEnable)
     588{
     589    for (QMap<QString, UISubMetric>::const_iterator iterator =  m_subMetrics.begin();
     590         iterator != m_subMetrics.end(); ++iterator)
     591    {
     592        if (!iterator.value().requiresGuestAdditions())
     593            continue;
     594        if (m_charts.contains(iterator.key()) && m_charts[iterator.key()])
     595        {
     596            m_charts[iterator.key()]->setEnabled(fEnable);
     597            m_charts[iterator.key()]->update();
     598        }
     599        if (m_infoLabels.contains(iterator.key()) && m_infoLabels[iterator.key()])
     600        {
     601            m_infoLabels[iterator.key()]->setEnabled(fEnable);
     602            m_infoLabels[iterator.key()]->update();
     603        }
     604    }
     605}
    559606#include "UIPerformanceMonitor.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIPerformanceMonitor.h

    r80158 r80162  
    4444class QLabel;
    4545class UIChart;
     46class UISession;
    4647
    4748class UISubMetric
     
    7071    bool isPercentage() const;
    7172
     73    bool requiresGuestAdditions() const;
     74    void setRequiresGuestAdditions(bool fRequiresGAs);
     75
    7276private:
    7377
     
    7983    QQueue<ULONG> m_data;
    8084    int m_iMaximumQueueSize;
     85    bool m_fRequiresGuestAdditions;
    8186};
    8287
     
    9095      * @param machine is machine reference.
    9196      * @param console is machine console reference. */
    92     UIPerformanceMonitor(QWidget *pParent, const CMachine &machine, const CConsole &console);
     97    UIPerformanceMonitor(QWidget *pParent, const CMachine &machine, const CConsole &console, const UISession *pSession);
    9398    ~UIPerformanceMonitor();
    9499
     
    96101
    97102    void sltTimeout();
     103    void sltGuestAdditionsStateChange();
    98104
    99105private:
     
    102108    void prepareObjects();
    103109    void preparePerformaceCollector();
     110    bool guestAdditionsAvailable(int iMinimumMajorVersion);
     111    void enableDisableGuestAdditionDependedWidgets(bool fEnable);
    104112    bool m_fGuestAdditionsAvailable;
    105113    /** Holds the machine instance. */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIVMInformationDialog.cpp

    r80132 r80162  
    263263
    264264        UIPerformanceMonitor *pPerformanceMonitor =
    265             new UIPerformanceMonitor(this, m_pMachineWindow->machine(), m_pMachineWindow->console());
     265            new UIPerformanceMonitor(this, m_pMachineWindow->machine(), m_pMachineWindow->console(), m_pMachineWindow->uisession());
    266266        if (pPerformanceMonitor)
    267267        {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette