Пример #1
0
void LOCACC::writeHtmlLogFile(QJsonArray logArray)
{
    QString logText = "<html><head><title>"+ getInteractivityName() +
            "</title></head><body><h1 style='text-align:center;'>Replacement Log for " + getInteractivityName() +"</h1>"
            "<table border='1' style='text-align: center;margin: auto'>"
            "<thead style='font-weight: bold;'><td>Screen</td><td>Element</td><td>Message</td><td>LOC Text</td><td>CommonId</td></thead>";
    for(int i = 0 ; i < logArray.count() ; i++)
    {
        QJsonObject obj = logArray.at(i).toObject();
        logText += "<tr><td>" + obj["screenId"].toString()
                     + "</td><td>" + obj["elementId"].toString()
                     + "</td><td>" + obj["messageId"].toString()
                     + "</td><td>" + obj["originalText"].toString()
                     + "</td><td>" + obj["commonId"].toString()
                     + "</td></tr>";
    }
    logText += "</table><h1 style='text-align:center;'>Total changes :" + QString::number(logArray.count()) + "</body></html>";

    QString str_htmlFilePath = getLogFilePath() + ".htm";
    QFile htmlLogFile(str_htmlFilePath);
    htmlLogFile.remove();
    htmlLogFile.open(QIODevice::ReadWrite | QIODevice::Text);
    QTextStream out(&htmlLogFile);
    out << logText;
    htmlLogFile.close();    
    QDesktopServices::openUrl(QUrl(str_htmlFilePath.replace("\\","/")));
}
Пример #2
0
QTreeWidgetItem* LOCACC::addElement(QStringList elementData, QTreeWidgetItem *parent)
{
    QJsonArray jArray = m_jsonMasterObj["locAccData"].toArray();
    QString parentScreen = parent->text(0);
    QJsonObject tempObj ;
    QTreeWidgetItem *newEleWidget;
    for(int i = 0 ; i < jArray.count() ; i++ )
    {
        tempObj = jArray.at(i).toObject();
        if(tempObj["id"] == parentScreen)
        {
            QJsonArray eleJArray = tempObj["elements"].toArray();
            if(messageExistance(elementData,eleJArray))
            {
                return false;
            }
            QJsonObject newEleObj = getElementJson(elementData);
            eleJArray.append(newEleObj);
            tempObj["elements"] = eleJArray;
            jArray.replace(i,tempObj);

            QStringList strList;
            strList << elementData;
            newEleWidget  = new QTreeWidgetItem(strList);
            parent->addChild(newEleWidget);
            break;
        }
    }
    m_jsonMasterObj["locAccData"] = jArray;
    writeFile();
    return newEleWidget;
}
Пример #3
0
bool FilmsListLoader::Populate( FilmItem* rootItem, QString fileName )
{
    DebugPrintFunc( "FilmsListLoader::Populate", fileName );

    QFile file( fileName );

    if( file.open(QIODevice::ReadOnly) )
    {
        QDataStream stream( &file );
        stream.setVersion( QDataStream::Qt_5_3 );

        QString databaseHeader; quint8 databaseVersion;
        stream >> databaseHeader >> databaseVersion;

        QByteArray data;
        stream >> data;
        file.close();

        if( !data.isEmpty() )
        {
            QJsonDocument rootDocument = QJsonDocument::fromJson(data);
            QJsonObject rootObject = rootDocument.object();
            QJsonArray filmsArray = rootObject["films"].toArray();

            for( int i = 0; i < filmsArray.count(); ++i )
            {
                rootItem->AppendChild( FromJsonObjectToFilm( filmsArray.at(i).toObject() ) );
            }
        }

        DebugPrint( "Success!" );
        DebugPrintFuncDone( "FilmsListLoader::Populate" );
        return( true );
    }
Пример #4
0
void NetWork::dealGetListInfo(QNetworkReply *reply)
{
	QJsonObject obj = getObject(*reply);
	if (obj.isEmpty())
		return;
	QJsonObject resultObj = obj.find("result").value().toObject();
	QJsonArray listObj = resultObj.find("tracks").value().toArray();

	QList<QStringList> rev_list;
	for (int i = 0; i < listObj.size(); i++)
	{
		QJsonObject mp3Obj = listObj.at(i).toObject();
		QString url = mp3Obj.find("mp3Url").value().toString();
		QString name = mp3Obj.find("name").value().toString();
		QJsonArray artistsList = mp3Obj.find("artists").value().toArray();
		QString artists = "";
		for (int j = 0; j < artistsList.count(); j++)
		{
			QJsonObject artistsObjName = artistsList.at(j).toObject();
			artists.append(artistsObjName.find("name").value().toString() + " ");
		}
		QJsonObject albumObj = mp3Obj.find("album").value().toObject();
		QString album = albumObj.find("name").value().toString();
		int songId = mp3Obj.find("id").value().toInt();
		QStringList list;
		list << name << artists << album << url << QString::number(songId);
		rev_list.insert(i, list);
	}
	emit musicInfo(rev_list);
}
Пример #5
0
QString Parse::generatePmlXml(QJsonObject obj) {

    QString _xml;

    QXmlStreamWriter *xml = new QXmlStreamWriter(&_xml);

    xml->writeStartElement("pmllist");
    //        xml->writeAttribute("version", "2.0");
    QJsonArray results = obj["results"].toArray();
    qWarning()<<"json count"<<results.count();
    foreach (const QJsonValue & value, results) {

        xml->writeStartElement("pml_item");
        QJsonObject pml_item = value.toObject();
        xml->writeTextElement("guid",pml_item["objectId"].toString());
        xml->writeTextElement("title",pml_item["title"].toString());
        xml->writeTextElement("description",pml_item["description"].toString());
        xml->writeTextElement("snapshot_small",(pml_item["snap"].toObject())["url"].toString());
        xml->writeTextElement("pmlfile",(pml_item["pmlfile"].toObject())["url"].toString());
        xml->writeTextElement("owner_username",(pml_item["owner"].toObject())["username"].toString());
        xml->writeTextElement("access_id",pml_item["ACL"].toObject().contains("*")?"2":"0");
        xml->writeTextElement("ispublic",pml_item["ACL"].toObject().contains("*")?"1":"0");
        xml->writeTextElement("keywords",pml_item["keywords"].toString());
        xml->writeTextElement("type",pml_item["type"].toString());
        xml->writeTextElement("createdAt",pml_item["createdAt"].toString());
        xml->writeTextElement("updatedAt",pml_item["updatedAt"].toString());


        xml->writeEndElement();  // pml_item
    }
Пример #6
0
MenuBarWidget::MenuBarWidget(MainWindow *parent) : QMenuBar(parent),
    m_mainWindow(parent),
    m_leftToolBar(NULL),
    m_rightToolBar(NULL)
{
    QFile file(SessionsManager::getReadableDataPath(QLatin1String("menu/menuBar.json")));
    file.open(QFile::ReadOnly);

    const QJsonArray definition = QJsonDocument::fromJson(file.readAll()).array();

    file.close();

    for (int i = 0; i < definition.count(); ++i)
    {
        const QJsonObject object = definition.at(i).toObject();
        Menu *menu = new Menu(Menu::getRole(object.value(QLatin1String("identifier")).toString()), this);
        menu->load(object);

        addMenu(menu);
    }

    if (!isNativeMenuBar())
    {
        setup();

        connect(ToolBarsManager::getInstance(), SIGNAL(toolBarModified(int)), this, SLOT(toolBarModified(int)));
    }
Пример #7
0
QMap<QString, TLMethod> GeneratorNG::readMethods(const QJsonDocument &document)
{
    const QJsonArray methods = document.object().value("methods").toArray();

    QMap<QString, TLMethod> result;

    for (int i = 0; i < methods.count(); ++i) {
        const QJsonObject obj = methods.at(i).toObject();

        const QString methodName = formatName(obj.value("method").toString());
        const quint32 methodId = obj.value("id").toString().toInt();

        TLMethod tlMethod;
        tlMethod.name = methodName;
        tlMethod.id = methodId;

        const QJsonArray params = obj.value("params").toArray();

        foreach (const QJsonValue &paramValue, params) {
            const QJsonObject &paramObj = paramValue.toObject();
            const QString paramName = formatMember(paramObj.value("name").toString());

            const QString paramType = paramObj.value("type").toString();

            tlMethod.params.append(TLParam(paramName, formatType(paramType)));
        }

        result.insert(methodName, tlMethod);

//        quint32 id = obj.value("id").toString().toInt();
//        qDebug() << name << QString::number(id, 0x10);
    }

    return result;
}
Пример #8
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;
}
Пример #9
0
bool Utils::exportAsPdf(const QString &fileName, const QJsonObject &contents) {
    QTextDocument doc;
    QString html;
    QTextStream stream(&html);

    stream << QString("<html><head><style type=\"text/css\">"
                      "h1 {color:red;} "
                      " "
                      "</style></head><body>");

    stream << QString("<h1>%1</h1>").arg(contents["name"].toString());

    stream << QString("<p>%1 <br>").arg(contents["totaltime"].toString());
    stream << QString(tr("Difficulty: %1<br>")).arg(contents["difficulty"].toDouble()); // FIXME: how can I access the array?
    stream << QString(tr("Restriction: %1</p>")).arg(contents["restriction"].toDouble());

    stream << QString(tr("<h2>Ingredients</h2>"));

    stream << "<ul>";
    QJsonArray ingredients = contents["ingredients"].toArray();
    for (int i = 0; i < ingredients.count(); i++) {
        QJsonObject ingredient = ingredients[i].toObject();
        stream << QString("<li>%1 %2 %3</li>").arg(ingredient["quantity"].toDouble())
                .arg(ingredient["type"].toString(), ingredient["name"].toString());
    }
    stream << "</ul>";

    stream << QString(tr("<h2>Directions</h2>"));
    stream << QString("<p>%1</p>").arg(contents["directions"].toString());

    stream << QString(tr("<h2>Photos</h2><br />"));
    QJsonArray photos = contents["photos"].toArray();
    for (int i = 0; i < photos.count(); i++)
        stream << QString("<img src='%1' width=200 />").arg(photos[i].toString());

    stream << QString("</body></html>");

    doc.setHtml(html);

    QPrinter printer;
    printer.setOutputFileName(fileName);
    printer.setOutputFormat(QPrinter::PdfFormat);
    doc.print(&printer);
    printer.newPage();

    return true;
}
Пример #10
0
void TvEpisodeDbList::load(const QJsonArray &json, const Configuration &configuration)
{
  for (int i = 0 ; i < json.count(); ++i) {
    TvEpisodeDb episode(configuration);
    episode.load(json.at(i).toObject());
    append(episode);
  }
}
Пример #11
0
void TvSeasonDbList::load(const QJsonArray& json, const Configuration& configuration)
{
  for (int i = 0 ; i < json.count(); ++i) {
    TvSeasonDb tvseason(configuration);
    tvseason.load(json.at(i).toObject());
    append(tvseason);
  }
}
Пример #12
0
bool indexDirectory(const QString& dir, const QString& dest)
{
    QVariantMap vm;
    QVariantMap pluginsVm;
    vm[QStringLiteral("Version")] = QStringLiteral("1.0");
    vm[QStringLiteral("Timestamp")] = QDateTime::currentMSecsSinceEpoch();

    QJsonArray plugins;

    QDirIterator it(dir, *metaDataFiles, QDir::Files, QDirIterator::Subdirectories);
    while (it.hasNext()) {
        it.next();
        const QString path = it.fileInfo().absoluteFilePath();
        QJsonObject obj = KPluginMetaData(path).rawData();
        obj.insert(QStringLiteral("FileName"), path);

        plugins.append(obj);
    }

    // Less than two plugin means it's not worth indexing
    if (plugins.count() < 2) {
        removeIndex(dir);
        return true;
    }

    QString destfile = dest;
    if (!QDir::isAbsolutePath(dest)) {
        destfile = dir + '/' + dest;
    }

    QDir().mkpath(QFileInfo(destfile).dir().absolutePath());
    QFile file(destfile);
    if (!file.open(QIODevice::WriteOnly)) {
        qWarning() << "Failed to open " << destfile;
        return false;
    }

    QJsonDocument jdoc;
    jdoc.setArray(plugins);
//     file.write(jdoc.toJson());
    file.write(jdoc.toBinaryData());
    qWarning() << "Generated " << destfile << " (" << plugins.count() << " plugins)";

    return true;
}
Пример #13
0
QTreeWidgetItem* LOCACC::addMessage(QStringList msgData, bool isAccTextSame, QTreeWidgetItem *parent)
{
    QString eleId = parent->text(0);
    QJsonArray jArray = m_jsonMasterObj["locAccData"].toArray();
    QString parentScreen = parent->parent()->text(0);
    QJsonObject tempObj ;
    QTreeWidgetItem *newMsg;
    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();
                    if(messageExistance(msgData,msgsArray))
                    {
                        return false;
                    }
                    QJsonObject newMsgJson = getMessageJson(msgData,isAccTextSame);
                    msgsArray.append(newMsgJson);
                    QStringList msgList;
                    msgList << msgData.at(0);
                    newMsg  = new QTreeWidgetItem(msgList);
                    setMessageTooltip(newMsg,newMsgJson);
                    parent->addChild(newMsg);
                    tempEleObj["messages"] = msgsArray;
                    eleJArray.replace(j,tempEleObj);
                    tempObj["elements"] = eleJArray;
                    jArray.replace(i,tempObj);
                    break;
                }
            }
        }
    }
    m_jsonMasterObj["locAccData"] = jArray;
    writeFile();
    return newMsg;
}
Пример #14
0
void TrackProvider::LoadRoutesFromFile()
{
    removeAllRoutes();
    QString routes_file = AppSettings::GetKey(AppSettings::MapEdit_Routes_File).toString();
    QFile file(routes_file);
    if(!file.open(QIODevice::ReadOnly))
        return;

    QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
    QJsonObject routesObj = doc.object();

    file.close();

    if(!routesObj["routes"].isArray()) return;
    QJsonArray routesArray = routesObj["routes"].toArray();

    for(int i=0;i<routesArray.count(); i++)
    {
        QJsonObject routeObj = routesArray.at(i).toObject();
        bool closed = routeObj["closed"].toBool();
        bool visible = routeObj["visible"].toBool();
        bool editable = routeObj["editable"].toBool();
        QString name = routeObj["name"].toString();

        OSMRoute newRoute;
        newRoute.name = name;
        newRoute.closed = closed;
        newRoute.visible = visible;
        newRoute.editable = editable;

        QJsonArray routePoints = routeObj["points"].toArray();
        for(int j=0; j<routePoints.count(); j++)
        {
            QJsonObject pointObj = routePoints.at(j).toObject();
            QPointF point;
            point.setX( pointObj["pos_x"].toDouble());
            point.setY( pointObj["pos_y"].toDouble());

            newRoute.addPoint(point);
        }

        routes.append(newRoute);
    }
}
Пример #15
0
bool LOCACC::deleteMessage(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);
                            tempEleObj["messages"] = msgsArray;
                            eleJArray.replace(j,tempEleObj);
                            tempObj["elements"] = eleJArray;
                            jArray.replace(i,tempObj);
                            break;
                        }
                    }
                }
            }
        }
    }
    m_jsonMasterObj["locAccData"] = jArray;
    currentItem->parent()->removeChild(currentItem);
    emptyTreeWidget(currentItem);
    writeFile();
    return true;
}
Пример #16
0
void SettingsEditorForm::processListResp(QJsonObject &obj)
{
    QString resource = obj["Resource"].toString();
    QJsonObject data = obj["Data"].toObject();
    QJsonArray resArr = data["Resources"].toArray();
    QJsonArray resDirsArr = data["ResourcesDirs"].toArray();

    QStringList resList;
    QStringList resDirsList;

    for(int i=0;i<resArr.count(); i++)
        resList.append( resArr.at(i).toString());

    for(int i=0;i<resDirsArr.count(); i++)
        resDirsList.append( resDirsArr.at(i).toString());

    updateTreeList(resource, resDirsList, resList);
    requestNewLists(resource, resDirsList);
}
Пример #17
0
void FavoriteMenu::load(QMenu *menu, bool download)
{
    //一旦クリア
    menu->clear();

    QAction *action;
    QByteArray data;
    QFile file(FAVORITE_DOWNLOAD_FILE);
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
    }else{
        QTextStream in(&file);
        in.setCodec("UTF-8");
        while(!in.atEnd()){
            data.append(in.readLine());
        }
        file.close();

        QJsonDocument json = QJsonDocument::fromJson(data);
        QJsonArray array = json.object().value("root").toArray();
        //フォルダ
        for(int i=0; i<array.count(); i++){
            //アイテム
            if(TO_VALUE(array.at(i), "array").isArray()){
                addItem(menu, TO_ARRAY(array.at(i)));
            }else{
//            qDebug() << "title:" << TO_STRING(array->at(i), KEY_TITLE);
                action = menu->addAction(TO_STRING(array.at(i), KEY_TITLE), this, SLOT(clickItem()));
                action->setData(TO_STRING(array.at(i), KEY_URL));
            }
        }

        //現状のデータの日付を保存
        m_currentLoadedFavDataDate = QDate::fromString(json.object().value("serial").toString().left(8), "yyyyMMdd");
//        qDebug() << json.object().value("serial").toString().left(8);
//        qDebug() << "serial=" << serial << "," << serial.toJulianDay();
//        qDebug() << "today =" << QDate::currentDate() << "," << QDate::currentDate().toJulianDay();

    }

    //ユーザー登録ぶん
    QSettings settings(FAV_FILE_NAME, FAV_FILE_FORMAT);
    settings.beginGroup(QStringLiteral(FAV_USER));
    QHash<QString, QVariant> list = settings.value(QStringLiteral(FAV_USER_BOOKMARK)).toHash();
    foreach (const QString &key, list.keys()) {
        action = menu->addAction(list.value(key).toString(), this, SLOT(clickItem()));
        action->setData(key);
    }
    settings.endGroup();


    //お気に入りをダウンロード
    if(download){
        updateFromInternet();
    }
}
Пример #18
0
void search::findinfile(){

    if(document->isEmpty()) {
        QFile file(":/city_data");
        if(file.open(QIODevice::ReadOnly)){
            QString citydata = file.readAll();
            //qDebug()<<citydata;
            QJsonParseError json_error;
            *document = QJsonDocument::fromJson(citydata.toUtf8(),&json_error);
            if(json_error.error != QJsonParseError::NoError) {
                qDebug()<<"json error"<<json_error.errorString();
                return;
            }
        }
        file.close();
    }
    //QString data = "[{\"s\":[true,1,5]},{\"s\":[true,1,5]}]";
    //qt 的 json不能解析{a:"xxx"}这种,只能{"a":"xxx"}这种key为字符串的json
    QJsonObject ob;
    QString n,p,pc,pv,fl;
    QJsonArray arr;
    if((!oldkey.isEmpty())&&(key.indexOf(oldkey)>-1 ))//继续输入时使用之前的结果,但减少不可以,因为tmp是不断更新的
    {
        arr = tmp;
        //qDebug()<<"arr = tmp";
    }
    else {
         arr = document->array();
         //qDebug()<<"arr = document->array()";
    }
    tmp = QJsonArray();//清空,准备储存新的结果
    for(int i=0;i<arr.count();i++)
    {
        ob = arr.at(i).toObject();
        n = ob.value("n").toString();
        p = ob.value("p").toString();//p和pc可以随便用
        pc = ob.value("pc").toString();
        pv = ob.value("pv").toString();
        fl = ob.value("fl").toString();
        p = n + p + pc + pv + fl;//p和pc可以随便用
        if(p.indexOf(key)!=-1)
        {
            //qDebug()<<"Found:"<<p;
            tmp +=arr.at(i);
            QListWidgetItem *item;
            item=new QListWidgetItem;
            item->setText(n + "-" + pv);
            item->setToolTip(ob.value("ac").toString());
            ui->listWidget->addItem(item);
        }
        //qDebug()<<"url:"<<ob.value("n");
    }

    oldkey = key;//备份当前搜索词
}
Пример #19
0
void RoomListDialog::onManagerResponseRoomlist(const QJsonObject &obj)
{
    if(!obj["result"].toBool())
        return;
    QJsonArray list;
    QTableWidgetItem *item = 0;
    list = obj["roomlist"].toArray();
    QJsonValue info;
    int row = 0;
    int column = 0;
    ui->progressBar->setMaximum(100);
    ui->tableWidget->clearContents();
    ui->tableWidget->setRowCount(0);
    QHash<QString, QJsonObject> tmpRoomsInfo;
    ui->tableWidget->clearContents();
    ui->tableWidget->setSortingEnabled(false);
    foreach(info, list){
        QJsonObject m = info.toObject();
        QString name = m["name"].toString();
        tmpRoomsInfo.insert(name, m);
        if(ui->checkBox->isChecked()){
            //Don't show it if room is full
            if(m["maxload"] == m["currentload"]){
                continue;
            }
        }

        if(row >= ui->tableWidget->rowCount())
            ui->tableWidget->insertRow(0);
        column = 0;

        item = new QTableWidgetItem(name);
        item->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget->setItem(0, column++, item);

        bool isPrivate = m["private"].toBool();
        item = new QTableWidgetItem(
                    isPrivate?tr("Private"):tr("Public"));
        item->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget->setItem(0, column++, item);

        item = new QTableWidgetItem;
        item->setTextAlignment(Qt::AlignCenter);
        item->setData(Qt::DisplayRole, m["currentload"].toDouble());
        ui->tableWidget->setItem(0, column++, item);

        item = new QTableWidgetItem;
        item->setTextAlignment(Qt::AlignCenter);
        item->setData(Qt::DisplayRole, m["maxload"].toDouble());
        ui->tableWidget->setItem(0, column++, item);

        row++;
        ui->progressBar->setValue(100*row/list.count());
    }
Пример #20
0
QTreeWidgetItem * LOCACC::getLocAccTree()
{ 
    QJsonArray locAccArray = m_jsonMasterObj["locAccData"].toArray();
    QJsonObject screenJObj;
    for(int i = 0 ; i < locAccArray.count() ; i++)
    {
        screenJObj = locAccArray.at(i).toObject();
        m_qtwiRoot->addChild(generateScreenTree(screenJObj));
    }
    return m_qtwiRoot;
}
Пример #21
0
void QJsonView::buildArray(const QString& name, const QJsonArray &arr, QTreeWidgetItem *parent)
{
    QTreeWidgetItem *item = createItem(
                name + (!name.isEmpty()? " " : "") + QString("[%1]").arg(arr.count()),
                parent,
                TYPE_ITEM_ARRAY
                );
    int i = 0;
    foreach (QJsonValue var, arr) {
        addItem(QString("[%1]").arg(i++), var, item);
    }
Пример #22
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);
}
Пример #23
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;
}
Пример #24
0
void SearchSuggester::replyFinished()
{
    if (!m_networkReply)
    {
        return;
    }

    if (m_model)
    {
        m_model->clear();
    }

    m_networkReply->deleteLater();

    if (m_networkReply->size() <= 0)
    {
        m_networkReply = NULL;

        return;
    }

    const QJsonDocument document = QJsonDocument::fromJson(m_networkReply->readAll());

    if (!document.isEmpty() && document.isArray() && document.array().count() > 1 && document.array().at(0).toString() == m_query)
    {
        const QJsonArray completionsArray = document.array().at(1).toArray();
        const QJsonArray descriptionsArray = document.array().at(2).toArray();
        const QJsonArray urlsArray = document.array().at(3).toArray();
        QList<SearchSuggestion> suggestions;

        for (int i = 0; i < completionsArray.count(); ++i)
        {
            SearchSuggestion suggestion;
            suggestion.completion = completionsArray.at(i).toString();
            suggestion.description = descriptionsArray.at(i).toString();
            suggestion.url = urlsArray.at(i).toString();

            if (m_model)
            {
                m_model->appendRow(new QStandardItem(suggestion.completion));
            }

            suggestions.append(suggestion);
        }

        emit suggestionsChanged(suggestions);
    }

    m_networkReply = NULL;
}
Пример #25
0
bool LOCACC::messageExistance(QStringList messageData, QJsonArray msgsArray)
{
    QString msgId = messageData.at(0);
    QJsonObject tempObj;
    for(int i = 0 ; i < msgsArray.count(); i++)
    {
        tempObj = msgsArray.at(i).toObject();
        if(tempObj["id"] == msgId)
        {
            return true;
        }
    }
    return false;
}
Пример #26
0
bool LOCACC::elementExistance(QStringList elementData, QJsonArray parentScreenJArray)
{
    QString eleId = elementData.at(0);
    QJsonObject tempObj;
    for(int i = 0 ; i < parentScreenJArray.count(); i++)
    {
        tempObj = parentScreenJArray.at(i).toObject();
        if(tempObj["id"] == eleId)
        {
            return true;
        }
    }
    return false;
}
Пример #27
0
QJsonObject LOCACC::fetchMessageJObject(QStringList messageData,QJsonArray msgsArray)
{
    QString msgId = messageData.at(0);
    QJsonObject tempObj;
    for(int i = 0 ; i < msgsArray.count(); i++)
    {
        tempObj = msgsArray.at(i).toObject();
        if(tempObj["id"] == msgId)
        {
            return tempObj;
        }
    }
    return tempObj;
}
Пример #28
0
bool LOCACC::screenExistance(QStringList screenData, QJsonArray locArray)
{
    QString screenId = screenData.at(0);
    QJsonObject tempObj;
    for(int i = 0 ; i < locArray.count() ; i++)
    {
        tempObj = locArray.at(i).toObject();
        if(tempObj["id"] == screenId)
        {
            return true;
        }
    }
    return false;
}
Пример #29
0
void nd::app::addRelation(const QJsonObject &obj)
{
    QJsonArray fields = obj.value("fields").toArray();
    int i = 0, len = fields.count();

    for(; i < len; i++) {
        QJsonObject field = fields.at(i).toObject();
        if (field.value("type").toString().toLower() == "array") {
            QString name = field.value("relation_name").toString();
            //qDebug() << name << solution->getRelationInfo(name);
            define(relation, name, solution->getRelationInfo(name));
        };
    };
}
Пример #30
0
QJsonObject LOCACC::fetchElementJObject(QStringList elementData, QJsonArray parentScreenJArray)
{
    QString eleId = elementData.at(0);
    QJsonObject tempObj;
    for(int i = 0 ; i < parentScreenJArray.count(); i++)
    {
        tempObj = parentScreenJArray.at(i).toObject();
        if(tempObj["id"] == eleId)
        {
            return tempObj;
        }
    }
    return tempObj;
}