コード例 #1
0
bool DmxAddress::fromJson(QJsonObject& obj) {
    QJsonValue universeValue = obj.value("universe");
    QJsonValue offsetValue = obj.value("offset");

    if(universeValue.isUndefined() || offsetValue.isUndefined()){
        qCritical() << "Missing universe or offset";
        return false;
    }

    universe = universeValue.toVariant().toInt();
    offset = offsetValue.toVariant().toInt();

    return true;
}
コード例 #2
0
ファイル: scene_document.cpp プロジェクト: byzin/Nanairo
/*!
  */
QVariant SceneDocument::toVariant(const QJsonValue& value) noexcept
{
  QVariant node;
  switch (value.type()) {
   case QJsonValue::Null: {
    zisc::raiseError("The json value is null.");
    break;
   }
   case QJsonValue::Bool:
   case QJsonValue::Double:
   case QJsonValue::String: {
    node = value.toVariant();
    break;
   }
   case QJsonValue::Array: {
    node = toVariant(value.toArray());
    break;
   }
   case QJsonValue::Object: {
    node = toVariant(value.toObject());
    break;
   }
   case QJsonValue::Undefined: {
    zisc::raiseError("The json value is undefined.");
    break;
   }
   default: {
    zisc::raiseError("Undefined json value type is specified.");
    break;
   }
  }
  return node;
}
コード例 #3
0
QVariant QJsonValueProto::toVariant() const
{
  QJsonValue *item = qscriptvalue_cast<QJsonValue*>(thisObject());
  if (item)
    return item->toVariant();
  return QVariant();
}
コード例 #4
0
ファイル: qversitutils.cpp プロジェクト: Distrotech/qtpim
/*!
 * Convert string \a json in JSON format to variant \a data.
 *
 * The format of the json string is assumed to be a one-item array.
 *
 * Returns true if the conversion is successful, false otherwise.
 *
 * \sa convertToJson()
 */
bool VersitUtils::convertFromJson(const QString &json, QVariant *data)
{
    const QJsonDocument jsonDoc = QJsonDocument::fromJson(json.toUtf8());
    const QJsonValue jsonValue = jsonDoc.array().at(0);
    if (jsonValue.isUndefined())
        return false;
    *data = jsonValue.toVariant();
    return true;
}
コード例 #5
0
ファイル: Mode7.cpp プロジェクト: AncientLysine/BiliLocal
Mode7::Mode7(const Comment &comment)
	: sprite(nullptr)
{
	Q_ASSERT(comment.mode == 7);
	QJsonArray data = QJsonDocument::fromJson(comment.string.toUtf8()).array();
	int l = data.size();
	if (l < 5){
		throw format_unrecognized();
	}
	QSize size = lApp->findObject<ARender>()->getActualSize();
	auto getDouble = [&data](int i){return data.at(i).toVariant().toDouble(); };
	double scale = getScale(comment.mode, comment.date, size);
	bPos = QPointF(getDouble(0), getDouble(1));
	ePos = l < 8 ? bPos : QPointF(getDouble(7), getDouble(8));
	int w = size.width(), h = size.height();
	if (bPos.x() < 1 && bPos.y() < 1 && ePos.x() < 1 && ePos.y() < 1){
		bPos.rx() *= w;
		ePos.rx() *= w;
		bPos.ry() *= h;
		ePos.ry() *= h;
		scale = 1;
	}
	else if (scale == 0){
		scale = 1;
	}
	else{
		QSizeF player = getPlayer(comment.date);
		QPoint offset = QPoint((w - player.width()*scale) / 2, (h - player.height()*scale) / 2);
		bPos = bPos*scale + offset;
		ePos = ePos*scale + offset;
	}
	QStringList alpha = data[2].toString().split('-');
	bAlpha = alpha[0].toDouble();
	eAlpha = alpha[1].toDouble();
	life = getDouble(3);
	QJsonValue v = l < 12 ? QJsonValue(true) : data[11];
	int effect = (v.isString() ? v.toString() == "true" : v.toVariant().toBool()) ? Config::getValue("/Danmaku/Effect", 5) / 2 : -1;
	QFont font = getFont(scale ? comment.font*scale : comment.font, l < 13 ? Utils::defaultFont(true) : data[12].toString());
	QString string = data[4].toString();
	sprite = lApp->findObject<ARender>()->getSprite();
	sprite->setAlpha(1.0);
	sprite->setColor(QColor::fromRgb(comment.color));
	sprite->setEffect(effect);
	sprite->setFont(font);
	sprite->setFrame(comment.isLocal());
	sprite->setText(string);
	zRotate = l < 6 ? 0 : getDouble(5);
	yRotate = l < 7 ? 0 : getDouble(6);
	wait = l < 11 ? 0 : getDouble(10) / 1000;
	stay = l < 10 ? 0 : life - wait - getDouble(9) / 1000;
	source = &comment;
	time = 0;
}
コード例 #6
0
ファイル: Network2.cpp プロジェクト: Disasm/karya-valya
void SocketHandler::HandleSuccessConnection(Message2 message)
{
    QJsonObject obj = Network2::ParseJson(message);

    qDebug() << obj["map"];
    qDebug() << obj["your_id"];

    map_ = obj["map"].toString();

    QJsonValue val = obj["your_id"];
    your_id_ = val.toVariant().toInt();

    emit readyToStart(your_id_, map_);
}
コード例 #7
0
QVariant JsonTablemodel::data(const QModelIndex &index, int role) const
{
	if (index.row() >= mData.count() || index.column() >= mMapping.count())
	{
		return QVariant();
	}

	if (role == Qt::DisplayRole || role == Qt::EditRole)
	{
		QJsonObject object = mData.at(index.row());
		QString name = mMapping.at(index.column());
        QJsonValue value = object[name];
        if (value.isDouble())
        {
            return QString("$") + QString::number(value.toDouble());
        }
        return value.toVariant();
	}
	return QVariant();
}
コード例 #8
0
ファイル: dbmodel.cpp プロジェクト: ndesai/pioneer-av-remote
QVariant DbModel::data(const QModelIndex &index, int role) const
{
    DEBUG << "index=" << index.row();
    if(index.isValid())
    {
        QHash<int, QByteArray> _roles = this->roleNames();
        QString _key = _roles.value(role);
        //        if((index.row() <= m_modelData.count() - 1) && index.row() >= 0)
        //        {
        //            QMap<QString, QString > _dataMap = m_modelData.at(index.row());
        //            return QVariant(_dataMap.value(_key));
        //        }
        QJsonObject root = m_jsonDocument.object();
        QJsonValueRef _arrayRef = root.find(m_name).value();
        QJsonArray _arrayMain = _arrayRef.toArray();
        QJsonValue val = _arrayMain.at(index.row());
        QVariantMap vm = val.toVariant().toMap();
        DEBUG << vm.value(_key);
        return QVariant(vm.value(_key));
    }
    return QVariant();
}
コード例 #9
0
QVariant ConversionUtil::fromJsonValue(QVariant::Type type, int userType, const QJsonValue &value) {

    switch (type) {
        case QVariant::Bool:
        case QVariant::Int:
        case QVariant::UInt:
        case QVariant::Double:
        case QVariant::String:
        case QVariant::Map:
            return value.toVariant();
        case QVariant::StringList: {
            QStringList stringList;
            for (const QJsonValue &item : value.toArray()) {
                stringList.append(item.toString());
            }
            return stringList;
        }
        case QVariant::DateTime:
            return QDateTime::fromMSecsSinceEpoch((qint64) value.toDouble());
        case QVariant::UserType: {
            MetaTypeRegistry::JsonConverters converters =
                    MetaTypeRegistry::jsonConverters(QMetaType::typeName(userType));
            if (converters.jsonValueToTypeConverter) {
                return converters.jsonValueToTypeConverter(value);
            } else {
                const char *typeName = QMetaType::typeName(userType);
                throw GameException(GameException::SerializationException, typeName ?
                                    QStringLiteral("User type not serializable: %1").arg(typeName) :
                                    QStringLiteral("Unknown user type: %1").arg(userType));
            }
        }
        default:
            throw GameException(GameException::SerializationException,
                                QStringLiteral("Unknown type: %1").arg(QVariant::typeToName(type)));
    }
}
コード例 #10
0
static Nuria::JsonMetaObjectReader::Error parseAnnotationsArray (const QJsonArray &array,
								 Nuria::RuntimeMetaObject::AnnotationMap &annotations) {
	for (int i = 0; i < array.size (); i++) {
		QJsonValue cur = array.at (i);
		if (!cur.isObject ()) {
			return Nuria::JsonMetaObjectReader::AnnotationIsNotAnObject;
		}
		
		// 
		QJsonObject obj = cur.toObject ();
		QJsonValue name = obj.value (QStringLiteral("name"));
		QJsonValue value = obj.value (QStringLiteral("value"));
		
		if (!name.isString ()) return Nuria::JsonMetaObjectReader::AnnotationNameIsNotAString;
		if (value.isNull ()) return Nuria::JsonMetaObjectReader::AnnotationValueHasUnknownType;
		
		annotations.insert (name.toString ().toUtf8 (), value.toVariant ());
		
	}
	
	// 
	return Nuria::JsonMetaObjectReader::NoError;
	
}
コード例 #11
0
ファイル: QStringEx.cpp プロジェクト: Znurre/nplayer
StringToken::StringToken(const QJsonValue &value)
{
	const QVariant &variant = value.toVariant();

	m_value = variant.toString();
}
コード例 #12
0
ファイル: Network2.cpp プロジェクト: Disasm/karya-valya
size_t Network2::ExtractObjId(const QJsonObject &json)
{
    QJsonValue val = json["obj"];

    return val.toVariant().toInt();
}
コード例 #13
0
ファイル: AssetsUtils.cpp プロジェクト: ACGaming/MultiMC5
/*
 * Returns true on success, with index populated
 * index is undefined otherwise
 */
bool loadAssetsIndexJson(QString path, AssetsIndex *index)
{
	/*
	{
	  "objects": {
		"icons/icon_16x16.png": {
		  "hash": "bdf48ef6b5d0d23bbb02e17d04865216179f510a",
		  "size": 3665
		},
		...
		}
	  }
	}
	*/

	QFile file(path);

	// Try to open the file and fail if we can't.
	// TODO: We should probably report this error to the user.
	if (!file.open(QIODevice::ReadOnly))
	{
		QLOG_ERROR() << "Failed to read assets index file" << path;
		return false;
	}

	// Read the file and close it.
	QByteArray jsonData = file.readAll();
	file.close();

	QJsonParseError parseError;
	QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &parseError);

	// Fail if the JSON is invalid.
	if (parseError.error != QJsonParseError::NoError)
	{
		QLOG_ERROR() << "Failed to parse assets index file:" << parseError.errorString()
					 << "at offset " << QString::number(parseError.offset);
		return false;
	}

	// Make sure the root is an object.
	if (!jsonDoc.isObject())
	{
		QLOG_ERROR() << "Invalid assets index JSON: Root should be an array.";
		return false;
	}

	QJsonObject root = jsonDoc.object();

	QJsonValue isVirtual = root.value("virtual");
	if (!isVirtual.isUndefined())
	{
		index->isVirtual = isVirtual.toBool(false);
	}

	QJsonValue objects = root.value("objects");
	QVariantMap map = objects.toVariant().toMap();

	for (QVariantMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
	{
		// QLOG_DEBUG() << iter.key();

		QVariant variant = iter.value();
		QVariantMap nested_objects = variant.toMap();

		AssetObject object;

		for (QVariantMap::const_iterator nested_iter = nested_objects.begin();
			 nested_iter != nested_objects.end(); ++nested_iter)
		{
			// QLOG_DEBUG() << nested_iter.key() << nested_iter.value().toString();
			QString key = nested_iter.key();
			QVariant value = nested_iter.value();

			if (key == "hash")
			{
				object.hash = value.toString();
			}
			else if (key == "size")
			{
				object.size = value.toDouble();
			}
		}

		index->objects.insert(iter.key(), object);
	}

	return true;
}