aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models/url_link_delegate.cpp
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/qt/models/url_link_delegate.cpp
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/qt/models/url_link_delegate.cpp')
-rw-r--r--ui/qt/models/url_link_delegate.cpp25
1 files changed, 24 insertions, 1 deletions
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);