Exemplo n.º 1
0
void HistoryMessagesTab::setSizes(const QList<int> &newSizes)
{
    Q_ASSERT(newSizes.size() == 4);

    Splitter->setSizes(newSizes.mid(0, 2));
    TimelineView->setSizes(newSizes.mid(2, 2));
}
Exemplo n.º 2
0
void tst_QColumnView::sizes()
{
    QColumnView view;
    QCOMPARE(view.columnWidths().count(), 0);

    QList<int> newSizes;
    newSizes << 10 << 4 << 50 << 6;

    QList<int> visibleSizes;
    view.setColumnWidths(newSizes);
    QCOMPARE(view.columnWidths(), visibleSizes);

    QDirModel model;
    view.setModel(&model);
    QModelIndex home = model.index(QDir::homePath());
    view.setCurrentIndex(home);

    QList<int> postSizes = view.columnWidths().mid(0, newSizes.count());
    QCOMPARE(postSizes, newSizes.mid(0, postSizes.count()));

    QVERIFY(view.columnWidths().count() > 1);
    QList<int> smallerSizes;
    smallerSizes << 6;
    view.setColumnWidths(smallerSizes);
    QList<int> expectedSizes = newSizes;
    expectedSizes[0] = 6;
    postSizes = view.columnWidths().mid(0, newSizes.count());
    QCOMPARE(postSizes, expectedSizes.mid(0, postSizes.count()));
}
Exemplo n.º 3
0
void Generator::update()
{
	m_error.clear();

	LanguageSettings settings("Current");
	m_dictionary_url = settings.dictionary();

	// Load dice
	QString dice_path = settings.dice();
	if (dice_path != m_dice_path) {
		m_dice_path.clear();
		m_dice.clear();
		m_dice_large.clear();

		QList<QStringList> dice;
		QFile file(dice_path);
		if (file.open(QFile::ReadOnly | QIODevice::Text)) {
			QTextStream stream(&file);
			stream.setCodec("UTF-8");
			while (!stream.atEnd()) {
				QStringList line = stream.readLine().split(',', QString::SkipEmptyParts);
				if (line.count() == 6) {
					dice.append(line);
				}
			}
			file.close();
		}

		if (dice.count() == 41) {
			m_dice_path = dice_path;
			m_dice = dice.mid(0, 16);
			m_dice_large = dice.mid(16);
		} else {
			m_dice = m_dice_large = QList<QStringList>() << QStringList("?");
			return setError(tr("Unable to read dice from file."));
		}
	}

	// Load words
	QString words_path = settings.words();
	if (words_path != m_words_path) {
		m_words_path.clear();
		m_words.clear();
		int count = 0;

		// Load cached words
		QString cache_dir = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/cache";
		QString cache_file = QCryptographicHash::hash(words_path.toUtf8(), QCryptographicHash::Sha1).toHex();
		QFileInfo cache_info(cache_dir + "/" + cache_file);
		if (cache_info.exists() && (cache_info.lastModified() > QFileInfo(words_path).lastModified())) {
			QFile file(cache_info.absoluteFilePath());
			if (file.open(QFile::ReadOnly)) {
				QDataStream stream(&file);
				quint32 magic, version;
				stream >> magic >> version;
				if ((magic == 0x54524945) && (version == 1)) {
					stream.setVersion(QDataStream::Qt_4_6);
					stream >> m_words;
					count = !m_words.isEmpty() * -1;
				}
Exemplo n.º 4
0
static TemplateList Simplified(const TemplateList &templates)
{
    TemplateList simplified;
    foreach (const Template &t, templates) {
        if (t.isEmpty()) {
            if (!t.file.getBool("enrollAll"))
                simplified.append(t);
            continue;
        }

        const bool fte = t.file.getBool("FTE");
        QList<QPointF> landmarks = t.file.landmarks();
        QList<QRectF> ROIs = t.file.ROIs();
        if (landmarks.size() % t.size() != 0) qFatal("TemplateList::simplified uneven landmark count.");
        if (ROIs.size() % t.size() != 0) qFatal("TemplateList::simplified uneven ROI count.");
        const int landmarkStep = landmarks.size() / t.size();
        const int ROIStep = ROIs.size() / t.size();

        for (int i=0; i<t.size(); i++) {
            if (!fte || !t.file.getBool("enrollAll")) {
                simplified.append(Template(t.file, t[i]));
                simplified.last().file.setROIs(ROIs.mid(i*ROIStep, ROIStep));
                simplified.last().file.setLandmarks(landmarks.mid(i*landmarkStep, landmarkStep));
            }
        }
    }
    return simplified;
}
Exemplo n.º 5
0
void widgetTest::updataData(QList<qint16> listData)
{
    //0-400 X
    XWidget->updateDate(listData.mid(0,WAVE_LENGHT_VALUE));
    //400-800 Y
    YWidget->updateDate(listData.mid(WAVE_LENGHT_VALUE-1,WAVE_LENGHT_VALUE));
    //800-1200 X'
    XxWidget->updateDate(listData.mid(2*WAVE_LENGHT_VALUE-1,WAVE_LENGHT_VALUE));
    //1200-1600 Y'
    YyWidget->updateDate(listData.mid(3*WAVE_LENGHT_VALUE-1,WAVE_LENGHT_VALUE));
}
Exemplo n.º 6
0
/*******************************************
  *类型:公有函数
  *功能:设置所有波形显示的数据
        更新数据后自动覆盖上一次的数据
  ******************************************/
void widgetTest::updataData(MyDataNode &data)
{
    QList<qint16 > list;
    for(int i=0;i<4;i++)
        for(int j=0;j<400;j++)
            list.append(data.data[i][j]);
    //0-400 X
    XWidget->updateDate(list.mid(0,WAVE_LENGHT_VALUE));
    //400-800 Y
    YWidget->updateDate(list.mid(WAVE_LENGHT_VALUE-1,WAVE_LENGHT_VALUE));
    //800-1200 X'
    XxWidget->updateDate(list.mid(2*WAVE_LENGHT_VALUE-1,WAVE_LENGHT_VALUE));
    //1200-1600 Y'
    YyWidget->updateDate(list.mid(3*WAVE_LENGHT_VALUE-1,WAVE_LENGHT_VALUE));
}
Exemplo n.º 7
0
/**
 * @brief Called when the search result was downloaded
 *        Emits "sigSearchDone" if there are no more pages in the result set
 * @param results List of results from scraper
 * @see TMDb::parseSearch
 */
void FanartTv::onSearchMovieFinished(QList<ScraperSearchResult> results)
{
    if (m_searchResultLimit == 0)
        emit sigSearchDone(results);
    else
        emit sigSearchDone(results.mid(0, m_searchResultLimit));
}
Exemplo n.º 8
0
QList<Team> FourMatchesContest::teamsAvailableToPlayAgainst(const Team& team, const QList<Team> &teamsToPlayAgainst )
{
  QList<Team> ret = teamsToPlayAgainst.mid( 1 );

    for( int i = 0; i < ret.size(); ++i ) {
        Team currentTeam = ret.at( i );
        if( currentTeam == team ) continue;

        bool alreadyExists = false;
        if ( mFirstPhase != NULL ) {
          alreadyExists |= mFirstPhase->exists( Match( team, currentTeam ) )
                          || mFirstPhase->exists( Match( currentTeam, team ) );
        }
        if ( mSecondPhase != NULL ) {
          alreadyExists |= mSecondPhase->exists( Match( team, currentTeam ) )
                          || mSecondPhase->exists( Match( currentTeam, team ) );
        }
        if ( mThirdPhase != NULL ) {
          alreadyExists |= mThirdPhase->exists( Match( team, currentTeam ) )
                          || mThirdPhase->exists( Match( currentTeam, team ) );
        }
        if ( mFourthPhase != NULL ) {
          alreadyExists |= mFourthPhase->exists( Match( team, currentTeam ) )
                          || mFourthPhase->exists( Match( currentTeam, team ) );
        }

        if ( alreadyExists ) {
          ret.removeAt( i );
          --i;
        }
    }
    return ret;
}
Exemplo n.º 9
0
/**
 * @brief TheTvDbImages::onSearchTvShowFinished
 * @param results Result list
 */
void TheTvDbImages::onSearchTvShowFinished(QList<ScraperSearchResult> results)
{
    if (m_searchResultLimit == 0)
        emit sigSearchDone(results);
    else
        emit sigSearchDone(results.mid(0, m_searchResultLimit));
}
bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item)
{
    Q_ASSERT(path.count() == 3);
    const int i = path.first();
    Q_ASSERT(i >= 0 && i < QInternal::DockCount);
    return docks[i].insertGap(path.mid(1), item);
}
Exemplo n.º 11
0
void SearchController::resultsAction()
{
    checkParams({"id"});

    const int id = params()["id"].toInt();
    int limit = params()["limit"].toInt();
    int offset = params()["offset"].toInt();

    const auto searchHandlers = sessionManager()->session()->getData<SearchHandlerDict>(SEARCH_HANDLERS);
    if (!searchHandlers.contains(id))
        throw APIError(APIErrorType::NotFound);

    const SearchHandlerPtr searchHandler = searchHandlers[id];
    const QList<SearchResult> searchResults = searchHandler->results();
    const int size = searchResults.size();

    if (offset > size)
        throw APIError(APIErrorType::Conflict, tr("Offset is out of range"));

    // normalize values
    if (offset < 0)
        offset = size + offset;
    if (offset < 0)  // check again
        throw APIError(APIErrorType::Conflict, tr("Offset is out of range"));
    if (limit <= 0)
        limit = -1;

    if ((limit > 0) || (offset > 0))
        setResult(getResults(searchResults.mid(offset, limit), searchHandler->isActive(), size));
    else
        setResult(getResults(searchResults, searchHandler->isActive(), size));
}
Exemplo n.º 12
0
void MediaPassionImages::onSearchMovieFinished(QList<ScraperSearchResult> results)
{
    if (m_searchResultLimit == 0)
        emit sigSearchDone(results);
    else
        emit sigSearchDone(results.mid(0, m_searchResultLimit));
}
Exemplo n.º 13
0
QList<NoteListItem> FileStorage::noteList(int limit)
{
    ensureChachePopulated();
    QList<NoteListItem> ret = cache.values();
    qSort(ret.begin(), ret.end(), noteListItemModifyComparer);
    // probably sort is unnecesary here if the only accessor is notemanager which also does sorting.
    return limit ? ret.mid(0, limit) : ret;
}
void tst_QList::mid() const
{
    QList<QString> list;
    list << "foo" << "bar" << "baz" << "bak" << "buck" << "hello" << "kitty";

    QCOMPARE(list.mid(3, 3),
             QList<QString>() << "bak" << "buck" << "hello");
}
Exemplo n.º 15
0
/**
 * @brief Called when the search result was downloaded
 *        Emits "sigSearchDone" if there are no more pages in the result set
 * @param results List of results from scraper
 * @see TMDb::parseSearch
 */
void TMDbImages::onSearchMovieFinished(QList<ScraperSearchResult> results)
{
    qDebug() << "Entered";
    if (m_searchResultLimit == 0)
        emit sigSearchDone(results);
    else
        emit sigSearchDone(results.mid(0, m_searchResultLimit));
}
Exemplo n.º 16
0
void
ArtistInfoWidget::onTracksFound( const QList<Tomahawk::query_ptr>& queries, ModelMode mode )
{
    Q_UNUSED( mode );

    m_topHitsModel->finishLoading();
    m_topHitsModel->appendQueries( queries.mid( 0, 20 ) );
}
Exemplo n.º 17
0
void Telegram::createChatUsers(const QString &title, const QList<int> &users)
{
    if( users.isEmpty() )
        return;

    p->chat_group_buffer[title] = users.mid(1);
    createChat(title, users.first());
}
Exemplo n.º 18
0
EltID Tree::getElementToSelectAfterDeletion()
{
    // Liste des éléments sélectionnés (ne doit pas être vide)
    QList<QTreeWidgetItem *> listSelectedItems = this->selectedItems();
    if (listSelectedItems.isEmpty())
        return EltID();

    // Vérification que le parent est le même pour tous les éléments
    QTreeWidgetItem * itemParent = listSelectedItems.first()->parent();
    if (!itemParent)
        return EltID();

    foreach (QTreeWidgetItem * item, listSelectedItems)
    {
        if (item->parent() != itemParent)
            return EltID();
    }

    // Récupération de la liste des enfants
    QList<QTreeWidgetItem *> listChildItems;
    for (int i = 0; i < itemParent->childCount(); i++)
        if (!itemParent->child(i)->isHidden())
            listChildItems << itemParent->child(i);

    // Séparation en 2 listes, d'après le dernier élément sélectionné
    int indexMid = listChildItems.indexOf(listSelectedItems.last());
    QList<QTreeWidgetItem *> listDebut = listChildItems.mid(0, indexMid + 1);
    QList<QTreeWidgetItem *> listFin = listChildItems.mid(indexMid + 1, -1);

    // Suppression de toutes les occurences des éléments sélectionnés dans la 1ère liste
    foreach (QTreeWidgetItem * item, listSelectedItems)
        listDebut.removeAll(item);

    // Détermination de l'élément à sélectionner
    QTreeWidgetItem * itemToSelect = itemParent;
    if (!listFin.isEmpty())
        itemToSelect = listFin.first();
    else if (!listDebut.isEmpty())
        itemToSelect = listDebut.last();

    // Récupération de l'identifiant
    return getItemID(itemToSelect);
}
QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const
{
    const int i = path.first();

    QRect r = docks[i].itemRect(path.mid(1));
    if (docks[i].o == Qt::Horizontal)
        r = QStyle::visualRect(mainWindow->layoutDirection(),
                                docks[i].rect, r);
    return r;
}
Exemplo n.º 20
0
void KisInputManager::Private::addKeyShortcut(KisAbstractInputAction* action, int index,
                                              const QList<Qt::Key> &keys)
{
    KisSingleActionShortcut *keyShortcut =
            new KisSingleActionShortcut(action, index);

    QList<Qt::Key> modifiers = keys.mid(1);
    keyShortcut->setKey(modifiers, keys.at(0));
    matcher.addShortcut(keyShortcut);
}
Exemplo n.º 21
0
int main ()
{
    QList<QString> first;
    QList<QString> second;
    first << "A" << "B" << "C" << "B" << "A";
    second = first.mid(2);
    assert(second.endsWith("B"));
    assert(second.size() != 3);
  return 0;
}
Exemplo n.º 22
0
void tst_QList::mid() const
{
    QList<QString> list;
    list << "foo" << "bar" << "baz" << "bak" << "buck" << "hello" << "kitty";

    QCOMPARE(list.mid(3, 3),
             QList<QString>() << "bak" << "buck" << "hello");

    QList<int> list1;
    QCOMPARE(list1.mid(1, 1).length(), 0);
}
Exemplo n.º 23
0
int main(int argc, char **argv)
{
    Q_UNUSED(argc);
    Q_UNUSED(argv);

    DataBase db;
    db.load();

    QFile file("../../download/test.txt");
    if (!file.open(QFile::ReadOnly)) {
        qWarning() << "Unable to open test file";
        return 1;
    }

    //Probe probe(&db);

    Svd *svd = new Svd(&db);
    svd->calculateFeatures();

    QFile result("../../results.txt");
    if (!result.open(QFile::WriteOnly)) {
        qWarning() << "can't write";
        return 1;
    }
    QTextStream out(&result);
    QTextStream stream(&file);
    while (!stream.atEnd()) {
        QString line = stream.readLine();
        int userid = line.toInt();
        User user(&db, userid);

        QList<RowAndCount> list;
        for (int i = 0; i < db.totalMovies(); ++i) {
            //Movie movie(&db, i);
            svd->setMovie(i);
            double guess = 1.0;
            if (/*movie.findVote(userid) != -1) {//*/user.seenMovie(i) == -1) {
                guess = svd->determine(userid);
                //qDebug() << userid << i << guess;
            }
            list.append(RowAndCount(i, guess));
        }
        qSort(list);
        list = list.mid(0, 10);
        QStringList top10;
        foreach(RowAndCount rowAndCount, list) {
            int sourceRow = rowAndCount.row;
            top10.append(QString("%1").arg(sourceRow));
            Q_ASSERT(rowAndCount.count >= 1 && rowAndCount.count <= 5);
            //qDebug() << rowAndCount.count;
        }

        out << /*list[0].count << ":" <<*/ userid << ":" << top10.join(",") << endl;
    }
Exemplo n.º 24
0
void splitAreas(QList<Geometry*> *firstHalf, QList<Geometry*> *secondHalf, QList<Geometry*> all) {
    int length1 = 1;
    int length2 = all.length()-1;
    int splitIdx = 0; //last index included in the first half of objs

    QList<Geometry*> prev1(all.mid(0,length1));
    QList<Geometry*> prev2(all.mid(1,all.length()-1));

    float prevArea1 = calcAreas(prev1);
    float prevArea2 = calcAreas(prev2);

    for (int i = 0; i < all.length(); i++) {
        length1++; //add one to firstHalf list of objs
        length2--; //remove one from secondHalf list
        QList<Geometry*> temp1(all.mid(0, length1));
        QList<Geometry*> temp2(all.mid(splitIdx, length2));

        float area1 = calcAreas(temp1);
        float area2 = calcAreas(temp2);
        if (area1 > area2) { //when area of first is finally greater than area 2
            //check if the previous split was better balanced:

            float prevDifference = glm::abs(prevArea2 - prevArea1);
            float newDifference = glm::abs(area1 - area2);
            if (prevDifference > newDifference) { //they are NOW more evenly split
                prev1 = temp1;
                prev2 = temp2;
            } else { //they were previously more evenly split
                //current prev1 and prev2 contain ideal split
                break; //dont replace the return value with the new lists
            }
        }else {
            //they havent been replaced, make prev=curr area calcs
            prevArea1 = area1;
            prevArea2 = area2;
        }
    }
    *firstHalf = prev1;
    *secondHalf = prev2;

}
Exemplo n.º 25
0
void SmokeClassFiles::write(const QList<QString>& keys)
{
    qDebug("writing out x_*.cpp [%s]", qPrintable(Options::module));
    
    // how many classes go in one file
    int count = keys.count() / Options::parts;
    int count2 = count;
    
    for (int i = 0; i < Options::parts; i++) {
        QSet<QString> includes;
        QString classCode;
        QTextStream classOut(&classCode);
        
        // write the class code to a QString so we can later prepend the #includes
        if (i == Options::parts - 1) count2 = -1;
        foreach (const QString& str, keys.mid(count * i, count2)) {
            const Class* klass = &classes[str];
            includes.insert(klass->fileName());
            writeClass(classOut, klass, str, includes);
        }
        
        // create the file
        QFile file(Options::outputDir.filePath("x_" + QString::number(i + 1) + ".cpp"));
        file.open(QFile::ReadWrite | QFile::Truncate);

        QTextStream fileOut(&file);
        
        // write out the header
        fileOut << "//Auto-generated by " << QCoreApplication::arguments()[0] << ". DO NOT EDIT.\n";

        // ... and the #includes
        QList<QString> sortedIncludes = includes.toList();
        qSort(sortedIncludes.begin(), sortedIncludes.end());
        foreach (const QString& str, sortedIncludes) {
            if (str.isEmpty())
                continue;
            fileOut << "#include <" << str << ">\n";
        }

        fileOut << "\n#include <smoke.h>\n#include <" << Options::module << "_smoke.h>\n";

        fileOut << "\nclass __internal_SmokeClass {};\n";

        fileOut << "\nnamespace __smoke" << Options::module << " {\n\n";

        // now the class code
        fileOut << classCode;
        
        fileOut << "\n}\n";
        
        file.close();
    }
}
QList<MidiPairCluster> MatchingService::cutMatchingMidiPairs(QList<MidiPairCluster>& pairs, const QByteArray& pitchAlignment) {
    QList<MidiPairCluster> result;

    QString alignment(pitchAlignment);
    while (alignment.endsWith("i")) {
        alignment.remove(alignment.size()-1, 1);
    }
    alignment.remove('d');

    int idx = 0;
    int splitpoint = alignment.size();
    for (int i = 0; i < pairs.count(); ++i) {
        idx += pairs.at(i).midiPairs.count();
        if (idx > splitpoint) {
            result = pairs.mid(i);
            pairs = pairs.mid(0, i);
        }
    }

    return result;
}
Exemplo n.º 27
0
bool Chord::PatternSort(const QList<int> &list1, const QList<int> &list2)
{
    // one list shorter than the other? sort based on length
    if (list1.length() < list2.length())
        return true;
    if (list1.length() > list2.length())
        return false;

    // both lists have same number of elements: perform lexicographic sorting
    QList<int>::const_iterator it1 = list1.begin();
    QList<int>::const_iterator it2 = list2.begin();
    for (;it1 != list1.end();++it1,++it2)
    {
        if (*it1 < *it2)
            return true;
        if (*it1 > *it2)
            return false;
        return PatternSort(list1.mid(1), list2.mid(1));
    }
    return false;
}
Exemplo n.º 28
0
void MessageHandler::processMessageRequest(QList<QByteArray> msg) {
    QList<QByteArray> return_path;

    int index = 0;
    while(!msg.at(index).isEmpty() && index < msg.size()) {
        return_path << msg.at(index);
        ++index;
    }
    
    QList<QByteArray> payload(msg.mid(index + 1));
    
    Q_EMIT requesetReceived(return_path, payload);
}
bool cluster_is_already_being_used(const QVector<double>& times_in, const QVector<double>& other_times_in, merge_across_channels_v2_opts opts)
{
    if (times_in.isEmpty())
        return false;
    if (other_times_in.isEmpty())
        return false;
    int T = opts.clip_size;
    QVector<double> times = times_in;
    QVector<double> other_times = other_times_in;
    qSort(times);
    qSort(other_times);
    QList<int> counts; //size = 2*T+1
    for (int a = 0; a < 2 * T + 1; a++) {
        counts << 0;
    }
    int ii_other = 0;
    for (int ii = 0; ii < times.count(); ii++) {
        double t0 = times[ii];
        while ((ii_other + 1 < other_times.count()) && (other_times[ii_other] < t0 - T))
            ii_other++;
        while ((ii_other < other_times.count()) && (other_times[ii_other] <= t0 + T)) {
            int diff = (int)(other_times[ii_other] - t0);
            if ((-T <= diff) && (diff <= T)) {
                counts[diff + T]++;
            }
            ii_other++;
        }
    }
    //look at +/- 3 timepoints
    int max_dt = 3;
    double best_frac = 0;
    int best_t = 0;
    for (int t = max_dt; t + max_dt < 2 * T + 1; t++) {
        int count0 = 0;
        for (int t2 = t - max_dt; t2 <= t + max_dt; t2++) {
            count0 += counts[t2];
        }
        double frac = count0 * 1.0 / times.count();
        if (frac > best_frac) {
            best_frac = frac;
            best_t = t;
        }
    }
    if (best_frac >= opts.event_fraction_threshold) {
        printf("Cluster is already being used: frac=%g, dt=%d!\n", best_frac, best_t - T);
        qDebug().noquote() << counts.mid(best_t - max_dt, max_dt * 2 + 1);
        return true;
    }
    return false;
}
Exemplo n.º 30
0
QList<Page *> FileEngine::listPages(QObject *parent, Engine::Filters filters, Engine::SortFlags sort, int depth, int limit)
{
    Q_D(const FileEngine);
    Q_UNUSED(parent)

    QList<Page *> ret;
    QList<Page *> pages;

    if (filters != NoFilter) {
        if (filters & Posts) {
            pages.append(d->posts);
        }

        if (filters & Pages) {
            pages.append(d->pages);
        }
    } else {
        pages = d->pages + d->posts;
    }


    if (depth == -1) {
        ret = pages;
    } else {
        Q_FOREACH (Page *page, pages) {
            if (depth != -1 && page->path().count(QLatin1Char('/')) > depth) {
                continue;
            }

            ret.append(page);
        }
    }

    // apply the sorting
    if (sort & Date && sort & Name) {
        qSort(ret.begin(), ret.end(), sort & Reversed ? dateNameGreaterThan : dateNameLessThan);
    } else if (sort & Date) {
        qSort(ret.begin(), ret.end(), sort & Reversed ? dateGreaterThan : dateLessThan);
    } else if (sort & Name) {
        qSort(ret.begin(), ret.end(), sort & Reversed ? nameGreaterThan : nameLessThan);
    }

    // Limit the list
    if (limit == -1) {
        return ret;
    } else {
        return ret.mid(0, limit);
    }
}