本文整理汇总了C++中QVector::first方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector::first方法的具体用法?C++ QVector::first怎么用?C++ QVector::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector
的用法示例。
在下文中一共展示了QVector::first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderPrivate
void QWebFramePrivate::renderPrivate(QPainter *painter, const QRegion &clip, bool contents)
{
if (!frame->view() || !frame->contentRenderer())
return;
QVector<QRect> vector = clip.rects();
if (vector.isEmpty())
return;
WebCore::FrameView* view = frame->view();
view->layoutIfNeededRecursive();
GraphicsContext context(painter);
if (!contents)
view->paint(&context, vector.first());
else
view->paintContents(&context, vector.first());
for (int i = 1; i < vector.size(); ++i) {
const QRect& clipRect = vector.at(i);
painter->save();
painter->setClipRect(clipRect, Qt::IntersectClip);
if (!contents)
view->paint(&context, clipRect);
else
view->paintContents(&context, clipRect);
painter->restore();
}
}
示例2: loader
ScriptEngine *loadEngine(const QString &language, Types::ComponentType type, QObject *parent,
const QVariantList &args = QVariantList())
{
Q_UNUSED(parent);
ScriptEngine *engine = 0;
auto filter = [&language](const KPluginMetaData &md) -> bool
{
return md.value(QStringLiteral("X-Plasma-API")) == language;
};
QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("plasma/scriptengines"), filter);
if (!plugins.isEmpty()) {
const QStringList componentTypes = KPluginMetaData::readStringList(plugins.first().rawData(), QStringLiteral("X-Plasma-ComponentTypes"));
if (((type & Types::AppletComponent) && !componentTypes.contains(QStringLiteral("Applet")))
|| ((type & Types::DataEngineComponent) && !componentTypes.contains(QStringLiteral("DataEngine")))) {
qCWarning(LOG_PLASMA) << "ScriptEngine" << plugins.first().name() << "does not provide Applet or DataEngine components, returning empty.";
return 0;
}
KPluginLoader loader(plugins.first().fileName());
KPluginFactory *factory = loader.factory();
if (factory) {
engine = factory->create<Plasma::ScriptEngine>(0, args);
} else {
qCWarning(LOG_PLASMA) << "Unable to load" << plugins.first().name() << "ScriptEngine";
}
}
return engine;
}
示例3: plotSpectr
void PlotterWindow::plotSpectr(HyperCube *ptrCube, uint dataX, uint dataY)
{
quint16 Chnls = ptrCube->GetCountofChannels();
qint16* pSpectrValues = new qint16[Chnls];
try{ //если можем получить точку гиперкуба
ptrCube->GetSpectrumPoint(dataX, dataY,pSpectrValues); // записали в pSpectrValues из гиперкуба
QVector<double> xArr(Chnls), yArr(Chnls);
for (quint16 i = 0; i < Chnls; ++i )
{
xArr[i] = i;
yArr[i] = pSpectrValues[i];
}
QVector<double> sortedYArr;
sortedYArr = yArr;
qSort(sortedYArr);
if (sortedYArr.first() < minY )
minY = sortedYArr.first();
if (sortedYArr.last() > maxY )
maxY = sortedYArr.last();
QString grafName;
grafName.append("X:");
grafName.append(QString::number(dataX));
grafName.append(" Y:");
grafName.append(QString::number(dataY));
m_customPlot->setInteraction(QCP::iRangeDrag , true);
m_customPlot->setInteraction(QCP::iRangeZoom , true);
m_customPlot->legend->setVisible(true);
if (!m_hold)
m_customPlot->clearGraphs();
m_customPlot->addGraph();
if (m_customPlot->graphCount() == 1) // первый график всегда черного цвета, остальные - рандомные
m_customPlot->graph()->setPen(QPen(Qt::black));
else
{
QColor color;
int limit = 256;
int randR = qrand() % limit;
int randG = qrand() % limit;
int randB = qrand() % limit;
color.setRgb(randR,randG,randB);
m_customPlot->graph()->setPen(QPen(color));
}
m_customPlot->graph()->setName(grafName);
m_customPlot->graph()->setData(xArr,yArr);
m_customPlot->xAxis->setRange(xArr.first(),xArr.last());
m_customPlot->yAxis->setRange(minY,maxY);
m_customPlot->replot();
}catch(...){
m_customPlot->replot();
}
delete pSpectrValues;
}
示例4: fromLayer
LayerTileSet LayerTileSet::fromLayer(const Layer &layer)
{
const QVector<Tile> tiles = layer.tiles();
const int cols = Tile::roundTiles(layer.width());
Q_ASSERT(!tiles.isEmpty());
QVector<TileRun> runs;
// First, Run Length Encode the tile vector
runs << TileRun { tiles.first(), 0, 0, 1, tiles.first().solidColor() };
for(int i=1;i<tiles.size();++i) {
if(runs.last().len < 0xffff && runs.last().tile.equals(tiles.at(i))) {
runs.last().len++;
} else {
runs << TileRun { tiles.at(i), i%cols, i/cols, 1, tiles.at(i).solidColor() };
}
}
// Count the number of solid color tiles.
QHash<quint32, int> colors;
for(const TileRun &tr : runs) {
if(tr.color.isValid())
colors[tr.color.rgba()] += tr.len;
}
// If half of the tiles are of the same
// solid color, use that as the background color.
// Otherwise, transparency is a safe default choice.
QColor background = Qt::transparent;
const int treshold = tiles.length() / 2;
for(QHash<quint32, int>::const_iterator i = colors.constBegin();i!=colors.constEnd();++i) {
if(i.value() >= treshold) {
background = QColor::fromRgba(i.key());
break;
}
}
// Remove solid color tiles that match the background
QMutableVectorIterator<TileRun> tri(runs);
while(tri.hasNext()) {
if(tri.next().color == background)
tri.remove();
}
// All done!
return LayerTileSet {
runs,
background
};
}
示例5: on_loadBtn_clicked
void BlobWindow::on_loadBtn_clicked()
{
QString name = ui->loadNameEdt->text();
QSqlQuery query;
QString qry_string = "SELECT floatsVec FROM Blobs WHERE Name='%1'";
query.exec(qry_string.arg(name));
query.first();
QByteArray data = query.value("floatsVec").toByteArray();
qDebug() << data.toHex() << __func__;
QVector<myType> *vec = unBlobifyCustom(data);
qDebug() << vec->first().flt << vec->first().bl << __func__;
}
示例6: rec
void ParserTests::testMemcheckSample3()
{
MSKIP_SINGLE("testfile does not exist");
initTest(QLatin1String("memcheck-output-sample3.xml"));
Valgrind::XmlProtocol::Parser parser;
Recorder rec(&parser);
parser.parse(m_socket);
m_process->waitForFinished();
QCOMPARE(m_process->exitStatus(), QProcess::NormalExit);
QCOMPARE(m_process->state(), QProcess::NotRunning);
QVERIFY2(parser.errorString().isEmpty(), qPrintable(parser.errorString()));
const QList<Error> errors = rec.errors;
QCOMPARE(errors.size(), 6);
{
const Error error = errors.at(0);
const QVector<Stack> stacks = error.stacks();
QCOMPARE(error.unique(), 0x1ll);
QCOMPARE(error.what(), QLatin1String("Conditional jump or move depends on uninitialised value(s)"));
QCOMPARE(error.kind(), UninitCondition);
QCOMPARE(stacks.size(), 1);
QCOMPARE(stacks.first().frames().size(), 12);
QVERIFY(!error.suppression().isNull());
QCOMPARE(error.suppression().frames().count(), stacks.first().frames().size());
QCOMPARE(error.suppression().kind(), QLatin1String("Memcheck:Cond"));
QVERIFY(!error.suppression().rawText().trimmed().isEmpty());
// rawtext contains <...> while <name></name> does not
QCOMPARE(error.suppression().name(), QLatin1String("insert_a_suppression_name_here"));
Suppression sup = error.suppression();
sup.setName(QLatin1String("<insert_a_suppression_name_here>"));
QCOMPARE(sup.toString().trimmed(), sup.rawText().trimmed());
QCOMPARE(error.suppression().frames().first().object(),
QLatin1String("/usr/lib/kde4/plugins/styles/qtcurve.so"));
QVERIFY(error.suppression().frames().first().function().isEmpty());
QCOMPARE(error.suppression().frames().last().function(), QLatin1String("main"));
QVERIFY(error.suppression().frames().last().object().isEmpty());
}
QCOMPARE(rec.suppcounts.count(), 3);
QCOMPARE(rec.suppcounts.at(0).second, qint64(1));
QCOMPARE(rec.suppcounts.at(1).second, qint64(2));
QCOMPARE(rec.suppcounts.at(2).second, qint64(3));
}
示例7: initialize
void Entity::initialize()
{
QByteArray vsrc =
"attribute highp vec4 vertexAttr;\n"
"attribute highp vec2 texAttr;\n"
"uniform mediump mat4 matrix;\n"
"varying highp vec2 texCoord;\n"
"void main(void)\n"
"{\n"
" texCoord = texAttr;\n"
" gl_Position = matrix * vertexAttr;\n"
"}\n";
QByteArray fsrc =
"uniform sampler2D texture;\n"
"varying highp vec2 texCoord;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = texture2D(texture, texCoord);\n"
"}\n";
m_program = generateShaderProgram(this, vsrc, fsrc);
m_vertexAttr = m_program->attributeLocation("vertexAttr");
m_texAttr = m_program->attributeLocation("texAttr");
m_matrixUniform = m_program->uniformLocation("matrix");
QVector<QImage> images = loadSoldierImages();
int w = images.first().width() + 2;
int h = images.first().height() + 2;
m_tileMod = (images.size() + 3) / 4;
QImage image(m_tileMod * w, 4 * h, QImage::Format_ARGB32_Premultiplied);
image.fill(Qt::transparent);
QPainter p(&image);
p.setCompositionMode(QPainter::CompositionMode_Source);
for (int i = 0; i < images.size(); ++i)
p.drawImage(w * (i % m_tileMod) + 1, h * (i / m_tileMod) + 1, images.at(i));
p.end();
qDebug() << "Initialized soldier image" << image.size();
m_tileWidth = w;
m_tileHeight = h;
m_texture = generateTexture(image, false, false);
m_textureSize = image.size();
}
示例8: tangentAtStart
QPointF RoundCornersCommand::tangentAtStart(const KoPathSegment &s)
{
QVector<QPointF> cp = s.controlPoints();
QPointF tn = cp[1] - cp.first();
qreal length = sqrt(tn.x() * tn.x() + tn.y() * tn.y());
return tn / length;
}
示例9: isVariantEditable
static bool
isVariantEditable(const QVariant &var)
{
if (var.canConvert<ApiArray>()) {
ApiArray array = var.value<ApiArray>();
QVector<QVariant> vals = array.values();
if (vals.isEmpty())
return false;
else
return isVariantEditable(vals.first());
}
switch (var.userType()) {
case QVariant::Bool:
case QVariant::Int:
case QVariant::UInt:
case QVariant::LongLong:
case QVariant::ULongLong:
case QMetaType::Float:
case QVariant::Double:
case QVariant::String:
return true;
default:
return false;
}
}
示例10: rangeFinder
AMRange AMUtility::rangeFinder(const QVector<double> &data, double valueToIgnore)
{
AMRange range = AMRange();
if (!data.isEmpty()){
double minimum = data.first();
double maximum = minimum;
for (int i = 1, size = data.size(); i < size; i++){
double value = data.at(i);
if (value < minimum && value != valueToIgnore)
minimum = value;
if (value > maximum && value != valueToIgnore)
maximum = value;
}
range.setRange(minimum, maximum);
}
return range;
}
示例11: calculateFixedTempoFirstBeat
// static
double BeatUtils::calculateFixedTempoFirstBeat(
bool enableOffsetCorrection,
const QVector<double> rawbeats, const int sampleRate,
const int totalSamples, const double globalBpm) {
if (rawbeats.size() == 0) {
return 0;
}
if (!enableOffsetCorrection) {
return rawbeats.first();
}
QVector <double> corrbeats;
// Length of a beat at globalBpm in mono samples.
const double beat_length = 60.0 * sampleRate / globalBpm;
double firstCorrectBeat = findFirstCorrectBeat(
rawbeats, sampleRate, globalBpm);
// We start building a fixed beat grid at globalBpm and the first beat from
// rawbeats that matches globalBpm.
double i = firstCorrectBeat;
while (i <= totalSamples) {
corrbeats << i;
i += beat_length;
}
if (rawbeats.size() == 1 || corrbeats.size()==1) {
return firstCorrectBeat;
}
/*
* calculateOffset compares the beats from the analyzer and the
* beats from the beat grid constructed above in corrbeats.
*/
// qDebug() << "Calculating best offset";
// double offset = calculateOffset(rawbeats, globalBpm, corrbeats, sampleRate);
// // Adjust firstCorrectBeat by offset
// firstCorrectBeat += offset;
// Find the smallest positive beat that is linked to firstCorrectBeat by
// beat_length steps.
double FirstFrame = firstCorrectBeat;
while (FirstFrame < 0) {
FirstFrame += beat_length;
}
while (FirstFrame > beat_length) {
FirstFrame -= beat_length;
}
// Round to nearest integer.
double firstBeat = floor(FirstFrame + 0.5);
if (sDebug) {
qDebug() << "calculateFixedTempoFirstBeat chose a first beat at frame" << firstBeat
<< "while the first raw beat was at" << rawbeats.at(0);
}
return firstBeat;
}
示例12: findFirstCorrectBeat
double BeatUtils::findFirstCorrectBeat(const QVector<double> rawbeats,
const int SampleRate, const double global_bpm) {
for (int i = N; i < rawbeats.size(); i++) {
// get start and end sample of the beats
double start_sample = rawbeats.at(i-N);
double end_sample = rawbeats.at(i);
// The time in seconds represented by this sample range.
double time = (end_sample - start_sample)/SampleRate;
// Average BPM within this sample range.
double avg_bpm = 60.0 * N / time;
//qDebug() << "Local BPM between beat " << (i-N) << " and " << i << " is " << avg_bpm;
// If the local BPM is within kCorrectBeatLocalBpmEpsilon of the global
// BPM then use this window as the first beat.
if (fabs(global_bpm - avg_bpm) <= kCorrectBeatLocalBpmEpsilon) {
//qDebug() << "Using beat " << (i-N) << " as first beat";
return start_sample;
}
}
// If we didn't find any beat that matched the window, return the first
// beat.
return !rawbeats.empty() ? rawbeats.first() : 0.0;
}
示例13: SaveBurstsDual
void SaveBurstsDual(const QVector<BurstDual> &burstVectorDual, const QString filename)
{
QFile file;
if(filename.isEmpty()) qFatal("SaveBursts: enter a valid filename");
else file.setFileName(filename);
if(burstVectorDual.size()==0) AlexEvalLog::warning("No dual bursts to save!");
if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) AlexEvalLog::warning(file.errorString());
QTextStream out(&file);
out.setRealNumberPrecision(11);
out <<"# ALEX dual bursts\n# "<<burstVectorDual.size()<<" bursts were analyzed.\n";
out<<burstVectorDual.first().toStringHeader().c_str();
for(int i=0;i<burstVectorDual.size();++i) {
out<<burstVectorDual.at(i).toString("",", ").c_str()<<"\n";
}
AlexEvalLog::text(burstVectorDual.size()+"bursts written to file "+file.fileName());
file.close();
// out <<"# start time in s\tburst duration in ms\tproximity ratio\tstoichiometry ratio\tnumber of photons\tn_Dem_Dex\tn_Aem_Dex\tn_Dem_Aex\tn_Aem_Aex\tduration Dem in ms\tduration Aem in ms\tPR_RAW\tS_RAW\ttype\n";
// for(int i=0;i<burstVectorDual.size();++i) {
// out <<burstVectorDual.at(i).startTime<<"\t"<<burstVectorDual.at(i).duration*1e3<<"\t"
// <<burstVectorDual.at(i).proximityRatio<<"\t"<<burstVectorDual.at(i).stoichiometryRatio<<"\t"<<burstVectorDual.at(i).numberOfPhotons<<"\t"
// <<burstVectorDual.at(i).n_Dem_Dex<<"\t"<<burstVectorDual.at(i).n_Aem_Dex<<"\t"<<burstVectorDual.at(i).n_Dem_Aex<<"\t"<<burstVectorDual.at(i).n_Aem_Aex<<"\t"<<burstVectorDual.at(i).durationDonor*1e3<<"\t"<<burstVectorDual.at(i).durationAcceptor*1e3<<"\t"<<burstVectorDual.at(i).proximityRatioRaw<<"\t"<<burstVectorDual.at(i).stoichiometryRatioRaw<<"\t"<<(int)burstVectorDual.at(i).type<<"\n";
// }
}
示例14: QDialog
GameVersionChoiceDialog::GameVersionChoiceDialog(const QList <BTech::GameVersion> &allowedVersions)
: QDialog()
{
setFixedSize(200, 300);
QVBoxLayout *checkBoxLayout = new QVBoxLayout;
checkBoxLayout->setAlignment(Qt::AlignTop);
QVector <QCheckBox *> checkBox;
group = new QButtonGroup;
group->setExclusive(true);
for (BTech::GameVersion version : allowedVersions) {
checkBox << new QCheckBox(BTech::gameVersionStringChange[version]);
group->addButton(checkBox.last());
checkBoxLayout->addWidget(checkBox.last());
}
checkBox.first()->setChecked(true);
QVBoxLayout *layout = new QVBoxLayout;
layout->addItem(checkBoxLayout);
confirmButton = new QPushButton(BTech::Strings::ButtonConfirm);
connect(confirmButton, &QPushButton::pressed, this, &GameVersionChoiceDialog::accept);
layout->addWidget(confirmButton);
setLayout(layout);
}
示例15: loader
ScriptEngine *loadEngine(const QString &language, Types::ComponentType type, QObject *parent,
const QVariantList &args = QVariantList())
{
ScriptEngine *engine = 0;
auto filter = [&language](const KPluginMetaData &md) -> bool
{
return md.value(QStringLiteral("X-Plasma-API")) == language;
};
QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("plasma/scriptengines"), filter);
if (plugins.count()) {
const QString componentTypes = plugins.first().value(QStringLiteral("X-Plasma-ComponentTypes"));
if (((type & Types::AppletComponent) && componentTypes != QLatin1String("Applet"))
|| ((type & Types::DataEngineComponent) && componentTypes != QLatin1String("DataEngine"))) {
return 0;
}
KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins);
KPluginLoader loader(lst.first().libraryPath());
KPluginFactory *factory = loader.factory();
if (factory) {
engine = factory->create<Plasma::ScriptEngine>(0, args);
}
}
return engine;
}