Merge branch 'staged' into dev

This commit is contained in:
Xiao YiFang 2022-05-24 21:03:58 +08:00
commit 49fab235b9
7 changed files with 32 additions and 20 deletions

View file

@ -131,22 +131,11 @@ using std::string;
emit errorOccurred( code );
}
// void AllowFrameReply::readDataFromBase()
// {
//// QByteArray data;
//// data.resize( baseReply->bytesAvailable() );
//// baseReply->read( data.data(), data.size() );
//// buffer += data;
// emit readyRead();
// }
qint64 AllowFrameReply::readData( char * data, qint64 maxSize )
{
auto bytesAvailable= baseReply->bytesAvailable();
qint64 size = qMin( maxSize, bytesAvailable );
baseReply->read( data, size );
// memcpy( data, buffer.data(), size );
// buffer.remove( 0, size );
return size;
}

View file

@ -2570,11 +2570,9 @@ void ArticleView::highlightFTSResults()
if( ftsSearchMatchCase )
flags |= QWebEnginePage::FindCaseSensitively;
for( int x = 0; x < allMatches.size(); x++ )
ui.definition->findText( allMatches.at( x ), flags );
if( !allMatches.isEmpty() )
{
highlightAllFtsOccurences( flags );
ui.definition->findText( allMatches.at( 0 ), flags );
// if( ui.definition->findText( allMatches.at( 0 ), flags ) )
{
@ -2591,6 +2589,25 @@ void ArticleView::highlightFTSResults()
} );
}
void ArticleView::highlightAllFtsOccurences( QWebEnginePage::FindFlags flags )
{
// Usually allMatches contains mostly duplicates. Thus searching for each element of
// allMatches to highlight them takes a long time => collect unique elements into a
// set and search for them instead.
// Don't use QList::toSet() or QSet's range constructor because they reserve space
// for QList::size() elements, whereas the final QSet size is likely 1 or 2.
QSet< QString > uniqueMatches;
for( int x = 0; x < allMatches.size(); ++x )
{
QString const & match = allMatches.at( x );
// Consider words that differ only in case equal if the search is case-insensitive.
uniqueMatches.insert( ftsSearchMatchCase ? match : match.toLower() );
}
for( QSet< QString >::const_iterator it = uniqueMatches.constBegin(); it != uniqueMatches.constEnd(); ++it )
ui.definition->findText( *it, flags );
}
void ArticleView::setActiveDictIds(ActiveDictIds ad) {
// ignore all other signals.
qDebug() << "receive dicts, current word:" << currentWord << ad.word << ":" << ad.dictIds;

View file

@ -80,8 +80,8 @@ class ArticleView: public QFrame
int ftsPosition;
void highlightFTSResults();
void highlightAllFtsOccurences( QWebEnginePage::FindFlags flags );
void performFtsFindOperation( bool backwards );
void showFindButtons();
public:
/// The popupView flag influences contents of the context menus to be

View file

@ -1054,8 +1054,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
for( ; ; )
{
//skip too long headword
if( !head.headword.isEmpty() && head.headword.size() < 30 )
if( !head.headword.isEmpty() )
{
uint32_t offset = chunks.startNewBlock();
chunks.addToBlock( &head.page, sizeof( head.page ) );

View file

@ -899,7 +899,7 @@ bool EpwingBook::getNextHeadword( EpwingHeadword & head )
}
else
{
allHeadwordPositions[ head.headword ]<<EWPos( pos.page, pos.offset );
allHeadwordPositions[ head.headword ] << EWPos( pos.page, pos.offset );
return true;
}
}
@ -973,7 +973,7 @@ bool EpwingBook::getNextHeadword( EpwingHeadword & head )
}
else
{
allHeadwordPositions[ head.headword ]<<EWPos( pos.page, pos.offset );
allHeadwordPositions[ head.headword ] << EWPos( pos.page, pos.offset );
return true;
}
}
@ -1128,6 +1128,9 @@ void EpwingBook::getArticle( QString & headword, QString & articleText,
headword = QString::fromUtf8( buffer, length );
finalizeText( headword );
if( text_only )
fixHeadword( headword );
articleText = getText( pos.page, pos.offset, text_only );
}

View file

@ -78,7 +78,7 @@ class EpwingBook
QStringList imageCacheList, soundsCacheList, moviesCacheList, fontsCacheList;
QMap< QString, QString > baseFontsMap, customFontsMap;
QVector< int > refPages, refOffsets;
QMap< QString, QList<EWPos> > allHeadwordPositions;
QMap< QString, QList< EWPos > > allHeadwordPositions;
QVector< EWPos > LinksQueue;
int refOpenCount, refCloseCount;
static Mutex libMutex;

View file

@ -1244,6 +1244,10 @@ void MainWindow::closeEvent( QCloseEvent * ev )
void MainWindow::quitApp()
{
if( inspector && inspector->isVisible() )
{
inspector->hide();
}
commitData();
qApp->quit();
}