Beispiel #1
0
QString Database::json_convert(Kind *kind){
    QJsonDocument *jdoc = new QJsonDocument;
    QJsonObject *root = new QJsonObject;
    root->insert(NAME, QJsonValue(kind->getName()));
    root->insert(SURNAME, QJsonValue(kind->getSurName()));
    root->insert(DATE, QJsonValue(kind->getDate().toString(DATESAVEFORMAT)));
    root->insert(STREET, QJsonValue(kind->getStreet()));
    root->insert(CITY, QJsonValue(kind->getCity()));
    root->insert(GROUP, QJsonValue(kind->getGroup()));
    root->insert(MAIL, QJsonValue(kind->getMail()));
    root->insert(NUMBER, QJsonValue(kind->getNumber()));
    QJsonObject *jtable = new QJsonObject;
    QJsonArray *keys = new QJsonArray;
    QJsonArray *tables = new QJsonArray;
    QJsonObject *values = new QJsonObject;
    std::map<QString, QString> *kt = kind->getTable();
    std::map<QString, QString>::iterator it;
    int i = 0;
    for(it = kt->begin(); it != kt->end(); it++){
        keys->insert(i, QJsonValue(it->first));
        values->insert(it->first, it->second);
        i++;
    }
    jtable->insert(KEY, QJsonValue(*keys));
    jtable->insert(VALUE, QJsonValue(*values));
    jtable->insert(NAME, QJsonValue(QString::fromStdString(TNAME)));
    tables->insert(0, QJsonValue(*jtable));
    root->insert(TABLE, QJsonValue(*tables));
    jdoc->setObject(*root);
    QString datefile = QString::fromUtf8(jdoc->toJson(QJsonDocument::Compact)) + QString::fromStdString(ENDL);
    return datefile;
}
Beispiel #2
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void DREAM3DSettings::setValue(const QString& key, const QVariant& value)
{
  if (QString::fromStdString(std::string(value.typeName())) == "QByteArray")
  {
    QByteArray byteArray = value.toByteArray().toBase64();
    QString str = QString::fromLocal8Bit(byteArray);
    QJsonArray jsonArray;
    jsonArray.insert(Value, str);
    jsonArray.insert(Type, value.typeName());
    m_Stack.top()->group.insert(key, jsonArray);
  }
  else
  {
    QJsonValue val = QJsonValue::fromVariant(value);

    if (QString::fromStdString(std::string(value.typeName())) == "QString")
    {
      QJsonArray jsonArray;
      jsonArray.insert(Value, val);
      jsonArray.insert(Type, value.typeName());
      m_Stack.top()->group.insert(key, jsonArray);
    }
    else
    {
      m_Stack.top()->group.insert(key, val);
    }
  }

  // If this is the root, write to the file
  if (m_Stack.top()->groupName.isEmpty())
  {
    writeToFile();
  }
}
Beispiel #3
0
QJsonObject JsonSaver::saveCity(const City& city)
{
    QJsonObject res;
    res.insert("name", QString::fromStdString(city.name()));

    QJsonArray buildings;
    int i = 0;
    for(const auto& b : city.buildings())
        buildings.insert(i++, saveBuilding(b));
    res.insert("buildings", buildings);

    res.insert("size", saveSizeU(city.map().size()));

    QJsonArray roads;
    i = 0;
    for(std::size_t x = 0; x < city.map().width(); x++)
        for(std::size_t y = 0; y < city.map().height(); y++)
            if(city.map().squareType({x, y}) == Map::SquareType::Road)
            {
                roads.insert(i++, savePointU({x, y}));
            }

    res.insert("roads", roads);

    return res;
}
Beispiel #4
0
bool LOCACC::updateScreen(QStringList newScreenData, QTreeWidgetItem *currentItem)
{
    QString screenId = currentItem->text(0);
    QJsonArray locArray = m_jsonMasterObj["locAccData"].toArray();
    QJsonObject tempObj;
    for(int i = 0 ; i < locArray.count() ; i++)
    {
        tempObj = locArray.at(i).toObject();
        if(tempObj["id"] == screenId)
        {
            locArray.removeAt(i);
            if(screenExistance(newScreenData,locArray))
            {
                return false;
            }
            tempObj["id"] = newScreenData.at(0);
            tempObj["name"] = newScreenData.at(1);
            locArray.insert(i,tempObj);
            break;
        }
    }
    m_jsonMasterObj["locAccData"] = locArray;
    currentItem->setText(0,newScreenData.at(0));
    writeFile();
    return true;
}
void TaskServices::refreshStatus()
{
    QJsonArray allServices;

    foreach( ServiceStatus* item, systemServices )
    {
        item->updateStatus();
        allServices.insert(allServices.size(), *item->getJsonObject());
    }
QJsonArray jsonHandler::listToJson(QStringList *list)
{
    QJsonArray jArray;

    for(int i = 0; i < list->count(); ++i)
    {
        jArray.insert(i,list->at(i));
    }
    return jArray;
}
Beispiel #7
0
void MainWindow::markAs(bool read, QString id, int status)
{
    request.setUrl(MARKERS_URL);
    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
    reqStatus = Markers;

    QJsonObject *obj = new QJsonObject();
    QJsonObject *obj2 = new QJsonObject();
    QJsonArray *arr = new QJsonArray();

    if(read) {
        obj->insert("action",QJsonValue(QString("markAsRead")));
    }
    else {
        obj->insert("action",QJsonValue(QString("keepUnread")));
    }
    if(status == CONTENT_ENTRY_ID) {

        obj->insert("type",QJsonValue(QString("entries")));
        arr->insert(0,QJsonValue(id));
        obj->insert("entryIds",*arr);
    }

    else if(status == CATEGORY_ENTRY_ID) {
        obj->insert("type",QJsonValue(QString("categories")));
        obj->insert("lastReadEntryId",QJsonValue(currentCategory->data(LAST_READ_ENTRY_ID).toString()));
        arr->insert(0,QJsonValue(id));
        obj->insert("categoryIds",*arr);
    }
    else if(status == FEED_ID) {
        obj->insert("type",QJsonValue(QString("feeds")));
        obj->insert("lastReadEntryId",QJsonValue(currentFeed->data(LAST_READ_ENTRY_ID).toString()));
        arr->insert(0,QJsonValue(id));
        obj->insert("feedIds",*arr);
    }
    QJsonDocument *doc = new QJsonDocument(*obj);
    o2req->post(request,doc->toJson());

    delete obj;
    delete obj2;
    delete arr;
    delete doc;
}
Beispiel #8
0
bool LOCACC::updateMessage(QStringList newMessageData, bool isAccTextSame, QTreeWidgetItem *currentItem)
{
    QString messageId = currentItem->text(0);
    QString eleId = currentItem->parent()->text(0);
    QJsonArray jArray = m_jsonMasterObj["locAccData"].toArray();
    QString parentScreen = currentItem->parent()->parent()->text(0);
    QJsonObject tempObj ;
    for(int i = 0 ; i < jArray.count() ; i++ )
    {
        tempObj = jArray.at(i).toObject();
        if(tempObj["id"] == parentScreen)
        {
            QJsonArray eleJArray = tempObj["elements"].toArray();
            QJsonObject tempEleObj;
            for(int j = 0 ; j < eleJArray.count(); j++)
            {
                tempEleObj = eleJArray.at(j).toObject();
                if(tempEleObj["id"] == eleId)
                {
                    QJsonArray msgsArray = tempEleObj["messages"].toArray();
                    QJsonObject tempMsgObj;
                    for(int k = 0; k < msgsArray.count() ; k++)
                    {
                        tempMsgObj = msgsArray.at(k).toObject();
                        if(tempMsgObj["id"] == messageId)
                        {
                            msgsArray.removeAt(k);
                            if(messageExistance(newMessageData,msgsArray))
                            {
                                return false;
                            }
                            QJsonObject newMsgObj = getMessageJson(newMessageData,isAccTextSame);
                            msgsArray.insert(k,newMsgObj);
                            tempEleObj["messages"] = msgsArray;
                            eleJArray.replace(j,tempEleObj);
                            tempObj["elements"] = eleJArray;
                            jArray.replace(i,tempObj);
                            setMessageTooltip(currentItem,newMsgObj);
                            break;
                        }
                    }
                }
            }
        }
    }
    m_jsonMasterObj["locAccData"] = jArray;
    currentItem->setText(0,newMessageData.at(0));
    writeFile();
    return true;
}
QJsonArray jsonHandler::modelToJson(QStandardItemModel *model, QStringList *list)
{
    QJsonArray jArray;
    QVariant modelValue;
    QVariantHash valueMap;

    for(int row = 0; row < model->rowCount(); ++row)
    {
        for(int col = 0; col < list->count(); ++col)
        {
            valueMap.insert(list->at(col),model->data(model->index(row,col)));
        }
        jArray.insert(row,QJsonObject::fromVariantHash(valueMap));
        valueMap.clear();
    }
    return jArray;
}
Beispiel #10
0
void JsonDbObject::addAncestor(QJsonArray *history, const int updateCount, const QString &hash) const
{
    if (updateCount < 1 || !history)
        return;

    int pos = updateCount - 1;
    for (int ii = history->size(); ii < updateCount; ii++)
        history->append(QJsonValue::Null);

    QJsonValue old = history->at(pos);
    if (old.isArray()) {
        QJsonArray multi = old.toArray();
        for (int ii = multi.size(); ii-- > 0;) {
            QString oldHash = multi.at(ii).toString();
            if (oldHash == hash) {
                return;
            } else if (oldHash < hash) {
                multi.insert(ii + 1, hash);
                history->replace(pos, multi);
                return;
            }
        }
        multi.prepend(hash);
        history->replace(pos, multi);
    } else if (!old.isString()) {
        history->replace(pos, hash);
    } else {
        QString oldHash = old.toString();
        if (oldHash == hash)
            return;

        QJsonArray multi;
        if (oldHash < hash) {
            multi.append(oldHash);
            multi.append(hash);
        } else if (oldHash > hash) {
            multi.append(hash);
            multi.append(oldHash);
        }
        history->replace(pos, multi);
    }
}
Beispiel #11
0
void jsonHandler::init_jsonFile()
{
    QJsonArray intArray;
    activityItem = QJsonObject();
    activityItem = mapToJson(&rideData);
    activityItem["TAGS"] = mapToJson(&tagData);

    if(hasOverride)
    {
        int i = 0;
        for(QHash<QString,QString>::const_iterator it =  overrideData.cbegin(), end = overrideData.cend(); it != end; ++it,++i)
        {
            QJsonObject objOverride,objValue;
            objValue.insert("value",it.value());
            objOverride.insert(it.key(),objValue);
            intArray.insert(i,objOverride);
        }
        activityItem["OVERRIDES"] = intArray;
    }
}
Beispiel #12
0
QJsonObject JsonSaver::saveBuildingType(const BuildingType& buildingtype)
{
    QJsonObject res;
    res.insert("name", QString::fromStdString(buildingtype.name));
    res.insert("size", saveSizeU(buildingtype.size));
    res.insert("recipes", QJsonArray());

    QJsonArray requirements;
    int i = 0;
    for(const auto& p : buildingtype.requirements)
    {
        QJsonObject o;
        o.insert("name", QString::fromStdString(ResourcesHandler::const_instance().get(p.first)));
        o.insert("amount", (double)p.second);
        requirements.insert(i++, o);
    }
    res.insert("requirements", requirements);

    return res;
}
Beispiel #13
0
bool LOCACC::updateElement(QStringList newElementData, QTreeWidgetItem *currentItem)
{
    QString elementId = currentItem->text(0);
    QJsonArray jArray = m_jsonMasterObj["locAccData"].toArray();
    QString parentScreen = currentItem->parent()->text(0);
    QJsonObject tempObj ;
    for(int i = 0 ; i < jArray.count() ; i++ )
    {
        tempObj = jArray.at(i).toObject();
        if(tempObj["id"] == parentScreen)
        {
            QJsonArray eleJArray = tempObj["elements"].toArray();
            QJsonObject eleObject ;
            for(int j = 0 ; j < eleJArray.count() ; j++)
            {
                eleObject = eleJArray.at(j).toObject();
                if(eleObject["id"] == elementId)
                {
                    eleJArray.removeAt(j);
                    if(elementExistance(newElementData,eleJArray))
                    {
                        return false;
                    }
                    QJsonObject newEleJson = getElementJson(newElementData);
                    newEleJson["messages"] = eleObject["messages"];
                    eleJArray.insert(j,newEleJson);
                    tempObj["elements"] = eleJArray;
                    jArray.replace(i,tempObj);
                    break;
                }
            }
        }
    }
    m_jsonMasterObj["locAccData"] = jArray;
    currentItem->setText(0,newElementData.at(0));
    writeFile();
    return true;
}
Beispiel #14
0
bool LOCACC::changeOrder(int currentIndex, int newIndex, QTreeWidgetItem *item)
{
     // qDebug() << "informal :" << currentIndex  ;
    if (item && ((currentIndex < newIndex &&  currentIndex < m_qtwiRoot->childCount() - 1)
                  ||  (currentIndex > 0 && currentIndex > newIndex)))
    {
        // Visual Update        
       QList<QTreeWidgetItem *> items = m_qtwiRoot->takeChildren();
       items.removeAt(currentIndex);
       items.insert(newIndex,item);
       m_qtwiRoot->insertChildren(0,items);

        // Actual Update
       QJsonArray locAccArray = m_jsonMasterObj.find("locAccData").value().toArray();
       QJsonObject objectToRemove = locAccArray.at(currentIndex).toObject();
       locAccArray.removeAt(currentIndex);
       locAccArray.insert(newIndex,objectToRemove);
       m_jsonMasterObj["locAccData"] = locAccArray;
       //writeFile();  // Do not update file on change in order.
       return true;
    }
    return false;
}
Beispiel #15
0
/*!
 * \brief JsonParser::addObject
 * Dodaje obiekt do pliku json
 * \param type typ obiektu
 * \param speed prędkość obiektu
 * \param model model tabeli ze wskazanymi punktami
 */
void JsonParser::addObject(QString type, double speed, QStandardItemModel *model)
{
    QJsonValue type_ = type;
    QJsonObject object;
    object.insert("TypeObject", type_);

    object.insert("Speed", speed);

    QJsonArray array;
    QJsonObject point;
    QJsonValue value;

    for (int i = 0; i <model->rowCount(); i++) {
        value = model->takeItem(i,0)->data(Qt::DisplayRole).toDouble();
        point.insert("CoordX", value);
        value = model->takeItem(i,1)->data(Qt::DisplayRole).toDouble();
        point.insert("CoordY", value);
        array.insert(i,point);
    }
    value = array;
    object.insert("Points", value);
    objects.push_back(object);

    QJsonDocument d;
    QJsonObject obj;
    obj.insert("Objects", static_cast<QJsonValue>(objects));
    d.setObject(obj);
    d.toJson();


    QFile file;
    file.setFileName(fileName);
    file.open(QIODevice::WriteOnly | QIODevice::Text);

    file.write(d.toJson());
    file.close();
}
Beispiel #16
0
bool MainWindow::on_subscibe()
{
    QJsonObject *json = new QJsonObject();
    QJsonObject *j1 = new QJsonObject();
    QJsonObject *j2 = new QJsonObject();
    QJsonArray *jarr = new QJsonArray();

    j1->insert("id",QJsonValue("user/" + userId + "/category/tech"));
    j1->insert("label",QJsonValue(QString("tech")));

    //j2->insert("id",userIdjson);
    //j2->insert("label",QJsonValue(QString("weekly")));

    json->insert("id",QJsonValue("feed/" + subDialog->getFeedUrl()));
    json->insert("title",QJsonValue(subDialog->getFeedTitle()));

    jarr->insert(0,*j1);
    //jarr->insert(1,*j2);

    json->insert("categories",*jarr);

    QJsonDocument *docu =  new QJsonDocument(*json);
    //qDebug() << docu->toJson();

    request.setUrl(SUBSCRIPTIONS_URL);
    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
    o2req->post(request,docu->toJson());
    reqCategories();

    delete json;
    delete j1;
    delete j2;
    delete jarr;

    return true;
}