aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/io_graph_dialog.cpp
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-01-17 13:50:56 -0800
committerAnders Broman <a.broman58@gmail.com>2018-01-18 05:16:18 +0000
commit0aad2bbc360d8a3ad7b610067c9f04ab0f681b91 (patch)
treeba49ae04fb950640d4a5e60147df09794d9a14dc /ui/qt/io_graph_dialog.cpp
parentd86f8202067e3671d2039a315e1abbd8cd6f1db9 (diff)
Qt: I/O graph fixes.
Use Qt::DecorationRole when setting and getting a color and Qt::CheckStateRole when setting and getting the check state of UatModel items. Add a default role for UatModel::data. Convert between value strings and their respective values where needed. Bug: 14317 Change-Id: Idd3eb773dc9944f982f6dbd7d49f73f4a60dd5a2 Reviewed-on: https://code.wireshark.org/review/25355 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Jim Young <jim.young.ws@gmail.com>
Diffstat (limited to 'ui/qt/io_graph_dialog.cpp')
-rw-r--r--ui/qt/io_graph_dialog.cpp69
1 files changed, 38 insertions, 31 deletions
diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp
index 2829220d1c..22b7924653 100644
--- a/ui/qt/io_graph_dialog.cpp
+++ b/ui/qt/io_graph_dialog.cpp
@@ -61,13 +61,14 @@
// http://www.qcustomplot.com/index.php/support/forum/62
// - We retap and redraw more than we should.
// - Smoothing doesn't seem to match GTK+
+// - Closing the color picker on macOS sends the dialog to the background.
+// - The color picker triggers https://bugreports.qt.io/browse/QTBUG-58699.
// To do:
// - Use scroll bars?
// - Scroll during live captures
// - Set ticks per pixel (e.g. pressing "2" sets 2 tpp).
-
const qreal graph_line_width_ = 1.0;
const int DEFAULT_MOVING_AVERAGE = 0;
@@ -432,11 +433,11 @@ void IOGraphDialog::addGraph(bool checked, QString name, QString dfilter, int co
uat_model_->setData(uat_model_->index(currentRow, colEnabled), checked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
uat_model_->setData(uat_model_->index(currentRow, colName), name);
uat_model_->setData(uat_model_->index(currentRow, colDFilter), dfilter);
- uat_model_->setData(uat_model_->index(currentRow, colColor), QColor(color_idx));
+ uat_model_->setData(uat_model_->index(currentRow, colColor), QColor(color_idx), Qt::DecorationRole);
uat_model_->setData(uat_model_->index(currentRow, colStyle), val_to_str_const(style, graph_style_vs, "None"));
- uat_model_->setData(uat_model_->index(currentRow, colYAxis), value_units);
+ uat_model_->setData(uat_model_->index(currentRow, colYAxis), val_to_str_const(value_units, y_axis_vs, "Packets"));
uat_model_->setData(uat_model_->index(currentRow, colYField), yfield);
- uat_model_->setData(uat_model_->index(currentRow, colSMAPeriod), moving_average);
+ uat_model_->setData(uat_model_->index(currentRow, colSMAPeriod), val_to_str_const(moving_average, moving_avg_vs, "None"));
// due to an EditTrigger, this will also start editing.
ui->graphUat->setCurrentIndex(new_index);
@@ -516,25 +517,29 @@ void IOGraphDialog::addDefaultGraph(bool enabled, int idx)
void IOGraphDialog::syncGraphSettings(int row)
{
- if (!uat_model_->index(row, colEnabled).isValid() || (ioGraphs_.size() <= row))
- return;
+ IOGraph *iog = ioGraphs_.value(row, Q_NULLPTR);
- IOGraph *iog = ioGraphs_[row];
+ if (!uat_model_->index(row, colEnabled).isValid() || !iog)
+ return;
- bool visible = uat_model_->data(uat_model_->index(row, colEnabled), Qt::DisplayRole).toBool();
+ bool visible = graphIsEnabled(row);
bool retap = !iog->visible() && visible;
+ QString data_str;
- iog->setName(uat_model_->data(uat_model_->index(row, colName), Qt::DisplayRole).toString());
- iog->setFilter(uat_model_->data(uat_model_->index(row, colDFilter), Qt::DisplayRole).toString());
+ iog->setName(uat_model_->data(uat_model_->index(row, colName)).toString());
+ iog->setFilter(uat_model_->data(uat_model_->index(row, colDFilter)).toString());
/* plot style depend on the value unit, so set it first. */
- iog->setValueUnits(uat_model_->data(uat_model_->index(row, colYAxis), Qt::DisplayRole).toUInt());
- iog->setValueUnitField(uat_model_->data(uat_model_->index(row, colYField), Qt::DisplayRole).toString());
+ data_str = uat_model_->data(uat_model_->index(row, colYAxis)).toString();
+ iog->setValueUnits((int) str_to_val(qUtf8Printable(data_str), y_axis_vs, IOG_ITEM_UNIT_PACKETS));
+ iog->setValueUnitField(uat_model_->data(uat_model_->index(row, colYField)).toString());
- iog->setColor(QRgb(uat_model_->data(uat_model_->index(row, colColor), Qt::DisplayRole).toUInt()));
- iog->setPlotStyle(uat_model_->data(uat_model_->index(row, colStyle), Qt::DisplayRole).toUInt());
+ iog->setColor(uat_model_->data(uat_model_->index(row, colColor), Qt::DecorationRole).value<QColor>().rgb());
+ data_str = uat_model_->data(uat_model_->index(row, colStyle)).toString();
+ iog->setPlotStyle((int) str_to_val(qUtf8Printable(data_str), graph_style_vs, 0));
- iog->moving_avg_period_ = uat_model_->data(uat_model_->index(row, colSMAPeriod), Qt::DisplayRole).toUInt();
+ data_str = uat_model_->data(uat_model_->index(row, colSMAPeriod)).toString();
+ iog->moving_avg_period_ = str_to_val(qUtf8Printable(data_str), moving_avg_vs, 0);
iog->setInterval(ui->intervalComboBox->itemData(ui->intervalComboBox->currentIndex()).toInt());
@@ -790,13 +795,20 @@ IOGraph *IOGraphDialog::currentActiveGraph() const
//if no currently selected item, go with first item enabled
for (int row = 0; row < uat_model_->rowCount(); row++)
{
- if (uat_model_->data(uat_model_->index(row, colEnabled), Qt::DisplayRole).toBool())
+ if (graphIsEnabled(row)) {
return ioGraphs_[row];
+ }
}
return NULL;
}
+bool IOGraphDialog::graphIsEnabled(int row) const
+{
+ Qt::CheckState state = uat_model_->data(uat_model_->index(row, colEnabled), Qt::CheckStateRole).value<Qt::CheckState>();
+ return state == Qt::Checked;
+}
+
// Scan through our graphs and gather information.
// QCPItemTracers can only be associated with QCPGraphs. Find the first one
// and associate it with our tracer. Set bar stacking order while we're here.
@@ -811,15 +823,15 @@ void IOGraphDialog::getGraphInfo()
if (uat_model_ != NULL) {
//all graphs may not be created yet, so bounds check the graph array
- for (int row = 0; ((row < uat_model_->rowCount()) && (row < ioGraphs_.size())); row++) {
- if (uat_model_->data(uat_model_->index(row, colEnabled), Qt::DisplayRole).toBool()) {
- IOGraph* iog = ioGraphs_[row];
+ for (int row = 0; row < uat_model_->rowCount(); row++) {
+ IOGraph* iog = ioGraphs_.value(row, Q_NULLPTR);
+ if (iog && graphIsEnabled(row)) {
QCPGraph *graph = iog->graph();
QCPBars *bars = iog->bars();
if (graph && (!base_graph_ || iog == selectedGraph)) {
base_graph_ = graph;
} else if (bars &&
- (uat_model_->data(uat_model_->index(row, colStyle), Qt::DisplayRole).toString().compare(val_to_str_const(IOGraph::psStackedBar, graph_style_vs, "None")) == 0) &&
+ (uat_model_->data(uat_model_->index(row, colStyle), Qt::DisplayRole).toString().compare(graph_style_vs[IOGraph::psStackedBar].strptr) == 0) &&
iog->visible()) {
bars->moveBelow(NULL); // Remove from existing stack
bars->moveBelow(prev_bars);
@@ -853,9 +865,8 @@ void IOGraphDialog::updateLegend()
// Find unique labels
if (uat_model_ != NULL) {
for (int row = 0; row < uat_model_->rowCount(); row++) {
- if (uat_model_->data(uat_model_->index(row, colEnabled), Qt::DisplayRole).toBool() &&
- ioGraphs_[row]) {
- IOGraph *iog = ioGraphs_[row];
+ IOGraph *iog = ioGraphs_.value(row, Q_NULLPTR);
+ if (graphIsEnabled(row) && iog) {
QString label(iog->valueUnitLabel());
if (!iog->scaledValueUnit().isEmpty()) {
label += " (" + iog->scaledValueUnit() + ")";
@@ -888,9 +899,9 @@ void IOGraphDialog::updateLegend()
if (uat_model_ != NULL) {
for (int row = 0; row < uat_model_->rowCount(); row++) {
- IOGraph *iog = ioGraphs_[row];
+ IOGraph *iog = ioGraphs_.value(row, Q_NULLPTR);
if (iog) {
- if (uat_model_->data(uat_model_->index(row, colEnabled), Qt::DisplayRole).toBool()) {
+ if (graphIsEnabled(row)) {
iog->addToLegend();
} else {
iog->removeFromLegend();
@@ -1088,7 +1099,7 @@ void IOGraphDialog::updateStatistics()
if (uat_model_ != NULL) {
for (int row = 0; row < uat_model_->rowCount(); row++) {
- if (uat_model_->data(uat_model_->index(row, colEnabled), Qt::DisplayRole).toBool()) {
+ if (graphIsEnabled(row)) {
++enabled_graphs;
}
}
@@ -1149,9 +1160,6 @@ void IOGraphDialog::loadProfileGraphs()
connect(uat_model_, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(modelDataChanged(QModelIndex)));
- connect(uat_model_, SIGNAL(rowsRemoved(QModelIndex, int, int)),
- this, SLOT(modelRowsRemoved()));
-
}
// Slots
@@ -1442,8 +1450,7 @@ void IOGraphDialog::makeCsv(QTextStream &stream) const
stream << "\"Interval start\"";
if (uat_model_ != NULL) {
for (int row = 0; row < uat_model_->rowCount(); row++) {
- if (uat_model_->data(uat_model_->index(row, colEnabled), Qt::DisplayRole).toBool() &&
- (ioGraphs_[row] != NULL)) {
+ if (graphIsEnabled(row) && ioGraphs_[row] != NULL) {
activeGraphs.append(ioGraphs_[row]);
if (max_interval < ioGraphs_[row]->maxInterval()) {
max_interval = ioGraphs_[row]->maxInterval();