VirtualBox

Changeset 80979 in vbox for trunk/src


Ignore:
Timestamp:
Sep 24, 2019 3:00:42 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9510. Drawing (optionally) an area chart for the CPU load.

File:
1 edited

Legend:

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

    r80913 r80979  
    164164    void setIsPieChartAllowed(bool fWithPieChart);
    165165
    166     bool drawPieChart() const;
    167     void setDrawPieChart(bool fDrawPieChart);
     166    bool usePieChart() const;
     167    void setShowPieChart(bool fShowPieChart);
    168168
    169169    bool useGradientLineColor() const;
    170170    void setUseGradientLineColor(bool fUseGradintLineColor);
     171
     172    bool useAreaChart() const;
     173    void setUseAreaChart(bool fUseAreaChart);
     174
     175    bool isAreaChartAllowed() const;
     176    void setIsAreaChartAllowed(bool fIsAreaChartAllowed);
    171177
    172178    QColor dataSeriesColor(int iDataSeriesIndex);
     
    187193    void sltCreateContextMenu(const QPoint &point);
    188194    void sltResetMetric();
    189     void sltSetDrawPieChart(bool fDrawPieChart);
     195    void sltSetShowPieChart(bool fShowPieChart);
     196    void sltSetUseAreaChart(bool fUseAreaChart);
    190197
    191198private:
     
    224231      * option to show it to user. see m_fIsPieChartAllowed. */
    225232    bool m_fIsPieChartAllowed;
    226     /**  m_fDrawPieChart is considered only if m_fIsPieChartAllowed is true. */
    227     bool m_fDrawPieChart;
     233    /**  m_fShowPieChart is considered only if m_fIsPieChartAllowed is true. */
     234    bool m_fShowPieChart;
    228235    bool m_fUseGradientLineColor;
     236    /** When it is true we draw an area graph where data series drawn on top of each other.
     237     *  We draw first data0 then data 1 on top. Makes sense where the summation of data is guaranteed not to exceed some max. */
     238    bool m_fUseAreaChart;
     239    /** For some charts it does not make sense to have an area chart. */
     240    bool m_fIsAreaChartAllowed;
    229241    QColor m_dataSeriesColor[DATA_SERIES_SIZE];
    230242    QString m_strXAxisLabel;
     
    232244    QString m_strResetActionLabel;
    233245    QString m_strPieChartToggleActionLabel;
     246    QString m_strAreaChartToggleActionLabel;
    234247};
    235248
     
    543556    , m_iOverlayAlpha(80)
    544557    , m_fIsPieChartAllowed(false)
    545     , m_fDrawPieChart(true)
     558    , m_fShowPieChart(true)
    546559    , m_fUseGradientLineColor(false)
     560    , m_fUseAreaChart(true)
     561    , m_fIsAreaChartAllowed(false)
    547562{
    548563    setContextMenuPolicy(Qt::CustomContextMenu);
     
    589604}
    590605
    591 bool UIChart::drawPieChart() const
    592 {
    593     return m_fDrawPieChart;
    594 }
    595 
    596 void UIChart::setDrawPieChart(bool fDrawChart)
    597 {
    598     if (m_fDrawPieChart == fDrawChart)
    599         return;
    600     m_fDrawPieChart = fDrawChart;
     606bool UIChart::usePieChart() const
     607{
     608    return m_fShowPieChart;
     609}
     610
     611void UIChart::setShowPieChart(bool fDrawChart)
     612{
     613    if (m_fShowPieChart == fDrawChart)
     614        return;
     615    m_fShowPieChart = fDrawChart;
    601616    update();
    602617}
     
    615630}
    616631
     632bool UIChart::useAreaChart() const
     633{
     634    return m_fUseAreaChart;
     635}
     636
     637void UIChart::setUseAreaChart(bool fUseAreaChart)
     638{
     639    if (m_fUseAreaChart == fUseAreaChart)
     640        return;
     641    m_fUseAreaChart = fUseAreaChart;
     642    update();
     643}
     644
     645bool UIChart::isAreaChartAllowed() const
     646{
     647    return m_fIsAreaChartAllowed;
     648}
     649
     650void UIChart::setIsAreaChartAllowed(bool fIsAreaChartAllowed)
     651{
     652    m_fIsAreaChartAllowed = fIsAreaChartAllowed;
     653}
    617654
    618655QColor UIChart::dataSeriesColor(int iDataSeriesIndex)
     
    658695    m_strResetActionLabel = QApplication::translate("UIVMInformationDialog", "Reset");
    659696    m_strPieChartToggleActionLabel = QApplication::translate("UIVMInformationDialog", "Show Pie Chart");
     697    m_strAreaChartToggleActionLabel = QApplication::translate("UIVMInformationDialog", "Draw Area Chart");
    660698    update();
    661699}
     
    729767        if (!m_fUseGradientLineColor)
    730768            painter.setPen(QPen(m_dataSeriesColor[k], 2.5));
    731         for (int i = 0; i < data->size() - 1; ++i)
     769        if (m_fUseAreaChart && m_fIsAreaChartAllowed)
    732770        {
    733             int j = i + 1;
    734             float fHeight = fH * data->at(i);
    735             float fX = (width() - m_iMarginRight) - ((data->size() -i - 1) * fBarWidth);
    736             float fHeight2 = fH * data->at(j);
    737             float fX2 = (width() - m_iMarginRight) - ((data->size() -j - 1) * fBarWidth);
    738             QLineF bar(fX, height() - (fHeight + m_iMarginBottom), fX2, height() - (fHeight2 + m_iMarginBottom));
    739             painter.drawLine(bar);
     771            QVector<QPointF> points;
     772            for (int i = 0; i < data->size(); ++i)
     773            {
     774                float fHeight = fH * data->at(i);
     775                if (k == 0)
     776                {
     777                    if (m_pMetric->data(1) && m_pMetric->data(1)->size() > i)
     778                        fHeight += fH * m_pMetric->data(1)->at(i);
     779                }
     780                float fX = (width() - m_iMarginRight) - ((data->size() - i - 1) * fBarWidth);
     781                if (i == 0)
     782                    points << QPointF(fX, height() - m_iMarginBottom);
     783                points << QPointF(fX, height() - (fHeight + m_iMarginBottom));
     784                if (i == data->size() - 1)
     785                    points << QPointF(fX, height() - + m_iMarginBottom);
     786            }
     787            painter.setPen(Qt::NoPen);
     788            painter.setBrush(m_dataSeriesColor[k]);
     789            painter.drawPolygon(points, Qt::WindingFill);
     790        }
     791        else
     792        {
     793            for (int i = 0; i < data->size() - 1; ++i)
     794            {
     795                int j = i + 1;
     796                float fHeight = fH * data->at(i);
     797                float fX = (width() - m_iMarginRight) - ((data->size() -i - 1) * fBarWidth);
     798                float fHeight2 = fH * data->at(j);
     799                float fX2 = (width() - m_iMarginRight) - ((data->size() -j - 1) * fBarWidth);
     800                QLineF bar(fX, height() - (fHeight + m_iMarginBottom), fX2, height() - (fHeight2 + m_iMarginBottom));
     801                painter.drawLine(bar);
     802            }
    740803        }
    741804    }
     
    764827    }
    765828
    766     if (m_fIsPieChartAllowed && m_fDrawPieChart)
     829    if (m_fIsPieChartAllowed && m_fShowPieChart)
    767830        drawCombinedPieCharts(painter, iMaximum);
    768831}
     
    9691032        QAction *pPieChartToggle = menu.addAction(m_strPieChartToggleActionLabel);
    9701033        pPieChartToggle->setCheckable(true);
    971         pPieChartToggle->setChecked(m_fDrawPieChart);
    972         connect(pPieChartToggle, &QAction::toggled, this, &UIChart::sltSetDrawPieChart);
    973     }
     1034        pPieChartToggle->setChecked(m_fShowPieChart);
     1035        connect(pPieChartToggle, &QAction::toggled, this, &UIChart::sltSetShowPieChart);
     1036    }
     1037    if (m_fIsAreaChartAllowed)
     1038    {
     1039        QAction *pAreaChartToggle = menu.addAction(m_strAreaChartToggleActionLabel);
     1040        pAreaChartToggle->setCheckable(true);
     1041        pAreaChartToggle->setChecked(m_fUseAreaChart);
     1042        connect(pAreaChartToggle, &QAction::toggled, this, &UIChart::sltSetUseAreaChart);
     1043    }
     1044
    9741045    menu.exec(mapToGlobal(point));
    9751046}
     
    9811052}
    9821053
    983 void UIChart::sltSetDrawPieChart(bool fDrawPieChart)
    984 {
    985     setDrawPieChart(fDrawPieChart);
     1054void UIChart::sltSetShowPieChart(bool fShowPieChart)
     1055{
     1056    setShowPieChart(fShowPieChart);
     1057}
     1058
     1059void UIChart::sltSetUseAreaChart(bool fUseAreaChart)
     1060{
     1061    setUseAreaChart(fUseAreaChart);
    9861062}
    9871063
     
    12971373    /* Configure charts: */
    12981374    if (m_charts.contains(m_strCPUMetricName) && m_charts[m_strCPUMetricName])
     1375    {
    12991376        m_charts[m_strCPUMetricName]->setIsPieChartAllowed(true);
     1377        m_charts[m_strCPUMetricName]->setIsAreaChartAllowed(true);
     1378    }
    13001379
    13011380    m_pRuntimeInfoWidget = new UIRuntimeInfoWidget(0, m_machine, m_console);
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