aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2017-07-16 12:32:40 +0200
committerMichael Mann <mmann78@netscape.net>2017-07-16 14:47:01 +0000
commit4beb7430d4f935cdd31826809e53f8fb0365d2c0 (patch)
tree809b20cf6788c08268cb95adc5b7aea1b6197a9a /ui
parent96ac279d986898e655fc18a3950caa6f5f214fe7 (diff)
Qt: refactor UatTreeView into something reusable
UatTreeView had two functions: 1. Saner navigation functionality when pressing tab. 2. Start editing when the currently selected item changes. Since this tab navigation functionality is desired in more places, extract this functionality. Add more documentation while at it and use an alternative, declarative style to connect signals. Move the second functionality to the caller since not all views need it. Change-Id: Ibe886f2c2763dbe024614203a44b72173fbbce06 Reviewed-on: https://code.wireshark.org/review/22639 Petri-Dish: Michael Mann <mmann78@netscape.net> Reviewed-by: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/CMakeLists.txt4
-rw-r--r--ui/qt/Makefile.am4
-rw-r--r--ui/qt/tabnav_tree_widget.cpp2
-rw-r--r--ui/qt/uat_dialog.cpp8
-rw-r--r--ui/qt/uat_dialog.h2
-rw-r--r--ui/qt/uat_dialog.ui6
-rw-r--r--ui/qt/uat_frame.cpp8
-rw-r--r--ui/qt/uat_frame.h2
-rw-r--r--ui/qt/uat_frame.ui6
-rw-r--r--ui/qt/widgets/tabnav_tree_view.cpp (renamed from ui/qt/uat_tree_view.cpp)23
-rw-r--r--ui/qt/widgets/tabnav_tree_view.h (renamed from ui/qt/uat_tree_view.h)31
11 files changed, 62 insertions, 34 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt
index 1ddcacf3a9..a2fb5d402b 100644
--- a/ui/qt/CMakeLists.txt
+++ b/ui/qt/CMakeLists.txt
@@ -37,6 +37,7 @@ set(WIRESHARK_WIDGET_HEADERS
widgets/label_stack.h
widgets/overlay_scroll_bar.h
widgets/syntax_line_edit.h
+ widgets/tabnav_tree_view.h
widgets/drag_drop_toolbar.h
)
@@ -171,7 +172,6 @@ set(WIRESHARK_QT_HEADERS
uat_dialog.h
uat_frame.h
uat_model.h
- uat_tree_view.h
voip_calls_dialog.h
voip_calls_info_model.h
wireless_frame.h
@@ -223,6 +223,7 @@ set(WIRESHARK_WIDGET_SRCS
widgets/label_stack.cpp
widgets/overlay_scroll_bar.cpp
widgets/syntax_line_edit.cpp
+ widgets/tabnav_tree_view.cpp
widgets/drag_drop_toolbar.cpp
)
@@ -351,7 +352,6 @@ set(WIRESHARK_QT_SRC
uat_dialog.cpp
uat_frame.cpp
uat_model.cpp
- uat_tree_view.cpp
voip_calls_dialog.cpp
voip_calls_info_model.cpp
wireless_frame.cpp
diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am
index bd3b1cbcd3..0acd5a527a 100644
--- a/ui/qt/Makefile.am
+++ b/ui/qt/Makefile.am
@@ -166,6 +166,7 @@ MOC_WIDGET_HDRS = \
widgets/label_stack.h \
widgets/overlay_scroll_bar.h \
widgets/syntax_line_edit.h \
+ widgets/tabnav_tree_view.h \
widgets/drag_drop_toolbar.h
#
@@ -302,7 +303,6 @@ MOC_HDRS = \
uat_dialog.h \
uat_frame.h \
uat_model.h \
- uat_tree_view.h \
voip_calls_dialog.h \
voip_calls_info_model.h \
wireless_frame.h \
@@ -466,6 +466,7 @@ WIRESHARK_QT_WIDGET_SRC = \
widgets/label_stack.cpp \
widgets/overlay_scroll_bar.cpp \
widgets/syntax_line_edit.cpp \
+ widgets/tabnav_tree_view.cpp \
widgets/drag_drop_toolbar.cpp
@@ -596,7 +597,6 @@ WIRESHARK_QT_SRC = \
uat_dialog.cpp \
uat_frame.cpp \
uat_model.cpp \
- uat_tree_view.cpp \
voip_calls_dialog.cpp \
voip_calls_info_model.cpp \
wireless_frame.cpp \
diff --git a/ui/qt/tabnav_tree_widget.cpp b/ui/qt/tabnav_tree_widget.cpp
index 3d07a1cf35..c45dc78d60 100644
--- a/ui/qt/tabnav_tree_widget.cpp
+++ b/ui/qt/tabnav_tree_widget.cpp
@@ -24,7 +24,7 @@
#include "tabnav_tree_widget.h"
-// Copy on UatTreeView, modified to use QTreeWidget instead of QTreeView.
+// Copy of TabnavTreeView, modified to use QTreeWidget instead of QTreeView.
TabnavTreeWidget::TabnavTreeWidget(QWidget *parent) : QTreeWidget(parent)
{
diff --git a/ui/qt/uat_dialog.cpp b/ui/qt/uat_dialog.cpp
index ab4d4a9a2d..06439a6096 100644
--- a/ui/qt/uat_dialog.cpp
+++ b/ui/qt/uat_dialog.cpp
@@ -73,6 +73,10 @@ UatDialog::UatDialog(QWidget *parent, epan_uat *uat) :
ui->uatTreeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
+ // start editing as soon as the field is selected or when typing starts
+ ui->uatTreeView->setEditTriggers(ui->uatTreeView->editTriggers() |
+ QAbstractItemView::CurrentChanged | QAbstractItemView::AnyKeyPressed);
+
// Need to add uat_move or uat_insert to the UAT API.
ui->uatTreeView->setDragEnabled(false);
qDebug() << "FIX Add drag reordering to UAT dialog";
@@ -115,8 +119,6 @@ void UatDialog::setUat(epan_uat *uat)
this, SLOT(modelDataChanged(QModelIndex)));
connect(uat_model_, SIGNAL(rowsRemoved(QModelIndex, int, int)),
this, SLOT(modelRowsRemoved()));
- connect(ui->uatTreeView, SIGNAL(currentItemChanged(QModelIndex,QModelIndex)),
- this, SLOT(viewCurrentChanged(QModelIndex,QModelIndex)));
ok_button_->setEnabled(!uat_model_->hasErrors());
if (uat_->help && strlen(uat_->help) > 0) {
@@ -147,7 +149,7 @@ void UatDialog::modelRowsRemoved()
// Invoked when a different field is selected. Note: when selecting a different
// field after editing, this event is triggered after modelDataChanged.
-void UatDialog::viewCurrentChanged(const QModelIndex &current, const QModelIndex &previous)
+void UatDialog::on_uatTreeView_currentItemChanged(const QModelIndex &current, const QModelIndex &previous)
{
if (current.isValid()) {
ui->deleteToolButton->setEnabled(true);
diff --git a/ui/qt/uat_dialog.h b/ui/qt/uat_dialog.h
index 68d92cb2e5..3faf542311 100644
--- a/ui/qt/uat_dialog.h
+++ b/ui/qt/uat_dialog.h
@@ -52,7 +52,7 @@ public:
private slots:
void modelDataChanged(const QModelIndex &topLeft);
void modelRowsRemoved();
- void viewCurrentChanged(const QModelIndex &current, const QModelIndex &previous);
+ void on_uatTreeView_currentItemChanged(const QModelIndex &current, const QModelIndex &previous);
void acceptChanges();
void rejectChanges();
void on_newToolButton_clicked();
diff --git a/ui/qt/uat_dialog.ui b/ui/qt/uat_dialog.ui
index e8fcdf74a7..01a5712073 100644
--- a/ui/qt/uat_dialog.ui
+++ b/ui/qt/uat_dialog.ui
@@ -12,7 +12,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="UatTreeView" name="uatTreeView">
+ <widget class="TabnavTreeView" name="uatTreeView">
<column>
<property name="text">
<string notr="true">1</string>
@@ -130,9 +130,9 @@
<header>widgets/elided_label.h</header>
</customwidget>
<customwidget>
- <class>UatTreeView</class>
+ <class>TabnavTreeView</class>
<extends>QTreeView</extends>
- <header>uat_tree_view.h</header>
+ <header>widgets/tabnav_tree_view.h</header>
</customwidget>
</customwidgets>
<resources>
diff --git a/ui/qt/uat_frame.cpp b/ui/qt/uat_frame.cpp
index 036a0b1637..afaf6a4859 100644
--- a/ui/qt/uat_frame.cpp
+++ b/ui/qt/uat_frame.cpp
@@ -66,6 +66,10 @@ UatFrame::UatFrame(QWidget *parent) :
ui->uatTreeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
+ // start editing as soon as the field is selected or when typing starts
+ ui->uatTreeView->setEditTriggers(ui->uatTreeView->editTriggers() |
+ QAbstractItemView::CurrentChanged | QAbstractItemView::AnyKeyPressed);
+
// XXX - Need to add uat_move or uat_insert to the UAT API for drag/drop
}
@@ -105,8 +109,6 @@ void UatFrame::setUat(epan_uat *uat)
this, SLOT(modelDataChanged(QModelIndex)));
connect(uat_model_, SIGNAL(rowsRemoved(QModelIndex, int, int)),
this, SLOT(modelRowsRemoved()));
- connect(ui->uatTreeView, SIGNAL(currentItemChanged(QModelIndex,QModelIndex)),
- this, SLOT(viewCurrentChanged(QModelIndex,QModelIndex)));
}
setWindowTitle(title);
@@ -175,7 +177,7 @@ void UatFrame::addRecord(bool copy_from_current)
// Invoked when a different field is selected. Note: when selecting a different
// field after editing, this event is triggered after modelDataChanged.
-void UatFrame::viewCurrentChanged(const QModelIndex &current, const QModelIndex &previous)
+void UatFrame::on_uatTreeView_currentItemChanged(const QModelIndex &current, const QModelIndex &previous)
{
if (current.isValid()) {
ui->deleteToolButton->setEnabled(true);
diff --git a/ui/qt/uat_frame.h b/ui/qt/uat_frame.h
index 07336fd02c..85acb55105 100644
--- a/ui/qt/uat_frame.h
+++ b/ui/qt/uat_frame.h
@@ -59,7 +59,7 @@ private:
private slots:
void modelDataChanged(const QModelIndex &topLeft);
void modelRowsRemoved();
- void viewCurrentChanged(const QModelIndex &current, const QModelIndex &previous);
+ void on_uatTreeView_currentItemChanged(const QModelIndex &current, const QModelIndex &previous);
void on_newToolButton_clicked();
void on_deleteToolButton_clicked();
void on_copyToolButton_clicked();
diff --git a/ui/qt/uat_frame.ui b/ui/qt/uat_frame.ui
index b99bf4ddd8..a9128e1a83 100644
--- a/ui/qt/uat_frame.ui
+++ b/ui/qt/uat_frame.ui
@@ -18,7 +18,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="UatTreeView" name="uatTreeView">
+ <widget class="TabnavTreeView" name="uatTreeView">
<column>
<property name="text">
<string notr="true">1</string>
@@ -138,9 +138,9 @@
<header>widgets/elided_label.h</header>
</customwidget>
<customwidget>
- <class>UatTreeView</class>
+ <class>TabnavTreeView</class>
<extends>QTreeView</extends>
- <header>uat_tree_view.h</header>
+ <header>widgets/tabnav_tree_view.h</header>
</customwidget>
</customwidgets>
<resources>
diff --git a/ui/qt/uat_tree_view.cpp b/ui/qt/widgets/tabnav_tree_view.cpp
index bb2e8501b7..4a431193cc 100644
--- a/ui/qt/uat_tree_view.cpp
+++ b/ui/qt/widgets/tabnav_tree_view.cpp
@@ -1,5 +1,5 @@
-/* uat_tree_view.cpp
- * Tree view of UAT data.
+/* tabnav_tree_view.cpp
+ * Tree view with saner tab navigation functionality.
*
* Copyright 2016 Peter Wu <peter@lekensteyn.nl>
*
@@ -22,18 +22,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "uat_tree_view.h"
+#include "tabnav_tree_view.h"
-UatTreeView::UatTreeView(QWidget *parent) : QTreeView(parent)
+TabnavTreeView::TabnavTreeView(QWidget *parent) : QTreeView(parent)
{
- // start editing as soon as the field is selected or when typing starts
- setEditTriggers(editTriggers() | CurrentChanged | AnyKeyPressed);
}
// Note: if a QTableView is used, then this is not needed anymore since Tab
// works as "expected" (move to next cell instead of row).
// Note 2: this does not help with fields with no widget (like filename).
-QModelIndex UatTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
+QModelIndex TabnavTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
QModelIndex current = currentIndex();
// If an item is currently selected, interpret Next/Previous. Otherwise,
@@ -55,7 +53,16 @@ QModelIndex UatTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModif
return QTreeView::moveCursor(cursorAction, modifiers);
}
-void UatTreeView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
+/*!
+ \fn void TabnavTreeView::currentItemChanged(QModelIndex *current, QModelIndex *previous)
+
+ This signal is emitted whenever the current item changes.
+
+ \a previous is the item that previously had the focus; \a current is the
+ new current item.
+ */
+
+void TabnavTreeView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
{
QTreeView::currentChanged(current, previous);
emit currentItemChanged(current, previous);
diff --git a/ui/qt/uat_tree_view.h b/ui/qt/widgets/tabnav_tree_view.h
index d7480b2e8a..625dc7c9c0 100644
--- a/ui/qt/uat_tree_view.h
+++ b/ui/qt/widgets/tabnav_tree_view.h
@@ -1,5 +1,5 @@
-/* uat_tree_view.h
- * Tree view of UAT data.
+/* tabnav_tree_view.h
+ * Tree view with saner tab navigation functionality.
*
* Copyright 2016 Peter Wu <peter@lekensteyn.nl>
*
@@ -22,17 +22,22 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef UAT_TREE_VIEW_H
-#define UAT_TREE_VIEW_H
+#ifndef TABNAV_TREE_VIEW_H
+#define TABNAV_TREE_VIEW_H
#include <config.h>
#include <QTreeView>
-class UatTreeView : public QTreeView
+/**
+ * Like QTreeView, but instead of changing to the next row (same column) when
+ * pressing Tab while editing, change to the next column (same row).
+ */
+class TabnavTreeView : public QTreeView
{
Q_OBJECT
+
public:
- UatTreeView(QWidget *parent = 0);
+ TabnavTreeView(QWidget *parent = 0);
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
protected slots:
@@ -41,4 +46,16 @@ protected slots:
signals:
void currentItemChanged(const QModelIndex &current, const QModelIndex &previous);
};
-#endif // UAT_TREE_VIEW_H
+#endif // TABNAV_TREE_VIEW_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:
+ */