Qt: Fill in our UAT delegate editor backgrounds.

Set setAutoFillBackground(true) for a bunch of our editors where
appropriate, similar to g4a2cd15aa5.

Change-Id: Ic87275e3be90af55b8352eb4742559d526dec2b6
Reviewed-on: https://code.wireshark.org/review/36386
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Gerald Combs 2020-03-12 17:36:57 -07:00 committed by Anders Broman
parent cd3af470b8
commit 73ea612d25
1 changed files with 36 additions and 34 deletions

View File

@ -40,6 +40,7 @@ QWidget *UatDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &
const QModelIndex &index) const
{
uat_field_t *field = indexToField(index);
QWidget *editor = nullptr;
switch (field->mode) {
case PT_TXTMOD_DIRECTORYNAME:
@ -47,13 +48,12 @@ QWidget *UatDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &
QString filename_old = index.model()->data(index, Qt::EditRole).toString();
EditorFileDialog* fileDialog = new EditorFileDialog(index, EditorFileDialog::Directory, parent, QString(field->title), filename_old);
//Use signals to accept data from cell
// Use signals to accept data from cell
connect(fileDialog, &EditorFileDialog::acceptEdit, this, &UatDelegate::applyFilename);
// Don't fall through and set setAutoFillBackground(true)
return fileDialog;
}
//shouldn't happen
return 0;
break;
case PT_TXTMOD_FILENAME:
if (index.isValid()) {
@ -62,49 +62,47 @@ QWidget *UatDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &
fileDialog->setOption(QFileDialog::DontConfirmOverwrite);
//Use signals to accept data from cell
// Use signals to accept data from cell
connect(fileDialog, &EditorFileDialog::acceptEdit, this, &UatDelegate::applyFilename);
// Don't fall through and set setAutoFillBackground(true)
return fileDialog;
}
//shouldn't happen
return 0;
break;
case PT_TXTMOD_COLOR:
if (index.isValid()) {
QColor color(index.model()->data(index, Qt::DecorationRole).toString());
QColorDialog * dialog = new QColorDialog(color, parent);
return dialog;
QColorDialog * colorDialog = new QColorDialog(color, parent);
// Don't fall through and set setAutoFillBackground(true)
return colorDialog;
}
//shouldn't happen
return 0;
break;
case PT_TXTMOD_ENUM:
{
// Note: the string repr. is written, not the integer value.
QComboBox *editor = new QComboBox(parent);
QComboBox *cb_editor = new QComboBox(parent);
const value_string *enum_vals = (const value_string *)field->fld_data;
for (int i = 0; enum_vals[i].strptr != NULL; i++) {
editor->addItem(enum_vals[i].strptr);
for (int i = 0; enum_vals[i].strptr != nullptr; i++) {
cb_editor->addItem(enum_vals[i].strptr);
}
return editor;
editor = cb_editor;
break;
}
case PT_TXTMOD_STRING:
// TODO add a live validator? Should SyntaxLineEdit be used?
return QStyledItemDelegate::createEditor(parent, option, index);
editor = QStyledItemDelegate::createEditor(parent, option, index);
break;
case PT_TXTMOD_DISPLAY_FILTER:
{
DisplayFilterEdit *editor = new DisplayFilterEdit(parent);
return editor;
}
editor = new DisplayFilterEdit(parent);
break;
case PT_TXTMOD_PROTO_FIELD:
{
FieldFilterEdit *editor = new FieldFilterEdit(parent);
return editor;
}
editor = new FieldFilterEdit(parent);
break;
case PT_TXTMOD_HEXBYTES:
{
// Requires input of the form "ab cd ef" (with possibly no or a colon
@ -114,25 +112,29 @@ QWidget *UatDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &
// QString types from QStyledItemDelegate are documented to return a
// QLineEdit. Note that Qt returns a subclass from QLineEdit which
// automatically adapts the width to the typed contents.
QLineEdit *editor = static_cast<QLineEdit *>(
QLineEdit *le_editor = static_cast<QLineEdit *>(
QStyledItemDelegate::createEditor(parent, option, index));
editor->setValidator(new QRegExpValidator(hexbytes_regex, editor));
return editor;
le_editor->setValidator(new QRegExpValidator(hexbytes_regex, le_editor));
editor = le_editor;
break;
}
case PT_TXTMOD_BOOL:
{
// model will handle creating checkbox
return 0;
}
break;
case PT_TXTMOD_NONE:
return 0;
break;
default:
g_assert_not_reached();
return 0;
break;
}
if (editor) {
editor->setAutoFillBackground(true);
}
return editor;
}
void UatDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const