QJsonObject DomainServerSettingsManager::responseObjectForType(const QString& typeValue, bool isAuthenticated) { QJsonObject responseObject; if (!typeValue.isEmpty() || isAuthenticated) { // convert the string type value to a QJsonValue QJsonValue queryType = typeValue.isEmpty() ? QJsonValue() : QJsonValue(typeValue.toInt()); const QString AFFECTED_TYPES_JSON_KEY = "assignment-types"; // enumerate the groups in the description object to find which settings to pass foreach(const QJsonValue& groupValue, _descriptionArray) { QJsonObject groupObject = groupValue.toObject(); QString groupKey = groupObject[DESCRIPTION_NAME_KEY].toString(); QJsonArray groupSettingsArray = groupObject[DESCRIPTION_SETTINGS_KEY].toArray(); QJsonObject groupResponseObject; foreach(const QJsonValue& settingValue, groupSettingsArray) { const QString VALUE_HIDDEN_FLAG_KEY = "value-hidden"; QJsonObject settingObject = settingValue.toObject(); if (!settingObject[VALUE_HIDDEN_FLAG_KEY].toBool()) { QJsonArray affectedTypesArray = settingObject[AFFECTED_TYPES_JSON_KEY].toArray(); if (affectedTypesArray.isEmpty()) { affectedTypesArray = groupObject[AFFECTED_TYPES_JSON_KEY].toArray(); } if (affectedTypesArray.contains(queryType) || (queryType.isNull() && isAuthenticated)) { // this is a setting we should include in the responseObject QString settingName = settingObject[DESCRIPTION_NAME_KEY].toString(); // we need to check if the settings map has a value for this setting QVariant variantValue; QVariant settingsMapGroupValue = _settingsMap.value(groupObject[DESCRIPTION_NAME_KEY].toString()); if (!settingsMapGroupValue.isNull()) { variantValue = settingsMapGroupValue.toMap().value(settingName); } if (variantValue.isNull()) { // no value for this setting, pass the default if (settingObject.contains(SETTING_DEFAULT_KEY)) { groupResponseObject[settingName] = settingObject[SETTING_DEFAULT_KEY]; } else { // users are allowed not to provide a default for string values // if so we set to the empty string groupResponseObject[settingName] = QString(""); } } else { groupResponseObject[settingName] = QJsonValue::fromVariant(variantValue); } } } } if (!groupResponseObject.isEmpty()) { // set this group's object to the constructed object responseObject[groupKey] = groupResponseObject; } }
void AutoUpdateChecker::handleUpdateCheckRequestFinished(QNetworkReply* reply) { Q_ASSERT(reply->isFinished()); if (reply->error() == QNetworkReply::NoError) { QTextStream stream(reply); stream.setCodec("UTF-8"); // Read all data and queue the reply for deletion QString jsonString = stream.readAll(); reply->deleteLater(); QJsonParseError error; QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonString.toUtf8(), &error); if (jsonDoc.isNull()) { qWarning() << "Update manifest malformed:" << error.errorString(); return; } QJsonArray array = jsonDoc.array(); if (array.isEmpty()) { qWarning() << "Update manifest doesn't contain an array"; return; } for (QJsonValueRef updateEntry : array) { if (updateEntry.isObject()) { QJsonObject updateObj = updateEntry.toObject(); if (!updateObj.contains("platform") || !updateObj.contains("arch") || !updateObj.contains("version") || !updateObj.contains("browser_url")) { qWarning() << "Update manifest entry missing vital field"; continue; } if (!updateObj["platform"].isString() || !updateObj["arch"].isString() || !updateObj["version"].isString() || !updateObj["browser_url"].isString()) { qWarning() << "Update manifest entry has unexpected vital field type"; continue; } if (updateObj["arch"] == QSysInfo::buildCpuArchitecture() && updateObj["platform"] == QSysInfo::productType()) { qDebug() << "Found update manifest match for current platform"; QString latestVersion = updateObj["version"].toString(); qDebug() << "Latest version of Moonlight for this platform is:" << latestVersion; QVector<int> latestVersionQuad; parseStringToVersionQuad(latestVersion, latestVersionQuad); for (int i = 0;; i++) { int latestVer = 0; int currentVer = 0; // Treat missing decimal places as 0 if (i < latestVersionQuad.count()) { latestVer = latestVersionQuad[i]; } if (i < m_CurrentVersionQuad.count()) { currentVer = m_CurrentVersionQuad[i]; } if (i >= latestVersionQuad.count() && i >= m_CurrentVersionQuad.count()) { break; } if (currentVer < latestVer) { qDebug() << "Update available"; emit onUpdateAvailable(updateObj["browser_url"].toString()); return; } else if (currentVer > latestVer) { qDebug() << "Update manifest version lower than current version"; return; } } qDebug() << "Update manifest version equal to current version"; return; } } else { qWarning() << "Update manifest contained unrecognized entry:" << updateEntry.toString(); } } qWarning() << "No entry in update manifest found for current platform: " << QSysInfo::buildCpuArchitecture() << QSysInfo::productType(); } else { qWarning() << "Update checking failed with error: " << reply->error(); reply->deleteLater(); } }
// Save the current data in window to disc // Return 0 if OK // 1 if no new data to save // etc // int MainWindow::savefunc() { QJsonObject savedata; QFile savefile(QStringLiteral(SAVE_FILE)); QJsonDocument savedoc; if(newdata == 0) { QMessageBox::about(this, tr("Ix Trak"), tr("No new data -\nEnter an RXR or NHS number")); return 1; } // Identifiers if(ui->rxrEdit->text().length()) { savedata["RXR"] = ui->rxrEdit->text(); ui->rxrEdit->clear(); } if(ui->nhsEdit->text().length()) { savedata["NHS"] = ui->nhsEdit->text(); ui->nhsEdit->clear(); } // Contact type if(ui->newContact->isChecked()) { savedata["Contact"] = "Clinic - new"; uncheckall(GROUP_CONTACT); } else if(ui->fuContact->isChecked()) { savedata["Contact"] = "Clinic - follow up"; uncheckall(GROUP_CONTACT); } else if(ui->critcareContact->isChecked()) { savedata["Contact"] = "Critical care"; uncheckall(GROUP_CONTACT); } else if(ui->adviceContact->isChecked()) { savedata["Contact"] = "Advice"; uncheckall(GROUP_CONTACT); } else if(ui->wardContact->isChecked()) { savedata["Contact"] = "Ward"; uncheckall(GROUP_CONTACT); } else if(ui->preclinicContact->isChecked()) { savedata["Contact"] = "Pre clinic investigation"; uncheckall(GROUP_CONTACT); } else if(ui->radiologyContact->isChecked()) { savedata["Contact"] = "Radiology meeting"; uncheckall(GROUP_CONTACT); } // Diagnosis QJsonArray diagArray; QJsonObject diag; if(ui->asthmaDiag->isChecked()) { diag["Diagnosis"] = "Asthma"; ui->asthmaDiag->setChecked(false); diagArray.append(diag); } if(ui->copdDiag->isChecked()) { diag["Diagnosis"] = "COPD"; ui->copdDiag->setChecked(false); diagArray.append(diag); } if(ui->bronchiectasisDiag->isChecked()) { diag["Diagnosis"] = "Bronchiectasis"; ui->bronchiectasisDiag->setChecked(false); diagArray.append(diag); } if(ui->ildDiag->isChecked()) { diag["Diagnosis"] = "Interstitial lung disease"; ui->ildDiag->setChecked(false); diagArray.append(diag); } if(ui->osaDiag->isChecked()) { diag["Diagnosis"] = "Sleep disorder"; ui->osaDiag->setChecked(false); diagArray.append(diag); } if(ui->coughDiag->isChecked()) { diag["Diagnosis"] = "Cough"; ui->coughDiag->setChecked(false); diagArray.append(diag); } if(ui->hypoventDiag->isChecked()) { diag["Diagnosis"] = "Hypoventilation"; ui->hypoventDiag->setChecked(false); diagArray.append(diag); } if(ui->sarcoidDiag->isChecked()) { diag["Diagnosis"] = "Sarcoidosis"; ui->sarcoidDiag->setChecked(false); diagArray.append(diag); } if(ui->critcareDiag->isChecked()) { diag["Diagnosis"] = "Critical care follow up"; ui->critcareDiag->setChecked(false); diagArray.append(diag); } if(ui->lvfDiag->isChecked()) { diag["Diagnosis"] = "Heart failure"; ui->lvfDiag->setChecked(false); diagArray.append(diag); } if(ui->obDiag->isChecked()) { diag["Diagnosis"] = "Obliterative bronchiolitis"; ui->obDiag->setChecked(false); diagArray.append(diag); } if(ui->trachDiag->isChecked()) { diag["Diagnosis"] = "Tracheomalacia"; ui->trachDiag->setChecked(false); diagArray.append(diag); } if(ui->vteDiag->isChecked()) { diag["Diagnosis"] = "Thromboembolic disease"; ui->vteDiag->setChecked(false); diagArray.append(diag); } if(ui->funcDiag->isChecked()) { diag["Diagnosis"] = "Functional"; ui->funcDiag->setChecked(false); diagArray.append(diag); } if(ui->queryDiag->isChecked()) { diag["Diagnosis"] = "Uncertain"; ui->queryDiag->setChecked(false); diagArray.append(diag); } if(ui->otherDiag->isChecked()) { diag["Diagnosis"] = "Other"; ui->otherDiag->setChecked(false); diagArray.append(diag); } if(diagArray.isEmpty()) savedata["Diagnoses"] = "None"; else savedata["Diagnoses"] = diagArray; if(ui->diagEdit->toPlainText().length()) { savedata["Diagnosis notes"] = ui->diagEdit->toPlainText(); ui->diagEdit->clear(); } // Investigation QJsonArray ixArray; QJsonObject ix; if(ui->pftIx->isChecked()) { ix["Investigation"] = "Pulmonary function tests"; ui->pftIx->setChecked(false); ixArray.append(ix); } if(ui->walkIx->isChecked()) { ix["Investigation"] = "6 minute walk"; ui->walkIx->setChecked(false); ixArray.append(ix); } if(ui->sleepIx->isChecked()) { ix["Investigation"] = "Sleep study"; ui->sleepIx->setChecked(false); ixArray.append(ix); } if(ui->oasysIx->isChecked()) { ix["Investigation"] = "Oasys diary"; ui->oasysIx->setChecked(false); ixArray.append(ix); } if(ui->pefrIx->isChecked()) { ix["Investigation"] = "Peak flow diary"; ui->pefrIx->setChecked(false); ixArray.append(ix); } if(ui->ctIx->isChecked()) { ix["Investigation"] = "CT thorax"; ui->ctIx->setChecked(false); ixArray.append(ix); } if(ui->igeIx->isChecked()) { ix["Investigation"] = "IgE"; ui->igeIx->setChecked(false); ixArray.append(ix); } if(ui->funcabsIx->isChecked()) { ix["Investigation"] = "Functional antibodies"; ui->funcabsIx->setChecked(false); ixArray.append(ix); } if(ui->asperIx->isChecked()) { ix["Investigation"] = "Aspergillus IgG"; ui->asperIx->setChecked(false); ixArray.append(ix); } if(ui->serolIx->isChecked()) { ix["Investigation"] = "Immunology"; ui->serolIx->setChecked(false); ixArray.append(ix); } if(ui->neuroIx->isChecked()) { ix["Investigation"] = "Neurophysiology"; ui->neuroIx->setChecked(false); ixArray.append(ix); } if(ui->bronchIx->isChecked()) { ix["Investigation"] = "Bronchoscopy"; ui->bronchIx->setChecked(false); ixArray.append(ix); } if(ui->echoIx->isChecked()) { ix["Investigation"] = "Echocardiogram"; ui->echoIx->setChecked(false); ixArray.append(ix); } if(ui->ettIx->isChecked()) { ix["Investigation"] = "Exercise tolerance test"; ui->ettIx->setChecked(false); ixArray.append(ix); } if(ui->otherIx->isChecked()) { ix["Investigation"] = "Other investigation - see notes"; ui->otherIx->setChecked(false); ixArray.append(ix); } if(ixArray.isEmpty()) savedata["Investigations"] = "None"; else savedata["Investigations"] = ixArray; if(ui->ixEdit->toPlainText().length()) { savedata["Investigation notes"] = ui->ixEdit->toPlainText(); ui->ixEdit->clear(); } // Referral QJsonArray refArray; QJsonObject ref; if(ui->physioRef->isChecked()) { ref["Referral"] = "Physiotherapy"; ui->physioRef->setChecked(false); refArray.append(ref); } if(ui->rehabRef->isChecked()) { ref["Referral"] = "Pulmonary rehabilitation"; ui->rehabRef->setChecked(false); refArray.append(ref); } if(ui->nurseRef->isChecked()) { ref["Referral"] = "Respiratory nurse"; ui->nurseRef->setChecked(false); refArray.append(ref); } if(ui->saltRef->isChecked()) { ref["Referral"] = "Speech and language therapy"; ui->saltRef->setChecked(false); refArray.append(ref); } if(ui->heartRef->isChecked()) { ref["Referral"] = "Cardiology"; ui->heartRef->setChecked(false); refArray.append(ref); } if(ui->entRef->isChecked()) { ref["Referral"] = "ENT"; ui->entRef->setChecked(false); refArray.append(ref); } if(ui->localRef->isChecked()) { ref["Referral"] = "Other local chest physician"; ui->localRef->setChecked(false); refArray.append(ref); } if(ui->asthmaRef->isChecked()) { ref["Referral"] = "Tertiary airways clinic"; ui->asthmaRef->setChecked(false); refArray.append(ref); } if(ui->ildRef->isChecked()) { ref["Referral"] = "Tertiary ILD clinic"; ui->ildRef->setChecked(false); refArray.append(ref); } if(ui->ventRef->isChecked()) { ref["Referral"] = "Long term ventilation service"; ui->ventRef->setChecked(false); refArray.append(ref); } if(ui->otherRef->isChecked()) { ref["Referral"] = "Other"; ui->otherRef->setChecked(false); refArray.append(ref); } if(refArray.isEmpty()) savedata["Referrals"] = "None"; else savedata["Referrals"] = refArray; if(ui->refEdit->toPlainText().length()) { savedata["Referral notes"] = ui->refEdit->toPlainText(); ui->refEdit->clear(); } // Disposal if(ui->dischDisp->isChecked()) { savedata["Disposal"] = "Discharge"; uncheckall(GROUP_DISPOSAL); } else if(ui->fuDisp->isChecked()) { savedata["Disposal"] = "Follow up"; savedata["Follow up"] = ui->fuEdit->text(); uncheckall(GROUP_DISPOSAL); ui->fuEdit->clear(); } else if(ui->dnadischDisp->isChecked()) { savedata["Disposal"] = "DNA - discharge"; uncheckall(GROUP_DISPOSAL); } else if(ui->dnafuDisp->isChecked()) { savedata["Disposal"] = "DNA - follow up"; savedata["Follow up"] = ui->fuEdit->text(); uncheckall(GROUP_DISPOSAL); } else if(ui->otherDisp->isChecked()) { savedata["Disposal"] = "Other / pending"; uncheckall(GROUP_DISPOSAL); } else if(ui->letterDisp->isChecked()) { savedata["Disposal"] = "Write with results"; uncheckall(GROUP_DISPOSAL); } if(ui->admitDisp->isChecked()) { savedata["Admit"] = "True"; ui->admitDisp->setChecked(false); } // Misc data if(ui->notesEdit->toPlainText().length()) { savedata["Notes"] = ui->notesEdit->toPlainText(); ui->notesEdit->clear(); } if(ui->radmeetCheck->isChecked()) { savedata["For radiology meeting"] = "True"; ui->radmeetCheck->setChecked(false); } if(ui->juniorCheck->isChecked()) { savedata["Seen by junior"] = "True"; ui->juniorCheck->setChecked(false); } QDate date; QTime time; savedata["Date"] = date.currentDate().toString("dd:MM:yyyy"); savedata["Time"] = time.currentTime().toString("hh:mm"); QStringList l; l = calculated_values->keys(); foreach(QString s, l) { savedata[s] = calculated_values->value(s); calculated_values->remove(s); }
void Authorization::loadFromJson(const QJsonObject &json) { if (json.isEmpty()) { return; } Q_D(Authorization); QScopedPointer<const PPEnumsMap> em(new PPEnumsMap); d->setId(json.value(QStringLiteral("id")).toString()); const QJsonObject ao = json.value(QStringLiteral("amount")).toObject(); PaymentAmount *oldAo = amount(); if (!ao.isEmpty()) { if (oldAo) { oldAo->loadFromJson(ao); } else { setAmount(new PaymentAmount(ao, this)); } } else { setAmount(nullptr); delete oldAo; } d->setPaymentMode(em->paymentModeTypeTokenToEnum(json.value(QStringLiteral("payment_mode")).toString())); d->setState(em->stateTypeTokenToEnum(json.value(QStringLiteral("state")).toString())); d->setReasonCode(em->reasonCodeTokenToEnum(json.value(QStringLiteral("reason_code")).toString())); d->setProtectionEligibility(em->protectionEligibilityTokenToEnum(json.value(QStringLiteral("protection_eligibility")).toString())); const QString pets = json.value(QStringLiteral("protection_eligibility_type")).toString(); if (!pets.isEmpty()) { QList<Geltan::PP::PayPal::ProtectionEligibilityType> petList; const QStringList petsList = pets.split(QChar(',')); petList.reserve(petsList.size()); for (const QString &pet : petsList) { petList.append(em->protectionEligibilityTypeTokenToEnum(pet)); } d->setProtectionEligibilityType(petList); } else { d->setProtectionEligibilityType(QList<Geltan::PP::PayPal::ProtectionEligibilityType>()); } const QJsonObject fmfo = json.value(QStringLiteral("fmf_details")).toObject(); FMFDetails *oldFmf = fmfDetails(); if (!fmfo.isEmpty()) { if (oldFmf) { oldFmf->loadFromJson(fmfo); } else { d->setFmfDetails(new FMFDetails(fmfo, this)); } } else { d->setFmfDetails(nullptr); delete oldFmf; } d->setParentPayment(json.value(QStringLiteral("parent_payment")).toString()); const QString vu = json.value(QStringLiteral("valid_until")).toString(); if (!vu.isEmpty()) { d->setValidUntil(QDateTime::fromString(vu, Qt::ISODate)); } else { d->setValidUntil(QDateTime()); } const QString ct = json.value(QStringLiteral("create_time")).toString(); if (!ct.isEmpty()) { d->setCreateTime(QDateTime::fromString(ct, Qt::ISODate)); } else { d->setCreateTime(QDateTime()); } const QString ut = json.value(QStringLiteral("update_time")).toString(); if (!ut.isEmpty()) { d->setUpdateTime(QDateTime::fromString(ut, Qt::ISODate)); } else { d->setUpdateTime(QDateTime()); } d->setReferenceId(json.value(QStringLiteral("reference_id")).toString()); d->setReceiptId(json.value(QStringLiteral("receipt_id")).toString()); const QJsonArray la = json.value(QStringLiteral("links")).toArray(); d->clearLinks(); Q_EMIT linksChanged(links()); if (!la.isEmpty()) { QList<Link*> linksToAdd; QJsonArray::const_iterator i = la.constBegin(); while (i != la.constEnd()) { linksToAdd.append(new Link(i->toObject())); ++i; } d->setLinks(linksToAdd); } }
void SystemClass::write(QJsonObject &json) const{ SystemLang::write(json); QJsonArray tab; QJsonObject obj; int l; // Experience if (m_initialLevel != -1) { json[jsonInitialLevel] = m_initialLevel; } if (m_maxLevel != -1) { json[jsonMaxLevel] = m_maxLevel; } if (m_expBase != -1) { json[jsonExpBase] = m_expBase; } if (m_expInflation != -1) { json[jsonExpInflation] = m_expInflation; } // Exp table tab = QJsonArray(); QHash<int, int>::const_iterator i; for (i = m_expTable.begin(); i != m_expTable.end(); i++){ QJsonObject objHash; QJsonArray tabKey; int level = i.key(); int value = i.value(); objHash["k"] = level; objHash["v"] = value; tab.append(objHash); } if (!tab.isEmpty()) { json[jsonExpTable] = tab; } // Statistics tab = QJsonArray(); l = m_statisticsProgression->invisibleRootItem()->rowCount(); for (int i = 0; i < l - 1; i++){ obj = QJsonObject(); SystemStatisticProgression *statisticsProgression = reinterpret_cast< SystemStatisticProgression *>(m_statisticsProgression->item(i) ->data().value<quintptr>()); statisticsProgression->write(obj); tab.append(obj); } if (!tab.isEmpty()) { json[jsonStats] = tab; } // Skills tab = QJsonArray(); l = m_skills->invisibleRootItem()->rowCount(); for (int i = 0; i < l - 1; i++){ obj = QJsonObject(); SystemClassSkill *classSkill = reinterpret_cast<SystemClassSkill*>( m_skills->item(i)->data().value<quintptr>()); classSkill->write(obj); tab.append(obj); } if (!tab.isEmpty()) { json[jsonSkills] = tab; } }
void Configuration::setJSONFile(const QString &file) { m_file = QDir::toNativeSeparators(file); QFile JSONFile(m_file); if (!JSONFile.exists()) { qWarning() << "Warning: gui-config.json does not exist!"; m_index = -1; debugLog = false; autoStart = false; autoHide = false; translucent = true; return; } JSONFile.open(QIODevice::ReadOnly | QIODevice::Text); if (!JSONFile.isOpen()) { qWarning() << "Critical Error: cannot open gui-config.json!"; } if(!JSONFile.isReadable()) { qWarning() << "Critical Error: cannot read gui-config.json!"; } QJsonParseError pe; QJsonDocument JSONDoc = QJsonDocument::fromJson(JSONFile.readAll(), &pe); if (pe.error != QJsonParseError::NoError) { qWarning() << pe.errorString(); } if (JSONDoc.isEmpty()) { qWarning() << "Warning: JSON Document" << m_file << "is empty!"; } QJsonObject JSONObj = JSONDoc.object(); QJsonArray CONFArray = JSONObj["configs"].toArray(); profileList.clear();//clear list before if (CONFArray.isEmpty()) { qWarning() << "configs is empty. Please check your gui-config.json"; m_index = -1;//apparently m_index is invalid. } else { for (QJsonArray::iterator it = CONFArray.begin(); it != CONFArray.end(); ++it) { QJsonObject json = (*it).toObject(); SSProfile p; p.backend = json["backend"].toString(); p.type = json["type"].toString(); p.profileName = json["profile"].toString(); p.server = json["server"].toString(); p.password = json["password"].toString(); p.server_port = json["server_port"].toString(); p.local_addr = json["local_address"].toString(); p.local_port = json["local_port"].toString(); p.method = json["method"].toString().toUpper();//using Upper-case in GUI p.timeout = json["timeout"].toString(); if (tfo_available) { p.fast_open = json["fast_open"].toBool(); } profileList << p; } m_index = JSONObj["index"].toInt(); } debugLog = JSONObj["debug"].toBool(); autoHide = JSONObj["autoHide"].toBool(); autoStart = JSONObj["autoStart"].toBool(); translucent = JSONObj["translucent"].toBool(); JSONFile.close(); }
Load::Load(QObject *parent) : QObject(parent), d_ptr(new LoadPrivate(this)) { Q_D(Load); ins = this; setObjectName("Load"); auto avProcess = [this](QNetworkReply *reply){ Q_D(Load); Task &task = d->queue.head(); int sharp = task.code.indexOf(QRegularExpression("[#_]")); switch (task.state){ case None: { QString i = task.code.mid(2, sharp - 2); QString p = sharp == -1 ? QString() : task.code.mid(sharp + 1); QString url("http://www.%1/video/av%2/"); url = url.arg(Utils::customUrl(Utils::Bilibili)).arg(i); if (!p.isEmpty()){ url += QString("index_%1.html").arg(p); } forward(QNetworkRequest(url), Page); break; } case Page: { d->model->clear(); QString api, id, video(reply->readAll()); int part = video.indexOf("<select"); if (part != -1 && sharp == -1){ QRegularExpression r("(?<=>).*?(?=</option>)"); QStringRef list(&video, part, video.indexOf("</select>", part) - part); QRegularExpressionMatchIterator i = r.globalMatch(list); api = "http://www.%1/video/%2/index_%3.html"; api = api.arg(Utils::customUrl(Utils::Bilibili)); while (i.hasNext()){ int index = d->model->rowCount() + 1; QStandardItem *item = new QStandardItem; item->setData(QUrl(api.arg(task.code).arg(index)), UrlRole); item->setData((task.code + "#%1").arg(index), StrRole); item->setData(Page, NxtRole); item->setData(Utils::decodeXml(i.next().captured()), Qt::EditRole); d->model->appendRow(item); } } if (d->model->rowCount() > 0){ emit stateChanged(task.state = Part); } else{ QRegularExpression r = QRegularExpression("cid[=\":]*\\d+", QRegularExpression::CaseInsensitiveOption); QRegularExpressionMatchIterator i = r.globalMatch(video); while (i.hasNext()){ QString m = i.next().captured(); m = QRegularExpression("\\d+").match(m).captured(); if (id.isEmpty()){ id = m; } else if (id != m){ id.clear(); break; } } if (!id.isEmpty()){ api = "http://comment.%1/%2.xml"; api = api.arg(Utils::customUrl(Utils::Bilibili)); forward(QNetworkRequest(api.arg(id)), File); } else{ emit stateChanged(203); qDebug() << "Fail to load danmaku, try biliApi"; dequeue(); } } break; } case File: { dumpDanmaku(reply->readAll(), Utils::Bilibili, false); emit stateChanged(task.state = None); dequeue(); break; } } }; auto avRegular = [](QString &code){ code.remove(QRegularExpression("/index(?=_\\d+\\.html)")); QRegularExpression r("a(v(\\d+([#_])?(\\d+)?)?)?"); r.setPatternOptions(QRegularExpression::CaseInsensitiveOption); return getRegular(r)(code); }; d->pool.append({ avRegular, 0, avProcess }); auto bbProcess = [this, avProcess](QNetworkReply *reply) { Q_D(Load); Task &task = d->queue.head(); switch (task.state) { case None: { QString i = task.code.mid(2); QString u = "http://www.%1/bangumi/i/%2/"; u = u.arg(Utils::customUrl(Utils::Bilibili)).arg(i); forward(QNetworkRequest(u), Page); break; } case Page: { d->model->clear(); QString page(reply->readAll()); QStringList list = page.split("<li data-index"); if (list.size() < 2) { emit stateChanged(task.state = None); dequeue(); break; } list.removeFirst(); QListIterator<QString> iter(list); iter.toBack(); while (iter.hasPrevious()) { QRegularExpression r; const QString &i = iter.previous(); r.setPattern("(?<=href=\")[^\"]+"); QString c = r.match(i).captured(); fixCode(c); r.setPattern("(?<=<span>).+(?=</span>)"); QString t = Utils::decodeXml(r.match(i).captured()); QStandardItem *item = new QStandardItem; item->setData(c, StrRole); item->setData(None, NxtRole); item->setData(t, Qt::EditRole); d->model->appendRow(item); } emit stateChanged(task.state = Part); } } }; auto bbRegular = [](QString &code) { code.replace(QRegularExpression("bangumi/i/(?=\\d+)"), "bb"); QRegularExpression r("b(b(\\d+)?)?"); r.setPatternOptions(QRegularExpression::CaseInsensitiveOption); return getRegular(r)(code); }; d->pool.append({ bbRegular, 0, bbProcess }); auto acProcess = [this](QNetworkReply *reply){ Q_D(Load); Task &task = d->queue.head(); int sharp = task.code.indexOf(QRegularExpression("[#_]")); switch (task.state){ case None: { QString i = task.code.mid(2, sharp - 2); QString p = sharp == -1 ? QString() : task.code.mid(sharp + 1); QString url("http://www.%1/v/ac%2"); url = url.arg(Utils::customUrl(Utils::AcFun)).arg(i); if (!p.isEmpty()){ url += QString("_%1").arg(p); } forward(QNetworkRequest(url), Page); break;; } case Page: { d->model->clear(); QRegularExpressionMatchIterator match = QRegularExpression("data-vid.*?</a>").globalMatch(reply->readAll()); while (match.hasNext()){ QStandardItem *item = new QStandardItem; QString part = match.next().captured(); QRegularExpression r; r.setPattern("(?<=>)[^>]+?(?=</a>)"); item->setData(Utils::decodeXml(r.match(part).captured()), Qt::EditRole); r.setPattern("(?<=data-vid=\").+?(?=\")"); QString next("http://static.comment.%1/V2/%2?pageSize=1000&pageNo=1"); next = next.arg(Utils::customUrl(Utils::AcFun)).arg(r.match(part).captured()); item->setData(next, UrlRole); item->setData((task.code + "#%1").arg(d->model->rowCount() + 1), StrRole); item->setData(File, NxtRole); d->model->appendRow(item); } if (sharp == -1 && d->model->rowCount() >= 2){ emit stateChanged(task.state = Part); } else{ int i = sharp == -1 ? 0 : task.code.mid(sharp + 1).toInt() - 1; if (i >= 0 && i < d->model->rowCount()){ forward(QNetworkRequest(d->model->item(i)->data(UrlRole).toUrl()), File); } else{ emit stateChanged(203); dequeue(); } } break; } case File: { QByteArray data = reply->readAll(); if (data != "[[],[],[]]"){ QNetworkRequest &request = task.request; QUrl url = request.url(); int page = QUrlQuery(url).queryItemValue("pageNo").toInt(); url.setQuery(QString()); request.setUrl(url); dumpDanmaku(data, Utils::AcFun, false); QUrlQuery query; query.addQueryItem("pageSize", "1000"); query.addQueryItem("pageNo", QString::number(page + 1)); url.setQuery(query); request.setUrl(url); forward(request, File); } else{ emit stateChanged(task.state = None); dequeue(); } break; } } }; auto acRegular = getRegular(QRegularExpression("a(c(\\d+([#_])?(\\d+)?)?)?", QRegularExpression::CaseInsensitiveOption)); d->pool.append({ acRegular, 0, acProcess }); auto abProcess = [this, acProcess](QNetworkReply *reply){ Q_D(Load); Task &task = d->queue.head(); int sharp = task.code.indexOf(QRegularExpression("[#_]")); switch (task.state){ case None: { QString url("http://www.%1/bangumi/video/page?bangumiId=%2&pageSize=30&pageNo=%3&order=2"); url = url.arg(Utils::customUrl(Utils::AcFun)).arg(task.code.mid(2, sharp - 2)); url = url.arg(sharp == -1 ? 1 : (task.code.mid(sharp + 1).toInt() - 1) / 30 + 1); forward(QNetworkRequest(url), Page); break; } case Page: { if (sharp != -1){ QJsonObject data = QJsonDocument::fromJson(reply->readAll()).object()["data"].toObject(); int i = task.code.mid(sharp + 1).toInt(); if (i > 0){ i = (i - 1) % 30; } else{ i = data["totalCount"].toInt(); if (i > 30){ task.code = task.code.left(sharp) + QString("#%1").arg(i); task.state = None; task.processer->process(nullptr); break; } } QJsonArray list = data["list"].toArray(); if (i < 0 || i >= list.size()){ emit stateChanged(203); dequeue(); break; } QString head("http://static.comment.%1/V2/%2?pageSize=1000&pageNo=1"); head = head.arg(Utils::customUrl(Utils::AcFun)); head = head.arg(list[i].toObject()["danmakuId"].toString()); forward(QNetworkRequest(head), File); break; } else{ d->model->clear(); } } case Part: { QJsonObject info = QJsonDocument::fromJson(reply->readAll()).object(); if (!info["success"].toBool() && d->model->rowCount() == 0){ emit stateChanged(info["status"].toInt()); dequeue(); } QJsonObject data = info["data"].toObject(); for (const QJsonValue &value : data["list"].toArray()){ QStandardItem *item = new QStandardItem; QJsonObject data = value.toObject(); item->setData(data["title"].toString(), Qt::EditRole); QString head("http://static.comment.%1/V2/%2?pageSize=1000&pageNo=1"); head = head.arg(Utils::customUrl(Utils::AcFun)).arg(data["danmakuId"].toString()); item->setData(head, UrlRole); item->setData((task.code + "#%1").arg(d->model->rowCount() + 1), StrRole); item->setData(File, NxtRole); d->model->appendRow(item); } if (task.state != Part){ emit stateChanged(task.state = Part); } if (data["pageNo"].toInt() < data["totalPage"].toInt()){ QUrl url = reply->request().url(); auto arg = QUrlQuery(url).queryItems(); for (auto &p : arg){ if (p.first == "pageNo"){ p.second = QString::number(p.second.toInt() + 1); break; } } QUrlQuery query; query.setQueryItems(arg); url.setQuery(query); d->remain.insert(d->manager.get(QNetworkRequest(url))); } break; } case File: { acProcess(reply); break; } } }; auto abRegular = getRegular(QRegularExpression("a(b(\\d+([#_])?(\\d+)?)?)?", QRegularExpression::CaseInsensitiveOption)); d->pool.append({ abRegular, 0, abProcess }); auto ccProcess = [this](QNetworkReply *reply){ Q_D(Load); Task &task = d->queue.head(); int sharp = task.code.indexOf(QRegularExpression("[#_]")); switch (task.state){ case None: { QString i = task.code.mid(2, sharp - 2); QString p = sharp == -1 ? QString() : task.code.mid(sharp + 1); QString url("http://www.%1/play/h%2/"); url = url.arg(Utils::customUrl(Utils::TuCao)).arg(i); if (!p.isEmpty()){ url += QString("#%1").arg(p); } forward(QNetworkRequest(url), Page); break; } case Page: { QString page = reply->readAll(); d->model->clear(); QRegularExpressionMatch m; QRegularExpression r("(?<=<li>)[^<]*(?=</li>)"); m = r.match(page, page.indexOf("<ul id=\"player_code\"")); QStringList list = m.captured().split("**"); m = r.match(page, m.capturedEnd()); QString code = m.captured(); for (const QString &iter : list){ QStandardItem *item = new QStandardItem; item->setData(iter.mid(iter.indexOf('|') + 1), Qt::EditRole); QString api("http://www.%1/index.php?m=mukio&c=index&a=init&playerID=%2"); api = api.arg(Utils::customUrl(Utils::TuCao)).arg((code + "-%1").arg(d->model->rowCount())); item->setData(api, UrlRole); item->setData((task.code + "#%1").arg(d->model->rowCount() + 1), StrRole); item->setData(File, NxtRole); d->model->appendRow(item); } if (sharp == -1 && d->model->rowCount() >= 2){ emit stateChanged(task.state = Part); } else{ int i = sharp == -1 ? 0 : task.code.mid(sharp + 1).toInt() - 1; if (i >= 0 && i < d->model->rowCount()){ forward(QNetworkRequest(d->model->item(i)->data(UrlRole).toUrl()), File); } else{ emit stateChanged(203); dequeue(); } } break; } case File: { dumpDanmaku(reply->readAll(), Utils::TuCao, false); emit stateChanged(task.state = None); dequeue(); break; } } }; auto ccRegular = [](QString &code){ code.replace(QRegularExpression("[Hh](?=\\d)"), "cc"); QRegularExpression r("c(c(\\d+([#_])?(\\d+)?)?)?"); r.setPatternOptions(QRegularExpression::CaseInsensitiveOption); return getRegular(r)(code); }; d->pool.append({ ccRegular, 0, ccProcess }); d->pool.append(Proc()); Proc *directProc = &d->pool.last(); directProc->process = [this](QNetworkReply *reply){ Q_D(Load); Task &task = d->queue.head(); switch (task.state){ case None: { QUrl url = QUrl::fromUserInput(task.code); task.request.setUrl(url); task.state = File; forward(); break; } case File: { Record load; QUrl url = reply->url(); QByteArray data(reply->readAll()); load.source = url.url(); load.access = url.isLocalFile() ? url.toLocalFile() : load.source; load.string = QFileInfo(task.code).fileName(); load.delay = task.delay; QString head = Utils::decodeTxt(data.left(512)); if (head.startsWith("[Script Info]")){ load.danmaku = Parse::parseComment(data, Utils::ASS); } else if (!head.startsWith("<?xml")){ load.danmaku = Parse::parseComment(data, Utils::AcFun); } else if (head.indexOf("<packet>") != -1){ load.danmaku = Parse::parseComment(data, Utils::Niconico); } else if (head.indexOf("<i>") != -1){ load.danmaku = Parse::parseComment(data, Utils::Bilibili); QString i = QRegularExpression("(?<=<chatid>)\\d+(?=</chatid>)").match(head).captured(); if (!i.isEmpty()){ load.source = "http://comment.%1/%2.xml"; load.source = load.source.arg(Utils::customUrl(Utils::Bilibili)).arg(i); } } else if (head.indexOf("<c>") != -1){ load.danmaku = Parse::parseComment(data, Utils::AcfunLocalizer); } if (load.delay != 0){ for (Comment &c : load.danmaku){ c.time += load.delay; } } Danmaku::instance()->appendToPool(&load); emit stateChanged(task.state = None); dequeue(); break; } } }; directProc->priority = -100; directProc->regular = [this, directProc](QString &code){ if (code.startsWith("full?") || code.startsWith("hist?")){ code.clear(); return false; } QUrl u = QUrl::fromUserInput(code); if (!u.host().isEmpty() && !u.path().isEmpty()){ return true; } if (QFileInfo(code).exists()){ return true; } code.clear(); return false; }; auto fullBiProcess = [this](QNetworkReply *reply){ Q_D(Load); Task &task = d->queue.head(); switch (task.state) { case None: { emit progressChanged(0); QString api("http://comment.%1/rolldate,%2"); api = api.arg(Utils::customUrl(Utils::Bilibili)); task.code = QUrlQuery(task.code.mid(5)).queryItemValue("source"); forward(QNetworkRequest(api.arg(QFileInfo(task.code).baseName())), Page); break; } case Page: { QByteArray data = reply->readAll(); QJsonArray date = QJsonDocument::fromJson(data).array(); if (date.isEmpty()) { emit stateChanged(203); dequeue(); break; } QJsonObject head = date.first().toObject(); QString url("http://comment.%1/dmroll,%2,%3"); url = url.arg(Utils::customUrl(Utils::Bilibili)); url = url.arg(head["timestamp"].toVariant().toInt()); url = url.arg(QFileInfo(task.code).baseName()); QNetworkRequest request(url); request.setAttribute(QNetworkRequest::User, data); forward(request, Code); break; } case Code: { QByteArray data = task.request.attribute(QNetworkRequest::User).toByteArray(); QJsonArray date = QJsonDocument::fromJson(data).array(); QMap<int, int> count; for (auto iter : date) { QJsonObject item = iter.toObject(); count[item["timestamp"].toVariant().toInt()] += item["new"].toVariant().toInt(); } data = reply->readAll(); if (count.size() >= 2) { int max = QRegularExpression("(?<=\\<max_count\\>).+(?=\\</max_count\\>)").match(data).captured().toInt(); int now = 0; auto getHistory = [d, &count, &task](int date) { QString url("http://comment.%1/dmroll,%2,%3"); url = url.arg(Utils::customUrl(Utils::Bilibili)); url = url.arg(date); url = url.arg(QFileInfo(task.code).baseName()); return d->manager.get(QNetworkRequest(url)); }; for (auto iter = count.begin() + 1;; ++iter) { now += iter.value(); if (iter + 1 == count.end()) { d->remain += getHistory(iter.key()); break; } else if (now + (iter + 1).value() > max) { d->remain += getHistory(iter.key()); now = 0; } } auto pool = QSharedPointer<QVector<Parse::ResultDelegate>>::create(); pool->append(Parse::parseComment(data, Utils::Bilibili)); double total = d->remain.size() + 2; for (QNetworkReply *iter : d->remain) { connect(iter, &QNetworkReply::finished, [=, &task]() { QByteArray data = iter->readAll(); pool->append(Parse::parseComment(data, Utils::Bilibili)); switch (iter->error()) { case QNetworkReply::NoError: emit progressChanged((total - d->remain.size()) / total); case QNetworkReply::OperationCanceledError: if (d->remain.isEmpty() && !pool->empty()) { Record load; load.full = true; for (auto &iter : *pool) { load.danmaku.append(iter); } load.source = task.code; Danmaku::instance()->appendToPool(&load); emit stateChanged(task.state = None); dequeue(); } default: break; } }); } emit progressChanged(2 / total); emit stateChanged(task.state = File); break; } else { emit progressChanged(1); dumpDanmaku(data, Utils::Bilibili, true); emit stateChanged(task.state = None); dequeue(); break; } } } }; auto fullBiRegular = QRegularExpression("^full\\?source=http://comment\\.bilibili\\.com/\\d+\\.xml$"); fullBiRegular.setPatternOptions(QRegularExpression::CaseInsensitiveOption); d->pool.append({ getRegular(fullBiRegular), 100, fullBiProcess }); auto histBiProcess = [this](QNetworkReply *reply){ Q_D(Load); Task &task = d->queue.head(); switch (task.state){ case None: { QUrlQuery query(task.code.mid(5)); task.code = query.queryItemValue("source"); QString cid = QFileInfo(task.code).baseName(); QString dat = query.queryItemValue("date"); QString url; QNetworkRequest request; if (dat != "0" && dat.toUInt() != QDateTime(QDate::currentDate()).toTime_t()){ url = QString("http://comment.%1/dmroll,%2,%3"); url = url.arg(Utils::customUrl(Utils::Bilibili)); url = url.arg(dat).arg(cid); int limit = QDateTime(QDateTime::fromTime_t(dat.toInt()).date().addDays(1)).toTime_t(); request.setAttribute(QNetworkRequest::User, limit); } else{ url = QString("http://comment.%1/%2.xml").arg(Utils::customUrl(Utils::Bilibili)); url = url.arg(cid); } request.setUrl(url); forward(request, File); break; } case File: { Record load; load.danmaku = Parse::parseComment(reply->readAll(), Utils::Bilibili); load.source = task.code; for (Record &iter : Danmaku::instance()->getPool()){ if (iter.source == load.source){ iter.full = false; iter.danmaku.clear(); iter.limit = 1; break; } } load.limit = task.request.attribute(QNetworkRequest::User).toInt(); Danmaku::instance()->appendToPool(&load); emit stateChanged(task.state = None); dequeue(); break; } } }; auto histBiRegular = QRegularExpression("^hist\\?source=http://comment\\.bilibili\\.com/\\d+\\.xml&date=\\d+$"); histBiRegular.setPatternOptions(QRegularExpression::CaseInsensitiveOption); d->pool.append({ getRegular(histBiRegular), 100, histBiProcess }); connect(this, &Load::stateChanged, [this](int code){ switch (code){ case None: case Page: case Part: case Code: case File: break; default: { Q_D(Load); if (!d->tryNext()){ emit errorOccured(code); } break; } } }); }
bool DomainServerSettingsManager::handleHTTPRequest(HTTPConnection* connection, const QUrl &url) { if (connection->requestOperation() == QNetworkAccessManager::PostOperation && url.path() == "/settings.json") { // this is a POST operation to change one or more settings QJsonDocument postedDocument = QJsonDocument::fromJson(connection->requestContent()); QJsonObject postedObject = postedDocument.object(); // we recurse one level deep below each group for the appropriate setting recurseJSONObjectAndOverwriteSettings(postedObject, _settingsMap, _descriptionObject); // store whatever the current _settingsMap is to file persistToFile(); // return success to the caller QString jsonSuccess = "{\"status\": \"success\"}"; connection->respond(HTTPConnection::StatusCode200, jsonSuccess.toUtf8(), "application/json"); return true; } else if (connection->requestOperation() == QNetworkAccessManager::GetOperation && url.path() == "/settings.json") { // this is a GET operation for our settings // check if there is a query parameter for settings affecting a particular type of assignment const QString SETTINGS_TYPE_QUERY_KEY = "type"; QUrlQuery settingsQuery(url); QString typeValue = settingsQuery.queryItemValue(SETTINGS_TYPE_QUERY_KEY); QJsonObject responseObject; if (typeValue.isEmpty()) { // combine the description object and our current settings map responseObject["descriptions"] = _descriptionObject; responseObject["values"] = QJsonDocument::fromVariant(_settingsMap).object(); } else { // convert the string type value to a QJsonValue QJsonValue queryType = QJsonValue(typeValue.toInt()); const QString AFFECTED_TYPES_JSON_KEY = "assignment-types"; // enumerate the groups in the description object to find which settings to pass foreach(const QString& group, _descriptionObject.keys()) { QJsonObject groupObject = _descriptionObject[group].toObject(); QJsonObject groupSettingsObject = groupObject[DESCRIPTION_SETTINGS_KEY].toObject(); QJsonObject groupResponseObject; foreach(const QString& settingKey, groupSettingsObject.keys()) { QJsonObject settingObject = groupSettingsObject[settingKey].toObject(); QJsonArray affectedTypesArray = settingObject[AFFECTED_TYPES_JSON_KEY].toArray(); if (affectedTypesArray.isEmpty()) { affectedTypesArray = groupObject[AFFECTED_TYPES_JSON_KEY].toArray(); } if (affectedTypesArray.contains(queryType)) { // this is a setting we should include in the responseObject // we need to check if the settings map has a value for this setting QVariant variantValue; QVariant settingsMapGroupValue = _settingsMap.value(group); if (!settingsMapGroupValue.isNull()) { variantValue = settingsMapGroupValue.toMap().value(settingKey); } if (variantValue.isNull()) { // no value for this setting, pass the default groupResponseObject[settingKey] = settingObject[SETTING_DEFAULT_KEY]; } else { groupResponseObject[settingKey] = QJsonValue::fromVariant(variantValue); } } } if (!groupResponseObject.isEmpty()) { // set this group's object to the constructed object responseObject[group] = groupResponseObject; } } } connection->respond(HTTPConnection::StatusCode200, QJsonDocument(responseObject).toJson(), "application/json"); return true; } return false; }
void MapIndicator::update_ind(Gamestate* actual) { QJsonArray mapObj = actual->mapObj.array(); int player = -1; bool playerTank = 0; float mapW = actual->mapInfo.object()["map_max"].toArray()[0].toDouble() - actual->mapInfo.object()["map_min"].toArray()[0].toDouble(); float mapH = actual->mapInfo.object()["map_max"].toArray()[1].toDouble() - actual->mapInfo.object()["map_min"].toArray()[1].toDouble(); for (int i =0; i<mapObj.size(); ++i) { if(mapObj[i].toObject()["icon"].toString() == QString("Player")) { player = i; if(mapObj[i].toObject()["type"].toString()==QString("ground_model")) { playerTank = 1; } break; } } if(mapObj.isEmpty() or player==-1 or (!playerTank and overlay)) { mapValid = false; this->hide(); } else if ((!overlay) or playerTank) { if(mapValid==false) { if(this->overlay) { QPixmap n(text.size()); n.fill(QColor(0,0,0,0)); text.setPixmap(n); cout << "Setting empty pixmap"<<endl; } else { QUrl url(dynamic_cast<InstrumentPanel*>(this->parent())->settings["url"].toString()+QString("/map.img")); QNetworkRequest request(url); cout << "Downloading image " << request.url().toString().toStdString()<<endl; manager->get(request); } } //cout << "Painting map Object!"<<endl; double playerX = mapObj[player].toObject()["x"].toDouble(); double playerY = mapObj[player].toObject()["y"].toDouble(); qDeleteAll(mapObjects->findChildren<QLabel*>()); for (int i =0; i<mapObj.size(); ++i) { QLabel* obj; ; double x = mapObj[i].toObject()["x"].toDouble(); double y = mapObj[i].toObject()["y"].toDouble(); int mapX = x*this->size().width(); int mapY = y*this->size().height(); int dist = sqrt((x-playerX)*mapW*(x-playerX)*mapW+(y-playerY)*mapH*(y-playerY)*mapW); //cout << dist<<endl; QWidget* obscure = mapObjects->childAt(mapX, mapY); int obscureX = text.fontMetrics().size(Qt::TextSingleLine, "00").width(); int obscureY = text.fontMetrics().size(Qt::TextSingleLine, "00").height(); QWidget* obscure2 = mapObjects->childAt(mapX+obscureX, mapY+obscureY); QWidget* obscure3 = mapObjects->childAt(mapX-obscureX, mapY-obscureY); QWidget* obscure4 = mapObjects->childAt(mapX-obscureX, mapY+obscureY); QWidget* obscure5 = mapObjects->childAt(mapX+obscureX, mapY-obscureY); if(!(obscure or obscure2 or obscure3 or obscure4 or obscure5)) { obj = new QLabel(mapObjects); obj->setText( QString::number(dist)); if(this->size().width()>400 and params["scaling_text"].toBool()) { QFont ff = obj->font(); ff.setPixelSize(this->size().width()/26); obj->setFont(ff); } obj->move(mapX, mapY); obj->show(); } if(!overlay) { obj = new QLabel(mapObjects); if( mapObj[i].toObject()["icon_bg"].toString().indexOf("Target")>-1) { obj->setStyleSheet(QString("QLabel { color: gold}")); } else { obj->setStyleSheet(QString("QLabel { color: ") + mapObj[i].toObject()["color"].toString()+QString("}")); } if(mapObj[i].toObject()["type"].toString() == QString("aircraft")) { obj->setText("^"); } else if(mapObj[i].toObject()["type"].toString() == QString("ground_model")) { obj->setText("="); } if(mapObj[i].toObject()["icon"].toString() == QString("Player")) { obj->setText("o"); obj->setStyleSheet(QString("QLabel { font: bold; color: green}")); } if(this->size().width()>400 and params["scaling_text"].toBool()) { QFont ff = obj->font(); ff.setPixelSize(this->size().width()/26); obj->setFont(ff); } //obj->setStyleSheet(QString("QLabel { color: ") + mapObj[i].toObject()["color"].toString()+QString("}")); obj->move(mapX-obj->fontMetrics().size(Qt::TextSingleLine, "0").height()/2, mapY-obj->fontMetrics().size(Qt::TextSingleLine, "0").height()/2); obj->show(); } /*if( mapObj[i].toObject()["icon_bg"].toString().indexOf("Target")>-1) { obj = new QLabel(mapObjects); obj->setText( QString("Target distance: ")+QString::number(dist)); // obj->setStyleSheet(QString("QLabel { color: ") + mapObj[i].toObject()["color"].toString()+QString("}")); obj->move(0,0); obj->show(); obj->setStyleSheet(QString("QLabel { font: bold 15px; color: red}")); obj->resize(obj->sizeHint()); }*/ } mapObjects->raise(); this->show(); mapValid = true; } }