aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-07-30 23:30:59 -0400
committerAnders Broman <a.broman58@gmail.com>2017-08-07 04:53:42 +0000
commitff7a6305a7eaa3c3815e813acc78a1660ae82293 (patch)
tree70b097d2097c5adbe904bb0d2364d8fb21773f8e /ui/qt
parent4dc835c9c6b7af68cd63ae9efa26ac23ee3d9365 (diff)
Use proper tab order for "file types" in UAT "table".
Directory and File "UAT types" have been using a separately launched dialog, instead of an "editor", so it breaks "tab rules". Create and treat (File) dialog as an editor. Change-Id: I983728abefb0cdd79899468a800328f1b56e2910 Reviewed-on: https://code.wireshark.org/review/22886 Reviewed-by: Michael Mann <mmann78@netscape.net> Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/CMakeLists.txt2
-rw-r--r--ui/qt/Makefile.am2
-rw-r--r--ui/qt/models/uat_delegate.cpp107
-rw-r--r--ui/qt/models/uat_delegate.h9
-rw-r--r--ui/qt/widgets/editor_file_dialog.cpp55
-rw-r--r--ui/qt/widgets/editor_file_dialog.h59
6 files changed, 189 insertions, 45 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt
index 197621fce4..1c63d693f1 100644
--- a/ui/qt/CMakeLists.txt
+++ b/ui/qt/CMakeLists.txt
@@ -30,6 +30,7 @@ set(WIRESHARK_WIDGET_HEADERS
widgets/display_filter_combo.h
widgets/display_filter_edit.h
widgets/drag_drop_toolbar.h
+ widgets/editor_file_dialog.h
widgets/elided_label.h
widgets/field_filter_edit.h
widgets/find_line_edit.h
@@ -227,6 +228,7 @@ set(WIRESHARK_WIDGET_SRCS
widgets/display_filter_combo.cpp
widgets/display_filter_edit.cpp
widgets/drag_drop_toolbar.cpp
+ widgets/editor_file_dialog.cpp
widgets/elided_label.cpp
widgets/field_filter_edit.cpp
widgets/find_line_edit.cpp
diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am
index a5d0add4be..29b56aec0f 100644
--- a/ui/qt/Makefile.am
+++ b/ui/qt/Makefile.am
@@ -159,6 +159,7 @@ MOC_WIDGET_HDRS = \
widgets/clickable_label.h \
widgets/display_filter_combo.h \
widgets/display_filter_edit.h \
+ widgets/editor_file_dialog.h \
widgets/elided_label.h \
widgets/field_filter_edit.h \
widgets/find_line_edit.h \
@@ -471,6 +472,7 @@ WIRESHARK_QT_WIDGET_SRC = \
widgets/clickable_label.cpp \
widgets/display_filter_combo.cpp \
widgets/display_filter_edit.cpp \
+ widgets/editor_file_dialog.cpp \
widgets/elided_label.cpp \
widgets/field_filter_edit.cpp \
widgets/find_line_edit.cpp \
diff --git a/ui/qt/models/uat_delegate.cpp b/ui/qt/models/uat_delegate.cpp
index ee149a2fc8..9d77337aef 100644
--- a/ui/qt/models/uat_delegate.cpp
+++ b/ui/qt/models/uat_delegate.cpp
@@ -31,6 +31,7 @@
#include <QCheckBox>
#include <ui/qt/widgets/display_filter_edit.h>
+#include <ui/qt/widgets/editor_file_dialog.h>
UatDelegate::UatDelegate(QObject *parent) : QStyledItemDelegate(parent)
{
@@ -49,11 +50,39 @@ QWidget *UatDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &
switch (field->mode) {
case PT_TXTMOD_DIRECTORYNAME:
- case PT_TXTMOD_FILENAME:
- // TODO tab navigation from this field is broken.
- // Do not create editor, a dialog will be opened in editorEvent
+ {
+ if (index.isValid()) {
+ QString filename_old = index.model()->data(index, Qt::EditRole).toString();
+ EditorFileDialog* fileDialog = new EditorFileDialog(index, parent, QString(field->title), filename_old);
+
+ fileDialog->setFileMode(QFileDialog::DirectoryOnly);
+
+ //Use signals to accept data from cell
+ connect(fileDialog, SIGNAL(acceptEdit(const QModelIndex &)), this, SLOT(applyDirectory(const QModelIndex&)));
+ return fileDialog;
+ }
+
+ //shouldn't happen
return 0;
+ }
+
+ case PT_TXTMOD_FILENAME:
+ {
+ if (index.isValid()) {
+ QString filename_old = index.model()->data(index, Qt::EditRole).toString();
+ EditorFileDialog* fileDialog = new EditorFileDialog(index, parent, QString(field->title), filename_old);
+ fileDialog->setFileMode(QFileDialog::ExistingFile);
+ fileDialog->setOption(QFileDialog::DontConfirmOverwrite);
+
+ //Use signals to accept data from cell
+ connect(fileDialog, SIGNAL(acceptEdit(const QModelIndex &)), this, SLOT(applyFilename(const QModelIndex &)));
+ return fileDialog;
+ }
+
+ //shouldn't happen
+ return 0;
+ }
case PT_TXTMOD_ENUM:
{
// Note: the string repr. is written, not the integer value.
@@ -143,64 +172,60 @@ void UatDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
model->setData(index, data, Qt::EditRole);
break;
}
-
+ case PT_TXTMOD_DIRECTORYNAME:
+ case PT_TXTMOD_FILENAME:
+ //do nothing, dialog signals will update table
+ break;
default:
QStyledItemDelegate::setModelData(editor, model, index);
}
}
-#if 0
-// Qt docs suggest overriding updateEditorGeometry, but the defaults seem sane.
void UatDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
- QStyledItemDelegate::updateEditorGeometry(editor, option, index);
-}
-#endif
-
-bool UatDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
-{
uat_field_t *field = indexToField(index);
switch (field->mode) {
case PT_TXTMOD_DIRECTORYNAME:
+ {
+ QRect rect = option.rect;
+ rect.setBottom(rect.width());
+ editor->setGeometry(rect);
+ break;
+ }
case PT_TXTMOD_FILENAME:
- if (event && (event->type() == QEvent::MouseButtonRelease ||
- event->type() == QEvent::MouseButtonDblClick)) {
- // Ignore these mouse events, only handle MouseButtonPress.
- return false;
- }
- if (index.isValid()) {
- QString filename_old = model->data(index, Qt::EditRole).toString();
- QString filename = openFileDialog(field, filename_old);
- // TODO should this overwrite only when !filename.isEmpty()?
- model->setData(index, filename, Qt::EditRole);
- }
- // returns false to ensure that QAbstractItemView::edit does not assume
- // the editing state. This causes the view's currentIndex to be changed
- // to the cell where this delegate was "created", as desired.
- return false;
-
+ {
+ QRect rect = option.rect;
+ rect.setWidth(600);
+ rect.setHeight(600);
+ editor->setGeometry(rect);
+ break;
+ }
default:
- return QStyledItemDelegate::editorEvent(event, model, option, index);
+ //the defaults for other editors seem sane.
+ QStyledItemDelegate::updateEditorGeometry(editor, option, index);
}
}
-QString UatDelegate::openFileDialog(uat_field_t *field, const QString &cur_path) const
+void UatDelegate::applyFilename(const QModelIndex& index)
{
- // Note: file dialogs have their parent widget set to NULL because we do not
- // have an editor nor the view that would attach us.
- switch (field->mode) {
- case PT_TXTMOD_DIRECTORYNAME:
- return QFileDialog::getExistingDirectory(NULL, field->title, cur_path);
+ if (index.isValid()) {
+ EditorFileDialog* fileDialog = static_cast<EditorFileDialog*>(sender());
- case PT_TXTMOD_FILENAME:
- return QFileDialog::getOpenFileName(NULL, field->title, cur_path,
- QString(), NULL, QFileDialog::DontConfirmOverwrite);
+ QStringList files = fileDialog->selectedFiles();
+ if (files.size() > 0) {
+ ((QAbstractItemModel *)index.model())->setData(index, files[0], Qt::EditRole);
+ }
+ }
+}
- default:
- g_assert_not_reached();
- return 0;
+void UatDelegate::applyDirectory(const QModelIndex& index)
+{
+ if (index.isValid()) {
+ EditorFileDialog* fileDialog = static_cast<EditorFileDialog*>(sender());
+ const QString &data = fileDialog->directory().absolutePath();
+ ((QAbstractItemModel *)index.model())->setData(index, data, Qt::EditRole);
}
}
diff --git a/ui/qt/models/uat_delegate.h b/ui/qt/models/uat_delegate.h
index 795161a686..81ad108864 100644
--- a/ui/qt/models/uat_delegate.h
+++ b/ui/qt/models/uat_delegate.h
@@ -28,7 +28,9 @@
#include <config.h>
#include <glib.h>
#include <epan/uat-int.h>
+
#include <QStyledItemDelegate>
+#include <QModelIndex>
class UatDelegate : public QStyledItemDelegate
{
@@ -43,15 +45,14 @@ public:
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
-#if 0
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
-#endif
- bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
+private slots:
+ void applyDirectory(const QModelIndex& index);
+ void applyFilename(const QModelIndex& index);
private:
uat_field_t *indexToField(const QModelIndex &index) const;
- QString openFileDialog(uat_field_t *field, const QString &cur_path) const;
};
#endif // UAT_DELEGATE_H
diff --git a/ui/qt/widgets/editor_file_dialog.cpp b/ui/qt/widgets/editor_file_dialog.cpp
new file mode 100644
index 0000000000..9f699ecf2d
--- /dev/null
+++ b/ui/qt/widgets/editor_file_dialog.cpp
@@ -0,0 +1,55 @@
+/* editor_file_dialog.h
+ *
+ * File dialog that can be used as an "inline editor" in a table
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <ui/qt/widgets/editor_file_dialog.h>
+
+EditorFileDialog::EditorFileDialog(const QModelIndex& index, QWidget* parent, Qt::WindowFlags flags)
+ : QFileDialog(parent, flags)
+ , index_(index)
+{
+}
+
+EditorFileDialog::EditorFileDialog(const QModelIndex& index, QWidget* parent, const QString& caption, const QString& directory, const QString& filter)
+ : QFileDialog(parent, caption, directory, filter)
+ , index_(index)
+{
+}
+
+void EditorFileDialog::accept()
+{
+ emit acceptEdit(index_);
+ QFileDialog::accept();
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/qt/widgets/editor_file_dialog.h b/ui/qt/widgets/editor_file_dialog.h
new file mode 100644
index 0000000000..9922fff201
--- /dev/null
+++ b/ui/qt/widgets/editor_file_dialog.h
@@ -0,0 +1,59 @@
+/* editor_file_dialog.h
+ *
+ * File dialog that can be used as an "inline editor" in a table
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef EDITOR_FILE_DIALOG_H_
+#define EDITOR_FILE_DIALOG_H_
+
+#include <QFileDialog>
+#include <QModelIndex>
+
+class EditorFileDialog : public QFileDialog
+{
+ Q_OBJECT
+public:
+ explicit EditorFileDialog(const QModelIndex& index, QWidget* parent, Qt::WindowFlags flags);
+ explicit EditorFileDialog(const QModelIndex& index, QWidget* parent = 0, const QString & caption = QString(), const QString & directory = QString(), const QString & filter = QString());
+
+ void accept();
+
+signals:
+ void acceptEdit(const QModelIndex& index);
+
+protected:
+ const QModelIndex index_; //saved index of table cell
+};
+
+#endif /* EDITOR_FILE_DIALOG_H_ */
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */