void SyntaxHighlighter::TextFormat::loadFromJson(const QJsonObject& o) {
		namespace Highlight = JEnt::Highlight;
		// Italicフラグ: デフォルト値=false
		auto itr = o.find(Highlight::italic);
		bool b = false;
		if(itr != o.end())
			b = itr.value().toBool(false);
		setFontItalic(b);
		// Boldフラグ: デフォルト値=QFont::Normal
		int w = QFont::Normal;
		itr = o.find(Highlight::bold);
		if(itr != o.end())
			w = itr.value().toBool(false) ? QFont::Bold : QFont::Normal;
		setFontWeight(w);
		// Underlineフラグ: デフォルト値=false
		b = false;
		itr = o.find(Highlight::underline);
		if(itr != o.end())
			b = itr.value().toBool(false);
		setFontUnderline(b);
		// Color RGB: デフォルト値=(128,128,128)
		QColor col(128,128,128);
		itr = o.find(Highlight::color);
		if(itr != o.end()) {
			QJsonArray ar = itr.value().toArray();
			if(ar.size() == 3)
				col.setRgb(ar[0].toInt(), ar[1].toInt(), ar[2].toInt());
		}
		setForeground(col);
	}
	void SyntaxHighlighter::Keywords::loadFromJson(const QJsonObject& o) {
		namespace Keyword = JEnt::Keyword;
		_strV.clear();
		_regV.clear();
		// AutoSpacingフラグ: デフォルト値=false
		bool b = false;
		auto itr = o.find(Keyword::auto_spacing);
		if(itr != o.end())
			b = itr.value().toBool(false);
		_bAutoSpacing = b;
		// CaseSensitiveフラグ: デフォルト値=false
		b = false;
		itr = o.find(Keyword::case_sensitive);
		if(itr != o.end())
			b = itr.value().toBool(false);
		_bCaseSensitive = b;
		// String or RegEx: デフォルト値=string
		QString strType = o.value(Keyword::type).toString(Keyword::string);
		bool bIsRegex = strType == Keyword::regex;

		QJsonArray ar = o.value(Keyword::words).toArray();
		for(const auto& w : ar) {
			QString word = w.toString();
			if(!word.isEmpty()) {
				if(bIsRegex) {
					// 正規表現によるキーワード指定
					_regV.emplace_back(word,
									   _bCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
				} else {
					// 文字列によるキーワード指定
					_strV.emplace_back(word);
				}
			}
		}
	}
	void SyntaxHighlighter::loadUserFormat(const QString& path) {
		QJsonDocument doc = _LoadJson(path);
		_formatMap.clear();
		QJsonObject root = doc.object();
		auto itr = root.find(JEnt::Highlight::highlights);
		if(itr != root.end()) {
			QJsonObject ent = itr.value().toObject();
			for(auto itr2 = ent.begin() ; itr2 != ent.end() ; itr2++)
				_formatMap.emplace(itr2.key().toStdString(), TextFormat(itr2.value().toObject()));
		}
		_refreshPairV();
	}
Example #4
0
// ------------ TwqUser::P_Follow ------------
void TwqUser::P_Follow::receiveInfo(const QJsonObject& jobj) {
	auto itr = jobj.find(JSONKWD::USER::Following);
	if(itr != jobj.end()) {
		_v.bFollowing = itr.value().toBool();
		haveF |= Flag;
	}
	itr = jobj.find("connections");
	if(itr != jobj.end()) {
		// friendships/lookup タイプ
		_v.bFollowing = itr.value().toObject().contains("following");
		haveF |= Flag;
	}
}
Example #5
0
QJsonObject Plugin14C::checkValuesCompatibility(const QJsonObject& values){
    QJsonObject result = values;

    if(result.find(DATE_14C_DELTA_R_STR) == result.end())
        result[DATE_14C_DELTA_R_STR] = 0;
    
    if(result.find(DATE_14C_DELTA_R_ERROR_STR) == result.end())
        result[DATE_14C_DELTA_R_ERROR_STR] = 0;
    
    // Force curve name to lower case :
    result[DATE_14C_REF_CURVE_STR] = result[DATE_14C_REF_CURVE_STR].toString().toLower();
    
    return result;
}
Example #6
0
void Config::load(QString filename)
{
    QFile f(filename);

    if (!f.open(QFile::ReadOnly)) {
        return;
    }

    QByteArray data = f.readAll();
    document = QJsonDocument::fromJson(data);

    if (!document.isObject()) {
        return;
    }

    if (!document.object()["name"].isString() || !document.object()["sounds"].isObject()) {
        return;
    }

    QJsonObject soundsConf = document.object()["sounds"].toObject();
    QFileInfo info(filename);
    QDir baseDir = info.absoluteDir();

    valid = true;

    for (QJsonObject::iterator i = soundsConf.begin(); i != soundsConf.end(); i++) {
        if (!i.value().isString()) {
            continue;
        }

        sounds[i.key()] = baseDir.filePath(i.value().toString());
    }
}
Example #7
0
void AnimationToJson::fromJsonObject(KeyFrame &keyFrame, const QJsonObject &object, const QString &fileName)
{
    keyFrame.setFileName(QFileInfo(fileName).dir().absolutePath() + "/" + object.find("fileName").value().toString());
    keyFrame.setOffset(pointFromJsonObject(object.find("offset").value().toObject()));
    keyFrame.setRect(rectFromJsonObject(object.find("rect").value().toObject()));

    QJsonObject customPropertiesObject = object.find("customProperties").value().toObject();
//    qDebug() << customPropertiesObject;
    for (auto it = customPropertiesObject.begin(); it != customPropertiesObject.end(); ++it) {
        keyFrame.setCustomProperty(it.key(), it.value().toDouble());
    }
//    for (const auto &value : customPropertiesObject) {
//        value.
//        qDebug() << value;
//        for (auto it = value.begin(); it != value.end(); ++it) {
//            keyFrame.setCustomProperty(it.key(), it.value().toDouble());
//        }
//    }

    for (const QJsonValue &value : object.find("hitBoxes").value().toArray()) {
        auto hitBox = new HitBox();
        fromJsonObject(*hitBox, value.toObject());
        keyFrame.insertHitBox(keyFrame.hitBoxes().count(), hitBox);
    }
}
v8::Local<v8::Object> QV8JsonWrapper::fromJsonObject(const QJsonObject &object)
{
    v8::Local<v8::Object> v8object = v8::Object::New();
    for (QJsonObject::const_iterator it = object.begin(); it != object.end(); ++it)
        v8object->Set(QJSConverter::toString(it.key()), fromJsonValue(it.value()));
    return v8object;
}
Example #9
0
static bool checkProtocol(const QJsonObject& in, SceneDeserializer::Info* info)
{
    if (in.find("protocol") == in.end())
    {
        if (info)
            info->error_message = "Could not detect protocol";
        return false;
    }
    else
    {
        auto protocol_version = in["protocol"].toDouble();
        if (protocol_version < 6)
        {
            if (info)
                info->error_message = "File was saved with a older protocol "
                                      "and can no longer be read.";
            return false;
        }
        else if (protocol_version > 6)
        {
            if (info)
                info->error_message = "File was saved with a newer protocol "
                                      "and cannot yet be read.";
            return false;
        }
    }
    return true;
}
Example #10
0
// ------------ TwqUser::P_Followed ------------
void TwqUser::P_Followed::receiveInfo(const QJsonObject& jobj) {
	auto itr = jobj.find("connections");
	if(itr != jobj.end()) {
		_v.bFollowed = itr.value().toObject().contains("followed_by");
		haveF |= Flag;
	}
}
Example #11
0
void dialogGameStats::updateGameStatsFromJsonResponse(const QJsonObject &jsonObject) {

    if (!jsonObject["top"].isNull()) {



            for(QJsonObject::const_iterator iter = jsonObject.begin(); iter != jsonObject.end(); ++iter) {
                if (iter.key() == "top")
                {

                   // while (this->ui->tableWidgetGameStats->rowCount() > 0)
                   // {
                   //     this->ui->tableWidgetGameStats->removeRow(0);
                   // }

                    this->ui->treeWidgetGameStats->clear();

                    //this->ui->tableWidgetGameStats->setColumnCount(2);
                   // this->ui->tableWidgetGameStats->horizontalHeaderItem(0)->setText("Viewers");
                   // this->ui->tableWidgetGameStats->horizontalHeaderItem(1)->setText("Game");


                    for (int i = 0; i <= iter.value().toArray().size(); i++)
                    {
                   // qDebug() << iter.value().toArray().at(i).toObject()["game"].toObject()["name"].toString();
                   // qDebug() <<  iter.value().toArray().at(i).toObject()["viewers"].toDouble();


                    if (iter.value().toArray().at(i).toObject()["game"].toObject()["name"].toString() != "") {
                        QTreeWidgetItem * item = new QTreeWidgetItem();
                        item->setText(0,QString::number(i+1));
                        item->setText(1,QString::number(iter.value().toArray().at(i).toObject()["viewers"].toDouble()));
                        item->setText(2,iter.value().toArray().at(i).toObject()["game"].toObject()["name"].toString());
                        item->setTextColor(1,  QColor(85,85,255));


                        this->ui->treeWidgetGameStats->addTopLevelItem(item);

                    }





                    }







                }
            }



        }

}
Example #12
0
ImageData::ImageData(const QJsonObject &json){
	for (auto j = json.begin(); j != json.end(); ++j){
		if (j.key() == "artists" && j.value().isArray()){
			const QJsonArray a = j.value().toArray();
			for (const auto &s : a){
				artists.push_back(s.toString());
			}
		}
		else if (j.key() == "culture" && j.value().isString()){
			culture = j.value().toString();
		}
		else if (j.key() == "title" && j.value().isString()){
			title = j.value().toString();
		}
		else if (j.key() == "work_type" && j.value().isString()){
			work_type = j.value().toString();
		}
		else if (j.key() == "has_nudity" && j.value().isBool()){
			has_nudity = j.value().toBool();
		}
		else if (j.key() == "id"){
			id = j.value().toInt();
		}
	}
}
QList<QString> SingleWeatherParamWidget::getDataFromJson(QString jsonStr){
    QList<QString> valueList;
    QJsonParseError jsonErr;
    QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8(), &jsonErr);
    if(jsonErr.error == QJsonParseError::NoError){
        if(!jsonDoc.isEmpty()){
            if(jsonDoc.isObject()){
                QJsonObject jobj = jsonDoc.object();
                QJsonObject::iterator it = jobj.begin();
                while(it != jobj.end()){
                    if(QJsonValue::Array == it.value().type()){
                        QJsonArray array = it.value().toArray();
                        int subArrayCount = array.count();
                        for(int i = 0;i < subArrayCount;i++){
                            QJsonArray subArray = array.at(i).toArray();
                            valueList.append(subArray.at(0).toString());
                            valueList.append(subArray.at(1).toString());
                        }
                    }
                    it++;
                }
            }
        }
    }
    return valueList;
}
Example #14
0
BaseJob::Status SyncJob::parseJson(const QJsonDocument& data)
{
    QJsonObject json = data.object();
    d->nextBatch = json.value("next_batch").toString();
    // TODO: presence
    // TODO: account_data
    QJsonObject rooms = json.value("rooms").toObject();

    const struct { QString jsonKey; JoinState enumVal; } roomStates[]
    {
        { "join", JoinState::Join },
        { "invite", JoinState::Invite },
        { "leave", JoinState::Leave }
    };
    for (auto roomState: roomStates)
    {
        const QJsonObject rs = rooms.value(roomState.jsonKey).toObject();
        d->roomData.reserve(rs.size());
        for( auto r = rs.begin(); r != rs.end(); ++r )
        {
            d->roomData.push_back({r.key(), r.value().toObject(), roomState.enumVal});
        }
    }

    return Success;
}
Example #15
0
void GetRequest::exec(AbstractWeiboApi *apiRequest)
{
  QByteArray responseStr;
  if (apiRequest->isHttpGet())
    responseStr = manager->getMethod(apiRequest->getUrl());
  else {
    QHttpMultiPart multiPart(QHttpMultiPart::FormDataType);
    QList<QHttpPart> partList = apiRequest->setPostMultiPart();
    for (int i = 0; i < partList.size(); i++)
      multiPart.append(partList.at(i));

    responseStr = manager->postMethod(apiRequest->getUrl(), multiPart);
  }
  QString error;
  JsonParser parser(responseStr);

  QJsonObject responseMap = parser.getJsonObject();

  if (responseMap.isEmpty())
    error = responseStr;
  else
    error = apiRequest->parse(responseMap);

  if (responseMap.find("error") != responseMap.end())
    error = responseStr;

  emit sendLog(apiRequest->getUrl().toString(), QDateTime::currentDateTime(),
               responseMap, error);
}
MCGUIComponent::Variables::Variables(const QJsonObject &o) {
    requires = o["requires"].toString("");
    for (auto it = o.begin(); it != o.end(); it++) {
        if (it.key() == "requires")
            continue;
        vars[it.key()] = *it;
    }
}
Example #17
0
void JobConfig::setPresetList(const QJsonObject& object) {
    for (auto it = object.begin(); it != object.end(); it++) {
        JobConfig* child = findChild<JobConfig*>(it.key(), Qt::FindDirectChildrenOnly);
        if (child) {
            child->setPresetList(it.value().toObject());
        }
    }
}
Example #18
0
// ------------ TwqUser::P_PictureURL ------------
void TwqUser::P_PictureURL::receiveInfo(const QJsonObject& jobj) {
	// profile_url項があればOK
	auto itr = jobj.find(JSONKWD::USER::Profile_url);
	if(itr != jobj.end()) {
		_v.profURL = itr.value().toString();
		haveF |= Flag;
	}
}
Example #19
0
void QJsonView::buildObject(const QString& name, const QJsonObject &obj, QTreeWidgetItem *parent)
{
   QTreeWidgetItem *item = createItem(name + (!name.isEmpty()? " " : "") + "{...}", parent, TYPE_ITEM_OBJECT);
   QJsonObject::const_iterator iterator = obj.begin();
   while( iterator != obj.end() ) {
       addItem(iterator.key(), iterator.value(), item);
       ++iterator;
   }
}
Example #20
0
//! Gets a reference to an object.
ObjectFront* VaultFront::object(
	const QJsonValue& objectInfoValue  //!< Json object that identifies the object. This can be ObjVer or ObjectVersion.
)
{
	// First identiy which type of id we have and
	// then get new front for the object.
	QJsonObject objectInfo = objectInfoValue.toObject();
	ObjectFront* front = 0;
	if( objectInfo.find( QString( "Title" ) ) != objectInfo.end() )
	{
		// This is an ObjectVersion Json object.
		QJsonValue objverJson = objectInfo[ "ObjVer" ];
		MFiles::ObjVer objver( objverJson.toObject() );
		front = this->newFront( objver.objId() );
	}
	else if( objectInfo.find( QString( "Type" ) ) != objectInfo.end() &&
			 objectInfo.find( QString( "Version" ) ) == objectInfo.end() )
	{
		// This is ObjID Json object.
		MFiles::ObjID objid( objectInfo );
		front = this->newFront( objid );
	}
	else if( objectInfo.find( QString( "Type" ) ) != objectInfo.end() &&
			 objectInfo.find( QString( "Version" ) ) != objectInfo.end() )
	{
		// This is ObjVer Json object.
		MFiles::ObjVer objver( objectInfo );
		front = this->newFront( objver.objId() );
	}
	else
	{
		// TODO: Error handling.
		front = 0;
	}

	// Set the ownership to JavaScript.
	if( front )
		QQmlEngine::setObjectOwnership( front, QQmlEngine::JavaScriptOwnership );

	// Return the front.
	return front;
}
Example #21
0
QJsonObject _getObjectSchema(const QString& title, const QJsonObject& object)
{
    QJsonObject properties;
    for (auto it = object.begin(); it != object.end(); ++it)
        properties[it.key()] = _getPropertySchema(it.key(), it.value());

    return QJsonObject{{"$schema", "http://json-schema.org/schema#"},
                       {"title", title},
                       {"type", "object"},
                       {"additionalProperties", false},
                       {"properties", properties}};
}
Example #22
0
QV4::ReturnedValue JsonObject::fromJsonObject(ExecutionEngine *engine, const QJsonObject &object)
{
    Scope scope(engine);
    Scoped<Object> o(scope, engine->newObject());
    ScopedString s(scope);
    ScopedValue v(scope);
    for (QJsonObject::const_iterator it = object.begin(); it != object.end(); ++it) {
        v = fromJsonValue(engine, it.value());
        o->put((s = engine->newString(it.key())).getPointer(), v);
    }
    return o.asReturnedValue();
}
Example #23
0
void MainWindow::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
    QJsonValue jsonObj = current->data(0, Qt::UserRole).toJsonValue();

    QJsonValue::Type jsonType = jsonObj.type();

    switch(jsonType)
    {
    case QJsonValue::Bool:
        ui->boolButton->setChecked(jsonObj.toBool());
        break;
    case QJsonValue::Double:
        ui->doubleValue->setValue(jsonObj.toDouble());
        break;
    case QJsonValue::String:
        ui->stringEdit->document()->setPlainText(jsonObj.toString());
        break;
    case QJsonValue::Array:
        {
            QJsonArray arr = jsonObj.toArray();
            int count = arr.count();

            ui->arrayList->clear();

            for(int i = 0; i < count; ++i)
            {
                QString label = renderJsonValue(arr.at(i));
                ui->arrayList->addItem(label);
            }
        }
        break;
    case QJsonValue::Object:
        {
            QJsonObject obj = jsonObj.toObject();
            ui->objectTable->setRowCount(obj.count());
            int row = 0;
            for(QJsonObject::ConstIterator i = obj.begin(); i != obj.end(); ++i, ++row)
            {
                QTableWidgetItem *keyItem = new QTableWidgetItem(i.key());
                QJsonValue val = i.value();
                QTableWidgetItem *valItem = new QTableWidgetItem(renderJsonValue(val));
                ui->objectTable->setItem(row, 0, keyItem);
                ui->objectTable->setItem(row, 1, valItem);
            }
        }
        break;
    default:
        break;
    }

    ui->typeSelector->setCurrentIndex(jsonObj.type() - 1);
}
Example #24
0
static bool checkType(const QJsonObject& in, SceneDeserializer::Info* info)
{
    // Check that the "type" field is "sb"
    if (in.find("type") == in.end() || in["type"].toString() != "sb")
    {
        if (info)
            info->error_message = "Could not recognize file.<br><br>"
                                  "If this file was saved in Antimony 0.7.7 or earlier, "
                                  "open it in Antimony 0.7.8 and re-save to upgrade to "
                                  "the current file format.";
        return false;
    }
    return true;
}
void ScheduleModel::getHolidays()
{
    LOG << "Get Holidays";
    QFile f(":/json/holidays.json");
    if(f.open(QIODevice::ReadOnly))
    {
        LOG << "Opened file";
        while(!f.atEnd())
        {
            auto line = f.readLine();
            if(!line.isEmpty() && !line.startsWith("#"))
            {
                //LOG << line;
                auto object = QJsonDocument::fromJson(line).object();
                auto value = object.value("data");
                if(value != QJsonValue::Undefined)
                {
                    object = value.toObject();
                    auto year = QDateTime::currentDateTime().date().year();
                    value = object.value(QString::number(year));
                    if(value != QJsonValue::Undefined)
                    {
                        //found current year
                        object = value.toObject();
                        //LOG << object;
                        QJsonObject monthObject;
                        for(auto itMonth = object.begin(); itMonth != object.end(); ++itMonth)
                        {
                            //month
                            monthObject = itMonth.value().toObject();
                            QJsonObject dayObject;
                            for(auto itDay = monthObject.begin(); itDay != monthObject.end(); ++itDay)
                            {
                                //day
                                dayObject = itDay.value().toObject();
                                auto value = dayObject.value("isWorking");
                                if(value != QJsonValue::Undefined)
                                {
                                    auto date = QDate(year, itMonth.key().toInt(), itDay.key().toInt());
                                    m_holidays.insert(date, value.toInt());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Example #26
0
void configFactory::Parse(){
  QFile json("../config.json");
  if (json.open(QIODevice::ReadOnly))
  {
    QJsonParseError  parseError;
    QJsonObject jsonDoc = QJsonDocument::fromJson(json.readAll(), &parseError).object();
    for (QJsonObject::iterator it = jsonDoc.begin(); it != jsonDoc.end(); it++)
    {
      MapOfConfigs[it.key()] = DetermineConfigObject(it.value().toObject());
    }
  }
  else
  {
  std::cout<<"Config json not found\n";
  }
}
Example #27
0
void MainWindow::buildJsonTree(QTreeWidgetItem *parent, QJsonValue &obj, QString key = "")
{
    QTreeWidgetItem *toAdd = NULL;
    switch(obj.type())
    {
    case QJsonValue::Bool:
    case QJsonValue::Double:
    case QJsonValue::String:
    case QJsonValue::Undefined:
    case QJsonValue::Null:
        toAdd = createJsonTreeLeaf(parent, obj, key);
        break;
    case QJsonValue::Array:
    {
        toAdd = new QTreeWidgetItem(parent);
        QJsonArray array = obj.toArray();
        int count = array.count();
        toAdd->setText(0, key+"["+QString::number(count)+"]");

        for(int i = 0; i < count; ++i)
        {
            QJsonValue val = array.at(i);
            buildJsonTree(toAdd, val, QString::number(i)+" : ");
        }
        break;
    }
    case QJsonValue::Object:
    {
        toAdd = new QTreeWidgetItem(parent);
        QJsonObject object = obj.toObject();
        int count = object.count();
        toAdd->setText(0, key+"{"+QString::number(count)+"}");

        for(QJsonObject::ConstIterator i = object.begin(); i != object.end(); ++i)
        {
            QJsonValue val = i.value();
            buildJsonTree(toAdd, val, i.key()+" : ");
        }
        break;
    }
    default:
        break;
    }

    toAdd->setData(0, Qt::UserRole, QVariant(obj));
    parent->addChild(toAdd);
}
Example #28
0
void QEditorSettings::fromJson(const QJsonObject &root){
    for( QJsonObject::ConstIterator it = root.begin(); it != root.end(); ++it ){
        if ( it.key() == "font" ){
            QJsonObject fontObj = it.value().toObject();
            if ( fontObj.contains("size") ){
                m_fontSize = root["size"].toInt();
                emit fontSizeChanged(m_fontSize);
            }
        } else {
            QEditorSettingsCategory* category = settingsFor(it.key());
            if ( category )
                category->fromJson(it.value());
            else
                qCritical("Failed to find settings for: %s", qPrintable(it.key()));
        }
    }
}
Example #29
0
Signal ReadGraph(const QJsonObject& obj)
{
	Signal signal{};

	auto it = obj.find("name");
	if (it != obj.end())
	{
		const auto sigName = it->toString();
		signal.name = std::move(sigName);

		it = obj.find("color");
		if (it != obj.end())
			signal.graphic.color = it->toString();
		
		it = obj.find("visible");
		if (it != obj.end())
			signal.graphic.visible = it->toBool();
		
		it = obj.find("range");
		if (it != obj.end())
		{
			auto vec = ToVector(it->toArray());
			signal.graphic.rangeLower = vec.front();
			signal.graphic.rangeUpper = vec.back();
		}
		
		it = obj.find("values");
		if (it != obj.end() && it->isArray())
		{
			signal.y = ToVector(it->toArray());
		}
		
		it = obj.find("ticks");
		if (it != obj.end() && it->isArray())
		{
			signal.graphic.ticks = ToVector(it->toArray());
		}

		it = obj.find("tickLabels");
		if (it != obj.end() && it->isArray())
		{
			signal.graphic.tickLabels = ToStrVector(it->toArray());
		}
	}

	return signal;
}
Example #30
0
void HouScene::load( const QString &filename )
{
	// open new file
	QFile file;
	file.setFileName(filename);
	file.open(QIODevice::ReadOnly | QIODevice::Text);

	QJsonDocument sd = QJsonDocument::fromJson(file.readAll());
	QJsonObject root = sd.object();

	// cameras ---
	if( root.contains("cameras") )
	{
		QJsonObject cameras = root.value("cameras").toObject();
		for( auto it = cameras.begin(), end = cameras.end(); it != end; ++it )
			m_cameras[it.key()] = loadCamera( it.value().toObject() );
	}
}