diff options
Diffstat (limited to 'ui/qt/widgets/profile_tree_view.cpp')
-rw-r--r-- | ui/qt/widgets/profile_tree_view.cpp | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/ui/qt/widgets/profile_tree_view.cpp b/ui/qt/widgets/profile_tree_view.cpp index afa86d71..ebac67c7 100644 --- a/ui/qt/widgets/profile_tree_view.cpp +++ b/ui/qt/widgets/profile_tree_view.cpp @@ -7,31 +7,28 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#include <ui/qt/models/url_link_delegate.h> #include <ui/qt/models/profile_model.h> #include <ui/qt/utils/qt_ui_utils.h> +#include <ui/qt/widgets/display_filter_edit.h> #include <ui/qt/widgets/profile_tree_view.h> #include <QDesktopServices> #include <QDir> +#include <QHeaderView> #include <QItemDelegate> #include <QLineEdit> -#include <QUrl> -ProfileUrlLinkDelegate::ProfileUrlLinkDelegate(QObject *parent) : UrlLinkDelegate (parent) {} +ProfileTreeEditDelegate::ProfileTreeEditDelegate(QWidget *parent) : QItemDelegate(parent), editor_(Q_NULLPTR) {} -void ProfileUrlLinkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +QWidget *ProfileTreeEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const { - /* Only paint links for valid paths */ - if (index.data(ProfileModel::DATA_PATH_IS_NOT_DESCRIPTION).toBool()) - UrlLinkDelegate::paint(painter, option, index); - else - QStyledItemDelegate::paint(painter, option, index); - + if (index.column() == ProfileModel::COL_AUTO_SWITCH_FILTER) { + return new DisplayFilterEdit(parent); + } + return QItemDelegate::createEditor(parent, option, index); } -ProfileTreeEditDelegate::ProfileTreeEditDelegate(QWidget *parent) : QItemDelegate(parent), editor_(Q_NULLPTR) {} - void ProfileTreeEditDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (qobject_cast<QLineEdit *>(editor)) @@ -46,8 +43,8 @@ ProfileTreeView::ProfileTreeView(QWidget *parent) : { delegate_ = new ProfileTreeEditDelegate(); setItemDelegateForColumn(ProfileModel::COL_NAME, delegate_); + setItemDelegateForColumn(ProfileModel::COL_AUTO_SWITCH_FILTER, delegate_); - connect(this, &QAbstractItemView::clicked, this, &ProfileTreeView::clicked); connect(delegate_, &ProfileTreeEditDelegate::commitData, this, &ProfileTreeView::itemUpdated); } @@ -80,19 +77,6 @@ void ProfileTreeView::selectionChanged(const QItemSelection &selected, const QIt } } -void ProfileTreeView::clicked(const QModelIndex &index) -{ - if (!index.isValid()) - return; - - /* Only paint links for valid paths */ - if (index.data(ProfileModel::DATA_INDEX_VALUE_IS_URL).toBool()) - { - QString path = QDir::toNativeSeparators(index.data().toString()); - QDesktopServices::openUrl(QUrl::fromLocalFile(path)); - } -} - void ProfileTreeView::selectRow(int row) { if (row < 0) @@ -117,3 +101,30 @@ bool ProfileTreeView::activeEdit() { return (state() == QAbstractItemView::EditingState); } + +// If our auto switch filters are shorter than the filter column title, +// stretch the name column. +void ProfileTreeView::showEvent(QShowEvent *) +{ + bool have_wide_filter = false; + int auto_switch_title_width = fontMetrics().horizontalAdvance(model()->headerData(ProfileModel::COL_AUTO_SWITCH_FILTER, Qt::Horizontal).toString()); + for (int row = 0; row < model()->rowCount(); row++) { + QString filter = model()->data(model()->index(row, ProfileModel::COL_AUTO_SWITCH_FILTER)).toString(); + if (fontMetrics().horizontalAdvance(filter) > auto_switch_title_width) { + have_wide_filter = true; + break; + } + } + + if (have_wide_filter) { + return; + } + + int col_name_size_hint = sizeHintForColumn(ProfileModel::COL_NAME); + int col_asf_size_hint = qMax(header()->sectionSizeHint(ProfileModel::COL_AUTO_SWITCH_FILTER), sizeHintForColumn(ProfileModel::COL_AUTO_SWITCH_FILTER)); + int extra = columnWidth(ProfileModel::COL_AUTO_SWITCH_FILTER) - col_asf_size_hint; + if (extra > 0) { + setColumnWidth(ProfileModel::COL_NAME, col_name_size_hint + extra); + } + +} |