Revert "fix:head lazy load"

This reverts commit 15702d860b.

Revert "add lazy loading to headwords dialog"

This reverts commit 473c61724f.
This commit is contained in:
YiFang 2022-05-05 20:59:50 +08:00 committed by xiaoyifang
parent 7eb0fa6d96
commit ffb1922bd7
6 changed files with 58 additions and 204 deletions

View file

@ -51,12 +51,9 @@ DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_,
ui.matchCase->setChecked( cfg.headwordsDialog.matchCase );
model = new HeadwordListModel( this );
model = new QStringListModel( this );
model->setStringList( headers );
connect(model,&HeadwordListModel::finished,this,[this](){
ui.exportButton->setEnabled(true);
ui.progressBar->hide();
});
proxy = new QSortFilterProxyModel( this );
proxy->setSourceModel( model );
@ -137,12 +134,16 @@ void DictHeadwords::setup( Dictionary::Class *dict_ )
setWindowTitle( QString::fromUtf8( dict->getName().c_str() ) );
auto size = dict->getWordCount();
model->setDict(dict);
headers.clear();
model->setStringList( headers );
dict->getHeadwords( headers );
model->setStringList( headers );
proxy->sort( 0 );
filterChanged();
if( size > AUTO_APPLY_LIMIT )
if( headers.size() > AUTO_APPLY_LIMIT )
{
cfg.headwordsDialog.autoApply = ui.autoApply->isChecked();
ui.autoApply->setChecked( false );
@ -154,7 +155,6 @@ void DictHeadwords::setup( Dictionary::Class *dict_ )
ui.autoApply->setChecked( cfg.headwordsDialog.autoApply );
}
ui.exportButton->setEnabled(false);
ui.applyButton->setEnabled( !ui.autoApply->isChecked() );
setWindowIcon( dict->getIcon() );
@ -169,7 +169,7 @@ void DictHeadwords::savePos()
cfg.headwordsDialog.searchMode = ui.searchModeCombo->currentIndex();
cfg.headwordsDialog.matchCase = ui.matchCase->isChecked();
if( model->totalCount() <= AUTO_APPLY_LIMIT )
if( headers.size() <= AUTO_APPLY_LIMIT )
cfg.headwordsDialog.autoApply = ui.autoApply->isChecked();
cfg.headwordsDialog.headwordsDialogGeometry = saveGeometry();
@ -226,14 +226,11 @@ void DictHeadwords::filterChanged()
QString pattern;
switch( syntax )
{
case QRegExp::FixedString:
pattern = QRegularExpression::escape( ui.filterLine->text() );
case QRegExp::FixedString: pattern = QRegularExpression::escape( ui.filterLine->text() );
break;
case QRegExp::WildcardUnix:
pattern = wildcardsToRegexp( ui.filterLine->text() );
case QRegExp::WildcardUnix: pattern = wildcardsToRegexp( ui.filterLine->text() );
break;
default:
pattern = ui.filterLine->text();
default: pattern = ui.filterLine->text();
break;
}
@ -248,6 +245,8 @@ void DictHeadwords::filterChanged()
QApplication::setOverrideCursor( Qt::WaitCursor );
proxy->setFilterRegularExpression( regExp );
proxy->sort( 0 );
QApplication::restoreOverrideCursor();
@ -273,7 +272,8 @@ void DictHeadwords::autoApplyStateChanged( int state )
void DictHeadwords::showHeadwordsNumber()
{
ui.headersNumber->setText( tr( "Unique headwords total: %1, filtered: %2" )
.arg( QString::number( model->totalCount() ), QString::number( proxy->rowCount() ) ) );
.arg( QString::number( headers.size() ) )
.arg( QString::number( proxy->rowCount() ) ) );
}
void DictHeadwords::saveHeadersToFile()
@ -303,7 +303,7 @@ void DictHeadwords::saveHeadersToFile()
if ( !file.open( QFile::WriteOnly | QIODevice::Text ) )
break;
int headwordsNumber = model->totalCount();
int headwordsNumber = proxy->rowCount();
// Setup progress dialog
int n = headwordsNumber;
@ -335,7 +335,7 @@ void DictHeadwords::saveHeadersToFile()
if( progress.wasCanceled() )
break;
QVariant value = model->getRow(i);
QVariant value = proxy->data( proxy->index( i, 0 ) );
if( !value.canConvert< QString >() )
continue;

View file

@ -14,7 +14,6 @@
#include "dictionary.hh"
#include "delegate.hh"
#include "helpwindow.hh"
#include "headwordslistmodel.h"
class DictHeadwords : public QDialog
{
@ -30,8 +29,8 @@ public:
protected:
Config::Class & cfg;
Dictionary::Class * dict;
HeadwordListModel * model;
QStringList headers;
QStringListModel * model;
QSortFilterProxyModel * proxy;
WordListItemDelegate * delegate;
QString dictId;

View file

@ -19,46 +19,6 @@
<item row="3" column="0">
<widget class="QListView" name="headersListView"/>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="autoApply">
<property name="toolTip">
<string>If checked any filter changes will we immediately applied to headwords list</string>
</property>
<property name="text">
<string>Auto apply</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="filterLine">
<property name="toolTip">
<string>Filter string (fixed string, wildcards or regular expression)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Filter:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="applyButton">
<property name="toolTip">
<string>Press this button to apply filter to headwords list</string>
</property>
<property name="text">
<string>Apply</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
@ -135,17 +95,44 @@
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QProgressBar" name="progressBar">
<property name="maximum">
<number>0</number>
<item row="2" column="1">
<widget class="QPushButton" name="applyButton">
<property name="toolTip">
<string>Press this button to apply filter to headwords list</string>
</property>
<property name="value">
<number>-1</number>
<property name="text">
<string>Apply</string>
</property>
<property name="invertedAppearance">
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="autoApply">
<property name="toolTip">
<string>If checked any filter changes will we immediately applied to headwords list</string>
</property>
<property name="text">
<string>Auto apply</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Filter:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="filterLine">
<property name="toolTip">
<string>Filter string (fixed string, wildcards or regular expression)</string>
</property>
</widget>
</item>
</layout>

View file

@ -226,7 +226,6 @@ DEFINES += PROGRAM_VERSION=\\\"$$VERSION\\\"
HEADERS += folding.hh \
article_inspect.h \
globalbroadcaster.h \
headwordslistmodel.h \
inc_case_folding.hh \
inc_diacritic_folding.hh \
mainwindow.hh \
@ -367,7 +366,6 @@ FORMS += groups.ui \
SOURCES += folding.cc \
article_inspect.cpp \
globalbroadcaster.cpp \
headwordslistmodel.cpp \
main.cc \
dictionary.cc \
config.cc \

View file

@ -1,88 +0,0 @@
#include "headwordslistmodel.h"
HeadwordListModel::HeadwordListModel(QObject *parent)
: QAbstractListModel(parent), wordsCount(0)
{}
int HeadwordListModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : wordsCount;
}
int HeadwordListModel::totalCount() const{
return totalSize;
}
bool HeadwordListModel::isFinish() const{
return wordsCount >=totalSize;
}
QString HeadwordListModel::getRow(int row)
{
if(fileSortedList.empty()){
fileSortedList<<fileList;
fileSortedList.sort();
}
return fileSortedList.at(row);
}
int HeadwordListModel::wordCount() const{
return wordsCount;
}
QVariant HeadwordListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.row() >= totalSize || index.row() < 0)
return QVariant();
if (role == Qt::DisplayRole) {
return fileList.at(index.row());
}
return QVariant();
}
bool HeadwordListModel::canFetchMore(const QModelIndex &parent) const
{
if (parent.isValid())
return false;
return (wordsCount < totalSize);
}
void HeadwordListModel::fetchMore(const QModelIndex &parent)
{
if (parent.isValid())
return;
int remainder = fileList.size() - wordsCount;
int itemsToFetch = qMin(100, remainder);
if (itemsToFetch <= 0)
return;
beginInsertRows(QModelIndex(), wordsCount, wordsCount + itemsToFetch - 1);
wordsCount+= itemsToFetch;
endInsertRows();
emit numberPopulated(wordsCount);
}
void HeadwordListModel::setDict(Dictionary::Class * dict){
_dict = dict;
totalSize = _dict->getWordCount();
wordsCount=0;
QThreadPool::globalInstance()->start(
[ this ]()
{
beginResetModel();
_dict->getHeadwords( fileList );
totalSize = fileList.size();
emit finished(totalSize);
endResetModel();
} );
}

View file

@ -1,42 +0,0 @@
#ifndef HEADWORDSLISTMODEL_H
#define HEADWORDSLISTMODEL_H
#include "dictionary.hh"
#include <QAbstractListModel>
#include <QStringList>
class HeadwordListModel : public QAbstractListModel
{
Q_OBJECT
public:
HeadwordListModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int totalCount() const;
int wordCount() const;
bool isFinish() const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QString getRow(int row);
signals:
void numberPopulated(int number);
void finished(int number);
public slots:
void setDict(Dictionary::Class * dict);
protected:
bool canFetchMore(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override;
private:
QStringList fileList;
QStringList fileSortedList;
long wordsCount;
long totalSize;
Dictionary::Class * _dict;
};
#endif // HEADWORDSLISTMODEL_H