aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2019-12-10 17:03:34 -0800
committerAlexis La Goutte <alexis.lagoutte@gmail.com>2019-12-11 05:12:17 +0000
commit90e80ac6af00cd49823b82e7fcc67dff088eff4b (patch)
treed7ec8b7f2b59703f3417267cda2cab0ea5b383ae /ui
parent3e0acea60488ac51ff9f181266b7e4f5928248d3 (diff)
Qt: Add some null checks.
Add some null checks identified by scan-build. Switch some dynamic_casts to qobject_casts. Change-Id: I2b97ee8cb71db4fc883b4081568f9a5db8af85b3 Reviewed-on: https://code.wireshark.org/review/35403 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/interface_toolbar.cpp16
-rw-r--r--ui/qt/models/column_list_model.cpp21
2 files changed, 24 insertions, 13 deletions
diff --git a/ui/qt/interface_toolbar.cpp b/ui/qt/interface_toolbar.cpp
index 7ffbf11ba9..f4517655ec 100644
--- a/ui/qt/interface_toolbar.cpp
+++ b/ui/qt/interface_toolbar.cpp
@@ -296,7 +296,7 @@ QWidget *InterfaceToolbar::createString(iface_toolbar_control *control)
void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray payload)
{
- if (QComboBox *combobox = dynamic_cast<QComboBox *>(widget))
+ if (QComboBox *combobox = qobject_cast<QComboBox *>(widget))
{
combobox->blockSignals(true);
switch (command)
@@ -362,7 +362,7 @@ void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray p
}
combobox->blockSignals(false);
}
- else if (InterfaceToolbarLineEdit *lineedit = dynamic_cast<InterfaceToolbarLineEdit *>(widget))
+ else if (InterfaceToolbarLineEdit *lineedit = qobject_cast<InterfaceToolbarLineEdit *>(widget))
{
// We don't block signals here because changes are applied with enter or apply button,
// and we want InterfaceToolbarLineEdit to always syntax check the text.
@@ -377,7 +377,7 @@ void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray p
break;
}
}
- else if (QCheckBox *checkbox = dynamic_cast<QCheckBox *>(widget))
+ else if (QCheckBox *checkbox = qobject_cast<QCheckBox *>(widget))
{
checkbox->blockSignals(true);
switch (command)
@@ -398,7 +398,7 @@ void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray p
}
checkbox->blockSignals(false);
}
- else if (QPushButton *button = dynamic_cast<QPushButton *>(widget))
+ else if (QPushButton *button = qobject_cast<QPushButton *>(widget))
{
if ((command == commandControlSet) &&
widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL)
@@ -410,7 +410,11 @@ void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray p
void InterfaceToolbar::setInterfaceValue(QString ifname, QWidget *widget, int num, int command, QByteArray payload)
{
- if (dynamic_cast<QComboBox *>(widget))
+ if (!widget) {
+ return;
+ }
+
+ if (qobject_cast<QComboBox *>(widget))
{
switch (command)
{
@@ -454,7 +458,7 @@ void InterfaceToolbar::setInterfaceValue(QString ifname, QWidget *widget, int nu
break;
}
}
- else if (dynamic_cast<InterfaceToolbarLineEdit *>(widget))
+ else if (qobject_cast<InterfaceToolbarLineEdit *>(widget))
{
switch (command)
{
diff --git a/ui/qt/models/column_list_model.cpp b/ui/qt/models/column_list_model.cpp
index 48cf4e2757..c08e40b7af 100644
--- a/ui/qt/models/column_list_model.cpp
+++ b/ui/qt/models/column_list_model.cpp
@@ -143,14 +143,19 @@ void ColumnTypeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model
else if (index.column() == ColumnListModel::COL_FIELDS)
{
FieldFilterEdit * ffe = qobject_cast<FieldFilterEdit *>(editor);
- if (ffe && ffe->checkFilter())
+ if (ffe)
{
- QModelIndex typeIndex = index.sibling(index.row(), ColumnListModel::COL_TYPE);
- model->setData(typeIndex, COL_CUSTOM, Qt::EditRole);
- model->setData(index, ffe->text(), Qt::EditRole);
+ if (ffe->checkFilter())
+ {
+ QModelIndex typeIndex = index.sibling(index.row(), ColumnListModel::COL_TYPE);
+ model->setData(typeIndex, COL_CUSTOM, Qt::EditRole);
+ model->setData(index, ffe->text(), Qt::EditRole);
+ }
+ else
+ {
+ ffe->setText(index.data().toString());
+ }
}
- else
- ffe->setText(index.data().toString());
if (index.data().toString().length() == 0)
{
@@ -176,8 +181,10 @@ void ColumnTypeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model
model->setData(typeIndex, COL_CUSTOM, Qt::EditRole);
model->setData(index, sle->text(), Qt::EditRole);
}
- else
+ else if (sle)
+ {
sle->setText(index.data().toString());
+ }
if (index.data().toString().length() == 0)
{