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>
This commit is contained in:
parent
d86f820206
commit
0aad2bbc36
|
@ -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))
|
||||
IOGraph *iog = ioGraphs_.value(row, Q_NULLPTR);
|
||||
|
||||
if (!uat_model_->index(row, colEnabled).isValid() || !iog)
|
||||
return;
|
||||
|
||||
IOGraph *iog = ioGraphs_[row];
|
||||
|
||||
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();
|
||||
|
|
|
@ -208,6 +208,7 @@ private:
|
|||
void makeCsv(QTextStream &stream) const;
|
||||
bool saveCsv(const QString &file_name) const;
|
||||
IOGraph *currentActiveGraph() const;
|
||||
bool graphIsEnabled(int row) const;
|
||||
|
||||
private slots:
|
||||
void updateWidgets();
|
||||
|
|
|
@ -95,7 +95,6 @@ QVariant UatModel::data(const QModelIndex &index, int role) const
|
|||
return qstr;
|
||||
}
|
||||
case PT_TXTMOD_BOOL:
|
||||
return "";
|
||||
case PT_TXTMOD_COLOR:
|
||||
return QVariant();
|
||||
default:
|
||||
|
@ -135,14 +134,12 @@ QVariant UatModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
if (role == Qt::DecorationRole) {
|
||||
if (field->mode == PT_TXTMOD_COLOR) {
|
||||
char *str = NULL;
|
||||
guint length = 0;
|
||||
field->cb.tostr(rec, &str, &length, field->cbdata.tostr, field->fld_data);
|
||||
if ((role == Qt::DecorationRole) && (field->mode == PT_TXTMOD_COLOR)) {
|
||||
char *str = NULL;
|
||||
guint length = 0;
|
||||
field->cb.tostr(rec, &str, &length, field->cbdata.tostr, field->fld_data);
|
||||
|
||||
return QColor(QString(str));
|
||||
}
|
||||
return QColor(QString(str));
|
||||
}
|
||||
|
||||
// expose error message if any.
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
UatModel(QObject *parent, QString tableName);
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
|
Loading…
Reference in New Issue