本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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]);
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
示例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;
}
示例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;
}
示例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);
}
示例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];
}
}
示例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;
}
示例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;
}