aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-01-31 12:03:49 -0800
committerStig Bjørlykke <stig@bjorlykke.org>2018-02-01 18:11:22 +0000
commit142c03516ec93948ad30191730ace09baa57aa8d (patch)
tree3df285de9061ca052eadaa1f734f62ae1618a7a6 /ui
parentd1b1575f6d1e0f922aead77b2933f9be55d1107b (diff)
Qt: Show Lua scripts as links in the about box.
Add UrlLinkDelegate::setColCheck, which lets you render strings as URLs or plain text according to a regex. Use it to show Lua scripts as URLs in the about box. Open links on double clicks and add column checks. Change-Id: Iaf5cd8a46a0b66a7d45079ba045ed2bbcb0ed005 Reviewed-on: https://code.wireshark.org/review/25542 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/about_dialog.cpp25
-rw-r--r--ui/qt/about_dialog.h2
-rw-r--r--ui/qt/models/url_link_delegate.cpp25
-rw-r--r--ui/qt/models/url_link_delegate.h13
4 files changed, 49 insertions, 16 deletions
diff --git a/ui/qt/about_dialog.cpp b/ui/qt/about_dialog.cpp
index 9e9cae5ef1..3e7725128b 100644
--- a/ui/qt/about_dialog.cpp
+++ b/ui/qt/about_dialog.cpp
@@ -150,15 +150,8 @@ PluginListModel::PluginListModel(QObject * parent) : AStringListListModel(parent
foreach(QStringList row, plugin_data)
{
QString type_name = row.at(2);
- QString tooltip;
typeNames_ << type_name;
-
-#ifdef HAVE_LUA
- if (type_name == wslua_plugin_type_name()) {
- tooltip = tr("Double-click to edit");
- }
-#endif
- appendRow(row, tooltip);
+ appendRow(row);
}
typeNames_.sort();
@@ -347,7 +340,7 @@ AboutDialog::AboutDialog(QWidget *parent) :
ui->tblFolders->setTextElideMode(Qt::ElideMiddle);
connect(ui->tblFolders, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(handleCopyMenu(QPoint)));
connect(ui->searchFolders, SIGNAL(textChanged(QString)), folderProxyModel, SLOT(setFilter(QString)));
- connect(ui->tblFolders, SIGNAL(clicked(QModelIndex)), this, SLOT(urlClicked(QModelIndex)));
+ connect(ui->tblFolders, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(urlDoubleClicked(QModelIndex)));
/* Plugins */
@@ -361,6 +354,10 @@ AboutDialog::AboutDialog(QWidget *parent) :
pluginTypeModel->setColumnToFilter(2);
ui->tblPlugins->setModel(pluginTypeModel);
ui->tblPlugins->setRootIsDecorated(false);
+ UrlLinkDelegate *plugin_delegate = new UrlLinkDelegate(this);
+ QString pattern = QString("^%1$").arg(wslua_plugin_type_name());
+ plugin_delegate->setColCheck(2, pattern);
+ ui->tblPlugins->setItemDelegateForColumn(3, plugin_delegate);
ui->cmbType->addItems(pluginModel->typeNames());
ui->tblPlugins->setContextMenuPolicy(Qt::CustomContextMenu);
ui->tblPlugins->setTextElideMode(Qt::ElideMiddle);
@@ -442,8 +439,11 @@ void AboutDialog::showEvent(QShowEvent * event)
QDialog::showEvent(event);
}
-void AboutDialog::urlClicked(const QModelIndex &idx)
+void AboutDialog::urlDoubleClicked(const QModelIndex &idx)
{
+ if (idx.column() != 1) {
+ return;
+ }
QTreeView * table = qobject_cast<QTreeView *>(sender());
if ( ! table )
return;
@@ -553,9 +553,12 @@ void AboutDialog::copyActionTriggered(bool copyRow)
#ifdef HAVE_LUA
void AboutDialog::on_tblPlugins_doubleClicked(const QModelIndex &index)
{
- const int row = index.row();
const int type_col = 2;
const int path_col = 3;
+ if (index.column() != path_col) {
+ return;
+ }
+ const int row = index.row();
const QAbstractItemModel *model = index.model();
if (model->index(row, type_col).data().toString() == wslua_plugin_type_name()) {
QDesktopServices::openUrl(QUrl::fromLocalFile(model->index(row, path_col).data().toString()));
diff --git a/ui/qt/about_dialog.h b/ui/qt/about_dialog.h
index 353926bc77..ec1f2450cd 100644
--- a/ui/qt/about_dialog.h
+++ b/ui/qt/about_dialog.h
@@ -93,7 +93,7 @@ private:
Ui::AboutDialog *ui;
private slots:
- void urlClicked(const QModelIndex &);
+ void urlDoubleClicked(const QModelIndex &);
void handleCopyMenu(QPoint);
void copyActionTriggered(bool row = false);
void copyRowActionTriggered();
diff --git a/ui/qt/models/url_link_delegate.cpp b/ui/qt/models/url_link_delegate.cpp
index 14d05daac1..205a35921a 100644
--- a/ui/qt/models/url_link_delegate.cpp
+++ b/ui/qt/models/url_link_delegate.cpp
@@ -11,12 +11,35 @@
#include <ui/qt/models/url_link_delegate.h>
#include <QPainter>
+#include <QRegExp>
UrlLinkDelegate::UrlLinkDelegate(QObject *parent)
- : QStyledItemDelegate(parent)
+ : QStyledItemDelegate(parent),
+ re_col_(-1),
+ url_re_(new QRegExp())
{}
+UrlLinkDelegate::~UrlLinkDelegate()
+{
+ delete url_re_;
+}
+
+void UrlLinkDelegate::setColCheck(int column, QString &pattern)
+{
+ re_col_ = column;
+ url_re_->setPattern(pattern);
+}
+
void UrlLinkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
+ if (re_col_ >= 0 && url_re_) {
+ QModelIndex re_idx = index.model()->index(index.row(), re_col_);
+ QString col_text = index.model()->data(re_idx).toString();
+ if (url_re_->indexIn(col_text) < 0) {
+ QStyledItemDelegate::paint(painter, option, index);
+ return;
+ }
+ }
+
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
diff --git a/ui/qt/models/url_link_delegate.h b/ui/qt/models/url_link_delegate.h
index fa1a20bd6c..c35a611d18 100644
--- a/ui/qt/models/url_link_delegate.h
+++ b/ui/qt/models/url_link_delegate.h
@@ -11,12 +11,11 @@
#ifndef URL_LINK_DELEGATE_H
#define URL_LINK_DELEGATE_H
-#include <config.h>
-
#include <QStyledItemDelegate>
#include <QStyleOptionViewItem>
#include <QModelIndex>
-#include <QAbstractItemModel>
+
+class QRegExp;
class UrlLinkDelegate : public QStyledItemDelegate
{
@@ -24,9 +23,17 @@ class UrlLinkDelegate : public QStyledItemDelegate
public:
explicit UrlLinkDelegate(QObject *parent = Q_NULLPTR);
+ ~UrlLinkDelegate();
+ // If pattern matches the string in column, render as a URL.
+ // Otherwise render as plain text.
+ void setColCheck(int column, QString &pattern);
protected:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
+
+private:
+ int re_col_;
+ QRegExp *url_re_;
};
#endif // URL_LINK_DELEGATE_H