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


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

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


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

示例1: setData

bool QgsCategorizedSymbolRendererModel::setData( const QModelIndex &index, const QVariant &value, int role )
{
  if ( !index.isValid() )
    return false;

  if ( index.column() == 0 && role == Qt::CheckStateRole )
  {
    mRenderer->updateCategoryRenderState( index.row(), value == Qt::Checked );
    emit dataChanged( index, index );
    return true;
  }

  if ( role != Qt::EditRole )
    return false;

  switch ( index.column() )
  {
    case 1: // value
    {
      // try to preserve variant type for this value
      QVariant val;
      switch ( mRenderer->categories().value( index.row() ).value().type() )
      {
        case QVariant::Int:
          val = value.toInt();
          break;
        case QVariant::Double:
          val = value.toDouble();
          break;
        case QVariant::List:
        {
          const QStringList parts = value.toString().split( ';' );
          QVariantList list;
          list.reserve( parts.count() );
          for ( const QString &p : parts )
            list << p;

          if ( list.count() == 1 )
            val = list.at( 0 );
          else
            val = list;
          break;
        }
        default:
          val = value.toString();
          break;
      }
      mRenderer->updateCategoryValue( index.row(), val );
      break;
    }
    case 2: // label
      mRenderer->updateCategoryLabel( index.row(), value.toString() );
      break;
    default:
      return false;
  }

  emit dataChanged( index, index );
  return true;
}
开发者ID:aaime,项目名称:QGIS,代码行数:60,代码来源:qgscategorizedsymbolrendererwidget.cpp

示例2: startTasks

void ChatView::startTasks()
{
# if defined(DEBUG_PERFORMANCE)
  QTime t;
  if (!m_messagesQueue.isEmpty())
    qDebug() << "ChatView::startTasks()" << SimpleID::encode(m_id);
# endif

  if (!m_messagesQueue.isEmpty()) {
    DEBUG_TIME_START

    if (m_messagesQueue.size() > MAX_MESSAGES_AT_ONCE) {
      QVariantList query;
#     if QT_VERSION >= 0x040700
      query.reserve(MAX_MESSAGES_AT_ONCE);
#     endif

      for (int i = 0; i < MAX_MESSAGES_AT_ONCE; ++i)
        query.append(m_messagesQueue.takeFirst());

      emit messages(query);
      DEBUG_TIME_ELAPSED_MQ

      QTimer::singleShot(0, this, SLOT(startTasks()));
    }
    else {
      emit messages(m_messagesQueue);
      DEBUG_TIME_ELAPSED_MQ

      m_messagesQueue.clear();
    }
  }
开发者ID:youngdev,项目名称:schat,代码行数:32,代码来源:ChatView.cpp

示例3: tag

void ItemTagsScriptable::tag()
{
    const auto args = currentArguments();

    auto tagName = args.value(0).toString();
    if ( tagName.isEmpty() ) {
        tagName = askTagName( addTagText(), m_userTags );
        if ( tagName.isEmpty() )
            return;
    }

    if ( args.size() <= 1 ) {
        const auto dataValueList = call("selectedItemsData").toList();

        QVariantList dataList;
        dataList.reserve( dataValueList.size() );
        for (const auto &itemDataValue : dataValueList) {
            auto itemData = itemDataValue.toMap();
            auto itemTags = ::tags(itemData);
            if ( addTag(tagName, &itemTags) )
                itemData.insert( mimeTags, itemTags.join(",") );
            dataList.append(itemData);
        }

        call( "setSelectedItemsData", QVariantList() << QVariant(dataList) );
    } else {
        for ( int row : rows(args, 1) ) {
            auto itemTags = tags(row);
            if ( addTag(tagName, &itemTags) )
                setTags(row, itemTags);
        }
    }
}
开发者ID:amosbird,项目名称:CopyQ,代码行数:33,代码来源:itemtags.cpp

示例4: data

QVariant SourcesModel::data(const QModelIndex& index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (index.row() >= m_size)
        return QVariant();

    Plasma::QueryMatch m = fetchMatch(index.row());
    Q_ASSERT(m.runner());

    switch(role) {
        case Qt::DisplayRole:
            return m.text();

        case Qt::DecorationRole:
            if (!m.iconName().isEmpty()) {
                return m.iconName();
            }

            return m.icon();

        case TypeRole:
            return m.matchCategory();

        case SubtextRole:
            return m.subtext();

        case ActionsRole: {
            const auto &actions = m_manager->actionsForMatch(m);
            if (actions.isEmpty()) {
                return QVariantList();
            }

            QVariantList actionsList;
            actionsList.reserve(actions.size());

            for (QAction *action : actions) {
                actionsList.append(QVariant::fromValue(action));
            }

            return actionsList;
        }
        case DuplicateRole:
            return m_duplicates.value(m.text());

            /*
        case PreviewTypeRole:
            return m.previewType();

        case PreviewUrlRole:
            return m.previewUrl();

        case PreviewLabelRole:
            return m.previewLabel();
            */
    }

    return QVariant();
}
开发者ID:KDE,项目名称:milou,代码行数:60,代码来源:sourcesmodel.cpp

示例5: convertToVariant

QVariantList convertToVariant(const QList<QString> &val)
{
  QVariantList ret;
  ret.reserve(val.count());
  for(const QString &s : val)
    ret.push_back(s);
  return ret;
}
开发者ID:michaelkvance,项目名称:renderdoc,代码行数:8,代码来源:PersistantConfig.cpp

示例6: metacall

int QDBusInterfacePrivate::metacall(QMetaObject::Call c, int id, void **argv)
{
    Q_Q(QDBusInterface);

    if (c == QMetaObject::InvokeMetaMethod) {
        int offset = metaObject->methodOffset();
        QMetaMethod mm = metaObject->method(id + offset);

        if (mm.methodType() == QMetaMethod::Signal) {
            // signal relay from D-Bus world to Qt world
            QMetaObject::activate(q, metaObject, id, argv);

        } else if (mm.methodType() == QMetaMethod::Slot || mm.methodType() == QMetaMethod::Method) {
            // method call relay from Qt world to D-Bus world
            // get D-Bus equivalent signature
            QString methodName = QString::fromLatin1(mm.name());
            const int *inputTypes = metaObject->inputTypesForMethod(id);
            int inputTypesCount = *inputTypes;

            // we will assume that the input arguments were passed correctly
            QVariantList args;
            args.reserve(inputTypesCount);
            int i = 1;
            for ( ; i <= inputTypesCount; ++i)
                args << QVariant(inputTypes[i], argv[i]);

            // make the call
            QDBusMessage reply = q->callWithArgumentList(QDBus::Block, methodName, args);

            if (reply.type() == QDBusMessage::ReplyMessage) {
                // attempt to demarshall the return values
                args = reply.arguments();
                QVariantList::ConstIterator it = args.constBegin();
                const int *outputTypes = metaObject->outputTypesForMethod(id);
                int outputTypesCount = *outputTypes++;

                if (mm.returnType() != QMetaType::UnknownType && mm.returnType() != QMetaType::Void) {
                    // this method has a return type
                    if (argv[0] && it != args.constEnd())
                        copyArgument(argv[0], *outputTypes++, *it);

                    // skip this argument even if we didn't copy it
                    --outputTypesCount;
                    ++it;
                }

                for (int j = 0; j < outputTypesCount && it != args.constEnd(); ++i, ++j, ++it) {
                    copyArgument(argv[i], outputTypes[j], *it);
                }
            }

            // done
            lastError = QDBusError(reply);
            return -1;
        }
    }
    return id;
}
开发者ID:,项目名称:,代码行数:58,代码来源:

示例7: deserializeInitDynamicPacket

void deserializeInitDynamicPacket(QDataStream &in, QMetaObjectBuilder &builder, QVariantList &values)
{
    quint32 numSignals = 0;
    quint32 numMethods = 0;
    quint32 numProperties = 0;

    in >> numSignals;
    in >> numMethods;

    int curIndex = 0;

    for (quint32 i = 0; i < numSignals; ++i) {
        QByteArray signature;
        in >> signature;
        ++curIndex;
        builder.addSignal(signature);
    }

    for (quint32 i = 0; i < numMethods; ++i) {
        QByteArray signature, returnType;

        in >> signature;
        in >> returnType;
        ++curIndex;
        const bool isVoid = returnType.isEmpty() || returnType == QByteArrayLiteral("void");
        if (isVoid)
            builder.addMethod(signature);
        else
            builder.addMethod(signature, QByteArrayLiteral("QRemoteObjectPendingCall"));
    }

    in >> numProperties;
    const quint32 initialListSize = values.size();
    if (static_cast<quint32>(values.size()) < numProperties)
        values.reserve(numProperties);
    else if (static_cast<quint32>(values.size()) > numProperties)
        for (quint32 i = numProperties; i < initialListSize; ++i)
            values.removeLast();

    for (quint32 i = 0; i < numProperties; ++i) {
        QByteArray name;
        QByteArray typeName;
        QByteArray signalName;
        in >> name;
        in >> typeName;
        in >> signalName;
        if (signalName.isEmpty())
            builder.addProperty(name, typeName);
        else
            builder.addProperty(name, typeName, builder.indexOfSignal(signalName));
        QVariant value;
        in >> value;
        if (i < initialListSize)
            values[i] = value;
        else
            values.append(value);
    }
}
开发者ID:NNemec,项目名称:qtremoteobjects,代码行数:58,代码来源:qremoteobjectpacket.cpp

示例8: dos_qvariant_setArray

void dos_qvariant_setArray(::DosQVariant *vptr, int size, ::DosQVariant **array)
{
    auto variant = static_cast<QVariant *>(vptr);
    QVariantList data;
    data.reserve(size);
    for (int i = 0; i < size; ++i)
        data << *(static_cast<QVariant *>(array[i]));
    variant->setValue(data);
}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例9: toVariant

/*!
  */
QVariant SceneDocument::toVariant(const QJsonArray& array) noexcept
{
  QVariantList node;
  node.reserve(array.size());
  for (const auto& element : array) {
    const auto value = toVariant(element);
    node.append(value);
  }
  return QVariant::fromValue(node);
}
开发者ID:byzin,项目名称:Nanairo,代码行数:12,代码来源:scene_document.cpp

示例10: appendItemsFlags

bool DataStore::appendItemsFlags(const PimItem::List &items, const QVector<Flag> &flags,
                                 bool *flagsChanged, bool checkIfExists,
                                 const Collection &col, bool silent)
{
    QSet<QByteArray> added;

    QVariantList itemsIds;
    itemsIds.reserve(items.count());
    Q_FOREACH (const PimItem &item, items) {
        itemsIds.append(item.id());
    }
开发者ID:KDE,项目名称:akonadi,代码行数:11,代码来源:datastore.cpp

示例11: QVariantList

QVariantList_ *newVariantList(DataValue *list, int len)
{
    QVariantList *vlist = new QVariantList();
    vlist->reserve(len);
    for (int i = 0; i < len; i++) {
        QVariant var;
        unpackDataValue(&list[i], &var);
        vlist->append(var);
    }
    return vlist;
}
开发者ID:chai2010,项目名称:qml,代码行数:11,代码来源:goqml.cpp

示例12: displayAboutPage

void KMReaderWin::displayAboutPage()
{
    QVariantHash data;
    data[QStringLiteral("version")] = QStringLiteral(KDEPIM_VERSION);
    data[QStringLiteral("firstStart")] = kmkernel->firstStart();

    QVariantList features;
    features.reserve(numKMailNewFeatures);
    for (int i = 0; i < numKMailNewFeatures; ++i) {
        features.push_back(i18n(kmailNewFeatures[i]));
    }
    data[QStringLiteral("newFeatures")] = features;

    QVariantList changes;
    changes.reserve(numKMailChanges);
    for (int i = 0; i < numKMailChanges; ++i) {
        features.push_back(i18n(kmailChanges[i]));
    }
    data[QStringLiteral("importantChanges")] = changes;

    displaySplashPage(QStringLiteral("introduction_kmail.html"), data);
}
开发者ID:KDE,项目名称:kdepim,代码行数:22,代码来源:kmreaderwin.cpp

示例13: initialize

void QRemoteObjectRegistry::initialize()
{
    qRegisterMetaType<QRemoteObjectSourceLocation>();
    qRegisterMetaTypeStreamOperators<QRemoteObjectSourceLocation>();
    qRegisterMetaType<QRemoteObjectSourceLocations>();
    qRegisterMetaTypeStreamOperators<QRemoteObjectSourceLocations>();
    QVariantList properties;
    properties.reserve(3);
    properties << QVariant::fromValue(QRemoteObjectSourceLocations());
    properties << QVariant::fromValue(QRemoteObjectSourceLocation());
    properties << QVariant::fromValue(QRemoteObjectSourceLocation());
    setProperties(properties);
}
开发者ID:LangeSebastian,项目名称:playground-qtremoteobjects,代码行数:13,代码来源:qremoteobjectregistry.cpp

示例14: untag

void ItemTagsScriptable::untag()
{
    const auto args = currentArguments();
    auto tagName = args.value(0).toString();

    if ( args.size() <= 1 ) {
        const auto dataValueList = call("selectedItemsData").toList();

        if ( tagName.isEmpty() ) {
            QStringList allTags;
            for (const auto &itemDataValue : dataValueList) {
                const auto itemData = itemDataValue.toMap();
                allTags.append( ::tags(itemData) );
            }

            tagName = askRemoveTagName(allTags);
            if ( allTags.isEmpty() )
                return;
        }

        QVariantList dataList;
        dataList.reserve( dataValueList.size() );
        for (const auto &itemDataValue : dataValueList) {
            auto itemData = itemDataValue.toMap();
            auto itemTags = ::tags(itemData);
            if ( removeTag(tagName, &itemTags) )
                itemData.insert( mimeTags, itemTags.join(",") );
            dataList.append(itemData);
        }

        call( "setSelectedItemsData", QVariantList() << QVariant(dataList) );
    } else {
        const auto rows = this->rows(args, 1);

        if ( tagName.isEmpty() ) {
            QStringList allTags;
            for (int row : rows)
                allTags.append( this->tags(row) );

            tagName = askRemoveTagName(allTags);
            if ( allTags.isEmpty() )
                return;
        }

        for (int row : rows) {
            auto itemTags = tags(row);
            if ( removeTag(tagName, &itemTags) )
                setTags(row, itemTags);
        }
    }
}
开发者ID:amosbird,项目名称:CopyQ,代码行数:51,代码来源:itemtags.cpp

示例15: createDecorationData

QVariantList EventQuery::createDecorationData(const QStringList & item) const
{
    Q_UNUSED(item);

    QVariantList decorationList;
    decorationList.reserve(Max_columns-1);

    for(int i = 0; i < Max_columns; i++) {
        //TODO: find out if event is also available in akonadi
        decorationList.append(QVariant());
    }

    return decorationList;
}
开发者ID:KDE,项目名称:conquirere,代码行数:14,代码来源:eventquery.cpp


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