当前位置: 首页>>代码示例>>C++>>正文


C++ QVector::reserve方法代码示例

本文整理汇总了C++中QVector::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector::reserve方法的具体用法?C++ QVector::reserve怎么用?C++ QVector::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QVector的用法示例。


在下文中一共展示了QVector::reserve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: calcCylinderVertices

QVector<GLfloat> calcCylinderVertices() {
	QVector<GLfloat> vertices;
	vertices.reserve(sides* 4 * 3);

	qreal theta = 0;
	for (int j = 0; j < sides; j++) {
		for(int i = 0; i < 2; i++) {
			vertices.append(qCos(theta));
			vertices.append(1.0f);
			vertices.append(qSin(theta));

			vertices.append(qCos(theta));
			vertices.append(-1.0f);
			vertices.append(qSin(theta));
		}

		theta += (2 * M_PI) / sides;
	}

	return vertices;
}
开发者ID:snake10,项目名称:sickle,代码行数:21,代码来源:cylinder.cpp

示例2: deleteFlags

bool Store::deleteFlags(const PimItem::List &items, const QSet<QByteArray> &flags, bool &flagsChanged)
{
    DataStore *store = connection()->storageBackend();

    QVector<Flag> flagList;
    flagList.reserve(flags.size());
    for (auto iter = flags.cbegin(), end = flags.cend(); iter != end; ++iter) {
        Flag flag = Flag::retrieveByName(QString::fromUtf8(*iter));
        if (!flag.isValid()) {
            continue;
        }

        flagList.append(flag);
    }

    if (!store->removeItemsFlags(items, flagList, &flagsChanged)) {
        qCDebug(AKONADISERVER_LOG) << "Store::deleteFlags: Unable to remove item flags";
        return false;
    }
    return true;
}
开发者ID:KDE,项目名称:akonadi,代码行数:21,代码来源:store.cpp

示例3: btConfig

QVector<QString> CDisplaySettingsPage::bookNameAbbreviationsTryVector() {
    QVector<QString> atv;
    atv.reserve(4);
    {
        QString settingsLanguage = btConfig().value<QString>("GUI/booknameLanguage");
        if (!settingsLanguage.isEmpty())
            atv.append(settingsLanguage);
    }
    {
        const QString localeLanguageAndCountry = QLocale::system().name();
        if (!localeLanguageAndCountry.isEmpty()) {
            atv.append(localeLanguageAndCountry);
            int i = localeLanguageAndCountry.indexOf('_');
            if (i > 0)
                atv.append(localeLanguageAndCountry.left(i));
        }
    }
    BT_ASSERT(CLanguageMgr::instance()->languageForAbbrev("en_US"));
    atv.append("en_US");
    return atv;
}
开发者ID:bibletime,项目名称:bibletime,代码行数:21,代码来源:cdisplaysettings.cpp

示例4: cleanupEmptyDirectories

    void ArtworksRepository::cleanupEmptyDirectories() {
        LOG_DEBUG << "#";
        int count = m_DirectoriesList.length();
        QVector<int> indicesToRemove;
        indicesToRemove.reserve(count);

        for (int i = 0; i < count; ++i) {
            const QString &directory = m_DirectoriesList[i];
            if (m_DirectoriesHash[directory] == 0) {
                indicesToRemove.append(i);
            }
        }

        if (!indicesToRemove.isEmpty()) {
            LOG_INFO << indicesToRemove.length() << "empty directory(ies)...";

            QVector<QPair<int, int> > rangesToRemove;
            Helpers::indicesToRanges(indicesToRemove, rangesToRemove);
            removeItemsAtIndices(rangesToRemove);
        }
    }
开发者ID:RostaTasha,项目名称:xpiks,代码行数:21,代码来源:artworksrepository.cpp

示例5: onTabsMoved

void TabWidget::onTabsMoved(const QString &oldPrefix, const QString &newPrefix, const QList<int> &indexes)
{
    const int newCurrentIndex = indexes.indexOf(currentIndex());
    Q_ASSERT(newCurrentIndex != -1);

    m_stackedWidget->hide();

    QVector<QWidget*> widgets;
    widgets.reserve(m_stackedWidget->count());

    while ( m_stackedWidget->count() > 0 ) {
        QWidget *w = m_stackedWidget->widget(0);
        widgets.append(w);
        m_stackedWidget->removeWidget(w);
    }

    foreach (int index, indexes) {
        Q_ASSERT(index >= 0);
        Q_ASSERT(index < widgets.count());
        m_stackedWidget->insertWidget(-1, widgets[index]);
    }
开发者ID:RavenB,项目名称:CopyQ,代码行数:21,代码来源:tabwidget.cpp

示例6: OGROpen

QVector<QgsDataItem*> QgsOgrDataCollectionItem::createChildren()
{
  QVector<QgsDataItem*> children;

  OGRSFDriverH hDriver;
  OGRDataSourceH hDataSource = OGROpen( TO8F( mPath ), false, &hDriver );
  if ( !hDataSource )
    return children;
  int numLayers = OGR_DS_GetLayerCount( hDataSource );

  children.reserve( numLayers );
  for ( int i = 0; i < numLayers; ++i )
  {
    QgsOgrLayerItem* item = dataItemForLayer( this, QString(), mPath, hDataSource, i );
    children.append( item );
  }

  OGR_DS_Destroy( hDataSource );

  return children;
}
开发者ID:rhurlin,项目名称:QGIS,代码行数:21,代码来源:qgsogrdataitems.cpp

示例7: sizeof

QVector<ShaderAttribute> QGraphicsHelperGL4::programAttributesAndLocations(GLuint programId)
{
    QVector<ShaderAttribute> attributes;
    GLint nbrActiveAttributes = 0;
    m_funcs->glGetProgramiv(programId, GL_ACTIVE_ATTRIBUTES, &nbrActiveAttributes);
    attributes.reserve(nbrActiveAttributes);
    char attributeName[256];
    for (GLint i = 0; i < nbrActiveAttributes; i++) {
        ShaderAttribute attribute;
        GLsizei attributeNameLength = 0;
        // Size is 1 for scalar and more for struct or arrays
        // Type is the GL Type
        m_funcs->glGetActiveAttrib(programId, i, sizeof(attributeName) - 1, &attributeNameLength,
                                   &attribute.m_size, &attribute.m_type, attributeName);
        attributeName[sizeof(attributeName) - 1] = '\0';
        attribute.m_location = m_funcs->glGetAttribLocation(programId, attributeName);
        attribute.m_name = QString::fromUtf8(attributeName, attributeNameLength);
        attributes.append(attribute);
    }
    return attributes;
}
开发者ID:James-intern,项目名称:Qt,代码行数:21,代码来源:qgraphicshelpergl4.cpp

示例8: dir

QVector<QString> VConfigManager::getNoteTemplates(DocType p_type) const
{
    QVector<QString> res;
    QDir dir(getTemplateConfigFolder());
    if (!dir.exists()) {
        dir.mkpath(getTemplateConfigFolder());
        return res;
    }

    dir.setFilter(QDir::Files | QDir::NoSymLinks);
    QStringList files = dir.entryList();
    res.reserve(files.size());
    for (auto const &item : files) {
        if (p_type == DocType::Unknown
            || p_type == VUtils::docTypeFromName(item)) {
            res.push_back(item);
        }
    }

    return res;
}
开发者ID:liunianbanbo,项目名称:vnote,代码行数:21,代码来源:vconfigmanager.cpp

示例9: submitItems

    void SpellCheckerService::submitItems(const QVector<ISpellCheckable *> &itemsToCheck) {
        if (!m_WorkerIsAlive) { return; }

        if (m_SpellCheckWorker != NULL && !m_SpellCheckWorker->isCancelled()) {
            QVector<SpellCheckItemBase *> items;
            int length = itemsToCheck.length();

            items.reserve(length);

            for (int i = 0; i < length; ++i) {
                SpellCheck::ISpellCheckable *itemToCheck = itemsToCheck.at(i);
                SpellCheckItem *item = new SpellCheckItem(itemToCheck, Common::SpellCheckAll);
                itemToCheck->connectSignals(item);
                items.append(item);
            }

            qInfo() << "SpellCheck service: about to submit" << length << "items";

            m_SpellCheckWorker->submitItems(items);
            m_SpellCheckWorker->submitItem(new SpellCheckSeparatorItem());
        }
    }
开发者ID:snikolau,项目名称:xpiks,代码行数:22,代码来源:spellcheckerservice.cpp

示例10: stateSelectionChanged

void StateMachineViewerServer::stateSelectionChanged()
{
    const QModelIndexList &selection = m_stateSelectionModel->selectedRows();
    qDebug() << selection;
    QVector<State> filter;
    filter.reserve(selection.size());
    foreach (const QModelIndex &index, selection) {
        State state = index.data(StateModel::StateValueRole).value<State>();
        bool addState = true;
        /// only pick the top-level items of the selection
        // NOTE: this might be slow for large selections, if someone wants to come up with a better
        // algorithm, please - go for it!
        foreach (State potentialParent, filter) {
            if (selectedStateMachine()->isDescendantOf(potentialParent, state)) {
                addState = false;
                break;
            }
        }

        if (addState)
            filter << state;
    }
开发者ID:iamsergio,项目名称:GammaRay,代码行数:22,代码来源:statemachineviewerserver.cpp

示例11: calcCylinderUVs

QVector<GLfloat> calcCylinderUVs() {
	QVector<GLfloat> UVs;
	UVs.reserve(sides * 4 * 2);

	qreal theta = 0;
	for (int j = 0; j < sides; j++) {
		for(int i = 0; i < 2; i++) {
			UVs.append(i);
			UVs.append(static_cast<float>(j) / sides);
		}

		UVs.append(qCos(theta));
		UVs.append(qSin(theta));

		UVs.append(qCos(theta));
		UVs.append(qSin(theta));

		theta += (2 * M_PI) / sides;
	}

	return UVs;
}
开发者ID:snake10,项目名称:sickle,代码行数:22,代码来源:cylinder.cpp

示例12: fetchCollectionsResponse

Protocol::FetchCollectionsResponse HandlerHelper::fetchCollectionsResponse(const Collection &col,
                                                                           const CollectionAttribute::List &attrs,
                                                                           bool includeStatistics,
                                                                           int ancestorDepth,
                                                                           const QStack<Collection> &ancestors,
                                                                           const QStack<CollectionAttribute::List> &ancestorAttributes,
                                                                           bool isReferenced,
                                                                           const QStringList &mimeTypes)
{
    Protocol::FetchCollectionsResponse response(col.id());
    response.setParentId(col.parentId());
    response.setName(col.name());
    response.setMimeTypes(mimeTypes);
    response.setRemoteId(col.remoteId());
    response.setRemoteRevision(col.remoteRevision());
    response.setResource(col.resource().name());
    response.setIsVirtual(col.isVirtual());

    if (includeStatistics) {
        const CollectionStatistics::Statistics stats = CollectionStatistics::self()->statistics(col);
        if (stats.count > -1) {
            Protocol::FetchCollectionStatsResponse statsResponse(stats.count,
                                                                 stats.count - stats.read,
                                                                 stats.size);
            response.setStatistics(statsResponse);
        }
    }

    if (!col.queryString().isEmpty()) {
        response.setSearchQuery(col.queryString());
        QVector<qint64> searchCols;
        const QStringList searchColIds = col.queryCollections().split(QLatin1Char(' '));
        searchCols.reserve(searchColIds.size());
        Q_FOREACH (const QString &searchColId, searchColIds) {
            searchCols << searchColId.toLongLong();
        }
        response.setSearchCollections(searchCols);
    }
开发者ID:KDE,项目名称:akonadi,代码行数:38,代码来源:handlerhelper.cpp

示例13: handleWithSamples

void Connection::handleWithSamples()
{
    QVector<quint8> newSamples;
    int i, count, size;
    int freq = FREQ;
    qint64 sum;

    if(channel == MIC) freq = MIC_FREQ; // mikrofon

    sum = 0;
    size = rawSamples.size();
    newSamples.reserve(INTERVAL);
    count = qRound(SAMPLES_PER_SEC/freq); // po ile uśredniać

    for(i=0;i<size;i++)
    {
        sum += rawSamples[i];
        if((i % count) == (count-1))
        {
            newSamples.append(qRound((float)sum / (float)count));
            sum = 0;
        }
    }
    if((i%count) > count/2)
    {
        newSamples.append(qRound((float)sum / (float)(i%count)));
    }

    samples << newSamples;

    size = newSamples.size();
    for(i=0;i<size;i++)
    {
        ++ln;
        ln = ln & Nmask;
        lastSamples[ln] = newSamples[i];
    }
}
开发者ID:PZSAS,项目名称:serv,代码行数:38,代码来源:connection.cpp

示例14: addFrame

void BackgroundFinder::addFrame(const QImage &img)
{
    if (_rolling.isEmpty())
    {
        for (int i = 0; i < img.width() * img.height(); i++)
        {
            _rolling.append(RollingMedianCalculator());
        }
    }


    QVector<QFuture<QRgb> > futures;
    futures.reserve(img.width() * img.height());
    for (int y = 0; y < img.height(); y++)
    {
        for (int x = 0; x < img.width(); x++)
        {
            const int index = y * img.width() + x;
            QFuture<QRgb> future = QtConcurrent::run(&_rolling[index],
                                                     &RollingMedianCalculator::next,
                                                     img.pixel(x,y));
            futures.append(future);
        }
    }

    QImage newBG(img.size(), img.format());
    for (int y = 0; y < img.height(); y++)
    {
        for (int x = 0; x < img.width(); x++)
        {
            const int index = y * img.width() + x;
            futures[index].waitForFinished();
            newBG.setPixel(x,y, futures.at(index).result());
        }
    }

    _bg = newBG;
}
开发者ID:raptorswing,项目名称:VideoObjectDetection,代码行数:38,代码来源:BackgroundFinder.cpp

示例15: linestringFromPolyline

std::unique_ptr<QgsPolygon> QgsGeometryFactory::fromPolygonXY( const QgsPolygonXY &polygon )
{
  std::unique_ptr< QgsPolygon > poly = qgis::make_unique< QgsPolygon >();

  QVector<QgsCurve *> holes;
  holes.reserve( polygon.size() );
  for ( int i = 0; i < polygon.size(); ++i )
  {
    std::unique_ptr< QgsLineString > l = linestringFromPolyline( polygon.at( i ) );
    l->close();

    if ( i == 0 )
    {
      poly->setExteriorRing( l.release() );
    }
    else
    {
      holes.push_back( l.release() );
    }
  }
  poly->setInteriorRings( holes );
  return poly;
}
开发者ID:alexbruy,项目名称:QGIS,代码行数:23,代码来源:qgsgeometryfactory.cpp


注:本文中的QVector::reserve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。