void QgsAmsLegendFetcher::handleFinished() { // Parse result QJsonParseError err; QJsonDocument doc = QJsonDocument::fromJson( mQueryReply, &err ); if ( doc.isNull() ) { emit error( QStringLiteral( "Parsing error:" ).arg( err.errorString() ) ); } QVariantMap queryResults = doc.object().toVariantMap(); QgsDataSourceUri dataSource( mProvider->dataSourceUri() ); QVector< QPair<QString, QImage> > legendEntries; foreach ( const QVariant &result, queryResults["layers"].toList() ) { QVariantMap queryResultMap = result.toMap(); QString layerId = queryResultMap[QStringLiteral( "layerId" )].toString(); if ( layerId != dataSource.param( QStringLiteral( "layer" ) ) && !mProvider->subLayers().contains( layerId ) ) { continue; } QVariantList legendSymbols = queryResultMap[QStringLiteral( "legend" )].toList(); foreach ( const QVariant &legendEntry, legendSymbols ) { QVariantMap legendEntryMap = legendEntry.toMap(); QString label = legendEntryMap[QStringLiteral( "label" )].toString(); if ( label.isEmpty() && legendSymbols.size() == 1 ) label = queryResultMap[QStringLiteral( "layerName" )].toString(); QByteArray imageData = QByteArray::fromBase64( legendEntryMap[QStringLiteral( "imageData" )].toByteArray() ); legendEntries.append( qMakePair( label, QImage::fromData( imageData ) ) ); } }
#include "tcomboboxmodelrecord.h" TComboBoxModelRecord::TComboBoxModelRecord(QWidget *parent) : QComboBox(parent) { currentModelColumn=0; editable_=false; connect( this,SIGNAL(currentIndexChanged(int)),SLOT(currentIndexChangedSlot(int)) ); } ///*! Devuelve el valor de la llave primaria del elemento seleccionado en el ComboBox //\return Valor de la llave primaria. //*/ QVariantList TComboBoxModelRecord::currentPKValues() { if ( count() == 0 ) return QVariantList(); ModelBase* m=(ModelBase*)originalModel; QVariantList values; if ( currentIndex() < 0 ) return QVariantList(); if ( currentIndex() == 0 && editable_ ) return QVariantList(); RecordBase *record = m->getRecord( editable_ ? lstFiltrados.at(currentIndex()) : currentIndex() ); foreach ( QString pk, record->property(QString(m->getTableName()+"PKAttributesList").toLocal8Bit()).toStringList() ) values.append( record->property( pk.toLocal8Bit() ) ); return values; } ///*! Selecciona el elemento en el ComboBox cuyo registro (Record) tenga la llave primaria \a id //\param id Valor de la llave primaria a seleccionar. //*/ void TComboBoxModelRecord::setCurrentPKValues(QVariantList lst) { if ( count() == 0 ) return; ModelBase* m=(ModelBase*)model(); if ( m->getRecord(0)->property(QString(m->getTableName()+"PKAttributesList").toLocal8Bit()).toStringList().size()!= lst.size()) return; for ( int f=0; f<m->modelSize(); f++ ) { RecordBase *record=m->getRecord(f); bool error=false; QStringList lstpk=record->property(QString(m->getTableName()+"PKAttributesList").toLocal8Bit()).toStringList(); for ( int c=0; c<lstpk.size(); c++) { QString pk=lstpk.at(c); if ( record->property(pk.toLocal8Bit()) != lst.at(c)) { error=true; break; } } if ( error ) continue; setCurrentIndex(f); break; } }
QUrl Media::thumbnail() const { if (m_thumbnail.isEmpty()) { //photo QVariantMap& media = m_message->media(); QVariantMap sz; if (m_message->mediaType() == tgl_message_media_photo) { QVariantList sizes = media["sizes"].toList(); for (int i = 0; i < sizes.size(); i++) { sz = sizes[i].toMap(); if (sz["type"].toString() == "s") break; } } else { sz = media["thumb"].toMap(); } tgl_photo_size photoSize; photoSize.w = sz["width"].toInt(); photoSize.w = sz["height"].toInt(); photoSize.size = sz["size"].toInt(); photoSize.loc.volume = sz["volume"].toLongLong(); photoSize.loc.dc = sz["dc"].toInt(); photoSize.loc.local_id = sz["local_id"].toInt(); photoSize.loc.secret = sz["secret"].toLongLong(); tgl_do_load_photo_size(gTLS, &photoSize, _loadThumbnailCallback, (void*)this); } return m_thumbnail; }
bool HubAccount::updateHubCategory(qint64 categoryId, qint64 parentCategoryId, QString name) { qint64 retVal = 0; qDebug() << "update hub category: " << categoryId << " - " << parentCategoryId << " - " << name; QVariantList categories = this->categories(); for(int index = 0; index < categories.size(); index++) { QVariant category = categories.at(index); QVariantMap categoryMap = category.toMap(); qint64 cacheCategoryId = categoryMap["categoryId"].toLongLong(); if (categoryId == cacheCategoryId) { categoryMap["name"] = name; categoryMap["parentCategoryId"] = parentCategoryId; retVal = _udsUtil->updateCategory(_accountId, categoryId, name, parentCategoryId); if (retVal <= 0) { qDebug() << "HubAccount::updateHubCategory: updateCategory failed for category: " << name << ", account: "<< _accountId << ", retVal: "<< retVal << "\n"; } else { _hubCache->setCategories(categories); } break; } } return (retVal > 0); }
bool QChemJobInfo::fromQVariantList(QVariantList const& list) { bool ok = (list.size() == 8) && list[0].canConvert<QString>() && list[1].canConvert<QString>() && list[2].canConvert<QString>() && list[3].canConvert<QString>() && list[4].canConvert<QString>() && list[5].canConvert<int>() && list[5].canConvert<int>() && list[7].canConvert<bool>(); if (ok) { m_data.insert(BaseName, list[0].toString()); m_data.insert(ServerName, list[1].toString()); m_data.insert(LocalWorkingDirectory, list[2].toString()); m_data.insert(RemoteWorkingDirectory,list[3].toString()); m_data.insert(InputString, list[4].toString()); m_charge = list[5].toInt(); m_multiplicity = list[6].toInt(); m_localFilesExist = list[7].toBool(); } return ok; }
void writeDesign(QXmlStreamWriter &stream, const QVariantList &v) { stream.writeStartElement("design"); stream.writeAttribute("name", v[1].toString()); for (int i = 2; i < v.size(); i++) { QVariant v2 = v[i]; if (v2.type() == QVariant::List) { QVariantList l2 = v2.toList(); if (l2.size() > 0) { if (l2.first() == "cellRef") { writeCellRef(stream, l2); } else { qWarning("Unexpected tag '%s' in 'design' tag", qPrintable(l2.first().toString())); } } } } stream.writeEndElement(); }
void writeNetlistInterface(QXmlStreamWriter &stream, const QVariantList &v) { stream.writeStartElement("interface"); for (int i = 1; i < v.size(); i++) { QVariant v2 = v[i]; if (v2.type() == QVariant::List) { QVariantList l2 = v2.toList(); if (l2.size() > 0) { QString tag = l2.first().toString(); if (tag == "port") { writePort(stream, l2); } else { qWarning("Unexpected tag '%s' in 'interface' tag", qPrintable(tag)); } } } } stream.writeEndElement(); }
// Learning algorithm dataset integeration void Dataset::get_training_dimensions(unsigned int *num_data, unsigned int *num_input, unsigned int *num_output) { *num_data = vdata.size(); *num_input = schema.size()-1; *num_output = 1; // Leave one out if (leave_item != DONT_LEAVE_ANY) (*num_data)--; // Filter Meta Columns for(int i=0; i<schema.size(); i++) { if (schema[i].value("Type").toInt() == COL_TYPE_META) { // cerr << "Removing column " << schema[i].value("Name").toString().toStdString() << endl; (*num_input)--; } if (schema[i].value("Type").toInt() == COL_TYPE_CAT) { QVariantList values = schema[i].value("Values").toList(); // cerr << "Feeding " << schema[i].value("Name").toString().toStdString() << " - " << values.size() << " combinations." << endl; (*num_input) += values.size() - 1; } } }
void Dataset::get_scale_flags(int should_scale[]) { unsigned input_index = 0; for(int i=0; i<schema.size() - 1; i++) { switch(schema[i].value("Type").toInt()) { case COL_TYPE_META: continue; case COL_TYPE_CAT: { QVariantList values = schema[i].value("Values").toList(); for(int j=0; j<values.size(); j++) { should_scale[input_index] = 0; input_index++; } break; } case COL_TYPE_NUM: should_scale[input_index] = 1; input_index++; break; default: qFatal("Unhandled variable type"); } } }
void OpenSearchEngine::suggestionsObtained() { const QByteArray response = m_suggestionsReply->readAll(); m_suggestionsReply->close(); m_suggestionsReply->deleteLater(); m_suggestionsReply = 0; QJsonParseError err; QJsonDocument json = QJsonDocument::fromJson(response, &err); const QVariant res = json.toVariant(); if (err.error != QJsonParseError::NoError || res.type() != QVariant::List) return; const QVariantList list = res.toList(); if (list.size() < 2) return; QStringList out; foreach (const QVariant &v, list.at(1).toList()) out.append(v.toString()); emit suggestions(out); }
void MainWindow::getGroups() { qDebug() << " GET GROUPS FROM QML "; QUrl current("https://api.vk.com/method/groups.get"); QUrlQuery query; query.addQueryItem("v","5.2"); query.addQueryItem("access_token",Token); query.addQueryItem("user_id","138685584"); query.addQueryItem("extended","1"); query.addQueryItem("count","1000"); query.addQueryItem("fields","members_count"); current.setQuery(query); QByteArray answer = GET(current); QVariantList List = JSON::parse(answer).toMap().value("response").toMap().value("items").toList(); // parse to list of objects Audio /*GET Audio QString du; for (int i=0; i<List.size(); i++) { QVariantMap current = List[i].toMap(); du = current.value("url").toString(); qDebug() << current.value("url").toString(); qDebug() << current.value("id").toString(); qDebug() << current.value("title").toString(); } */ QQmlContext* context = rootContext(); groupModel = new GroupModel(); for (int i=0; i<List.size(); i++) { QVariantMap current = List[i].toMap(); groupModel->addGroup(Group(current.value("name").toString(),current.value("type").toString(),current.value("photo_50").toString(),current.value("members_count").toString(),current.value("id").toString())); /*QVariantList attachments = current.value("attachments").toList(); for (int k=0; k<attachments.size(); k++) { QVariantMap cur = attachments[k].toMap(); if (cur.value("type").toString() == "audio") { qDebug() << "Audio"; qDebug() << cur.value("audio").toMap().value("url").toString(); links.append(cur.value("audio").toMap().value("url").toString()); } }*/ } context->setContextProperty("groupModel", groupModel); //if success loaded data if (1){ wallObj = rootObject(); QMetaObject::invokeMethod((QObject*)wallObj, "showGroupList"); } }
bool GetLocationsReply::parse(const QByteArray& data) { JsonDataAccess jsonObject; QVariant node = jsonObject.loadFromBuffer(data); if (jsonObject.hasError()) { qWarning() << "error converting JSON data: " << jsonObject.error().errorMessage(); } else { qDebug() << "before parse: " << QString(data); QVariantMap map = node.value<QVariantMap>(); if (map["status"].toString() == "OK") { m_status = true; QVariantList friendList = map["friends"].value<QVariantList>(); for (int i = 0; i < friendList.size(); i++) { QString friendStr = friendList[i].toString(); QStringList fields = friendStr.split(","); // if incorrect number of fields, stop parsing if (fields.size() != 4) return false; QString ppId = fields.at(0); double x = fields.at(1).toDouble(); double y = fields.at(2).toDouble(); int visibility = fields.at(3).toInt(); m_friends.append(User(ppId, x, y, visibility)); } return true; } } return false; }
QgsAmsProvider::QgsAmsProvider( const QString &uri, const ProviderOptions &options ) : QgsRasterDataProvider( uri, options ) { mLegendFetcher = new QgsAmsLegendFetcher( this ); QgsDataSourceUri dataSource( dataSourceUri() ); const QString authcfg = dataSource.authConfigId(); mServiceInfo = QgsArcGisRestUtils::getServiceInfo( dataSource.param( QStringLiteral( "url" ) ), authcfg, mErrorTitle, mError ); mLayerInfo = QgsArcGisRestUtils::getLayerInfo( dataSource.param( QStringLiteral( "url" ) ) + "/" + dataSource.param( QStringLiteral( "layer" ) ), authcfg, mErrorTitle, mError ); const QVariantMap extentData = mLayerInfo.value( QStringLiteral( "extent" ) ).toMap(); mExtent.setXMinimum( extentData[QStringLiteral( "xmin" )].toDouble() ); mExtent.setYMinimum( extentData[QStringLiteral( "ymin" )].toDouble() ); mExtent.setXMaximum( extentData[QStringLiteral( "xmax" )].toDouble() ); mExtent.setYMaximum( extentData[QStringLiteral( "ymax" )].toDouble() ); mCrs = QgsArcGisRestUtils::parseSpatialReference( extentData[QStringLiteral( "spatialReference" )].toMap() ); if ( !mCrs.isValid() ) { appendError( QgsErrorMessage( tr( "Could not parse spatial reference" ), QStringLiteral( "AMSProvider" ) ) ); return; } const QVariantList subLayersList = mLayerInfo.value( QStringLiteral( "subLayers" ) ).toList(); mSubLayers.reserve( subLayersList.size() ); for ( const QVariant &sublayer : subLayersList ) { mSubLayers.append( sublayer.toMap()[QStringLiteral( "id" )].toString() ); mSubLayerVisibilities.append( true ); } mTimestamp = QDateTime::currentDateTime(); mValid = true; }
QVariant QuickInterpreter::call(QObject *ctx, const QString &func, const QVariantList &args) { QSList l; for (int i=0; i<args.size(); ++i) { const QVariant &v = args.at(i); switch (v.type()) { case QMetaType::QObjectStar: l.append(wrap(qvariant_cast<QObject *>(v))); break; case QMetaType::VoidStar: qWarning("QuickInterpreter::call: don't know what to do with a " "QVariant::VoidPointer here..."); break; default: { QuickScriptVariant qsvar(this, v); if (qsvar.isNative()) l.append(qsvar.toNative()); else l.append(qsvar); break; } } } return call(ctx, func, l); }
void Widget::get_friends() { get_Dialog(); QUrl current("https://api.vk.com/method/friends.get"); QUrlQuery Param; Param.addQueryItem("access_token",Setting::access_token); Param.addQueryItem("fields","city,domain"); Param.addQueryItem("v","5.40"); current.setQuery(Param); QByteArray answer = GET(current); if(answer.isEmpty()) { qDebug() << "Ничего не вернули"; exit(-1); } QVariantList List = parse(answer).toMap().value("response").toMap().value("items").toList(); for(int i = 0; i < List.size(); i++) { QVariantMap current = List[i].toMap(); QString tmp = current.value("first_name").toString() + " " + current.value("last_name").toString(); users[tmp] = current.value("id").toString(); } for(User::iterator itr = users.begin(); itr != users.end(); itr++) ui->FriendsList->addItem(itr.key()); emit friends_loaded(true); }
/* ========================================================================== */ QVariant LispPlugin::exec(QVariant procName, QVariant _exps) { QVariant result; assert(isa(_exps, "StringList")); QVariantList exps = _exps.toList(); if ("*" == procName) { auto a = exps[0].toDouble(); auto b = exps[1].toDouble(); return a * b; } else if ("+" == procName) { auto a = exps[0].toDouble(); auto b = exps[1].toDouble(); return a + b; } else if ("-" == procName) { auto a = exps[0].toDouble(); auto b = exps[1].toDouble(); return a - b; } else if ("<=" == procName) { auto a = exps[0].toDouble(); auto b = exps[1].toDouble(); return a <= b; } else { if (exps.size() == 1) _exps = exps.takeFirst(); return CallExternal(procName.toByteArray(), _exps); } throw runtime_error( QString("Unable to resolve symbol: %1 in this context") .arg(procName.toString()).toStdString()); }
void writeCell(QXmlStreamWriter &stream, const QVariantList &v) { stream.writeStartElement("cell"); stream.writeAttribute("name", v[1].toString()); for (int i = 2; i < v.size(); i++) { QVariant v2 = v[i]; if (v2.type() == QVariant::List) { QVariantList l2 = v2.toList(); if (l2.size() > 0) { QString tag = l2.first().toString(); if (tag == "cellType") { //stream.writeAttribute("type", l2[1].toString()); } else if (tag == "view") { writeView(stream, l2); } else { qWarning("Unexpected tag '%s' in 'cell' tag", qPrintable(tag)); } } } } stream.writeEndElement(); }
/** * Juz 1, Fatiha, s1, v1 * Juz 2, Baqara, s2, v142 * Juz 3, Baqara, s2, v253 * * needs to turn into * Juz 1, fatiha s1,v1 * juz2, baqara,s2,v142 * juz3, baqara,s2,v253 * juz 1, baqara s2,v1 */ QVariantList ThreadUtils::normalizeJuzs(QVariantList const& source) { QVariantList result; int lastJuzId = 1; int n = source.size(); QMap<int,bool> processed; for (int i = 0; i < n; i++) { QVariantMap current = source[i].toMap(); if ( current.value("juz_id").toInt() > 0 ) { lastJuzId = current.value("juz_id").toInt(); int surah = current.value(KEY_CHAPTER_ID).toInt(); if ( current.value("verse_number").toInt() > 1 && !processed.contains(surah) ) { QVariantMap copy = current; copy["juz_id"] = lastJuzId-1; copy["verse_number"] = 1; result << copy; // baqara:1 processed[surah] = true; } } else { current["juz_id"] = lastJuzId; } result << current; } return result; }
void writePort(QXmlStreamWriter &stream, const QVariantList &v) { if (v.size() != 3) { qWarning("Wrong port description"); return; } stream.writeStartElement("port"); if (v[1].type() == QVariant::List) { QVariantList l = v[1].toList(); if (l[0].toString() != "array") { qWarning("Wrong port name description"); } else { stream.writeAttribute("name", l[1].toString()); stream.writeAttribute("arraySize", QString::number(l[2].toInt())); } } else { stream.writeAttribute("name", v[1].toString()); } stream.writeEndElement(); }
toResultPlanModel::toResultPlanModel(toEventQuery *query, QObject *parent) : QAbstractItemModel(parent) , Query(query) , HeadersRead(false) { Query->setParent(this); // this will satisfy QObject's disposal Headers << HeaderDesc{"Operation", 0} << HeaderDesc{"Options", 0} << HeaderDesc{"Object name", 0} << HeaderDesc{"Mode", 0} << HeaderDesc{"Cost", 0} << HeaderDesc{"%CPU", Qt::AlignRight} << HeaderDesc{"Bytes", Qt::AlignRight} << HeaderDesc{"Rows", Qt::AlignRight} << HeaderDesc{"Time", 0} << HeaderDesc{"Access pred.", 0} << HeaderDesc{"Filter pred.", 0} << HeaderDesc{"TEMP Space", Qt::AlignRight} << HeaderDesc{"Startpartition", 0} << HeaderDesc{"Endpartition", 0}; ; rootItem = new toPlanTreeItem("root", QList<QVariant>()); QVariantList sqlidData; for (int i = sqlidData.size(); i < Headers.size(); i++) sqlidData << ""; rootItem->appendChild(sqlidItem = new toPlanTreeItem("sqlid", sqlidData, rootItem)); connect(Query, SIGNAL(dataAvailable(toEventQuery*)), this, SLOT(slotPoll(toEventQuery*))); connect(Query, SIGNAL(done(toEventQuery*, unsigned long)), this, SLOT(slotQueryDone(toEventQuery*))); connect(Query, SIGNAL(error(toEventQuery*,toConnection::exception const &)), this, SLOT(slotErrorHanler(toEventQuery*, toConnection::exception const &))); }
void HubAccount::initializeCategories(QVariantList newCategories) { qDebug() << "HubAccount::initializeCategories " << _categoriesInitialized; if (!_categoriesInitialized) { qint64 retVal = -1; if (_hubCache->categories().size() == 0) { QVariantList categories; for(int index = 0; index < newCategories.size(); index++) { QVariantMap category = newCategories[index].toMap(); retVal = _udsUtil->addCategory(_accountId, category["name"].toString(), category["parentCategoryId"].toLongLong()); if (retVal == -1) { qDebug() << "HubAccount::initializeCategories: add category failed for: " << category; break; } category["categoryId"] = retVal; categories << category; } if (retVal > 0) { _hubCache->setCategories(categories); } } QVariantList items = _hubCache->items(); _categoriesInitialized = true; } }
void TestControllerTest::testResults() { ITestSuite* suite = new FakeTestSuite(TestSuiteName, m_project); m_testController->addTestSuite(suite); QSignalSpy spy(m_testController, SIGNAL(testRunFinished(KDevelop::ITestSuite*,KDevelop::TestResult))); QVERIFY(spy.isValid()); QList<TestResult::TestCaseResult> results; results << TestResult::Passed << TestResult::Failed << TestResult::Error << TestResult::Skipped << TestResult::NotRun; foreach (TestResult::TestCaseResult result, results) { emitTestResult(suite, result); QCOMPARE(spy.size(), 1); QVariantList arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 2); QVERIFY(arguments.first().canConvert<ITestSuite*>()); QCOMPARE(arguments.first().value<ITestSuite*>(), suite); QVERIFY(arguments.at(1).canConvert<TestResult>()); QCOMPARE(arguments.at(1).value<TestResult>().suiteResult, result); foreach (const QString& testCase, suite->cases()) { QCOMPARE(arguments.at(1).value<TestResult>().testCaseResults[testCase], result); } }
bool HubAccount::removeHubCategory(qint64 categoryId) { bool retval = false; qDebug() << "remove hub category: " << categoryId; QVariantList categories = this->categories(); QVariantList newCategories; for(int index = 0; index < categories.size(); index++) { QVariant category = categories.at(index); QVariantMap categoryMap = category.toMap(); qint64 cacheCategoryId = categoryMap["categoryId"].toLongLong(); if (categoryId == cacheCategoryId) { retval = _udsUtil->removeCategory(_accountId, categoryId); if (!retval) { qDebug() << "HubAccount::removeHubCategory: removeCategory failed for category: " << categoryId << ", account: "<< _accountId << ", retval: "<< retval << "\n"; break; } } else { newCategories << category; } } if (retval) { _hubCache->setCategories(newCategories); } return (retval); }
QVariantMap VolumeRequest::mutateRecords(QVariantList &records) { QVariantMap mutatedRecords; int max = 0, min = INT_MAX, average = 0; int total = 0, size = records.size(); for ( int i = 0; i < size; i++ ) { QVariantMap record = records.at(i).toMap(); QString sQuantityRemaining = m_beerid != NULL ? record.value(SF_NAMESPACE "__quantity_remaining__c").toString() : record.value("quantity_remaining").toString(); QString dateString = m_beerid != NULL ? record.value(SF_NAMESPACE "__date__c").toString() : record.value("date").toString(); int quantityRemaining = sQuantityRemaining.toInt(); max = std::max(quantityRemaining, max); min = std::min(quantityRemaining, min); total += quantityRemaining; mutatedRecords[labelForDateString(dateString)] = sQuantityRemaining; } average = total / size; this->setMin(min); this->setMax(max); this->setAverage(average); this->setTotal(total); return mutatedRecords; }
/** * Returns all the torrents in JSON format. * * The return value is a JSON-formatted list of dictionaries. * The dictionary keys are: * - "hash": Torrent hash * - "name": Torrent name * - "size": Torrent size * - "progress: Torrent progress * - "dlspeed": Torrent download speed * - "upspeed": Torrent upload speed * - "priority": Torrent priority (-1 if queuing is disabled) * - "num_seeds": Torrent seeds connected to * - "num_complete": Torrent seeds in the swarm * - "num_leechs": Torrent leechers connected to * - "num_incomplete": Torrent leechers in the swarm * - "ratio": Torrent share ratio * - "eta": Torrent ETA * - "state": Torrent state * - "seq_dl": Torrent sequential download state * - "f_l_piece_prio": Torrent first last piece priority state * - "force_start": Torrent force start state * - "label": Torrent label */ QByteArray btjson::getTorrents(QString filter, QString label, QString sortedColumn, bool reverse, int limit, int offset) { QVariantList torrentList; TorrentFilter torrentFilter(filter, TorrentFilter::AnyHash, label); foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents()) { if (torrentFilter.match(torrent)) torrentList.append(toMap(torrent)); } std::sort(torrentList.begin(), torrentList.end(), QTorrentCompare(sortedColumn, reverse)); int size = torrentList.size(); // normalize offset if (offset < 0) offset = size + offset; if ((offset >= size) || (offset < 0)) offset = 0; // normalize limit if (limit <= 0) limit = -1; // unlimited if ((limit > 0) || (offset > 0)) return json::toJson(torrentList.mid(offset, limit)); else return json::toJson(torrentList); }
void Widget::get_Dialog() { QUrl current("https://api.vk.com/method/messages.getDialogs"); QUrlQuery Param; Param.addQueryItem("access_token",Setting::access_token); Param.addQueryItem("count","6"); Param.addQueryItem("v","5.40"); current.setQuery(Param); QByteArray answer = GET(current); if(answer.isEmpty()) { qDebug() << "Ничего не вернули"; exit(-1); } QVariantList List = parse(answer).toMap().value("response").toMap().value("items").toList(); for(int i = 0; i < List.size(); i++) { QListWidget *listWidget = new QListWidget; QVariantMap current = List[i].toMap().value("message").toMap(); QString tmp = current.value("title").toString(); get_Message(current.value("user_id").toString()); ui->dialogList->addTab(listWidget, tmp); } }
void HistoryModel::addItem (QString title, QString url, QDateTime date, QObject *browserWidget) { Util::DefaultHookProxy_ptr proxy (new Util::DefaultHookProxy); emit hookAddingToHistory (proxy, title, url, date, browserWidget); if (proxy->IsCancelled ()) return; QVariantList result = proxy->GetReturnValue ().toList (); int size = result.size (); if (size >= 1) title = result.at (0).toString (); if (size >= 2) url = result.at (1).toString (); if (size >= 3) date = result.at (2).toDateTime (); HistoryItem item = { title, date, url }; Core::Instance ().GetStorageBackend ()->AddToHistory (item); }
void Widget::get_Message(QString id) { QUrl current("https://api.vk.com/method/messages.getHistory"); QUrlQuery Param; Param.addQueryItem("access_token",Setting::access_token); Param.addQueryItem("user_id",id); Param.addQueryItem("v","5.40"); current.setQuery(Param); QByteArray answer = GET(current); if(answer.isEmpty()) { qDebug() << "Ничего не вернули сообщения"; exit(-1); } QVariantList List = parse(answer).toMap().value("response").toMap().value("items").toList(); for(int i = 0; i < List.size(); i++) { QVariantMap current = List[i].toMap(); QString tmp = current.value("body").toString(); //+ " " + current.value("last_name").toString(); messages[tmp] = current.value("id").toString(); qDebug() << current.value("body").toString(); } for(User::iterator itr = messages.begin(); itr != messages.end(); itr++) ui->listWidget->addItem(itr.key()); }
QString TraceDock::printArrayItem(const QVariant & value, const ArrayType * type, int state) { QStringList caps; QVariantList array = value.value<QVariantList>(); // incompatible arrays might lead to wrong indices and crashes if(array.size() != type->size) return QString(); const SymbolType * subtype = sim_->typeInfo(type->subtype); // first check existing fields for(int i=0; i < type->size; ++i) { if(dynamic_cast<const PODType*>(subtype) != NULL) { caps << printPODItem(array[i], dynamic_cast<const PODType*>(subtype)); } else if(dynamic_cast<const OptionType*>(subtype) != NULL) { caps << printOptionItem(array[i], dynamic_cast<const OptionType*>(subtype)); } else if(dynamic_cast<const ArrayType*>(subtype) != NULL) { caps << printArrayItem(array[i], dynamic_cast<const ArrayType*>(subtype), state); } else if(dynamic_cast<const ListType*>(subtype) != NULL) { caps << printChildren(array[i].toStringList(), state); } else { caps << ""; } } return QString("{%1}").arg(caps.join(",")); }
void QgsAmsLegendFetcher::handleFinished() { // Parse result QJson::Parser parser; bool ok = false; QVariantMap queryResults = parser.parse( mQueryReply, &ok ).toMap(); if ( !ok ) { emit error( QString( "Parsing error at line %1: %2" ).arg( parser.errorLine() ).arg( parser.errorString() ) ); } QgsDataSourceUri dataSource( mProvider->dataSourceUri() ); QList< QPair<QString, QImage> > legendEntries; foreach ( const QVariant& result, queryResults["layers"].toList() ) { QVariantMap queryResultMap = result.toMap(); QString layerId = queryResultMap["layerId"].toString(); if ( layerId != dataSource.param( "layer" ) && !mProvider->subLayers().contains( layerId ) ) { continue; } QVariantList legendSymbols = queryResultMap["legend"].toList(); foreach ( const QVariant& legendEntry, legendSymbols ) { QVariantMap legendEntryMap = legendEntry.toMap(); QString label = legendEntryMap["label"].toString(); if ( label.isEmpty() && legendSymbols.size() == 1 ) label = queryResultMap["layerName"].toString(); QByteArray imageData = QByteArray::fromBase64( legendEntryMap["imageData"].toByteArray() ); legendEntries.append( qMakePair( label, QImage::fromData( imageData ) ) ); } }