From fdea8e6b144ba376eac917f5a267ad3208d917b6 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Mon, 28 Dec 2020 20:09:27 +0800 Subject: [PATCH] feat(searchList): Clear selection of other lists when select a row. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 当选中某一行时,取消其他列表项的选中 Log: 当选中某一行时,取消其他列表项的选中 --- control/search-list-view.h | 2 ++ src/content-widget.cpp | 23 ++++++++++++++++++++++- src/content-widget.h | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/control/search-list-view.h b/control/search-list-view.h index 665ef48..46a42c4 100644 --- a/control/search-list-view.h +++ b/control/search-list-view.h @@ -23,6 +23,8 @@ public: int getCurrentType(); static int getResType(const QString&); + bool is_current_list = false; + private: SearchItemModel * m_model = nullptr; SearchItem * m_item = nullptr; diff --git a/src/content-widget.cpp b/src/content-widget.cpp index cd33649..336fdef 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -1,6 +1,7 @@ #include "content-widget.h" #include #include +#include ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent) { @@ -158,6 +159,16 @@ void ContentWidget::refreshSearchList(const QVector& types, const QVectorsetupWidget(type, path); + searchList->is_current_list = true; + Q_EMIT this->currentItemChanged(); + searchList->is_current_list = false; + }); + connect(this, &ContentWidget::currentItemChanged, searchList, [ = ]() { + if (! searchList->is_current_list) { + searchList->blockSignals(true); + searchList->clearSelection(); + searchList->blockSignals(false); + } }); } @@ -173,10 +184,20 @@ void ContentWidget::refreshSearchList(const QVector& types, const QVectorinsertWidget(0, searchList); m_listLyt->insertWidget(0, titleLabel); m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height()); - searchList->setCurrentIndex(searchList->model()->index(0,1, QModelIndex())); + searchList->setCurrentIndex(searchList->model()->index(0, 0, QModelIndex())); m_detailView->setupWidget(searchList->getCurrentType(), bestList.at(0)); connect(searchList, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) { m_detailView->setupWidget(type, path); + searchList->is_current_list = true; + Q_EMIT this->currentItemChanged(); + searchList->is_current_list = false; + }); + connect(this, &ContentWidget::currentItemChanged, searchList, [ = ]() { + if (! searchList->is_current_list) { + searchList->blockSignals(true); + searchList->clearSelection(); + searchList->blockSignals(false); + } }); } diff --git a/src/content-widget.h b/src/content-widget.h index 1edb645..cb70f51 100644 --- a/src/content-widget.h +++ b/src/content-widget.h @@ -38,6 +38,9 @@ private: QString getTitleName(const int&); +Q_SIGNALS: + void currentItemChanged(); + private Q_SLOTS: void clearSearchList(); };