fix(frontend): Two list items can be selected simultaneously.

Description: 修复可以同时选中两个列表项的bug

Log: 修复可以同时选中两个列表项的bug
Bug: http://172.17.66.192/biz/bug-view-40056.html
This commit is contained in:
zhangjiaping 2021-02-26 11:42:40 +08:00
parent 067bc79234
commit 25c18aa4f0
2 changed files with 4 additions and 1 deletions

View File

@ -47,6 +47,7 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const
m_type = type; m_type = type;
connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, [ = ]() { connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, [ = ]() {
Q_EMIT this->currentRowChanged(getCurrentType(), m_item->m_pathlist.at(this->currentIndex().row())); Q_EMIT this->currentRowChanged(getCurrentType(), m_item->m_pathlist.at(this->currentIndex().row()));
m_isSelected = true;
}); });
} }
@ -78,7 +79,7 @@ void SearchListView::setList(QStringList list)
{ {
QModelIndex index = this->currentIndex(); QModelIndex index = this->currentIndex();
m_model->setList(list); m_model->setList(list);
if (index.row() >= 0 && index.row() < list.length()) { if (index.row() >= 0 && index.row() < list.length() && m_isSelected) {
this->blockSignals(true); this->blockSignals(true);
this->setCurrentIndex(index); this->setCurrentIndex(index);
this->blockSignals(false); this->blockSignals(false);
@ -184,4 +185,5 @@ int SearchListView::getResType(const QString& path) {
*/ */
void SearchListView::clearSelection() { void SearchListView::clearSelection() {
this->selectionModel()->clearSelection(); this->selectionModel()->clearSelection();
m_isSelected = false;
} }

View File

@ -61,6 +61,7 @@ public:
private: private:
SearchItemModel * m_model = nullptr; SearchItemModel * m_model = nullptr;
SearchItem * m_item = nullptr; SearchItem * m_item = nullptr;
bool m_isSelected = false;
HighlightItemDelegate * m_styleDelegate = nullptr; HighlightItemDelegate * m_styleDelegate = nullptr;