diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp index cbd2f14453..236d54ef94 100644 --- a/ui/qt/io_graph_dialog.cpp +++ b/ui/qt/io_graph_dialog.cpp @@ -205,9 +205,9 @@ IOGraphDialog::IOGraphDialog(QWidget &parent, CaptureFile &cf) : stat_timer_->start(stat_update_interval_); // Intervals (ms) - ui->intervalComboBox->addItem(tr("0.001 sec"), 1); - ui->intervalComboBox->addItem(tr("0.01 sec"), 10); - ui->intervalComboBox->addItem(tr("0.1 sec"), 100); + ui->intervalComboBox->addItem(tr("1 ms"), 1); + ui->intervalComboBox->addItem(tr("10 ms"), 10); + ui->intervalComboBox->addItem(tr("100 ms"), 100); ui->intervalComboBox->addItem(tr("1 sec"), 1000); ui->intervalComboBox->addItem(tr("10 sec"), 10000); ui->intervalComboBox->addItem(tr("1 min"), 60000); @@ -261,7 +261,15 @@ IOGraphDialog::IOGraphDialog(QWidget &parent, CaptureFile &cf) : QRgb pcolor = QColor(iogs->color).rgb(); int color_idx; IOGraph::PlotStyles style = plot_style_to_name_.key(iogs->style, IOGraph::psLine); - io_graph_item_unit_t value_units = value_unit_to_name_.key(iogs->yaxis, IOG_ITEM_UNIT_PACKETS); + + io_graph_item_unit_t value_units; + if (g_strcmp0(iogs->yaxis, "Bytes/s") == 0) { // Silently upgrade obsolete yaxis unit name + value_units = value_unit_to_name_.key(iogs->yaxis, IOG_ITEM_UNIT_BYTES); + } else if (g_strcmp0(iogs->yaxis, "Bits/s") == 0) { // Silently upgrade obsolete yaxis unit name + value_units = value_unit_to_name_.key(iogs->yaxis, IOG_ITEM_UNIT_BITS); + } else { + value_units = value_unit_to_name_.key(iogs->yaxis, IOG_ITEM_UNIT_PACKETS); + } for (color_idx = 0; color_idx < colors_.size(); color_idx++) { if (pcolor == colors_[color_idx]) break; @@ -733,6 +741,7 @@ void IOGraphDialog::updateLegend() { QCustomPlot *iop = ui->ioPlot; QSet vu_label_set; + QString intervalText = ui->intervalComboBox->itemText(ui->intervalComboBox->currentIndex()); iop->legend->setVisible(false); iop->yAxis->setLabel(QString()); @@ -754,11 +763,20 @@ void IOGraphDialog::updateLegend() // All the same. Use the Y Axis label. if (vu_label_set.size() == 1) { - iop->yAxis->setLabel(vu_label_set.values()[0]); + iop->yAxis->setLabel(vu_label_set.values()[0] + "/" + intervalText); return; } - // Differing labels. Create a legend. + // Differing labels. Create a legend with a Title label at top. + // Legend Title thanks to: http://www.qcustomplot.com/index.php/support/forum/443 + QCPStringLegendItem* legendTitle = qobject_cast(iop->legend->elementAt(0)); + if (legendTitle == NULL) { + legendTitle = new QCPStringLegendItem(iop->legend, QString("")); + iop->legend->insertRow(0); + iop->legend->addElement(0, 0, legendTitle); + } + legendTitle->setText(QString(intervalText + " Intervals ")); + for (int i = 0; i < ui->graphTreeWidget->topLevelItemCount(); i++) { QTreeWidgetItem *ti = ui->graphTreeWidget->topLevelItem(i); IOGraph *iog = NULL; @@ -1166,6 +1184,8 @@ void IOGraphDialog::on_intervalComboBox_currentIndexChanged(int) if (need_retap) { scheduleRetap(true); } + + updateLegend(); } void IOGraphDialog::on_todCheckBox_toggled(bool checked) @@ -1920,9 +1940,9 @@ QMap IOGraph::valueUnitsToNames() { QMap vuton; - vuton[IOG_ITEM_UNIT_PACKETS] = QObject::tr("Packets/s"); - vuton[IOG_ITEM_UNIT_BYTES] = QObject::tr("Bytes/s"); - vuton[IOG_ITEM_UNIT_BITS] = QObject::tr("Bits/s"); + vuton[IOG_ITEM_UNIT_PACKETS] = QObject::tr("Packets"); + vuton[IOG_ITEM_UNIT_BYTES] = QObject::tr("Bytes"); + vuton[IOG_ITEM_UNIT_BITS] = QObject::tr("Bits"); vuton[IOG_ITEM_UNIT_CALC_SUM] = QObject::tr("SUM(Y Field)"); vuton[IOG_ITEM_UNIT_CALC_FRAMES] = QObject::tr("COUNT FRAMES(Y Field)"); vuton[IOG_ITEM_UNIT_CALC_FIELDS] = QObject::tr("COUNT FIELDS(Y Field)"); diff --git a/ui/qt/qcustomplot.cpp b/ui/qt/qcustomplot.cpp index a6f734b1ba..e850b02633 100644 --- a/ui/qt/qcustomplot.cpp +++ b/ui/qt/qcustomplot.cpp @@ -23490,3 +23490,40 @@ QPen QCPItemBracket::mainPen() const return mSelected ? mSelectedPen : mPen; } +// Legend Title - Added to Wireshark +// From: http://www.qcustomplot.com/index.php/support/forum/443 + +QCPStringLegendItem::QCPStringLegendItem(QCPLegend *pParent, const QString& strText) + : QCPAbstractLegendItem(pParent) + , m_strText(strText) +{ +} + +QString QCPStringLegendItem::text() const +{ + return m_strText; +} + +void QCPStringLegendItem::setText(const QString& strText) +{ + m_strText = strText; +} + +void QCPStringLegendItem::draw(QCPPainter *pPainter) +{ + pPainter->setFont(mFont); + pPainter->setPen(QPen(mTextColor)); + QRectF textRect = pPainter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, m_strText); + pPainter->drawText(mRect.x() + (mMargins.left() * 0.5), mRect.y(), textRect.width(), textRect.height(), Qt::TextDontClip | Qt::AlignHCenter, m_strText); +} + +QSize QCPStringLegendItem::minimumSizeHint() const +{ + QSize cSize(0, 0); + QFontMetrics fontMetrics(mFont); + QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip, m_strText); + cSize.setWidth(textRect.width() + mMargins.left() + mMargins.right()); + cSize.setHeight(textRect.height() + mMargins.top() + mMargins.bottom()); + return cSize; +} + diff --git a/ui/qt/qcustomplot.h b/ui/qt/qcustomplot.h index af32bc3bf3..47b3cc2e93 100644 --- a/ui/qt/qcustomplot.h +++ b/ui/qt/qcustomplot.h @@ -3765,5 +3765,26 @@ protected: QPen mainPen() const; }; +// Legend Title - Added to Wireshark +// From: http://www.qcustomplot.com/index.php/support/forum/443 + +class QCPStringLegendItem : public QCPAbstractLegendItem +{ + Q_OBJECT + +public: + explicit QCPStringLegendItem(QCPLegend *pParent, const QString& strText); + + QString text() const; + void setText(const QString& strText); + +protected: + virtual void draw(QCPPainter *painter); + virtual QSize minimumSizeHint() const; + +private: + QString m_strText; +}; + #endif // QCUSTOMPLOT_H