diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-01-31 12:03:49 -0800 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2018-02-01 18:11:22 +0000 |
commit | 142c03516ec93948ad30191730ace09baa57aa8d (patch) | |
tree | 3df285de9061ca052eadaa1f734f62ae1618a7a6 /ui/qt/models | |
parent | d1b1575f6d1e0f922aead77b2933f9be55d1107b (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')
-rw-r--r-- | ui/qt/models/url_link_delegate.cpp | 25 | ||||
-rw-r--r-- | ui/qt/models/url_link_delegate.h | 13 |
2 files changed, 34 insertions, 4 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); 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 |