本文整理汇总了C++中QList::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ QList::reserve方法的具体用法?C++ QList::reserve怎么用?C++ QList::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QList
的用法示例。
在下文中一共展示了QList::reserve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadSurveyChunk
/**
* @brief cwRegionLoadTask::loadSurveyChunk
* @param protoChunk
* @param chunk
*/
void cwRegionLoadTask::loadSurveyChunk(const CavewhereProto::SurveyChunk& protoChunk, cwSurveyChunk *chunk)
{
QList<cwStation> stations;
stations.reserve(protoChunk.stations_size());
for(int i = 0 ; i < protoChunk.stations_size(); i++) {
cwStation station = loadStation(protoChunk.stations(i));
stations.append(station);
}
QList<cwShot> shots;
shots.reserve(protoChunk.shots_size());
for(int i = 0; i < protoChunk.shots_size(); i++) {
cwShot shot = loadShot(protoChunk.shots(i));
shots.append(shot);
}
if(stations.count() - 1 != shots.count()) {
qDebug() << "Shot, station count mismatch, survey chunk invalid:" << stations.count() << shots.count();
return;
}
for(int i = 0; i < stations.count() - 1; i++) {
cwStation fromStation = stations[i];
cwStation toStation = stations[i + 1];
cwShot shot = shots[i];
chunk->appendShot(fromStation, toStation, shot);
}
}
示例2: loadScrap
/**
* @brief cwRegionLoadTask::loadScrap
* @param protoScrap
* @param scrap
*/
void cwRegionLoadTask::loadScrap(const CavewhereProto::Scrap& protoScrap, cwScrap *scrap)
{
QVector<QPointF> outlinePoint;
outlinePoint.resize(protoScrap.outlinepoints_size());
for(int i = 0; i < protoScrap.outlinepoints_size(); i++) {
outlinePoint[i] = loadPointF(protoScrap.outlinepoints(i));
}
scrap->setPoints(outlinePoint);
QList<cwNoteStation> stations;
stations.reserve(protoScrap.notestations_size());
for(int i = 0; i < protoScrap.notestations_size(); i++) {
stations.append(loadNoteStation(protoScrap.notestations(i)));
}
scrap->setStations(stations);
QList<cwLead> leads;
leads.reserve(protoScrap.leads_size());
for(int i = 0; i < protoScrap.leads_size(); i++) {
leads.append(loadLead(protoScrap.leads(i)));
}
scrap->setLeads(leads);
loadNoteTranformation(protoScrap.notetransformation(), scrap->noteTransformation());
scrap->setCalculateNoteTransform(protoScrap.calculatenotetransform());
scrap->setTriangulationData(loadTriangulatedData(protoScrap.triangledata()));
scrap->setType((cwScrap::ScrapType)protoScrap.type());
}
示例3: separableFilter
void Document::separableFilter(const QVector<qreal> &filter)
{
if (std::min(m_selection.height(), m_selection.width()) < filter.size()) {
qWarning() << "Too large filter!";
}
if (filter.size() < 2) {
qWarning() << "Filter size must be at least 2";
}
qDebug() << "separableFilter(" << filter << ")";
int n = filter.size() - 1;
QList<ConcurrentLinearFilter> jobs;
jobs.reserve(m_selection.height());
for (int line = m_selection.top(); line <= m_selection.bottom(); ++line) {
QVector<QRgb> head(n);
for (int i = 0; i < n; ++i)
head[i] = m_image.pixel(abs(m_selection.x() - n + i), line);
QVector<QRgb> tail(n);
for (int i = 0; i < n; ++i) {
int x = m_selection.right() + 1 + i;
if (x >= m_image.width())
x = 2 * m_image.width() - x - 1;
tail[i] = m_image.pixel(x, line);
}
jobs.append(ConcurrentLinearFilter(filter, head, tail, m_selection.width(), sizeof(QRgb),
m_image.scanLine(line) + m_selection.left() * sizeof(QRgb)));
}
QtConcurrent::blockingMap(jobs, ConcurrentLinearFilter::process);
jobs.clear();
jobs.reserve(m_selection.width());
for (int column = m_selection.left(); column <= m_selection.right(); ++column) {
QVector<QRgb> head(n);
for (int i = 0; i < n; ++i)
head[i] = m_image.pixel(column, abs(m_selection.top() - n + i));
QVector<QRgb> tail(n);
for (int i = 0; i < n; ++i) {
int y = m_selection.bottom() + 1 + i;
if (y >= m_image.height())
y = 2 * m_image.height() - y - 1;
tail[i] = m_image.pixel(column, y);
}
jobs.append(ConcurrentLinearFilter(filter, head, tail, m_selection.height(), m_image.bytesPerLine(),
m_image.scanLine(m_selection.top()) + column * sizeof(QRgb)));
}
QtConcurrent::blockingMap(jobs, ConcurrentLinearFilter::process);
setModified(true);
emit repaint(m_selection);
}
示例4: mapToReversedLists
//! populate two lists (ks, vs) from map - in reverse order
template <class Key, class T> void mapToReversedLists( const QMap< Key, T >& map, QList<Key>& ks, QList<T>& vs )
{
ks.reserve( map.size() );
vs.reserve( map.size() );
typename QMap<Key, T>::const_iterator i = map.constEnd();
while ( i-- != map.constBegin() )
{
ks.append( i.key() );
vs.append( i.value() );
}
}
示例5: exportContacts
QString SeasideCache::exportContacts()
{
QVersitContactExporter exporter;
QList<QContact> contacts;
contacts.reserve(instance->m_people.count());
QList<QContactLocalId> contactsToFetch;
contactsToFetch.reserve(instance->m_people.count());
const QContactLocalId selfId = instance->m_manager.selfContactId();
typedef QHash<QContactLocalId, SeasideCacheItem>::iterator iterator;
for (iterator it = instance->m_people.begin(); it != instance->m_people.end(); ++it) {
if (it.key() == selfId) {
continue;
} else if (it->hasCompleteContact) {
contacts.append(it->contact);
} else {
contactsToFetch.append(it.key());
}
}
if (!contactsToFetch.isEmpty()) {
QList<QContact> fetchedContacts = instance->m_manager.contacts(contactsToFetch);
contacts.append(fetchedContacts);
}
if (!exporter.exportContacts(contacts)) {
qWarning() << Q_FUNC_INFO << "Failed to export contacts: " << exporter.errorMap();
return QString();
}
QFile vcard(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)
+ QDir::separator()
+ QDateTime::currentDateTime().toString("ss_mm_hh_dd_mm_yyyy")
+ ".vcf");
if (!vcard.open(QIODevice::WriteOnly)) {
qWarning() << "Cannot open " << vcard.fileName();
return QString();
}
QVersitWriter writer(&vcard);
if (!writer.startWriting(exporter.documents())) {
qWarning() << Q_FUNC_INFO << "Can't start writing vcards " << writer.error();
return QString();
}
// TODO: thread
writer.waitForFinished();
return vcard.fileName();
}
示例6: addChildren
void GeoTreeModel::addChildren(GeoObjectListItem* sfcList,
GeoLib::SurfaceVec const& surface_vec,
size_t start_index,
size_t end_index)
{
const std::vector<GeoLib::Surface*>* surfaces = surface_vec.getVector();
const std::vector<GeoLib::Point*> &nodesVec(*((*surfaces)[start_index]->getPointVec()));
for (size_t i = start_index; i < end_index; i++)
{
QList<QVariant> surface;
surface.reserve(4);
surface << "Surface " + QString::number(i) << "" <<
"" << "";
const GeoLib::Surface &sfc(*(*surfaces)[i]);
GeoTreeItem* surfaceItem(new GeoTreeItem(surface, sfcList, &sfc));
sfcList->appendChild(surfaceItem);
int nElems = static_cast<int>((*surfaces)[i]->getNTriangles());
for (int j = 0; j < nElems; j++)
{
QList<QVariant> elem;
elem.reserve(4);
const GeoLib::Triangle &triangle(*sfc[j]);
elem << j << static_cast<int>(triangle[0])
<< static_cast<int>(triangle[1])
<< static_cast<int>(triangle[2]);
TreeItem* child(new TreeItem(elem, surfaceItem));
surfaceItem->appendChild(child);
for (int k = 0; k < 3; k++)
{
QList<QVariant> node;
node.reserve(4);
const GeoLib::Point &pnt(*(nodesVec[triangle[k]]));
node << static_cast<int>(triangle[k])
<< QString::number(pnt[0], 'f')
<< QString::number(pnt[1], 'f')
<< QString::number(pnt[2], 'f');
child->appendChild(new TreeItem(node, child));
}
}
}
for (auto pnt = surface_vec.getNameIDMapBegin(); pnt != surface_vec.getNameIDMapEnd(); ++pnt)
QVariant pnt_data (sfcList->child(pnt->second)->setData(1, QString::fromStdString(pnt->first)));
INFO("%d surfaces added.", end_index - start_index);
}
示例7: fillNeighborStructures
void MeshGenerator::fillNeighborStructures()
{
QList<QSet<int> > vertexElements;
vertexElements.reserve(nodeList.count());
for (int i = 0; i < nodeList.count(); i++)
vertexElements.push_back(QSet<int>());
for (int i = 0; i < elementList.count(); i++)
if (elementList[i].isUsed)
for (int elemNode = 0; elemNode < (elementList[i].isTriangle() ? 3 : 4); elemNode++)
vertexElements[elementList[i].node[elemNode]].insert(i);
for (int i = 0; i < edgeList.count(); i++)
{
if (edgeList[i].isUsed && edgeList[i].marker != -1)
{
QSet<int> neighbours = vertexElements[edgeList[i].node[0]];
neighbours.intersect(vertexElements[edgeList[i].node[1]]);
assert((neighbours.size() > 0) && (neighbours.size() <= 2));
edgeList[i].neighElem[0] = neighbours.values()[0];
if (neighbours.size() == 2)
edgeList[i].neighElem[1] = neighbours.values()[1];
}
}
}
示例8: insertRows
bool GenericEditableTableModel::insertRows ( int row, int count, const QModelIndex & parent)
{
if(row<0 || row>rowCount()){
return false;
}
beginInsertRows(parent, row, row+count-1);
modelData.reserve(rowCount()+count);
int colCount=columnCount();
int currentRowCount=rowCount();
for(int i=0; i<count; i++){
QList<QHash<int,QVariant> > newCols;
newCols.reserve(colCount);
for(int j=0; j<colCount; j++){
newCols.append(QHash<int,QVariant>());
}
if(row==currentRowCount){
modelData.append(newCols);
}else{
modelData.insert(row+i, newCols);
}
}
endInsertRows();
return true;
}
示例9: initialize
void initialize(const FileList &targetFiles, const FileList &queryFiles)
{
Output::initialize(targetFiles, queryFiles);
bestMatches.reserve(queryFiles.size());
for (int i=0; i<queryFiles.size(); i++)
bestMatches.append(BestMatch(-std::numeric_limits<float>::max(), QPair<int,int>(-1, -1)));
}
示例10: shouldAddItemInTreeList
void FollowupReminderInfoDialogTest::shouldAddItemInTreeList()
{
FollowUpReminderInfoDialog dlg;
FollowUpReminderInfoWidget *infowidget = dlg.findChild<FollowUpReminderInfoWidget *>(QStringLiteral("FollowUpReminderInfoWidget"));
QTreeWidget *treeWidget = infowidget->findChild<QTreeWidget *>(QStringLiteral("treewidget"));
QList<FollowUpReminder::FollowUpReminderInfo *> lstInfo;
lstInfo.reserve(10);
for (int i = 0; i < 10; ++i) {
FollowUpReminder::FollowUpReminderInfo *info = new FollowUpReminder::FollowUpReminderInfo();
lstInfo.append(info);
}
dlg.setInfo(lstInfo);
//We load invalid infos.
QCOMPARE(treeWidget->topLevelItemCount(), 0);
//Load valid infos
for (int i = 0; i < 10; ++i) {
FollowUpReminder::FollowUpReminderInfo *info = new FollowUpReminder::FollowUpReminderInfo();
info->setOriginalMessageItemId(42);
info->setMessageId(QStringLiteral("foo"));
info->setFollowUpReminderDate(QDate::currentDate());
info->setTo(QStringLiteral("To"));
lstInfo.append(info);
}
dlg.setInfo(lstInfo);
QCOMPARE(treeWidget->topLevelItemCount(), 10);
}
示例11:
static QList<double> _calcEqualIntervalBreaks( double minimum, double maximum, int classes )
{
// Equal interval algorithm
//
// Returns breaks based on dividing the range ('minimum' to 'maximum')
// into 'classes' parts.
double step = ( maximum - minimum ) / classes;
QList<double> breaks;
double value = minimum;
breaks.reserve( classes );
for ( int i = 0; i < classes; i++ )
{
value += step;
breaks.append( value );
}
// floating point arithmetics is not precise:
// set the last break to be exactly maximum so we do not miss it
breaks[classes-1] = maximum;
return breaks;
}
示例12: load
void CookieJar::load()
{
QFile cookieFile(m_cookieFileName);
if (!cookieFile.open(QIODevice::ReadOnly))
return;
QDataStream stream(&cookieFile);
quint8 version;
stream >> version;
if (version != cookieFileVersion)
return;
QList<QNetworkCookie> cookies;
qint32 count;
stream >> count;
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
cookies.reserve(count);
#endif
for (int i = 0; i < count && !stream.atEnd(); ++i) {
QByteArray rawCookie;
stream >> rawCookie;
cookies += QNetworkCookie::parseCookies(rawCookie);
}
setAllCookies(cookies);
expireCookies();
}
示例13: pool
QList<float> pool(const Mat &bottom, const Mat &top) const
{
QList<float> features;
for (int i=0; i<=top.rows-3; i+=3) {
for (int j=0; j<=top.cols-3; j+=3) {
QList<float> vals;
vals.reserve(3*3 + 4*4);
// Top values
for (int k=0; k<3; k++) {
const float *data = top.ptr<float>(i+k, j);
for (int l=0; l<3; l++)
vals.append(data[l]);
}
// Bottom values
for (int k=0; k<4; k++) {
const float *data = bottom.ptr<float>(4*i/3+k, 4*j/3);
for (int l=0; l<4; l++)
vals.append(data[l]);
}
double mean, stddev;
Common::MeanStdDev(vals, &mean, &stddev);
features.append(mean);
features.append(stddev);
}
}
return features;
}
示例14: foreach
QList<VDPtr> VideoDevice::getSystemDevices() {
auto udevs = VideoDeviceImpl::getSystemDevices();
QList<VDPtr> devs;
devs.reserve(udevs.size());
foreach (const auto &dev, udevs) {
devs << VDPtr(new VideoDevice(dev));
}
示例15: _q_sourceLayoutChanged
void QIdentityProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint)
{
Q_Q(QIdentityProxyModel);
for (int i = 0; i < proxyIndexes.size(); ++i) {
q->changePersistentIndex(proxyIndexes.at(i), q->mapFromSource(layoutChangePersistentIndexes.at(i)));
}
layoutChangePersistentIndexes.clear();
proxyIndexes.clear();
QList<QPersistentModelIndex> parents;
parents.reserve(sourceParents.size());
foreach (const QPersistentModelIndex &parent, sourceParents) {
if (!parent.isValid()) {
parents << QPersistentModelIndex();
continue;
}
const QModelIndex mappedParent = q->mapFromSource(parent);
Q_ASSERT(mappedParent.isValid());
parents << mappedParent;
}
q->layoutChanged(parents, hint);
}