本文整理汇总了C++中QVector::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector::resize方法的具体用法?C++ QVector::resize怎么用?C++ QVector::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector
的用法示例。
在下文中一共展示了QVector::resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qAbs
QVector<qreal> PolarChartLogValueAxisRadial::calculateLayout() const
{
QLogValueAxis *logValueAxis = qobject_cast<QLogValueAxis *>(axis());
QVector<qreal> points;
points.resize(logValueAxis->tickCount());
const qreal logMax = std::log10(logValueAxis->max()) / std::log10(logValueAxis->base());
const qreal logMin = std::log10(logValueAxis->min()) / std::log10(logValueAxis->base());
const qreal innerEdge = logMin < logMax ? logMin : logMax;
const qreal delta = (axisGeometry().width() / 2.0) / qAbs(logMax - logMin);
const qreal initialSpan = (qCeil(innerEdge) - innerEdge) * delta;
for (int i = 0; i < logValueAxis->tickCount(); ++i)
points[i] = initialSpan + (delta * qreal(i));
return points;
}
示例2: threadSafePicture
void TestQgsSvgCache::threadSafePicture()
{
// QPicture playback is NOT thread safe with implicitly shared copies - this
// unit test checks that concurrent drawing of svg as QPicture from QgsSvgCache
// returns a detached copy which is safe to use across threads
// refs:
// https://issues.qgis.org/issues/17077
// https://issues.qgis.org/issues/17089
QgsSvgCache cache;
QString svgPath = TEST_DATA_DIR + QStringLiteral( "/sample_svg.svg" );
// smash picture rendering over multiple threads
QVector< int > list;
list.resize( 100 );
QtConcurrent::blockingMap( list, RenderPictureWrapper( cache, svgPath ) );
}
示例3: writeImage
bool ImageIO::writeImage(QVector<int> &pixels, const QString &filePath, const LayerDesc &desc, int width, int height)
{
assert(desc.numChannels() == 3);
QVector<float> image;
image.resize(pixels.size()*3);
float* data = image.data();
for(int i=0; i<pixels.size(); i++){
int value = pixels.at(i);
double fvalue = (double)value / 255.0;
data[3*i] = fvalue - floor(fvalue);
fvalue = (double)value / (255.0*255.0);
data[3*i+1] = fvalue - floor(fvalue);
fvalue = (double)value / (255.0*255.0*255.0);
data[3*i+2] = fvalue - floor(fvalue);
}
return writeImage(image,filePath,desc,width,height);
}
示例4: getSoundInputFromUID
int getSoundInputFromUID(int inputid, const QString& uid)
{
if(uid.isEmpty())
return inputid;
QVector<SoundDevice> inputdev;
int count = 0;
TT_GetSoundDevices(NULL, &count);
inputdev.resize(count);
if(count)
TT_GetSoundDevices(&inputdev[0], &count);
SoundDevice dev;
if(getSoundDevice(uid, inputdev, dev))
inputid = dev.nDeviceID;
return inputid;
}
示例5: synchronizeSimulator
void NeuroMlWorker::synchronizeSimulator(Simulator *simulator) {
NeuronSimulator* neuronSimulator = qobject_cast<NeuronSimulator*>(simulator);
QVector<CylinderVBOData> renderableData;
renderableData.resize(m_cylinders.size());
double scale = neuronSimulator->scale();
for(int i = 0; i < m_cylinders.size(); i++) {
const CylinderFrustum& cylinder = m_cylinders.at(i);
CylinderVBOData &renderableCylinder = renderableData[i];
renderableCylinder.radius1 = scale * cylinder.startRadius.value();
renderableCylinder.radius2 = scale * cylinder.endRadius.value();
renderableCylinder.vertex1 = scale * QVector3D(cylinder.start.x.value(), cylinder.start.y.value(), cylinder.start.z.value());
renderableCylinder.vertex2 = scale * QVector3D(cylinder.end.x.value(), cylinder.end.y.value(), cylinder.end.z.value());
}
neuronSimulator->cylinderData()->setData(renderableData);
neuronSimulator->m_cylinders = m_cylinders;
neuronSimulator->m_boundingBox = m_boundingBox;
}
示例6: renderer
QgsRasterRenderer* QgsPalettedRendererWidget::renderer()
{
int nColors = mTreeWidget->topLevelItemCount();
QColor* colorArray = new QColor[nColors];
QVector<QString> labels;
for ( int i = 0; i < nColors; ++i )
{
colorArray[i] = mTreeWidget->topLevelItem( i )->background( 1 ).color();
QString label = mTreeWidget->topLevelItem( i )->text( 2 );
if ( !label.isEmpty() )
{
if ( i >= labels.size() ) labels.resize( i + 1 );
labels[i] = label;
}
}
int bandNumber = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
return new QgsPalettedRasterRenderer( mRasterLayer->dataProvider(), bandNumber, colorArray, nColors, labels );
}
示例7: compileFunctions
bool JsonDbReduceDefinition::compileFunctions(QJSEngine *scriptEngine, QJsonObject definition, JsonDbJoinProxy *proxy,
QVector<QJSValue> &functions, QString &message)
{
bool status = true;
QStringList functionNames = (QStringList()
<< QLatin1String("add")
<< QLatin1String("subtract")
<< QLatin1String("sourceKeyFunction"));
int i = 0;
functions.resize(3);
foreach (const QString &functionName, functionNames) {
int functionNumber = i++;
if (!definition.contains(functionName))
continue;
QString script = definition.value(functionName).toString();
QString jsonDbBinding = proxy
? QStringLiteral("{createUuidFromString: proxy.createUuidFromString}")
: QStringLiteral("{}"); // strict mode causes the above to fail if proxy is undefined
// first, package it as a function that takes a jsondb proxy and returns the add/subtract function
QJSValue moduleFunction = scriptEngine->evaluate(QString::fromLatin1("(function (proxy) { %3 var jsondb = %2; return (%1); })")
.arg(script)
.arg(jsonDbBinding)
.arg(jsondbSettings->useStrictMode() ? QLatin1Literal("\"use strict\"; ") : QLatin1Literal("/* use nonstrict mode */")));
if (moduleFunction.isError() || !moduleFunction.isCallable()) {
message = QString::fromLatin1("Unable to parse %1 function: %2").arg(functionName).arg(moduleFunction.toString());
status = false;
continue;
}
// now pass it the jsondb proxy to get the add/subtract function
QJSValueList args;
if (proxy)
args << scriptEngine->newQObject(proxy);
else
args << QJSValue(QJSValue::UndefinedValue);
QJSValue function = moduleFunction.call(args);
if (function.isError() || !function.isCallable()) {
message = QString::fromLatin1("Unable to evaluate %1 function: %2").arg(functionName).arg(function.toString());
status = false;
}
functions[functionNumber] = function;
}
示例8: compressedObject
TraceObject* CachegrindLoader::compressedObject(const QString& name)
{
if ((name[0] != '(') || !name[1].isDigit()) return _data->object(checkUnknown(name));
// compressed format using _objectVector
int p = name.indexOf(')');
if (p<2) {
error(QStringLiteral("Invalid compressed ELF object ('%1')").arg(name));
return 0;
}
int index = name.midRef(1, p-1).toInt();
TraceObject* o = 0;
p++;
while((name.length()>p) && name.at(p).isSpace()) p++;
if (name.length()>p) {
if (_objectVector.size() <= index) {
int newSize = index * 2;
#if TRACE_LOADER
qDebug() << " CachegrindLoader: objectVector enlarged to "
<< newSize;
#endif
_objectVector.resize(newSize);
}
QString realName = checkUnknown(name.mid(p));
o = (TraceObject*) _objectVector.at(index);
if (o && (o->name() != realName)) {
error(QStringLiteral("Redefinition of compressed ELF object index %1 (was '%2') to %3")
.arg(index).arg(o->name()).arg(realName));
}
o = _data->object(realName);
_objectVector.replace(index, o);
}
else {
if ((_objectVector.size() <= index) ||
( (o=(TraceObject*)_objectVector.at(index)) == 0)) {
error(QStringLiteral("Undefined compressed ELF object index %1").arg(index));
return 0;
}
}
return o;
}
示例9: processorStarted
bool ALSACapturer::processorStarted()
{
m_max = 0.f;
m_error = 0.f;
snd_pcm_hw_params_t *hwparams;
snd_pcm_hw_params_alloca(&hwparams);
thePcmHandle = 0;
if (snd_pcm_open(&thePcmHandle, theDevice.toLatin1(), SND_PCM_STREAM_CAPTURE, thePeriodSize * thePeriods) < 0)
fprintf(stderr, "Error opening PCM device %s\n", qPrintable(theDevice));
else if (snd_pcm_hw_params_any(thePcmHandle, hwparams) < 0)
fprintf(stderr, "Can not configure this PCM device.\n");
else if (snd_pcm_hw_params_set_access(thePcmHandle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0)
fprintf(stderr, "Error setting access.\n");
else if (snd_pcm_hw_params_set_format(thePcmHandle, hwparams, SND_PCM_FORMAT_S16_LE) < 0)
fprintf(stderr, "Error setting format.\n");
else if (snd_pcm_hw_params_set_rate_resample(thePcmHandle, hwparams, theFrequency))
fprintf(stderr, "The rate %d Hz is not supported by your hardware.\n", theFrequency);
else if (snd_pcm_hw_params_set_channels(thePcmHandle, hwparams, theChannels) < 0)
fprintf(stderr, "Error setting channels.\n");
else if (snd_pcm_hw_params_set_periods(thePcmHandle, hwparams, thePeriods, 0) < 0)
fprintf(stderr, "Error setting periods.\n");
else if (snd_pcm_hw_params_set_buffer_size(thePcmHandle, hwparams, (thePeriodSize * thePeriods)) < 0)
fprintf(stderr, "Error setting buffersize.\n");
else if (snd_pcm_hw_params(thePcmHandle, hwparams) < 0)
fprintf(stderr, "Error setting HW params.\n");
else
{
uint f;
snd_pcm_hw_params_get_rate_resample(thePcmHandle, hwparams, &f);
qDebug() << "*** ACTUAL FREQUENCY" << f;
m_inData.resize(thePeriodSize * theChannels);
assert(!snd_pcm_nonblock(thePcmHandle, 1));
snd_pcm_prepare(thePcmHandle);
m_normalisation.clear();
for (uint c = 0; c < numOutputs(); c++)
m_inAvg[c] = 0.f;
return true;
}
if (thePcmHandle)
snd_pcm_close(thePcmHandle);
thePcmHandle = 0;
return false;
}
示例10: compressedFile
// Note: Callgrind sometimes gives different IDs for same file
// (when references to same source file come from different ELF objects)
TraceFile* CachegrindLoader::compressedFile(const QString& name)
{
if ((name[0] != '(') || !name[1].isDigit()) return _data->file(checkUnknown(name));
// compressed format using _fileVector
int p = name.indexOf(')');
if (p<2) {
error(QStringLiteral("Invalid compressed file ('%1')").arg(name));
return 0;
}
int index = name.midRef(1, p-1).toUInt();
TraceFile* f = 0;
p++;
while((name.length()>p) && name.at(p).isSpace()) p++;
if (name.length()>p) {
if (_fileVector.size() <= index) {
int newSize = index * 2;
#if TRACE_LOADER
qDebug() << " CachegrindLoader::fileVector enlarged to "
<< newSize;
#endif
_fileVector.resize(newSize);
}
QString realName = checkUnknown(name.mid(p));
f = (TraceFile*) _fileVector.at(index);
if (f && (f->name() != realName)) {
error(QStringLiteral("Redefinition of compressed file index %1 (was '%2') to %3")
.arg(index).arg(f->name()).arg(realName));
}
f = _data->file(realName);
_fileVector.replace(index, f);
}
else {
if ((_fileVector.size() <= index) ||
( (f=(TraceFile*)_fileVector.at(index)) == 0)) {
error(QStringLiteral("Undefined compressed file index %1").arg(index));
return 0;
}
}
return f;
}
示例11: generateData
void Generator::generateData(const QAudioFormat& format, unsigned char* ptr, qint64 length)
{
const int channelBytes = format.sampleSize() / 8;
if (length <= 0)
return;
QMutexLocker lock(m_mutex);
QVector<qreal> channels;
channels.resize(2);
// LOG_INFO() << "generating Sounds" << QDateTime::currentDateTime() << length;
initializeSounds();
while (length) {
generateTone(channels[0], channels[1], m_sampleIndex);
//const qreal x = soundFunc(2 * M_PI * frequency * qreal(sampleIndex ) / format.sampleRate());
for (int i=0; i<format.channelCount(); ++i) {
if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::UnSignedInt) {
const quint8 value = static_cast<quint8>((1.0 + channels[i]) / 2 * 255);
*reinterpret_cast<quint8*>(ptr) = value;
} else if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::SignedInt) {
const qint8 value = static_cast<qint8>(channels[i] * 127);
*reinterpret_cast<quint8*>(ptr) = value;
} else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::UnSignedInt) {
quint16 value = static_cast<quint16>((1.0 + channels[i]) / 2 * 65535);
if (format.byteOrder() == QAudioFormat::LittleEndian)
qToLittleEndian<quint16>(value, ptr);
else
qToBigEndian<quint16>(value, ptr);
} else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::SignedInt) {
qint16 value = static_cast<qint16>(channels[i] * 32767);
if (format.byteOrder() == QAudioFormat::LittleEndian)
qToLittleEndian<qint16>(value, ptr);
else
qToBigEndian<qint16>(value, ptr);
}
ptr += channelBytes;
length -= channelBytes;
}
++m_sampleIndex;
}
}
示例12: rearrangeDct
void FourierDCT::rearrangeDct(QVector<Complex> &elements, bool inverse)
{
QVector<Complex> result;
if (!inverse) {
for (int k = 0; k < elements.size(); k += 2) {
result << elements.at(k);
}
for (int k = elements.size() - 1; k >= 0; k -= 2) {
result << elements.at(k);
}
} else {
result.resize(elements.size());
for (int i = 0; i < elements.size() / 2; i++) {
result[2 * i] = elements.at(i);
result[2 * i + 1] = elements.at(elements.size() - 1 - i);
}
}
elements = result;
}
示例13: getPlatformList
QVector<cl_platform_id> getPlatformList()
{
QVector<cl_platform_id> list;
cl_int rv = CL_SUCCESS;
cl_uint count = 0;
rv = clGetPlatformIDs(0, NULL, &count);
if (rv!=CL_SUCCESS || !count)
{
return list;
}
list.resize(count);
rv = clGetPlatformIDs(list.size(), list.data(), NULL);
if (rv!=CL_SUCCESS)
{
list.clear();
}
return list;
}
示例14: uniformName
QVector<ShaderUniform> QGraphicsHelperES2::programUniformsAndLocations(GLuint programId)
{
QVector<ShaderUniform> uniforms;
GLint nbrActiveUniforms = 0;
m_funcs->glGetProgramiv(programId, GL_ACTIVE_UNIFORMS, &nbrActiveUniforms);
uniforms.resize(nbrActiveUniforms);
for (GLint i = 0; i < nbrActiveUniforms; i++) {
ShaderUniform uniform;
QByteArray uniformName(256, '\0');
// Size is 1 for scalar and more for struct or arrays
// Type is the GL Type
m_funcs->glGetActiveUniform(programId, i, 256, NULL, &uniform.m_size, &uniform.m_type , uniformName.data());
uniform.m_location = m_funcs->glGetUniformLocation(programId, uniformName.constData());
uniform.m_name = QString::fromUtf8(uniformName);
uniforms.append(uniform);
}
return uniforms;
}
示例15: ParseAsksData
void ParseAsksData(const QJsonObject& json, QVector<AsksData>& vecAsksData)
{
QJsonArray jaSubPrice = json[szAttributeName[AN_PRICE]].toArray();
QJsonArray jaSubLevel = json[szAttributeName[AN_LEVEL]].toArray();
QJsonArray jaSubAmount = json[szAttributeName[AN_AMOUNT]].toArray();
QJsonArray jaSubAccuAmount = json[szAttributeName[AN_ACCUAMOUNT]].toArray();
vecAsksData.resize(jaSubPrice.size());
for (int ix = 0; ix != vecAsksData.size(); ++ix)
{
AsksData& ad = vecAsksData[ix];
ad.dPrice = jaSubPrice[ix].toDouble();
ad.dLevel = jaSubLevel[ix].toDouble();
ad.dAmount = jaSubAmount[ix].toDouble();
ad.dAccuAmount = jaSubAccuAmount[ix].toDouble();
}
}