From 25794f504692e5a36c490438814e9dfda8aaa2dd Mon Sep 17 00:00:00 2001 From: tpearson Date: Sun, 29 May 2011 19:00:37 +0000 Subject: TQt4 port kchmviewer This enables compilation under both Qt3 and Qt4 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kchmviewer@1234150 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/kchmsearchengine_impl.cpp | 152 +++++++++++++++++++++--------------------- 1 file changed, 76 insertions(+), 76 deletions(-) (limited to 'src/kchmsearchengine_impl.cpp') diff --git a/src/kchmsearchengine_impl.cpp b/src/kchmsearchengine_impl.cpp index 286832a..52515c7 100644 --- a/src/kchmsearchengine_impl.cpp +++ b/src/kchmsearchengine_impl.cpp @@ -21,11 +21,11 @@ ***************************************************************************/ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include @@ -45,7 +45,7 @@ static const char SPLIT_CHARACTERS[] = "!()*&^%#@[]{}':;,.?/|/?<>\\-+=~`"; static const char WORD_CHARACTERS[] = "$_"; -int TermList::compareItems( QPtrCollection::Item i1, QPtrCollection::Item i2 ) +int TermList::compareItems( TQPtrCollection::Item i1, TQPtrCollection::Item i2 ) { if( ( (Term*)i1 )->frequency == ( (Term*)i2 )->frequency ) return 0; @@ -54,35 +54,35 @@ int TermList::compareItems( QPtrCollection::Item i1, QPtrCollection::Item i2 ) return 1; } -QDataStream &operator>>( QDataStream &s, Document &l ) +TQDataStream &operator>>( TQDataStream &s, Document &l ) { s >> l.docNumber; s >> l.frequency; return s; } -QDataStream &operator<<( QDataStream &s, const Document &l ) +TQDataStream &operator<<( TQDataStream &s, const Document &l ) { - s << (Q_INT16)l.docNumber; - s << (Q_INT16)l.frequency; + s << (TQ_INT16)l.docNumber; + s << (TQ_INT16)l.frequency; return s; } -Index::Index( const QString &dp, const QString & ) - : QObject( 0, 0 ), dict( 8999 ), docPath( dp ) +Index::Index( const TQString &dp, const TQString & ) + : TQObject( 0, 0 ), dict( 8999 ), docPath( dp ) { lastWindowClosed = false; - connect( qApp, SIGNAL( lastWindowClosed() ), - this, SLOT( setLastWinClosed() ) ); + connect( tqApp, TQT_SIGNAL( lastWindowClosed() ), + this, TQT_SLOT( setLastWinClosed() ) ); } -Index::Index( const QStringList &dl, const QString & ) - : QObject( 0, 0 ), dict( 20011 ) +Index::Index( const TQStringList &dl, const TQString & ) + : TQObject( 0, 0 ), dict( 20011 ) { docList = dl; lastWindowClosed = false; - connect( qApp, SIGNAL( lastWindowClosed() ), - this, SLOT( setLastWinClosed() ) ); + connect( tqApp, TQT_SIGNAL( lastWindowClosed() ), + this, TQT_SLOT( setLastWinClosed() ) ); } void Index::setLastWinClosed() @@ -90,17 +90,17 @@ void Index::setLastWinClosed() lastWindowClosed = true; } -void Index::setDictionaryFile( const QString &f ) +void Index::setDictionaryFile( const TQString &f ) { dictFile = f; } -void Index::setDocListFile( const QString &f ) +void Index::setDocListFile( const TQString &f ) { docListFile = f; } -void Index::setDocList( const QStringList &lst ) +void Index::setDocList( const TQStringList &lst ) { docList = lst; } @@ -110,7 +110,7 @@ bool Index::makeIndex() if ( docList.isEmpty() ) return false; - QStringList::Iterator it = docList.begin(); + TQStringList::Iterator it = docList.begin(); int steps = docList.count() / 100; if ( !steps ) @@ -136,7 +136,7 @@ bool Index::makeIndex() } -void Index::insertInDict( const QString &str, int docNum ) +void Index::insertInDict( const TQString &str, int docNum ) { Entry *e = 0; if ( dict.count() ) @@ -156,10 +156,10 @@ void Index::insertInDict( const QString &str, int docNum ) } -bool Index::parseDocumentToStringlist( const QString & filename, QStringList & tokenlist ) +bool Index::parseDocumentToStringlist( const TQString & filename, TQStringList & tokenlist ) { - QString parsedbuf, parseentity; - QString text; + TQString parsedbuf, parseentity; + TQString text; if ( !::mainWindow->chmFile()->getFileContentAsString( &text, filename ) ) { @@ -183,19 +183,19 @@ bool Index::parseDocumentToStringlist( const QString & filename, QStringList & t { STATE_OUTSIDE_TAGS, // outside HTML tags; parse text STATE_IN_HTML_TAG, // inside HTML tags; wait for end tag - STATE_IN_QUOTES, // inside HTML tags and inside quotes; wait for end quote (in var QuoteChar) + STATE_IN_TQUOTES, // inside HTML tags and inside quotes; wait for end quote (in var QuoteChar) STATE_IN_HTML_ENTITY, // inside HTML entity; parse the entity }; state_t state = STATE_OUTSIDE_TAGS; - QChar QuoteChar; // used in STATE_IN_QUOTES + TQChar QuoteChar; // used in STATE_IN_TQUOTES for ( unsigned int j = 0; j < text.length(); j++ ) { - QChar ch = text[j]; + TQChar ch = text[j]; if ( (j % 20000) == 0 ) - qApp->processEvents( QEventLoop::ExcludeUserInput ); + tqApp->tqprocessEvents( TQEventLoop::ExcludeUserInput ); if ( state == STATE_IN_HTML_TAG ) { @@ -203,7 +203,7 @@ bool Index::parseDocumentToStringlist( const QString & filename, QStringList & t // Ignore everything until we see '>' (end of HTML tag) or quote char (quote start) if ( ch == '"' || ch == '\'' ) { - state = STATE_IN_QUOTES; + state = STATE_IN_TQUOTES; QuoteChar = ch; } else if ( ch == '>' ) @@ -211,7 +211,7 @@ bool Index::parseDocumentToStringlist( const QString & filename, QStringList & t continue; } - else if ( state == STATE_IN_QUOTES ) + else if ( state == STATE_IN_TQUOTES ) { // We are inside quoted text inside HTML tag. // Ignore everything until we see the quote character again @@ -252,7 +252,7 @@ bool Index::parseDocumentToStringlist( const QString & filename, QStringList & t // Don't we have a space? if ( parseentity.lower() != "nbsp" ) { - QString entity = ::mainWindow->chmFile()->impl()->decodeEntity( parseentity ); + TQString entity = ::mainWindow->chmFile()->impl()->decodeEntity( parseentity ); if ( entity.isNull() ) { @@ -283,7 +283,7 @@ bool Index::parseDocumentToStringlist( const QString & filename, QStringList & t if ( ch == '&' ) { state = STATE_IN_HTML_ENTITY; - parseentity = QString::null; + parseentity = TQString(); continue; } @@ -293,20 +293,20 @@ bool Index::parseDocumentToStringlist( const QString & filename, QStringList & t // Ok, we have a valid character outside HTML tags, and probably some in buffer already. // If it is char or letter, add it and continue - if ( ch.isLetterOrNumber() || m_charsword.find( ch ) != -1 ) + if ( ch.isLetterOrNumber() || m_charsword.tqfind( ch ) != -1 ) { parsedbuf.append( ch ); continue; } // If it is a split char, add the word to the dictionary, and then add the char itself. - if ( m_charssplit.find( ch ) != -1 ) + if ( m_charssplit.tqfind( ch ) != -1 ) { if ( !parsedbuf.isEmpty() ) tokenlist.push_back( parsedbuf.lower() ); tokenlist.push_back( ch.lower() ); - parsedbuf = QString::null; + parsedbuf = TQString(); continue; } @@ -315,7 +315,7 @@ tokenize_buf: if ( !parsedbuf.isEmpty() ) { tokenlist.push_back( parsedbuf.lower() ); - parsedbuf = QString::null; + parsedbuf = TQString(); } } @@ -327,22 +327,22 @@ tokenize_buf: } -void Index::parseDocument( const QString &filename, int docNum ) +void Index::parseDocument( const TQString &filename, int docNum ) { - QStringList terms; + TQStringList terms; if ( !parseDocumentToStringlist( filename, terms ) ) return; - for ( QStringList::Iterator it = terms.begin(); it != terms.end(); ++it ) + for ( TQStringList::Iterator it = terms.begin(); it != terms.end(); ++it ) insertInDict( *it, docNum ); } void Index::writeDict() { - QDictIterator it( dict ); - QFile f( dictFile ); + TQDictIterator it( dict ); + TQFile f( dictFile ); if ( !f.open( IO_WriteOnly ) ) { @@ -350,7 +350,7 @@ void Index::writeDict() return; } - QDataStream s( &f ); + TQDataStream s( &f ); s << (int) 1; // version s << m_charssplit; s << m_charsword; @@ -368,27 +368,27 @@ void Index::writeDict() void Index::writeDocumentList() { - QFile f( docListFile ); + TQFile f( docListFile ); if ( !f.open( IO_WriteOnly ) ) { qWarning( "Index::writeDocumentList: could not write dictionary file %s", docListFile.ascii() ); return; } - QDataStream s( &f ); + TQDataStream s( &f ); s << docList; } bool Index::readDict() { - QFile f( dictFile ); + TQFile f( dictFile ); if ( !f.open( IO_ReadOnly ) ) return false; dict.clear(); - QDataStream s( &f ); - QString key; + TQDataStream s( &f ); + TQString key; int version; - QValueList docs; + TQValueList docs; s >> version; s >> m_charssplit; @@ -407,19 +407,19 @@ bool Index::readDict() bool Index::readDocumentList() { - QFile f( docListFile ); + TQFile f( docListFile ); if ( !f.open( IO_ReadOnly ) ) return false; - QDataStream s( &f ); + TQDataStream s( &f ); s >> docList; return true; } -QStringList Index::query( const QStringList &terms, const QStringList &termSeq, const QStringList &seqWords ) +TQStringList Index::query( const TQStringList &terms, const TQStringList &termSeq, const TQStringList &seqWords ) { TermList termList; - QStringList::ConstIterator it = terms.begin(); + TQStringList::ConstIterator it = terms.begin(); for ( it = terms.begin(); it != terms.end(); ++it ) { Entry *e = 0; @@ -431,7 +431,7 @@ QStringList Index::query( const QStringList &terms, const QStringList &termSeq, } else { - return QStringList(); + return TQStringList(); } } @@ -440,18 +440,18 @@ QStringList Index::query( const QStringList &terms, const QStringList &termSeq, Term *minTerm = termList.first(); if ( !termList.count() ) - return QStringList(); + return TQStringList(); termList.removeFirst(); - QValueList minDocs = minTerm->documents; - QValueList::iterator C; - QValueList::ConstIterator It; + TQValueList minDocs = minTerm->documents; + TQValueList::iterator C; + TQValueList::ConstIterator It; Term *t = termList.first(); for ( ; t; t = termList.next() ) { - QValueList docs = t->documents; + TQValueList docs = t->documents; C = minDocs.begin(); while ( C != minDocs.end() ) @@ -475,7 +475,7 @@ QStringList Index::query( const QStringList &terms, const QStringList &termSeq, } } - QStringList results; + TQStringList results; qHeapSort( minDocs ); if ( termSeq.isEmpty() ) @@ -486,7 +486,7 @@ QStringList Index::query( const QStringList &terms, const QStringList &termSeq, return results; } - QString fileName; + TQString fileName; for ( C = minDocs.begin(); C != minDocs.end(); ++C ) { @@ -500,9 +500,9 @@ QStringList Index::query( const QStringList &terms, const QStringList &termSeq, } -bool Index::searchForPhrases( const QStringList &phrases, const QStringList &words, const QString &filename ) +bool Index::searchForPhrases( const TQStringList &phrases, const TQStringList &words, const TQString &filename ) { - QStringList parsed_document; + TQStringList parsed_document; if ( !parseDocumentToStringlist( filename, parsed_document ) ) return false; @@ -510,12 +510,12 @@ bool Index::searchForPhrases( const QStringList &phrases, const QStringList &wor miniDict.clear(); // Initialize the dictionary with the words in phrase(s) - for ( QStringList::ConstIterator cIt = words.begin(); cIt != words.end(); ++cIt ) + for ( TQStringList::ConstIterator cIt = words.begin(); cIt != words.end(); ++cIt ) miniDict.insert( *cIt, new PosEntry( 0 ) ); // Fill the dictionary with the words from the document unsigned int word_offset = 3; - for ( QStringList::ConstIterator it = parsed_document.begin(); it != parsed_document.end(); it++, word_offset++ ) + for ( TQStringList::ConstIterator it = parsed_document.begin(); it != parsed_document.end(); it++, word_offset++ ) { PosEntry * entry = miniDict[ *it ]; @@ -525,33 +525,33 @@ bool Index::searchForPhrases( const QStringList &phrases, const QStringList &wor // Dump it /* - QDictIterator it( miniDict ); + TQDictIterator it( miniDict ); for( ; it.current(); ++it ) { - QString text( it.currentKey() ); - QValueList pos = miniDict[text]->positions; + TQString text( it.currentKey() ); + TQValueList pos = miniDict[text]->positions; for ( unsigned int i = 1; i < pos.size(); i++ ) - text += " " + QString::number( pos[i] ); + text += " " + TQString::number( pos[i] ); qDebug( "%s", text.ascii()); } */ - QValueList first_word_positions; + TQValueList first_word_positions; - for ( QStringList::ConstIterator phrase_it = phrases.begin(); phrase_it != phrases.end(); phrase_it++ ) + for ( TQStringList::ConstIterator phrase_it = phrases.begin(); phrase_it != phrases.end(); phrase_it++ ) { - QStringList phrasewords = QStringList::split( ' ', *phrase_it ); + TQStringList phrasewords = TQStringList::split( ' ', *phrase_it ); first_word_positions = miniDict[ phrasewords[0] ]->positions; for ( unsigned int j = 1; j < phrasewords.count(); ++j ) { - QValueList next_word_it = miniDict[ phrasewords[j] ]->positions; - QValueList::iterator dict_it = first_word_positions.begin(); + TQValueList next_word_it = miniDict[ phrasewords[j] ]->positions; + TQValueList::iterator dict_it = first_word_positions.begin(); while ( dict_it != first_word_positions.end() ) { - if ( next_word_it.find( *dict_it + 1 ) != next_word_it.end() ) + if ( next_word_it.tqfind( *dict_it + 1 ) != next_word_it.end() ) { (*dict_it)++; ++dict_it; -- cgit v1.2.3