Skip to content

Commit

Permalink
Merge branch 'staged' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed May 24, 2022
2 parents f497c5e + 19a09b5 commit 49fab23
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
11 changes: 0 additions & 11 deletions article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
23 changes: 20 additions & 3 deletions articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
{
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion articleview.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions epwing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
7 changes: 5 additions & 2 deletions epwing_book.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion epwing_book.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,10 @@ void MainWindow::closeEvent( QCloseEvent * ev )

void MainWindow::quitApp()
{
if( inspector && inspector->isVisible() )
{
inspector->hide();
}
commitData();
qApp->quit();
}
Expand Down

0 comments on commit 49fab23

Please sign in to comment.