From 03adffe2f38e497ea6a8207b17804dd8e92972db Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Mon, 24 Jun 2024 20:48:15 +0800 Subject: [PATCH] opt: headword dialog ,limited filter number --- src/headwordsmodel.cc | 4 ++-- src/ui/dictheadwords.cc | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/headwordsmodel.cc b/src/headwordsmodel.cc index ae2bdafe73..64873c90c5 100644 --- a/src/headwordsmodel.cc +++ b/src/headwordsmodel.cc @@ -102,9 +102,9 @@ void HeadwordListModel::requestFinished() return; } beginResetModel(); - words.clear(); - words << filterWords; + words = QStringList( filterWords ); endResetModel(); + emit numberPopulated( words.size() ); } } diff --git a/src/ui/dictheadwords.cc b/src/ui/dictheadwords.cc index b99a390e4d..c389baeb57 100644 --- a/src/ui/dictheadwords.cc +++ b/src/ui/dictheadwords.cc @@ -109,10 +109,6 @@ DictHeadwords::DictHeadwords( QWidget * parent, Config::Class & cfg_, Dictionary connect( ui.headersListView, &QAbstractItemView::clicked, this, &DictHeadwords::itemClicked ); - connect( proxy, &QAbstractItemModel::dataChanged, this, &DictHeadwords::showHeadwordsNumber ); - connect( ui.filterMaxResult, &QSpinBox::valueChanged, this, [ this ]( int _value ) { - model->setMaxFilterResults( _value ); - } ); ui.headersListView->installEventFilter( this ); @@ -136,6 +132,7 @@ void DictHeadwords::setup( Dictionary::Class * dict_ ) const auto size = dict->getWordCount(); std::shared_ptr< HeadwordListModel > other = std::make_shared< HeadwordListModel >(); model.swap( other ); + model->setMaxFilterResults( ui.filterMaxResult->value() ); model->setDict( dict ); proxy->setSourceModel( model.get() ); proxy->sort( 0 ); @@ -155,6 +152,13 @@ void DictHeadwords::setup( Dictionary::Class * dict_ ) dictId = QString( dict->getId().c_str() ); QApplication::restoreOverrideCursor(); + connect( model.get(), &HeadwordListModel::numberPopulated, this, [ this ]( int _ ) { + showHeadwordsNumber(); + } ); + connect( proxy, &QAbstractItemModel::dataChanged, this, &DictHeadwords::showHeadwordsNumber ); + connect( ui.filterMaxResult, &QSpinBox::valueChanged, this, [ this ]( int _value ) { + model->setMaxFilterResults( _value ); + } ); } void DictHeadwords::savePos()