diff options
author | Roland Knall <roland.knall@br-automation.com> | 2017-11-24 15:46:30 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-11-26 15:57:56 +0000 |
commit | d8658716277bbb2378819d25997ce0646b72c9c2 (patch) | |
tree | 1f4453fcc2a8a020c848ac98f7eac3e0cbdcdf58 /ui | |
parent | d35ed012ce62fae4344e80a0df3742619a4eaa0f (diff) |
Qt: About Dialog move to QTreeView and fix copy
- Fix an issue, where the url was opened twice on Linux
- Make the filter case insensitive if so wished for
- Allow the copy to either copy the selected column (just Copy) or copy the complete row, with tab separation
- Move to QTreeView instead to make it similar to the rest of the tables
Change-Id: Ie6064f2ad2014e24546553c5febe63358e2f69ec
Reviewed-on: https://code.wireshark.org/review/24570
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Jim Young <jim.young.ws@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/about_dialog.cpp | 126 | ||||
-rw-r--r-- | ui/qt/about_dialog.h | 3 | ||||
-rw-r--r-- | ui/qt/about_dialog.ui | 208 | ||||
-rw-r--r-- | ui/qt/models/astringlist_list_model.cpp | 100 | ||||
-rw-r--r-- | ui/qt/models/astringlist_list_model.h | 21 | ||||
-rw-r--r-- | ui/qt/models/url_link_delegate.cpp | 39 | ||||
-rw-r--r-- | ui/qt/models/url_link_delegate.h | 15 |
7 files changed, 277 insertions, 235 deletions
diff --git a/ui/qt/about_dialog.cpp b/ui/qt/about_dialog.cpp index 6cce925663..cd2c6ec536 100644 --- a/ui/qt/about_dialog.cpp +++ b/ui/qt/about_dialog.cpp @@ -61,6 +61,7 @@ #include <QDesktopServices> #include <QClipboard> #include <QMenu> +#include <QFileInfo> AuthorListModel::AuthorListModel(QObject * parent) : AStringListListModel(parent) @@ -78,16 +79,16 @@ AStringListListModel(parent) while (!ReadFile_authors.atEnd()) { QString line = ReadFile_authors.readLine(); - if ( ! readAck ) - { - if ( line.trimmed().length() == 0 ) - continue; - if ( line.startsWith("------") ) + if ( ! readAck && line.trimmed().length() == 0 ) continue; - } + if ( line.startsWith("------") ) + continue; if ( line.compare(QStringLiteral("Acknowledgements") ) == 0 ) + { readAck = true; + continue; + } else if ( rx.indexIn(line) != -1 ) appendRow( QStringList() << rx.cap(1).trimmed() << rx.cap(2).trimmed()); @@ -289,16 +290,17 @@ AboutDialog::AboutDialog(QWidget *parent) : AuthorListModel * authorModel = new AuthorListModel(this); AStringListListSortFilterProxyModel * proxyAuthorModel = new AStringListListSortFilterProxyModel(this); proxyAuthorModel->setSourceModel(authorModel); + proxyAuthorModel->setFilterCaseSensitivity(Qt::CaseInsensitive); proxyAuthorModel->setColumnToFilter(0); proxyAuthorModel->setColumnToFilter(1); ui->tblAuthors->setModel(proxyAuthorModel); + ui->tblAuthors->setRootIsDecorated(false); ui->pte_Authors->clear(); ui->pte_Authors->appendPlainText(authorModel->acknowledgment()); ui->pte_Authors->moveCursor(QTextCursor::Start); - ui->tblAuthors->horizontalHeader()->setStretchLastSection(true); ui->tblAuthors->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->tblAuthors, &QTableView::customContextMenuRequested, this, &AboutDialog::handleCopyMenu); + connect(ui->tblAuthors, &QTreeView::customContextMenuRequested, this, &AboutDialog::handleCopyMenu); connect(ui->searchAuthors, SIGNAL(textChanged(QString)), proxyAuthorModel, SLOT(setFilter(QString))); /* Wireshark tab */ @@ -332,13 +334,17 @@ AboutDialog::AboutDialog(QWidget *parent) : folderProxyModel->setSourceModel(folderModel); folderProxyModel->setColumnToFilter(1); folderProxyModel->setFilterType(AStringListListSortFilterProxyModel::FilterByStart); - ui->tblFolders->setModel(folderProxyModel); + AStringListListUrlProxyModel * folderDisplayModel = new AStringListListUrlProxyModel(this); + folderDisplayModel->setSourceModel(folderProxyModel); + folderDisplayModel->setUrlColumn(1); + ui->tblFolders->setModel(folderDisplayModel); + ui->tblFolders->setRootIsDecorated(false); ui->tblFolders->setItemDelegateForColumn(1, new UrlLinkDelegate(this)); ui->tblFolders->setItemDelegateForColumn(2, new HTMLTextDelegate(this)); ui->tblFolders->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->tblFolders, &QTableView::customContextMenuRequested, this, &AboutDialog::handleCopyMenu); + connect(ui->tblFolders, &QTreeView::customContextMenuRequested, this, &AboutDialog::handleCopyMenu); connect(ui->searchFolders, SIGNAL(textChanged(QString)), folderProxyModel, SLOT(setFilter(QString))); - connect(ui->tblFolders, &QTableView::clicked, this, &AboutDialog::urlClicked ); + connect(ui->tblFolders, &QTreeView::clicked, this, &AboutDialog::urlClicked ); /* Plugins */ @@ -352,13 +358,12 @@ AboutDialog::AboutDialog(QWidget *parent) : pluginTypeModel->setSourceModel(pluginFilterModel); pluginTypeModel->setColumnToFilter(2); ui->tblPlugins->setModel(pluginTypeModel); - ui->tblPlugins->setItemDelegateForColumn(3, new UrlLinkDelegate(this)); + ui->tblPlugins->setRootIsDecorated(false); ui->cmbType->addItems(pluginModel->typeNames()); ui->tblPlugins->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->tblPlugins, &QTableView::customContextMenuRequested, this, &AboutDialog::handleCopyMenu); + connect(ui->tblPlugins, &QTreeView::customContextMenuRequested, this, &AboutDialog::handleCopyMenu); connect(ui->searchPlugins, SIGNAL(textChanged(QString)), pluginFilterModel, SLOT(setFilter(QString))); connect(ui->cmbType, SIGNAL(currentIndexChanged(QString)), pluginTypeModel, SLOT(setFilter(QString))); - connect(ui->tblFolders, &QTableView::clicked, this, &AboutDialog::urlClicked ); #else ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tab_plugins)); @@ -368,15 +373,16 @@ AboutDialog::AboutDialog(QWidget *parent) : ShortcutListModel * shortcutModel = new ShortcutListModel(this); AStringListListSortFilterProxyModel * shortcutProxyModel = new AStringListListSortFilterProxyModel(this); shortcutProxyModel->setSourceModel(shortcutModel); + shortcutProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); shortcutProxyModel->setColumnToFilter(1); shortcutProxyModel->setColumnToFilter(2); ui->tblShortcuts->setModel(shortcutProxyModel); + ui->tblShortcuts->setRootIsDecorated(false); ui->tblShortcuts->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->tblShortcuts, &QTableView::customContextMenuRequested, this, &AboutDialog::handleCopyMenu); + connect(ui->tblShortcuts, &QTreeView::customContextMenuRequested, this, &AboutDialog::handleCopyMenu); connect(ui->searchShortcuts, SIGNAL(textChanged(QString)), shortcutProxyModel, SLOT(setFilter(QString))); /* License */ - #if defined(_WIN32) f_license.setFileName(get_datafile_path("COPYING.txt")); #else @@ -405,16 +411,16 @@ void AboutDialog::resizeEvent(QResizeEvent * event) foreach ( QWidget * tabPage, pages ) { - QList<QTableView *> childs = tabPage->findChildren<QTableView*>(); + QList<QTreeView *> childs = tabPage->findChildren<QTreeView*>(); if ( childs.count() == 0 ) continue; - QTableView * table = childs.at(0); + QTreeView * tree = childs.at(0); - int columnCount = table->model()->columnCount(); + int columnCount = tree->model()->columnCount(); for ( int cnt = 0; cnt < columnCount; cnt++ ) - table->setColumnWidth(cnt, tabPage->width() / columnCount); - table->horizontalHeader()->setStretchLastSection(true); + tree->setColumnWidth(cnt, tabPage->width() / columnCount); + tree->header()->setStretchLastSection(true); } QDialog::resizeEvent(event); @@ -422,7 +428,7 @@ void AboutDialog::resizeEvent(QResizeEvent * event) void AboutDialog::urlClicked(const QModelIndex &idx) { - QTableView * table = qobject_cast<QTableView *>(sender()); + QTreeView * table = qobject_cast<QTreeView *>(sender()); if ( ! table ) return; @@ -430,44 +436,70 @@ void AboutDialog::urlClicked(const QModelIndex &idx) if ( urlText.isEmpty() ) return; - QUrl url = QUrl(urlText, QUrl::StrictMode); - if ( url.isValid() ) - QDesktopServices::openUrl(url); + QFileInfo fi (urlText); + if ( fi.isDir() && fi.exists() ) + { + QUrl url = QUrl::fromLocalFile(urlText); + if ( url.isValid() ) + QDesktopServices::openUrl(url); + } } void AboutDialog::handleCopyMenu(QPoint pos) { - QTableView * table = qobject_cast<QTableView *>(sender()); - if ( ! table ) + QTreeView * tree = qobject_cast<QTreeView *>(sender()); + if ( ! tree ) return; - QModelIndex index = table->indexAt(pos); + QModelIndex index = tree->indexAt(pos); if ( ! index.isValid() ) return; - QAction * copyAction = new QAction("Copy to Clipboard", this); - copyAction->setData(VariantPointer<QTableView>::asQVariant(table)); - connect(copyAction, &QAction::triggered, this, &AboutDialog::copyActionTriggered); - QMenu * menu = new QMenu(this); - menu->addAction(copyAction); - menu->popup(table->viewport()->mapToGlobal(pos)); + + QAction * copyColumnAction = menu->addAction(tr("Copy")); + copyColumnAction->setData(VariantPointer<QTreeView>::asQVariant(tree)); + connect(copyColumnAction, &QAction::triggered, this, &AboutDialog::copyActionTriggered); + + QAction * copyRowAction = menu->addAction(tr("Copy Row(s)")); + copyRowAction->setData(VariantPointer<QTreeView>::asQVariant(tree)); + connect(copyRowAction, &QAction::triggered, this, &AboutDialog::copyRowActionTriggered); + + menu->popup(tree->viewport()->mapToGlobal(pos)); +} + +void AboutDialog::copyRowActionTriggered() +{ + copyActionTriggered(true); } -void AboutDialog::copyActionTriggered() +void AboutDialog::copyActionTriggered(bool copyRow) { QAction * sendingAction = qobject_cast<QAction *>(sender()); if ( ! sendingAction ) return; - QTableView * table = VariantPointer<QTableView>::asPtr(sendingAction->data()); + QTreeView * tree = VariantPointer<QTreeView>::asPtr(sendingAction->data()); - QModelIndexList selIndeces = table->selectionModel()->selectedIndexes(); + QModelIndexList selIndeces = tree->selectionModel()->selectedIndexes(); + + int copyColumn = -1; + if ( ! copyRow ) + { + QMenu * menu = qobject_cast<QMenu *>(sendingAction->parentWidget()); + if ( menu ) + { + QPoint menuPosOnTable = tree->mapFromGlobal(menu->pos()); + QModelIndex clickedIndex = tree->indexAt(menuPosOnTable); + if ( clickedIndex.isValid() ) + copyColumn = clickedIndex.column(); + } + } QString clipdata; if ( selIndeces.count() > 0 ) { - int columnCount = table->model()->columnCount(); + int columnCount = tree->model()->columnCount(); QList<int> visitedRows; foreach(QModelIndex index, selIndeces) @@ -476,11 +508,23 @@ void AboutDialog::copyActionTriggered() continue; QStringList row; - for ( int cnt = 0; cnt < columnCount; cnt++ ) + if ( copyRow ) + { + for ( int cnt = 0; cnt < columnCount; cnt++ ) + { + QModelIndex dataIdx = tree->model()->index(index.row(), cnt); + row << tree->model()->data(dataIdx).toString(); + } + } + else { - QModelIndex dataIdx = table->model()->index(index.row(), cnt); - row << table->model()->data(dataIdx).toString(); + if ( copyColumn < 0 ) + copyColumn = index.column(); + + QModelIndex dataIdx = tree->model()->index(index.row(), copyColumn); + row << tree->model()->data(dataIdx).toString(); } + clipdata.append(row.join("\t\t").append("\n")); visitedRows << index.row(); diff --git a/ui/qt/about_dialog.h b/ui/qt/about_dialog.h index f2c65758e2..7aed3e2d57 100644 --- a/ui/qt/about_dialog.h +++ b/ui/qt/about_dialog.h @@ -95,7 +95,8 @@ private: private slots: void urlClicked(const QModelIndex &); void handleCopyMenu(QPoint); - void copyActionTriggered(); + void copyActionTriggered(bool row = false); + void copyRowActionTriggered(); }; diff --git a/ui/qt/about_dialog.ui b/ui/qt/about_dialog.ui index 8d029382f6..ef45c43755 100644 --- a/ui/qt/about_dialog.ui +++ b/ui/qt/about_dialog.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>740</width> - <height>600</height> + <height>610</height> </rect> </property> <property name="windowTitle"> @@ -35,119 +35,42 @@ <attribute name="title"> <string>Wireshark</string> </attribute> - <layout class="QVBoxLayout" name="verticalLayout_7"> + <layout class="QVBoxLayout" name="verticalLayout"> <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>38</height> - </size> - </property> - </spacer> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QLabel" name="label_logo"> - <property name="text"> - <string/> - </property> - <property name="pixmap"> - <pixmap resource="../../image/about.qrc">:/about/wssplash.png</pixmap> - </property> - <property name="scaledContents"> - <bool>false</bool> - </property> - <property name="alignment"> - <set>Qt::AlignHCenter|Qt::AlignTop</set> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_title"> - <property name="text"> - <string><span size=\"x-large\" weight=\"bold\">Network Protocol Analyzer</span></string> - </property> - <property name="alignment"> - <set>Qt::AlignCenter</set> - </property> - </widget> - </item> - </layout> - </item> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>48</height> - </size> - </property> - </spacer> - </item> - </layout> + <widget class="QLabel" name="label_logo"> + <property name="text"> + <string/> + </property> + <property name="pixmap"> + <pixmap resource="../../image/about.qrc">:/about/wssplash.png</pixmap> + </property> + <property name="scaledContents"> + <bool>false</bool> + </property> + <property name="alignment"> + <set>Qt::AlignHCenter|Qt::AlignTop</set> + </property> + </widget> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <spacer name="horizontalSpacer_3"> - <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="QLabel" name="label_wireshark"> - <property name="text"> - <string/> - </property> - <property name="scaledContents"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_4"> - <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> + <widget class="QLabel" name="label_title"> + <property name="text"> + <string><span size=\"x-large\" weight=\"bold\">Network Protocol Analyzer</span></string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> </item> <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> + <widget class="QLabel" name="label_wireshark"> + <property name="text"> + <string/> </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>357</height> - </size> + <property name="scaledContents"> + <bool>true</bool> </property> - </spacer> + </widget> </item> </layout> </widget> @@ -164,17 +87,22 @@ </widget> </item> <item> - <widget class="QTableView" name="tblAuthors"> + <widget class="QTreeView" name="tblAuthors"> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ContiguousSelection</enum> + </property> <property name="selectionBehavior"> <enum>QAbstractItemView::SelectRows</enum> </property> - </widget> - </item> - <item> - <widget class="QPlainTextEdit" name="pte_Authors"> - <property name="readOnly"> + <attribute name="headerMinimumSectionSize"> + <number>100</number> + </attribute> + <attribute name="headerStretchLastSection"> <bool>true</bool> - </property> + </attribute> </widget> </item> </layout> @@ -192,7 +120,13 @@ </widget> </item> <item> - <widget class="QTableView" name="tblFolders"> + <widget class="QTreeView" name="tblFolders"> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ContiguousSelection</enum> + </property> <property name="selectionBehavior"> <enum>QAbstractItemView::SelectRows</enum> </property> @@ -246,7 +180,13 @@ </layout> </item> <item> - <widget class="QTableView" name="tblPlugins"> + <widget class="QTreeView" name="tblPlugins"> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ContiguousSelection</enum> + </property> <property name="selectionBehavior"> <enum>QAbstractItemView::SelectRows</enum> </property> @@ -267,10 +207,36 @@ </widget> </item> <item> - <widget class="QTableView" name="tblShortcuts"> + <widget class="QTreeView" name="tblShortcuts"> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ContiguousSelection</enum> + </property> <property name="selectionBehavior"> <enum>QAbstractItemView::SelectRows</enum> </property> + <property name="textElideMode"> + <enum>Qt::ElideNone</enum> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab_3"> + <attribute name="title"> + <string>Acknowledgments</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_8"> + <item> + <widget class="QPlainTextEdit" name="pte_Authors"> + <property name="readOnly"> + <bool>true</bool> + </property> </widget> </item> </layout> @@ -314,8 +280,8 @@ <slot>accept()</slot> <hints> <hint type="sourcelabel"> - <x>248</x> - <y>254</y> + <x>254</x> + <y>595</y> </hint> <hint type="destinationlabel"> <x>157</x> @@ -330,8 +296,8 @@ <slot>reject()</slot> <hints> <hint type="sourcelabel"> - <x>316</x> - <y>260</y> + <x>322</x> + <y>595</y> </hint> <hint type="destinationlabel"> <x>286</x> diff --git a/ui/qt/models/astringlist_list_model.cpp b/ui/qt/models/astringlist_list_model.cpp index 61c6a6e39a..8da5a3b0a4 100644 --- a/ui/qt/models/astringlist_list_model.cpp +++ b/ui/qt/models/astringlist_list_model.cpp @@ -9,11 +9,14 @@ #include <QSortFilterProxyModel> #include <QStringList> +#include <QPalette> +#include <QApplication> +#include <QBrush> #include <ui/qt/models/astringlist_list_model.h> AStringListListModel::AStringListListModel(QObject * parent): - QAbstractItemModel(parent) +QAbstractTableModel(parent) {} AStringListListModel::~AStringListListModel() { modelData.clear(); } @@ -57,34 +60,20 @@ QVariant AStringListListModel::headerData(int section, Qt::Orientation orientati QVariant AStringListListModel::data(const QModelIndex &index, int role) const { - if ( role != Qt::DisplayRole || ! index.isValid() || index.row() >= rowCount() ) + if ( ! index.isValid() || index.row() >= rowCount() ) return QVariant(); - QStringList data = modelData.at(index.row()); + if ( role == Qt::DisplayRole ) + { + QStringList data = modelData.at(index.row()); - if ( index.column() < columnCount() ) - return qVariantFromValue(data.at(index.column())); + if ( index.column() < columnCount() ) + return qVariantFromValue(data.at(index.column())); + } return QVariant(); } -QModelIndex AStringListListModel::index(int row, int column, const QModelIndex & parent) const -{ - Q_UNUSED(parent); - - if ( row >= rowCount() || column >= columnCount() ) - return QModelIndex(); - - return createIndex(row, column); -} - -QModelIndex AStringListListModel::parent(const QModelIndex & parent) const -{ - Q_UNUSED(parent); - - return QModelIndex(); -} - AStringListListSortFilterProxyModel::AStringListListSortFilterProxyModel(QObject * parent) : QSortFilterProxyModel(parent) { @@ -97,7 +86,7 @@ bool AStringListListSortFilterProxyModel::lessThan(const QModelIndex &left, cons QString leftData = sourceModel()->data(left).toStringList().join(","); QString rightData = sourceModel()->data(right).toStringList().join(","); - return QString::localeAwareCompare(leftData, rightData) < 0; + return leftData.compare(rightData, sortCaseSensitivity()) < 0; } void AStringListListSortFilterProxyModel::setFilter(const QString & filter) @@ -106,10 +95,18 @@ void AStringListListSortFilterProxyModel::setFilter(const QString & filter) invalidateFilter(); } -bool AStringListListSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +static bool AContainsB(const QString &a, const QString &b, Qt::CaseSensitivity cs) { - bool check = false; + return a.contains(b, cs); +} + +static bool AStartsWithB(const QString &a, const QString &b, Qt::CaseSensitivity cs) +{ + return a.startsWith(b, cs); +} +bool AStringListListSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ if ( columnsToFilter_.count() == 0 ) return true; @@ -119,16 +116,18 @@ bool AStringListListSortFilterProxyModel::filterAcceptsRow(int sourceRow, const continue; QModelIndex chkIdx = sourceModel()->index(sourceRow, column, sourceParent); - if ( type_ == FilterByContains && sourceModel()->data(chkIdx).toString().contains(filter_) ) - check = true; - else if ( type_ == FilterByStart && sourceModel()->data(chkIdx).toString().startsWith(filter_) ) - check = true; + QString dataString = sourceModel()->data(chkIdx).toString(); + + /* Default is filter by string a contains string b */ + bool (*compareFunc)(const QString&, const QString&, Qt::CaseSensitivity) = AContainsB; + if ( type_ == FilterByStart ) + compareFunc = AStartsWithB; - if ( check ) - break; + if ( compareFunc(dataString, filter_, filterCaseSensitivity()) ) + return true; } - return check; + return false; } void AStringListListSortFilterProxyModel::setFilterType(AStringListListFilterType type) @@ -155,6 +154,43 @@ void AStringListListSortFilterProxyModel::clearColumnsToFilter() invalidateFilter(); } +AStringListListUrlProxyModel::AStringListListUrlProxyModel(QObject * parent): + QIdentityProxyModel(parent) +{} + +void AStringListListUrlProxyModel::setUrlColumn(int column) +{ + if ( column < columnCount() && ! urls_.contains(column) ) + urls_ << column; +} + +bool AStringListListUrlProxyModel::isUrlColumn(int column) const +{ + return urls_.contains(column); +} + +QVariant AStringListListUrlProxyModel::data(const QModelIndex &index, int role) const +{ + QVariant result = QIdentityProxyModel::data(index, role); + + if ( urls_.contains(index.column()) ) + { + if ( Qt::ForegroundRole ) + { + if ( result.canConvert(QVariant::Brush) ) + { + QBrush selected = result.value<QBrush>(); + selected.setColor(QApplication::palette().link().color()); + return selected; + } + } else if ( Qt::TextColorRole ) { + return QApplication::palette().link().color(); + } + } + + return result; +} + /* * Editor modelines * diff --git a/ui/qt/models/astringlist_list_model.h b/ui/qt/models/astringlist_list_model.h index 12250b1d45..a7459cdfe5 100644 --- a/ui/qt/models/astringlist_list_model.h +++ b/ui/qt/models/astringlist_list_model.h @@ -12,13 +12,14 @@ #include <config.h> -#include <QAbstractItemModel> +#include <QAbstractTableModel> #include <QModelIndex> #include <QList> #include <QStringList> #include <QSortFilterProxyModel> +#include <QIdentityProxyModel> -class AStringListListModel : public QAbstractItemModel +class AStringListListModel : public QAbstractTableModel { Q_OBJECT @@ -31,9 +32,6 @@ public: virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; - virtual QModelIndex parent(const QModelIndex & parent = QModelIndex()) const; - protected: virtual void appendRow(const QStringList &, const QModelIndex &parent = QModelIndex()); @@ -74,7 +72,20 @@ private: QList<int> columnsToFilter_; }; +class AStringListListUrlProxyModel : public QIdentityProxyModel +{ + Q_OBJECT +public: + explicit AStringListListUrlProxyModel(QObject * parent = Q_NULLPTR); + + void setUrlColumn(int); + bool isUrlColumn(int) const; + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + +private: + QList<int> urls_; +}; #endif // ASTRINGLIST_LIST_MODEL_H diff --git a/ui/qt/models/url_link_delegate.cpp b/ui/qt/models/url_link_delegate.cpp index a058a883d1..503a606100 100644 --- a/ui/qt/models/url_link_delegate.cpp +++ b/ui/qt/models/url_link_delegate.cpp @@ -1,4 +1,4 @@ -/* url_link.cpp +/* url_link_delegate.cpp * Delegates for displaying links as links, including elide model * * Wireshark - Network traffic analyzer @@ -28,41 +28,16 @@ void UrlLinkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio QStyleOptionViewItem options = option; initStyleOption(&options, index); - QString text = options.text; - if (text.isEmpty()) - return; + QStyleOptionViewItem opt = option; + initStyleOption(&opt, index); - int one_em = option.fontMetrics.height(); - QString short_dir = option.fontMetrics.elidedText(text, Qt::ElideMiddle, one_em * 10); + opt.font.setUnderline(true); - painter->save(); - QFont font = option.font; - font.setUnderline(true); - painter->setFont(font); - painter->setPen(option.palette.link().color()); - painter->drawText(option.rect, Qt::AlignLeft | Qt::AlignVCenter, short_dir); - - painter->restore(); -} - -QSize UrlLinkDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - QStyleOptionViewItem options = option; - initStyleOption(&options, index); - - QString text = options.text; - if (text.isEmpty()) - return QStyledItemDelegate::sizeHint(option, index); - - int one_em = option.fontMetrics.height(); - QString short_dir = option.fontMetrics.elidedText(text, Qt::ElideMiddle, one_em * 10); - - QTextDocument doc; - doc.setHtml(short_dir); - doc.setTextWidth(options.rect.width()); - return QSize(doc.idealWidth(), doc.size().height()); + QStyledItemDelegate::paint(painter, opt, index); } -/* * Editor modelines +/* + * Editor modelines * * Local Variables: * c-basic-offset: 4 diff --git a/ui/qt/models/url_link_delegate.h b/ui/qt/models/url_link_delegate.h index 3977fbfe43..9bd0542133 100644 --- a/ui/qt/models/url_link_delegate.h +++ b/ui/qt/models/url_link_delegate.h @@ -28,8 +28,17 @@ public: protected: void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; - - }; #endif // URL_LINK_DELEGATE_H + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + */ |