C++ (Qt) // ОСТАВЛЯЕМ ТЕКСТ if(cfg.preferences.langStatSort == 0)listFull = originalText.toLower().split(QRegExp("[\\s\\W\\d_]+"),QString::SkipEmptyParts); // ОСТАВЛЯЕМ АНГЛИЙКИЙ if(cfg.preferences.langStatSort == 1)listFull = originalText.toLower().split(QRegExp("[^a-z]+"),QString::SkipEmptyParts); // ОСТАВЛЯЕМ РУССКИЙ if(cfg.preferences.langStatSort == 2)listFull = originalText.toLower().split(QRegExp(QString::fromUtf8("[^а-яё]+")),QString::SkipEmptyParts);
C++ (Qt)const QString mask[3] = { QString("[\\s\\W\\d_]+"), QString("[^a-z]+"), QString::fromUtf8("[^а-яё]+"),};QRegExp rexp(mask[cfg.preferences.langStatSort]);listFull = originalText.toLower().split(rexp, QString::SkipEmptyParts);
C++ (Qt)void MainWindow::wordStat(){ QTime tm; tm.start(); QClipboard *clipboard = QApplication::clipboard(); QString originalText = clipboard->text(); QString addZero; QStringList listFull; QStringList frequencyList; qDebug() << "Reade Data: " << tm.elapsed(); tm.start(); textory.clear(); textory.enableAdd( true ); // ОСТАВЛЯЕМ ВЕСЬ ТЕКСТ/АНГЛИЙСКИЙ/РУССКИЙ const QString mask[3] = { QString("[\\s\\W\\d_]+"), QString("[^a-z]+"), QString::fromUtf8("[^а-яё]+"), }; QRegExp rexp(mask[cfg.preferences.langStatSort]); listFull = originalText.toLower().split(rexp, QString::SkipEmptyParts); qDebug() << "Data split: " << tm.elapsed(); tm.start(); // ПОСТРОЕНИЕ СПИСКА QRegExp rx(muRegExp); rx.setPatternSyntax(QRegExp::Wildcard); QHash<QString, int> frequencyHash; foreach (QString s, listFull) ++frequencyHash[s]; frequencyList.reserve(listFull.size()); foreach (QString s, listFull) { if(s.size() < cfg.preferences.minSizeWord || s.size() > cfg.preferences.maxSizeWord )continue; if(!muRegExp.isEmpty() && !rx.exactMatch(s))continue; int & num = frequencyHash[s]; if(num < 0) continue; if(num >= cfg.preferences.minRepeats ) { if(cfg.preferences.typeOfSort == 2)frequencyList.prepend(s + '\t' + QString::number(long(num))); if(cfg.preferences.typeOfSort == 1)frequencyList.prepend(s + '\t' + QString::number(long(num))); if(cfg.preferences.typeOfSort == 0) { addZero = QString::number(long(num)).rightJustified(6, '0'); frequencyList.prepend(addZero + s + '\t' + QString::number(long(num))); } } num = -num; } qDebug() << "Count: " << tm.elapsed(); tm.start(); if(cfg.preferences.typeOfSort != 2)qSort(frequencyList); // ВЫВОД СПИСКА qDebug() << "Data sort: " << tm.elapsed(); tm.start(); if(cfg.preferences.typeOfSort == 0 || cfg.preferences.typeOfSort == 2) { foreach (QString itm, frequencyList) { if(cfg.preferences.typeOfSort == 0)itm.remove(0,6); textory.addItem( Textory::Item( 1, itm ) ); } } if(cfg.preferences.typeOfSort == 1) { QListIterator<QString>itm(frequencyList); itm.toBack(); while (itm.hasPrevious()) textory.addItem( Textory::Item( 1, itm.previous() ) ); } qDebug() << "Out list: " << tm.elapsed(); tm.start(); cfg.textoryName = "Frequency list (" + QString::number(long(listFull.size())) + ")"; ui.textoryPaneWidget->getTextoryLabel().setText( cfg.textoryName ); qDebug() << "Write name: " << tm.elapsed();}
C++ (Qt) if(cfg.preferences.typeOfSort == 2)frequencyList.prepend(s + '\t' + QString::number(long(num))); if(cfg.preferences.typeOfSort == 1)frequencyList.prepend(s + '\t' + QString::number(long(num))); if(cfg.preferences.typeOfSort == 0) {}
C++ (Qt)// в началеconst MyPref & pref = cfg.preferences; // MyPref = тот тип что cfg.preferencesenum { sort_None = 0, sort_Freq = 1, sort_Crazy = 2, // даете имена по смыслу, этл для примера};...if (pref.typeOfSort != sort_None) frequencyList.prepend(s + '\t' + QString::number(long(num)));else {...
C++ (Qt)enum { sort_None = 0, sort_Freq = 1, sort_Crazy = 2, // даете имена по смыслу, этл для примера};
C++ (Qt)void MainWindow::wordStat(){ QTime tm; tm.start(); const Config::Preferences & pref = cfg.preferences; QClipboard *clipboard = QApplication::clipboard(); QString originalText = clipboard->text(); QString addZero; QStringList listFull; QStringList frequencyList; qDebug() << "Reade Data: " << tm.elapsed(); tm.start(); textory.clear(); textory.enableAdd( true ); // ОСТАВЛЯЕМ ВЕСЬ ТЕКСТ/АНГЛИЙСКИЙ/РУССКИЙ const QString mask[3] = { QString("[\\s\\W\\d_]+"), QString("[^a-z]+"), QString::fromUtf8("[^а-яё]+"), }; QRegExp rexp(mask[pref.langStatSort]); listFull = originalText.toLower().split(rexp, QString::SkipEmptyParts); qDebug() << "Data split: " << tm.elapsed(); tm.start(); // ПОСТРОЕНИЕ СПИСКА QRegExp rx(muRegExp); rx.setPatternSyntax(QRegExp::Wildcard); QHash<QString, int> frequencyHash; foreach (QString s, listFull) ++frequencyHash[s]; frequencyList.reserve(listFull.size()); foreach (QString s, listFull) { if (s.size() < pref.minSizeWord || s.size() > pref.maxSizeWord )continue; if (!muRegExp.isEmpty() && !rx.exactMatch(s))continue; int & num = frequencyHash[s]; if (num < 0) continue; if (num >= pref.minRepeats ) { if (pref.typeOfSort != 0) frequencyList.prepend(s + '\t' + QString::number(long(num))); else { addZero = QString::number(long(num)).rightJustified(6, '0'); frequencyList.prepend(addZero + s + '\t' + QString::number(long(num))); } } num = -num; } qDebug() << "Count: " << tm.elapsed(); tm.start(); if (pref.typeOfSort != 2)qSort(frequencyList); // ВЫВОД СПИСКА qDebug() << "Data sort: " << tm.elapsed(); tm.start(); if (pref.typeOfSort == 0 || pref.typeOfSort == 2) { foreach (QString itm, frequencyList) { if(pref.typeOfSort == 0)itm.remove(0,6); textory.addItem( Textory::Item( 1, itm ) ); } } if (pref.typeOfSort == 1) { QListIterator<QString>itm(frequencyList); itm.toBack(); while (itm.hasPrevious()) textory.addItem( Textory::Item( 1, itm.previous() ) ); } qDebug() << "Out list: " << tm.elapsed(); tm.start(); cfg.textoryName = "Frequency list (" + QString::number(long(listFull.size())) + ")"; ui.textoryPaneWidget->getTextoryLabel().setText( cfg.textoryName ); qDebug() << "Write name: " << tm.elapsed();}
C++ (Qt)void MainWindow::textoryInBuffer(){ QStringList textoryStrings; QString line; QList< Textory::Item > const & items = textory.getItems(); QList< Textory::Item >::const_iterator i; for ( i = items.constBegin(); i != items.constEnd(); ++i ){ line = i->word.toUtf8(); textoryStrings.append(line); } QApplication::clipboard()->setText( textoryStrings.join( QString::fromLatin1( "\n" ) ) );}