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


C++ QVariantHash::end方法代码示例

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


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

示例1: configure

void ScanFoldersModel::configure()
{
    const QVariantHash dirs = Preferences::instance()->getScanDirs();

    for (QVariantHash::const_iterator i = dirs.begin(), e = dirs.end(); i != e; ++i) {
        if (i.value().type() == QVariant::Int)
            addPath(i.key(), static_cast<PathType>(i.value().toInt()), QString());
        else
            addPath(i.key(), CUSTOM_LOCATION, i.value().toString());
    }
}
开发者ID:paolo-sz,项目名称:qBittorrent,代码行数:11,代码来源:scanfoldersmodel.cpp

示例2: encodeData

QString QJson::encodeData(const QVariant &data, EncodeOptions options, QString *errorMessage,
	int indentation, QString currentLinePrefix)
{
	QString indentedLinePrefix = options.testFlag(Compact) ?
		QString::fromLatin1("") :
		(currentLinePrefix + QString::fromLatin1(" ").repeated(indentation));

	QString optionalNewLine = options.testFlag(Compact) ?
		QString::fromLatin1("") :
		(QString::fromLatin1("\n") + currentLinePrefix);

	QString optionalIndentedNewLine = options.testFlag(Compact) ?
		QString::fromLatin1("") :
		(QString::fromLatin1("\n") + indentedLinePrefix);

	QString encoded;

	switch (data.type())
	{
	case(QVariant::Bool) :
		encoded += QString::fromLatin1(data.toBool() ? "true" : "false");
		break;

	case(QVariant::Int) :
	case(QVariant::UInt) :
	case(QVariant::LongLong) :
	case(QVariant::ULongLong) :
							  Q_ASSERT(data.canConvert(QVariant::String));
		encoded = data.toString();
		break;

	case(QVariant::Double) :
		encoded = QString::number(data.toDouble(), 'g', 16);
		if (!encoded.contains(QString::fromLatin1(".")) && !encoded.contains(QString::fromLatin1("e")))
			encoded += ".0";
		break;

	case(QVariant::String) :
		encoded = encodeString(data.toString());
		break;

	case(QVariant::ByteArray) :
		encoded = encodeByteArray(data.toByteArray());
		break;

	case(QVariant::List) :
	{
		encoded = QString::fromLatin1("[") + optionalIndentedNewLine;
		QVariantList list = data.toList();
		for (int i = 0; i < list.count(); ++i)
		{
			if (i) encoded += QString::fromLatin1(",") + optionalIndentedNewLine;
			encoded += encodeData(list.at(i), options, errorMessage, indentation, indentedLinePrefix);
			if (errorMessage && !errorMessage->isNull())
				return QString();
		}
		encoded += optionalNewLine + QString::fromLatin1("]");
	}
						 break;

	case(QVariant::StringList) :
	{
		encoded = QString::fromLatin1("[") + optionalIndentedNewLine;
		QStringList list = data.toStringList();
		for (int i = 0; i < list.count(); ++i)
		{
			if (i) encoded += QString::fromLatin1(",") + optionalIndentedNewLine;
			encoded += encodeData(list.at(i), options, errorMessage, indentation, indentedLinePrefix);
			if (errorMessage && !errorMessage->isNull())
				return QString();
		}
		encoded += optionalNewLine + QString::fromLatin1("]");
	}
							   break;

	case(QVariant::Map) :
	{
		encoded = QString::fromLatin1("{") + optionalIndentedNewLine;
		QVariantMap map = data.toMap();
		QVariantMap::iterator i;
		bool first = true;
		for (i = map.begin(); i != map.end(); ++i)
		{
			if (!first)
				encoded += QString::fromLatin1(",") + optionalIndentedNewLine;
			first = false;
			encoded += encodeString(i.key());
			encoded += options.testFlag(Compact) ? QString::fromLatin1(":") : QString::fromLatin1(" : ");
			encoded += encodeData(i.value(), options, errorMessage, indentation, indentedLinePrefix);
			if (errorMessage && !errorMessage->isNull())
				return QString();
		}
		encoded += optionalNewLine + QString::fromLatin1("}");
	}
						break;

	case(QVariant::Hash) :
	{
		encoded = QString::fromLatin1("{") + optionalIndentedNewLine;
		QVariantHash hash = data.toHash();
//.........这里部分代码省略.........
开发者ID:HoS0,项目名称:DesktopManager,代码行数:101,代码来源:qjson.cpp

示例3: Py_BuildValue

/*static*/
PyObject * PythonScript::VariantToPython(const QVariant & v)
{
    int i;
    QVariantList::const_iterator iList;
    QVariantList list;
#if QT_VERSION >= 0x040500
    QVariantHash::const_iterator iHash;
    QVariantHash hash;
#endif
    QVariantMap::const_iterator iMap;
    QVariantMap map;
    PyObject * pyList, * pyDict;

    if (v.isNull()) Py_RETURN_NONE;

    switch ((QMetaType::Type)v.type()) {
    case QVariant::Double:
        return Py_BuildValue("d", v.toDouble());
    case QVariant::Bool:
        if (v.toBool()) Py_RETURN_TRUE;
        else Py_RETURN_FALSE;
    case QVariant::Int:
        return Py_BuildValue("i", v.toInt());
    case QVariant::LongLong:
        return Py_BuildValue("L", v.toLongLong());
    case QVariant::UInt:
        return Py_BuildValue("I", v.toUInt());
    case QVariant::ULongLong:
        return Py_BuildValue("K", v.toULongLong());
    case QVariant::Char:
    case QVariant::String:
#ifdef Py_UNICODE_WIDE
    {
        QVector<uint> tmp = v.toString().toUcs4();
        return Py_BuildValue("u#", tmp.constData(), tmp.count());
    }
#else
    return Py_BuildValue("u", v.toString().constData());
#endif
    case QVariant::List:
    case QVariant::StringList:
        list = v.toList();

        pyList = PyList_New(list.size());
        for (i = 0, iList = list.begin(); iList != list.end(); ++iList, ++i) {
            PyList_SetItem(pyList, i, PythonScript::VariantToPython(*iList));
        }
        return pyList;
#if QT_VERSION >= 0x040500
    case QVariant::Hash:
        hash = v.toHash();

        pyDict = PyDict_New();
        for (iHash = hash.begin(); iHash != hash.end(); ++iHash) {
            PyDict_SetItemString(pyDict, qPrintable(iHash.key()), PythonScript::VariantToPython(iHash.value()));
        }
        return pyDict;
#endif
    case QVariant::Map:
        map = v.toMap();

        pyDict = PyDict_New();
        for (iMap = map.begin(); iMap != map.end(); ++iMap) {
            PyDict_SetItemString(pyDict, qPrintable(iMap.key()), PythonScript::VariantToPython(iMap.value()));
        }
        return pyDict;
    case QMetaType::QObjectStar:
        return PythonScript::QObjectToPython(v.value<QObject*>());
#if QT_VERSION < 0x050000
    case QMetaType::QWidgetStar:
        return PythonScript::QObjectToPython(qobject_cast<QObject*>(v.value<QWidget*>()));
#endif
    default:
        PyErr_Format(PyExc_TypeError, qPrintable(tr("the type %s is currently not supported")), v.typeName());
        return NULL;
    }
    Py_RETURN_NONE;
}
开发者ID:Berenco,项目名称:texworks,代码行数:79,代码来源:TWPythonPlugin.cpp


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