diff options
author | Michael Mann <mmann78@netscape.net> | 2017-06-22 11:34:48 -0400 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-06-26 02:44:05 +0000 |
commit | 1b7f5d9f798634770656a82aaa2df30f7f01a9b0 (patch) | |
tree | d6f5e76b402f8125bb2ca25c6c88c6b99408880b /ui/qt | |
parent | 395775acce1ef9624fdf2030179683f37a27cd59 (diff) | |
download | wireshark-1b7f5d9f798634770656a82aaa2df30f7f01a9b0.tar.gz |
Convert filter expressions preference data to a UAT.
The filter expressions data was shoved into the preference file in a
very loose, non-arrayed form. It's much easier to manage in code
(and for users in a separate file) as a UAT.
The GTK GUI was hacked to use the existing UAT dialog rather than
rewrite the pref_filter_expressions.c to support a UAT. Should
be okay since it's deprecated.
Change-Id: I688cebb4b7b6594878c1398365e79a205f1902d9
Ping-Bug: 13814
Reviewed-on: https://code.wireshark.org/review/22354
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/filter_expression_frame.cpp | 6 | ||||
-rw-r--r-- | ui/qt/filter_expressions_preferences_frame.cpp | 352 | ||||
-rw-r--r-- | ui/qt/filter_expressions_preferences_frame.h | 33 | ||||
-rw-r--r-- | ui/qt/filter_expressions_preferences_frame.ui | 188 | ||||
-rw-r--r-- | ui/qt/main_window.h | 1 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 44 | ||||
-rw-r--r-- | ui/qt/preferences_dialog.cpp | 10 | ||||
-rw-r--r-- | ui/qt/preferences_dialog.h | 1 |
8 files changed, 348 insertions, 287 deletions
diff --git a/ui/qt/filter_expression_frame.cpp b/ui/qt/filter_expression_frame.cpp index 2057cf1ee4..15fae7eeeb 100644 --- a/ui/qt/filter_expression_frame.cpp +++ b/ui/qt/filter_expression_frame.cpp @@ -23,6 +23,7 @@ #include <ui_filter_expression_frame.h> #include <epan/filter_expressions.h> +#include <epan/uat-int.h> #include <ui/preference_utils.h> #include <QPushButton> @@ -91,6 +92,7 @@ void FilterExpressionFrame::on_labelLineEdit_textChanged(const QString) void FilterExpressionFrame::on_buttonBox_accepted() { + gchar* err = NULL; QByteArray label_ba = ui->labelLineEdit->text().toUtf8(); QByteArray expr_ba = ui->displayFilterLineEdit->text().toUtf8(); @@ -98,7 +100,9 @@ void FilterExpressionFrame::on_buttonBox_accepted() on_buttonBox_rejected(); emit filterExpressionsChanged(); - prefs_main_write(); + + uat_save(uat_get_table_by_name("Display expressions"), &err); + g_free(err); } void FilterExpressionFrame::on_buttonBox_rejected() diff --git a/ui/qt/filter_expressions_preferences_frame.cpp b/ui/qt/filter_expressions_preferences_frame.cpp index 3284da5949..1b47225797 100644 --- a/ui/qt/filter_expressions_preferences_frame.cpp +++ b/ui/qt/filter_expressions_preferences_frame.cpp @@ -31,14 +31,13 @@ #include "wireshark_application.h" #include "qt_ui_utils.h" +#include <wsutil/report_message.h> #include <QLineEdit> #include <QKeyEvent> #include <QTreeWidgetItemIterator> -static const int enabled_col_ = 0; -static const int label_col_ = 1; -static const int expression_col_ = 2; +#include <QDebug> // This shouldn't exist in its current form. Instead it should be the "display filters" // dialog, and the "dfilters" file should support a "show in toolbar" flag. @@ -46,257 +45,230 @@ static const int expression_col_ = 2; FilterExpressionsPreferencesFrame::FilterExpressionsPreferencesFrame(QWidget *parent) : QFrame(parent), ui(new Ui::FilterExpressionsPreferencesFrame), - cur_column_(0), - cur_line_edit_(NULL) + uat_model_(NULL), + uat_delegate_(NULL), + uat_(NULL) { ui->setupUi(this); - int one_em = ui->expressionTreeWidget->fontMetrics().height(); - ui->expressionTreeWidget->resizeColumnToContents(enabled_col_); - ui->expressionTreeWidget->setColumnWidth(label_col_, one_em * 10); - ui->expressionTreeWidget->setColumnWidth(expression_col_, one_em * 5); - - ui->expressionTreeWidget->setMinimumWidth(one_em * 15); - ui->expressionTreeWidget->setMinimumHeight(one_em * 10); - - ui->expressionTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); - ui->expressionTreeWidget->setDragEnabled(true); - ui->expressionTreeWidget->viewport()->setAcceptDrops(true); - ui->expressionTreeWidget->setDropIndicatorShown(true); - ui->expressionTreeWidget->setDragDropMode(QAbstractItemView::InternalMove); - - ui->expressionTreeWidget->clear(); - - for (struct filter_expression *fe = *pfilter_expression_head; fe != NULL; fe = fe->next) { - if (fe->deleted) continue; - addExpression(fe->enabled, fe->label, fe->expression); - } - - updateWidgets(); +#ifdef Q_OS_MAC + ui->newToolButton->setAttribute(Qt::WA_MacSmallSize, true); + ui->deleteToolButton->setAttribute(Qt::WA_MacSmallSize, true); + ui->copyToolButton->setAttribute(Qt::WA_MacSmallSize, true); + ui->pathLabel->setAttribute(Qt::WA_MacSmallSize, true); +#endif + + // FIXME: this prevents the columns from being resized, even if the text + // within a combobox needs more space (e.g. in the USER DLT settings). For + // very long filenames in the SSL RSA keys dialog, it also results in a + // vertical scrollbar. Maybe remove this since the editor is not limited to + // the column width (and overlays other fields if more width is needed)? +#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) + ui->uatTreeView->header()->setResizeMode(QHeaderView::ResizeToContents); +#else + ui->uatTreeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); +#endif + + // XXX - Need to add uat_move or uat_insert to the UAT API for drag/drop } FilterExpressionsPreferencesFrame::~FilterExpressionsPreferencesFrame() { delete ui; + delete uat_delegate_; + delete uat_model_; } -void FilterExpressionsPreferencesFrame::unstash() +void FilterExpressionsPreferencesFrame::setUat(epan_uat *uat) { - struct filter_expression *cur_fe = *pfilter_expression_head, *new_fe_head = NULL, *new_fe = NULL; - bool changed = false; + QString title(tr("Unknown User Accessible Table")); - QTreeWidgetItemIterator it(ui->expressionTreeWidget); - while (*it) { - struct filter_expression *fe = g_new0(struct filter_expression, 1); + uat_ = uat; - if (!new_fe_head) { - new_fe_head = fe; - } else { - new_fe->next = fe; - } - new_fe = fe; - - new_fe->enabled = (*it)->checkState(enabled_col_) == Qt::Checked ? TRUE : FALSE; - new_fe->label = qstring_strdup((*it)->text(label_col_)); - new_fe->expression = qstring_strdup((*it)->text(expression_col_)); - - if (cur_fe == NULL) { - changed = true; - } else { - if (cur_fe->enabled != new_fe->enabled || - g_strcmp0(cur_fe->label, new_fe->label) != 0 || - g_strcmp0(cur_fe->expression, new_fe->expression) != 0) { - changed = true; - } - cur_fe = cur_fe->next; - } - ++it; - } + ui->pathLabel->clear(); + ui->pathLabel->setEnabled(false); - if (cur_fe) changed = true; + if (uat_) { + if (uat_->name) { + title = uat_->name; + } - cur_fe = new_fe_head; - if (changed) { - cur_fe = *pfilter_expression_head; - *pfilter_expression_head = new_fe_head; - wsApp->emitAppSignal(WiresharkApplication::FilterExpressionsChanged); + QString abs_path = gchar_free_to_qstring(uat_get_actual_filename(uat_, FALSE)); + ui->pathLabel->setText(abs_path); + ui->pathLabel->setUrl(QUrl::fromLocalFile(abs_path).toString()); + ui->pathLabel->setToolTip(tr("Open ") + uat->filename); + ui->pathLabel->setEnabled(true); + + uat_model_ = new UatModel(NULL, uat); + uat_delegate_ = new UatDelegate; + ui->uatTreeView->setModel(uat_model_); + ui->uatTreeView->setItemDelegate(uat_delegate_); + + connect(uat_model_, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + 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))); + + connect(this, SIGNAL(rejected()), this, SLOT(rejectChanges())); + connect(this, SIGNAL(accepted()), this, SLOT(acceptChanges())); } - while (cur_fe) { - struct filter_expression *fe = cur_fe; - cur_fe = fe->next; - g_free(fe->label); - g_free(fe->expression); - g_free(fe); - } + setWindowTitle(title); } -void FilterExpressionsPreferencesFrame::keyPressEvent(QKeyEvent *evt) +void FilterExpressionsPreferencesFrame::acceptChanges() { - if (cur_line_edit_ && cur_line_edit_->hasFocus()) { - switch (evt->key()) { - case Qt::Key_Escape: - cur_line_edit_->setText(saved_col_string_); - /* Fall Through */ - case Qt::Key_Enter: - case Qt::Key_Return: - switch (cur_column_) { - case label_col_: - labelEditingFinished(); - break; - case expression_col_: - expressionEditingFinished(); - break; - default: - break; - } + if (!uat_) return; - delete cur_line_edit_; - return; - default: - break; + if (uat_->changed) { + gchar *err = NULL; + + if (!uat_save(uat_, &err)) { + report_failure("Error while saving %s: %s", uat_->name, err); + g_free(err); } - } - QFrame::keyPressEvent(evt); -} -void FilterExpressionsPreferencesFrame::addExpression(bool enabled, const QString label, const QString expression) -{ - QTreeWidgetItem *item = new QTreeWidgetItem(ui->expressionTreeWidget); + if (uat_->post_update_cb) { + uat_->post_update_cb(); + } - item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); - item->setCheckState(enabled_col_, enabled ? Qt::Checked : Qt::Unchecked); - item->setText(label_col_, label); - item->setText(expression_col_, expression); + //Filter expressions don't affect dissection, so there is no need to + //send any events to that effect. However, the app needs to know + //about any button changes. + wsApp->emitAppSignal(WiresharkApplication::FilterExpressionsChanged); + } } -void FilterExpressionsPreferencesFrame::updateWidgets() +void FilterExpressionsPreferencesFrame::rejectChanges() { - int num_selected = ui->expressionTreeWidget->selectedItems().count(); - - ui->copyToolButton->setEnabled(num_selected == 1); - ui->deleteToolButton->setEnabled(num_selected > 0); + if (!uat_) return; + + if (uat_->changed) { + gchar *err = NULL; + uat_clear(uat_); + if (!uat_load(uat_, &err)) { + report_failure("Error while loading %s: %s", uat_->name, err); + g_free(err); + } + //Filter expressions don't affect dissection, so there is no need to + //send any events to that effect + } } -void FilterExpressionsPreferencesFrame::on_expressionTreeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) +void FilterExpressionsPreferencesFrame::addRecord(bool copy_from_current) { - ui->deleteToolButton->setEnabled(current ? true : false); + if (!uat_) return; - if (previous && ui->expressionTreeWidget->itemWidget(previous, label_col_)) { - ui->expressionTreeWidget->removeItemWidget(previous, label_col_); + const QModelIndex ¤t = ui->uatTreeView->currentIndex(); + if (copy_from_current && !current.isValid()) return; + + // should not fail, but you never know. + if (!uat_model_->insertRows(uat_model_->rowCount(), 1)) { + qDebug() << "Failed to add a new record"; + return; } - if (previous && ui->expressionTreeWidget->itemWidget(previous, expression_col_)) { - ui->expressionTreeWidget->removeItemWidget(previous, expression_col_); + const QModelIndex &new_index = uat_model_->index(uat_model_->rowCount() - 1, 0); + if (copy_from_current) { + uat_model_->copyRow(new_index.row(), current.row()); } + // due to an EditTrigger, this will also start editing. + ui->uatTreeView->setCurrentIndex(new_index); + // trigger updating error messages and the OK button state. + modelDataChanged(new_index); } -void FilterExpressionsPreferencesFrame::on_expressionTreeWidget_itemActivated(QTreeWidgetItem *item, int column) +// Invoked when a different field is selected. Note: when selecting a different +// field after editing, this event is triggered after modelDataChanged. +void FilterExpressionsPreferencesFrame::viewCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous) { - if (!item || cur_line_edit_) return; - - QWidget *editor = NULL; - cur_column_ = column; - - switch (column) { - case label_col_: - { - cur_line_edit_ = new QLineEdit(); - saved_col_string_ = item->text(label_col_); - connect(cur_line_edit_, SIGNAL(editingFinished()), this, SLOT(labelEditingFinished())); - editor = cur_line_edit_; - break; - } - case expression_col_: - { - DisplayFilterEdit *display_edit = new DisplayFilterEdit(); - saved_col_string_ = item->text(expression_col_); - connect(display_edit, SIGNAL(textChanged(QString)), - display_edit, SLOT(checkDisplayFilter(QString))); - connect(display_edit, SIGNAL(editingFinished()), this, SLOT(expressionEditingFinished())); - editor = cur_line_edit_ = display_edit; - break; - } - default: - return; - } - - if (cur_line_edit_) { - cur_line_edit_->setText(saved_col_string_); - cur_line_edit_->selectAll(); - connect(cur_line_edit_, SIGNAL(destroyed()), this, SLOT(lineEditDestroyed())); + if (current.isValid()) { + ui->deleteToolButton->setEnabled(true); + ui->copyToolButton->setEnabled(true); + } else { + ui->deleteToolButton->setEnabled(false); + ui->copyToolButton->setEnabled(false); } - if (editor) { - QFrame *edit_frame = new QFrame(); - QHBoxLayout *hb = new QHBoxLayout(); - QSpacerItem *spacer = new QSpacerItem(5, 10); - - hb->addWidget(editor, 0); - hb->addSpacerItem(spacer); - hb->setStretch(1, 1); - hb->setContentsMargins(0, 0, 0, 0); - - edit_frame->setLineWidth(0); - edit_frame->setFrameStyle(QFrame::NoFrame); - // The documentation suggests setting autoFillbackground. That looks silly - // so we clear the item text instead. - item->setText(cur_column_, ""); - edit_frame->setLayout(hb); - ui->expressionTreeWidget->setItemWidget(item, cur_column_, edit_frame); - editor->setFocus(); - } + checkForErrorHint(current, previous); } -void FilterExpressionsPreferencesFrame::lineEditDestroyed() +// Invoked when a field in the model changes (e.g. by closing the editor) +void FilterExpressionsPreferencesFrame::modelDataChanged(const QModelIndex &topLeft) { - cur_line_edit_ = NULL; + checkForErrorHint(topLeft, QModelIndex()); } -void FilterExpressionsPreferencesFrame::labelEditingFinished() +// Invoked after a row has been removed from the model. +void FilterExpressionsPreferencesFrame::modelRowsRemoved() { - QTreeWidgetItem *item = ui->expressionTreeWidget->currentItem(); - if (!cur_line_edit_ || !item) return; - - item->setText(label_col_, cur_line_edit_->text()); - ui->expressionTreeWidget->removeItemWidget(item, label_col_); + const QModelIndex ¤t = ui->uatTreeView->currentIndex(); + checkForErrorHint(current, QModelIndex()); } -void FilterExpressionsPreferencesFrame::expressionEditingFinished() +// If the current field has errors, show them. +// Otherwise if the row has not changed, but the previous field has errors, show them. +// Otherwise pick the first error in the current row. +// Otherwise show the error from the previous field (if any). +// Otherwise clear the error hint. +void FilterExpressionsPreferencesFrame::checkForErrorHint(const QModelIndex ¤t, const QModelIndex &previous) { - QTreeWidgetItem *item = ui->expressionTreeWidget->currentItem(); - if (!cur_line_edit_ || !item) return; + if (current.isValid()) { + if (trySetErrorHintFromField(current)) { + return; + } - item->setText(expression_col_, cur_line_edit_->text()); - ui->expressionTreeWidget->removeItemWidget(item, expression_col_); + const int row = current.row(); + if (row == previous.row() && trySetErrorHintFromField(previous)) { + return; + } + + for (int i = 0; i < uat_model_->columnCount(); i++) { + if (trySetErrorHintFromField(uat_model_->index(row, i))) { + return; + } + } + } + + if (previous.isValid()) { + if (trySetErrorHintFromField(previous)) { + return; + } + } + + ui->hintLabel->clear(); } -void FilterExpressionsPreferencesFrame::on_expressionTreeWidget_itemSelectionChanged() +bool FilterExpressionsPreferencesFrame::trySetErrorHintFromField(const QModelIndex &index) { - updateWidgets(); + const QVariant &data = uat_model_->data(index, Qt::UserRole + 1); + if (!data.isNull()) { + // use HTML instead of PlainText because that handles wordwrap properly + ui->hintLabel->setText("<small><i>" + html_escape(data.toString()) + "</i></small>"); + return true; + } + return false; } -static const QString new_button_label_ = QObject::tr("My Filter"); void FilterExpressionsPreferencesFrame::on_newToolButton_clicked() { - addExpression(true, new_button_label_, QString()); + addRecord(); } void FilterExpressionsPreferencesFrame::on_deleteToolButton_clicked() { - QTreeWidgetItem *item = ui->expressionTreeWidget->currentItem(); - if (item) { - ui->expressionTreeWidget->invisibleRootItem()->removeChild(item); + const QModelIndex ¤t = ui->uatTreeView->currentIndex(); + if (uat_model_ && current.isValid()) { + if (!uat_model_->removeRows(current.row(), 1)) { + qDebug() << "Failed to remove row"; + } } } void FilterExpressionsPreferencesFrame::on_copyToolButton_clicked() { - if (!ui->expressionTreeWidget->currentItem()) return; - QTreeWidgetItem *ti = ui->expressionTreeWidget->currentItem(); - - addExpression(ti->checkState(enabled_col_) == Qt::Checked, - ti->text(label_col_), ti->text(expression_col_)); + addRecord(true); } /* diff --git a/ui/qt/filter_expressions_preferences_frame.h b/ui/qt/filter_expressions_preferences_frame.h index eaefb49a7e..0eff7587dd 100644 --- a/ui/qt/filter_expressions_preferences_frame.h +++ b/ui/qt/filter_expressions_preferences_frame.h @@ -24,8 +24,9 @@ #include <QFrame> -class QLineEdit; -class QTreeWidgetItem; +#include <ui/qt/geometry_state_dialog.h> +#include <ui/qt/uat_model.h> +#include <ui/qt/uat_delegate.h> namespace Ui { class FilterExpressionsPreferencesFrame; @@ -36,31 +37,29 @@ class FilterExpressionsPreferencesFrame : public QFrame Q_OBJECT public: - explicit FilterExpressionsPreferencesFrame(QWidget *parent = 0); + explicit FilterExpressionsPreferencesFrame(QWidget *parent = NULL); ~FilterExpressionsPreferencesFrame(); - void unstash(); + void setUat(struct epan_uat *uat); -protected: - void keyPressEvent(QKeyEvent *evt); + void acceptChanges(); + void rejectChanges(); private: Ui::FilterExpressionsPreferencesFrame *ui; - int cur_column_; - QLineEdit *cur_line_edit_; - QString saved_col_string_; + UatModel *uat_model_; + UatDelegate *uat_delegate_; + struct epan_uat *uat_; - void addExpression(bool enabled, const QString label, const QString expression); + void checkForErrorHint(const QModelIndex ¤t, const QModelIndex &previous); + bool trySetErrorHintFromField(const QModelIndex &index); + void addRecord(bool copy_from_current = false); private slots: - void updateWidgets(void); - void on_expressionTreeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); - void on_expressionTreeWidget_itemActivated(QTreeWidgetItem *item, int column); - void lineEditDestroyed(); - void labelEditingFinished(); - void expressionEditingFinished(); - void on_expressionTreeWidget_itemSelectionChanged(); + void modelDataChanged(const QModelIndex &topLeft); + void modelRowsRemoved(); + void viewCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous); void on_newToolButton_clicked(); void on_deleteToolButton_clicked(); void on_copyToolButton_clicked(); diff --git a/ui/qt/filter_expressions_preferences_frame.ui b/ui/qt/filter_expressions_preferences_frame.ui index b973d7d7ee..d7dbd288c4 100644 --- a/ui/qt/filter_expressions_preferences_frame.ui +++ b/ui/qt/filter_expressions_preferences_frame.ui @@ -17,75 +17,133 @@ <number>0</number> </property> <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QTreeWidget" name="expressionTreeWidget"> - <column> - <property name="text"> - <string>Enabled</string> - </property> - </column> - <column> - <property name="text"> - <string>Button Label</string> - </property> - </column> - <column> - <property name="text"> - <string>Filter Expression</string> - </property> - </column> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QToolButton" name="newToolButton"> - <property name="icon"> - <iconset resource="../../image/toolbar.qrc"> - <normaloff>:/stock/plus-8.png</normaloff>:/stock/plus-8.png</iconset> - </property> + <item> + <widget class="UatTreeView" name="uatTreeView"> + <column> + <property name="text"> + <string notr="true">1</string> + </property> + <property name="dragEnabled"> + <bool>false</bool> + </property> + </column> </widget> - </item> - <item> - <widget class="QToolButton" name="deleteToolButton"> - <property name="icon"> - <iconset resource="../../image/toolbar.qrc"> - <normaloff>:/stock/minus-8.png</normaloff>:/stock/minus-8.png</iconset> - </property> + </item> + <item> + <widget class="QLabel" name="hintLabel"> + <property name="styleSheet"> + <string notr="true">QLabel { color: red; }</string> + </property> + <property name="text"> + <string/> + </property> + <property name="textFormat"> + <set>Qt::RichText</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> </widget> - </item> - <item> - <widget class="QToolButton" name="copyToolButton"> - <property name="toolTip"> - <string>Copy this filter.</string> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset resource="../../image/toolbar.qrc"> - <normaloff>:/stock/copy-8.png</normaloff>:/stock/copy-8.png</iconset> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,1"> + <item> + <widget class="QToolButton" name="newToolButton"> + <property name="toolTip"> + <string>Create a new entry.</string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../../image/toolbar.qrc"> + <normaloff>:/stock/plus-8.png</normaloff>:/stock/plus-8.png + </iconset> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="deleteToolButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Remove this entry.</string> + </property> + <property name="icon"> + <iconset resource="../../image/toolbar.qrc"> + <normaloff>:/stock/minus-8.png</normaloff>:/stock/minus-8.png + </iconset> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="copyToolButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Copy this entry.</string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../../image/toolbar.qrc"> + <normaloff>:/stock/copy-8.png</normaloff>:/stock/copy-8.png + </iconset> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="ElidedLabel" name="pathLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="openExternalLinks"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> </layout> </widget> - <resources> + <customwidgets> + <customwidget> + <class>ElidedLabel</class> + <extends>QLabel</extends> + <header>elided_label.h</header> + </customwidget> + <customwidget> + <class>UatTreeView</class> + <extends>QTreeView</extends> + <header>uat_tree_view.h</header> + </customwidget> + </customwidgets> + <resources> <include location="../../image/toolbar.qrc"/> </resources> <connections/> diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 1849e63eb8..a3509219e6 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -296,6 +296,7 @@ public slots: void captureFileSaveStarted(const QString &file_path); void filterExpressionsChanged(); + static gboolean filter_expression_add_action(const void *key, void *value, void *user_data); void launchRLCGraph(bool channelKnown, guint16 ueid, guint8 rlcMode, guint16 channelType, guint16 channelId, guint8 direction); diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 51851e6caa..8f675926d9 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -894,9 +894,36 @@ void MainWindow::captureFileSaveStarted(const QString &file_path) main_ui_->statusBar->pushFileStatus(tr("Saving %1" UTF8_HORIZONTAL_ELLIPSIS).arg(file_info.baseName())); } +struct filter_expression_data +{ + MainWindow* window; + bool actions_added; +}; + +gboolean MainWindow::filter_expression_add_action(const void *key _U_, void *value, void *user_data) +{ + filter_expression_t* fe = (filter_expression_t*)value; + struct filter_expression_data* data = (filter_expression_data*)user_data; + + if (!fe->enabled) + return FALSE; + + QAction *dfb_action = new QAction(fe->label, data->window->filter_expression_toolbar_); + dfb_action->setToolTip(fe->expression); + dfb_action->setData(fe->expression); + dfb_action->setProperty(dfe_property_, true); + data->window->filter_expression_toolbar_->addAction(dfb_action); + connect(dfb_action, SIGNAL(data->window->triggered()), data->window, SLOT(data->window->displayFilterButtonClicked())); + data->actions_added = true; + return FALSE; +} + void MainWindow::filterExpressionsChanged() { - bool actions_added = false; + struct filter_expression_data data; + + data.window = this; + data.actions_added = false; // Recreate filter buttons foreach (QAction *act, filter_expression_toolbar_->actions()) { @@ -908,18 +935,9 @@ void MainWindow::filterExpressionsChanged() } // XXX Add a context menu for removing and changing buttons. - for (struct filter_expression *fe = *pfilter_expression_head; fe != NULL; fe = fe->next) { - if (!fe->enabled) continue; - QAction *dfb_action = new QAction(fe->label, filter_expression_toolbar_); - dfb_action->setToolTip(fe->expression); - dfb_action->setData(fe->expression); - dfb_action->setProperty(dfe_property_, true); - filter_expression_toolbar_->addAction(dfb_action); - connect(dfb_action, SIGNAL(triggered()), this, SLOT(displayFilterButtonClicked())); - actions_added = true; - } - - if (actions_added) { + filter_expression_iterate_expressions(filter_expression_add_action, &data); + + if (data.actions_added) { main_ui_->displayFilterToolBar->adjustSize(); } } diff --git a/ui/qt/preferences_dialog.cpp b/ui/qt/preferences_dialog.cpp index 26b4c62fcd..2c7f9b905a 100644 --- a/ui/qt/preferences_dialog.cpp +++ b/ui/qt/preferences_dialog.cpp @@ -438,6 +438,8 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : prefs_pane_to_item_[ppCapture] = pd_ui_->prefsTree->topLevelItem(1); prefs_pane_to_item_[ppFilterExpressions] = pd_ui_->prefsTree->topLevelItem(2); + pd_ui_->filterExpressonsFrame->setUat(uat_get_table_by_name("Display expressions")); + // Printing prefs don't apply here. module_t *print_module = prefs_find_module("print"); if (print_module) print_module->use_gui = FALSE; @@ -900,7 +902,7 @@ void PreferencesDialog::on_buttonBox_accepted() } pd_ui_->columnFrame->unstash(); - pd_ui_->filterExpressonsFrame->unstash(); + pd_ui_->filterExpressonsFrame->acceptChanges(); prefs_main_write(); if (save_decode_as_entries(&err) < 0) @@ -948,6 +950,12 @@ void PreferencesDialog::on_buttonBox_accepted() } } +void PreferencesDialog::on_buttonBox_rejected() +{ + //handle frames that don't have their own OK/Cancel "buttons" + pd_ui_->filterExpressonsFrame->rejectChanges(); +} + void PreferencesDialog::on_buttonBox_helpRequested() { wsApp->helpTopicAction(HELP_PREFERENCES_DIALOG); diff --git a/ui/qt/preferences_dialog.h b/ui/qt/preferences_dialog.h index 987cfcdee8..2f35471b3c 100644 --- a/ui/qt/preferences_dialog.h +++ b/ui/qt/preferences_dialog.h @@ -91,6 +91,7 @@ private slots: void on_advancedTree_itemActivated(QTreeWidgetItem *item, int column); void on_buttonBox_accepted(); + void on_buttonBox_rejected(); void on_buttonBox_helpRequested(); }; |