Qt io_graph: Use Interval value when generating Y-axis label or legend

The I/O Graph allows the user to choose from several different Y-axis units.
Three of the selectable Y-axis units unconditionally imply a per-second
time unit (/s) regardless of the actual I/O Graph Interval value selected.
In addition the Y-axis label includes the “/s” as a suffix regardless of the
current Interval value.

This patch removes "/s" suffix from the Y-axis pick-list units.  This patch
also dynamically adds the selected Interval value to the Y-Axis label or
alternatively as the first line of the legend box that is displayed if the
various enabled graphs have differing Y-axis values.  For readability the
pick-list values for sub-second Interval values are changed to 1 ms, 10 ms
and 100 ms from the original pick-list values of 0.001 sec, 0.01 sec and
0.1 sec respectively.

To support adding a “Title” to the legend, the QCustomPlot widget is
augmented with “Legend Title” source authored by “David” as posted at:

  http://www.qcustomplot.com/index.php/support/forum/443

Note: This patch changes the valid Y-axis unit values stored within the
io_graphs preferences files.  Any io_graphs files having entries with the
now obsolete Y-Axis values of “Packets/s”, “Bytes/s” or “Bits/s“ will be
silently upgraded to “Packets”, "Bytes" and "Bits" respectively when
saved.

Bug: 11855
Change-Id: I503ff6dc20b09d90f087342084fb0db6e0080c7f
Reviewed-on: https://code.wireshark.org/review/12219
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Jim Young 2015-11-24 10:50:08 -05:00 committed by Michael Mann
parent 9eda2fa063
commit 0fa13371d1
3 changed files with 87 additions and 9 deletions

View File

@ -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<QString> 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<QCPStringLegendItem*>(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<io_graph_item_unit_t, QString> IOGraph::valueUnitsToNames()
{
QMap<io_graph_item_unit_t, QString> 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)");

View File

@ -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;
}

View File

@ -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