QJSValue THREEMatrix4::applyVector3Array(QJSValue floatArray, int offset, int length) { if(!floatArray.isArray()) { qDebug().nospace() << "THREEMatrix4::" << __FUNCTION__ << " invalid parameter type for floatArray, expected JS array"; return m_engine->newQObject(this); } static THREEVector3 v1(parent(), m_engine); QVariantList list = floatArray.toVariant().toList(); if (offset < 0) offset = 0; if (length < 0 || length == 0) length = list.length(); if (offset + length > list.length()) length = list.length() - offset; for ( int i = 0, j = offset; i < length; i += 3, j += 3 ) { v1.m_x = float(floatArray.property(j).toNumber()); v1.m_y = float(floatArray.property(j + 1).toNumber()); v1.m_z = float(floatArray.property(j + 2).toNumber()); v1._applyMatrix4( this ); floatArray.setProperty(j, QJSValue(v1.m_x)); floatArray.setProperty(j + 1, QJSValue(v1.m_y)); floatArray.setProperty(j + 2, QJSValue(v1.m_z)); } return floatArray; }
void NetworkBus::onAlllineDataModelFinished(QNetworkReply* reply){ if(reply->error() != QNetworkReply::NoError){ m_error = QString::fromUtf8("所有线路数据请求错误,请检查网络后重试!"); onError(); reply->deleteLater(); return; }else{ JsonDataAccess jda; // at are you const QVariant qtData = jda.loadFromBuffer(reply->readAll()); // TODO if qtData has some error const QVariantMap map = qtData.toMap(); const QString msg = map.values("msg").value(0).toString(); const QString success = map.values("success").value(0).toString(); if(success != "true" || msg != "ok"){ m_error = QString::fromUtf8("所有线路数据返回不成功,请检查网络后重试!"); onError(); reply->deleteLater(); return; } // const QVariantList data = map["data"].toList(); if(data.isEmpty() || data.length() == 0){ m_error = QString::fromUtf8("未查询到所有公交车线路数据!"); onError(); reply->deleteLater(); return ; } QString result = ""; m_alllineDataModel->clear(); for(int i=0;i<data.length();i++){ const QVariantMap iMap = data.at(i).toMap(); busline *bus = new busline; bus->setBeginTime(iMap.value("begin_time").toString()); bus->setEndTime(iMap.value("end_time").toString()); bus->setId(iMap.value("id").toString()); bus->setStartStation(iMap.value("start_station").toString()); bus->setEndStation(iMap.value("end_station").toString()); bus->setPrice(iMap.value("price").toString()); bus->setLineName(iMap.value("line_name").toString()); bus->setIsOpen(iMap.value("isopen").toInt());//1 bus->setDir(iMap.value("dir").toInt());//0/1 bus->setCityId(m_city_id); if(bus->getIsOpen() == 1) m_alllineDataModel->append(bus); } reply->deleteLater(); } qDebug()<< "m_allline datamodel size:" << m_alllineDataModel->size(); m_error = QString::fromUtf8("查询到所有公交车线路数据!"); this->setProcess(false); emit processChanged(); emit alllineDataModelChanged(); }
//----------------------------------------------------------------------------- //! //----------------------------------------------------------------------------- tDualAnalogWidget::tDualAnalogWidget( int pageNumber, tIInstrumentProductFactory* pProductFactory, QWidget* pParent ) : tTemplateWidget( pProductFactory, pageNumber, pParent ) , m_LeftLimitIndex( 0 ) , m_RightLimitIndex( 0 ) { Assert( pProductFactory ); if ( pProductFactory ) { QVariantList analogRanges = tWidgetSettings::Instance()->TemplateAnalogRanges( m_PageNumber ); if( analogRanges.length() > 0 ) { m_LeftLimitIndex = analogRanges[0].toInt(); } if( analogRanges.length() > 1 ) { m_RightLimitIndex = analogRanges[1].toInt(); } m_pAnalogGauge1 = pProductFactory->GetAnalogGauge( DATA_TYPE_INVALID, this ); m_pAnalogGauge1->SetCustomHobartLimits( m_LeftLimitIndex ); m_pLayout->addWidget( m_pAnalogGauge1, 0, 0, 2, 1 ); m_Gauges << m_pAnalogGauge1; m_pAnalogGauge2 = pProductFactory->GetAnalogGauge( DATA_TYPE_INVALID, this ); m_pAnalogGauge2->SetCustomHobartLimits( m_RightLimitIndex ); m_pLayout->addWidget( m_pAnalogGauge2, 1, 1, 1, 2 ); m_Gauges << m_pAnalogGauge2; m_pDigitalGauge1 = pProductFactory->GetDigitalGauge( DATA_TYPE_INVALID, this ); m_pDigitalGauge1->SetBorders( false, false, true, false ); m_pLayout->addWidget( m_pDigitalGauge1, 0, 1 ); m_Gauges << m_pDigitalGauge1; m_pDigitalGauge2 = pProductFactory->GetDigitalGauge( DATA_TYPE_INVALID, this ); m_pDigitalGauge2->SetBorders( false ); m_pLayout->addWidget( m_pDigitalGauge2, 0, 2 ); m_Gauges << m_pDigitalGauge2; int analog1H = Widgets::GetScreenHeight(); int analog1W = analog1H; int analog2W = Widgets::GetScreenWidth() - analog1W; int analog2H = analog2W; int digitalH = Widgets::GetScreenHeight() - analog2H; int digitalW = analog2W / 2; m_pAnalogGauge1 ->setFixedSize( analog1W, analog1H ); m_pAnalogGauge2 ->setFixedSize( analog2W, analog2H ); m_pDigitalGauge1 ->setFixedSize( digitalW, digitalH ); m_pDigitalGauge2 ->setFixedSize( digitalW, digitalH ); LoadDataItems(); } }
//! [1] void NetworkBus::onSublineInfFinished(QNetworkReply* reply){ if(reply->error() != QNetworkReply::NoError){ m_error = QString::fromUtf8("站点信息请求失败,请检查网络后重试!"); onError(); reply->deleteLater(); return ; }else{ JsonDataAccess jda; // at are you const QVariant qtData = jda.loadFromBuffer(reply->readAll()); // TODO if qtData has some error const QVariantMap map = qtData.toMap(); const QString msg = map.values("msg").value(0).toString(); const QString success = map.values("success").value(0).toString(); if(success != "true" || msg != "ok"){ m_error = QString::fromUtf8("站点信息返回不成功,请稍后重试!"); onError(); reply->deleteLater(); return; } const QVariantMap data = map["data"].toMap(); const QVariantList stations = data["stations"].toList(); if(stations.isEmpty() || stations.length() == 0){ m_error = QString::fromUtf8("未查询到站点数据!"); onError(); reply->deleteLater(); return ; } m_dataModel->clear(); for(int i=0;i<stations.length();i++){ const QVariantMap var = stations.at(i).toMap(); station *sta = new station(); sta->setCode(var["code"].toString()); sta->setId(var["id"].toString()); sta->setLat(var["lat"].toString()); sta->setLng(var["lng"].toString()); // QString name = QString::number(i+1) ; // name.append(var["name"].toString()); sta->setIndex(QString::number(i+1)); // qDebug() << "name string : " << name ; sta->setName(var["name"].toString()); if(m_dir == 0) startStation->append(sta); else endStation->append(sta); } m_dataModel->append(m_dir == 0 ? *startStation : *endStation); } qDebug() << "\nm_dataModel size :"<<m_dataModel->size() << "\n"; emit dataModelChanged(); emit buslineChanged(); reply->deleteLater(); this->get_lineisopen(); }
//--------------------------------------------------------- // oscColorNote //--------------------------------------------------------- void MuseScore::oscColorNote(QVariantList list) { qDebug() << list; if(!cs) return; if (list.length() != 2 && list.length() != 3) return; int tick; int pitch; QColor noteColor("red"); //default to red bool ok; tick = list[0].toInt(&ok); if (!ok) return; pitch = list[1].toInt(&ok); if (!ok) return; if(list.length() == 3 && list[2].canConvert(QVariant::String)) { QColor color(list[2].toString()); if(color.isValid()) noteColor = color; } Measure* measure = cs->tick2measure(tick); if(!measure) return; Segment* s = measure->findSegment(Segment::SegChordRest, tick); if (!s) return; //get all chords in segment... int n = cs->nstaves() * VOICES; for (int i = 0; i < n; i++) { Element* e = s->element(i); if (e && e->isChordRest()) { ChordRest* cr = static_cast<ChordRest*>(e); if(cr->type() == Element::CHORD) { Chord* chord = static_cast<Chord*>(cr); for (int idx = 0; idx < chord->notes().length(); idx++) { Note* note = chord->notes()[idx]; if (note->pitch() == pitch) { cs->startCmd(); cs->undo(new ChangeProperty(note, P_COLOR, noteColor)); cs->endCmd(); cs->end(); return; } } } } } }
bool model::Network::emitNetwork(XMASNetwork &network) { auto &componentMap = network.getComponentMap(); std::clock_t c_start = std::clock(); QVariantList compList; for(auto &it : componentMap) { XMASComponent *comp = it.second; if (comp) { QVariantMap map; convertToQml(map, comp); compList.append(map); } } QVariantList channelList; for (auto &it : componentMap) { XMASComponent *comp = it.second; if (comp) { QVariantList list; connectInQml(list, comp); channelList.append(list); } } QVariantMap qmlNetwork; qmlNetwork["complist"] = compList; qmlNetwork["channellist"] = channelList; emit packetChanged(); emit packetChanged(); // Var is not implemented in qml yet. No known semantics for var //qmlNetwork["var"] = QString(network.getVar().stl().c_str()); auto cne = network.getNetworkExtension<CompositeNetworkExtension>(false); if(cne){ this->m_alias = cne->alias.c_str(); this->m_boxedImage = cne->boxedImage; this->m_imageName = cne->imageName.c_str(); } auto cve = network.getNetworkExtension<CanvasNetworkExtension>(false); if(cve){ this->m_size = QSize(cve->width,cve->height); } emit createNetwork(qmlNetwork); std::clock_t c_end = std::clock(); qDebug() << "CPU time used: " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " ms" << " for " << compList.length() << " components and " << channelList.length() << " channels"; return true; }
static void bindParameters(const QVariantList& bindValues, QSqlQuery *sqlQuery) { if (!bindValues.isEmpty()) { for (int i = bindValues.length() - 1; i >= 0; --i) { sqlQuery->bindValue(i, bindValues.at(i)); } } }
void Bb10Ui::onChannelListTriggered(const QVariantList index) { // Headers are not clickable if (index.length() < 2) return; QModelIndex modelIndex = qobject_cast<DataModelAdapter*>(m_channelListView->dataModel())->getQModelIndex(index); BufferInfo bufferInfo = modelIndex.data(NetworkModel::BufferInfoRole).value<BufferInfo>(); BufferId id = bufferInfo.bufferId(); if (!id.isValid()) return; QString bufferName = bufferInfo.bufferName(); qDebug() << "xxxxx Bb10Ui::onChannelListTriggered bufferInfo = " << bufferInfo << " index = " << index << " modelIndex = " << modelIndex; ChatView *view = qobject_cast<ChatView *>(m_chatViews.value(id)); if (!view) { view = new ChatView(id, bufferName); m_chatViews[id] = view; } m_currentBufferId = id; Client::bufferModel()->switchToBuffer(id); Client::networkModel()->clearBufferActivity(id); Client::setBufferLastSeenMsg(id, view->getLastMsgId()); Client::backlogManager()->checkForBacklog(id); navPanePush(view->getPage()); // ask channelListView to update the appearance qobject_cast<DataModelAdapter*>(m_channelListView->dataModel())->handleBufferModelDataChanged(modelIndex, modelIndex); }
/* * Create files/directories based on the provided array */ void FileEngine::createEntries(const QString &jsonString) { QVariantList entryList = QJsonDocument::fromJson(QByteArray(jsonString.toLatin1())).array().toVariantList(); for (int i=0; i < entryList.length(); i++) { QMap<QString, QVariant> entryMap = entryList.at(i).toMap(); QString type = entryMap.value("type").toString(); QString path = entryMap.value("path").toString(); QString name = entryMap.value("name").toString(); // Create directories if (type == "directory") { QDir dir(path); bool success = dir.mkdir(QString("%1/%2").arg(path, name)); } else if (type == "file") { QFile file(QString("%1/%2").arg(path, name)); file.open(QFile::WriteOnly); } } }
void tst_JsonRpcConnection::echoRequestTest() { mIODevice = new MockIODevice("data/echoRequest.jsonrpc"); mConnection = new JsonRpcConnection(mIODevice); connect(mConnection, SIGNAL(disconnected()), SLOT(onDisconnected())); QSignalSpy requestReceivedSpy(mConnection, SIGNAL(requestReceived(const JsonRpcMessage &))); QSignalSpy responseReceivedSpy(mConnection, SIGNAL(responseReceived(const JsonRpcMessage &))); QSignalSpy disconnectedSpy(mConnection, SIGNAL(disconnected())); QList<QVariant> arguments; mIODevice->open(QIODevice::ReadWrite); mEventLoop.exec(); QVERIFY(requestReceivedSpy.count() == 1); QVERIFY(responseReceivedSpy.count() == 0); QVERIFY(disconnectedSpy.count() == 1); JsonRpcMessage request; arguments = requestReceivedSpy.takeFirst(); request = arguments.at(0).value<JsonRpcMessage>(); QCOMPARE(request.idAsVariant().toUInt(), (quint32)1); QCOMPARE(request.method(), QString("echo")); QVariantList params = request.parameters(); QVERIFY(params.length() == 1); QCOMPARE(params.at(0).toString(), QString("Hello JSON-RPC")); }
BattleChoice fromJson<BattleChoice>(const QVariantMap &v){ static QStringList bchoices = QStringList() << "cancel" << "attack" << "switch" << "rearrange" << "shiftcenter" << "tie" << "item"; BattleChoice info; info.type = std::max(bchoices.indexOf(v.value("type").toString()), 0); info.playerSlot = v.value("slot").toInt(); if (info.type == AttackType) { info.choice.attack.attackSlot = v.value("attackSlot").toInt(); info.choice.attack.mega = v.value("mega").toBool(); if (v.value("target").isValid()) { info.choice.attack.attackTarget = v.value("target").toInt(); } else { info.choice.attack.attackTarget = !info.playerSlot; } } else if (info.type == SwitchType) { info.choice.switching.pokeSlot = v.value("pokeSlot").toInt(); } else if (info.type == RearrangeType) { if (v.value("neworder").canConvert<QVariantList>()) { QVariantList list = v.value("neworder").toList(); for (int i = 0; i < list.length() && i < 6; i++) { info.choice.rearrange.pokeIndexes[i] = list.value(i).toInt(); } } } else if (info.type == ItemType) { info.choice.item.item = v.value("item").toInt(); info.choice.item.target = v.value("target").toInt(); info.choice.item.attack = v.value("attack").toInt(); } return info; }
int BdLogic::buildInactiveProjectList() { QVariantMap resourcesMapFromJson; QVariantList projectListFromJson; QVariantMap projectFromJson; resourcesMapFromJson = m_boxMapParsedJson[BoxNames[DLSTATE_RESOURCES]].toMap(); resourcesMapFromJson = resourcesMapFromJson["resources"].toMap(); projectListFromJson = resourcesMapFromJson["projects"].toList(); m_currentInactiveProjectDlIx = 0; m_inactiveProjectUUIDList.clear(); for(int projectIx = 0; projectIx < projectListFromJson.length(); projectIx++) { projectFromJson = projectListFromJson[projectIx].toMap(); if(projectFromJson["status"].toString() == QString("inactive")) { m_inactiveProjectUUIDList.push_back(projectFromJson["uuid"].toString()); } } return BDLOGIC_STATUS_OK; }
void KRemoteModel::gotHeaders(QVariantList headers) { if(st_ == Headers) { emit beginInsertColumns(QModelIndex(), 0, headers.length() - 1); hdrs_ = headers; emit endInsertColumns(); setState(Fetching); } }
void JsonSerializer::addArray(const QVariantList &list) { m_buffer.append("["); for (int i = 0; i < list.length(); i++) { if (i > 0) m_buffer.append(","); addVariant(list[i]); } m_buffer.append("]"); }
void QxCommand::restore(QVariantList list) { int i = 0; icon_.loadFromData(list.at(i++).toByteArray(), "PNG"); description_ = list.at(i++).toString(); keys_ = list.at(i++).toString(); script_ = list.at(i++).toString(); target_ = list.at(i++).toInt(); if (i < list.length()) { autoSaveFile_ = list.at(i++).toBool(); if (i < list.length()) autoOpenNextLink_ = list.at(i++).toBool(); else autoOpenNextLink_ = false; } else autoSaveFile_ = false; }
void Evaluate::addArray(QVariantList &list) { m_buffer.append("["); for (int i = 0; i < list.length(); i++) { if (i > 0) m_buffer.append(","); addVariant(list[i]); } m_buffer.append("]"); }
void KRemoteModel::gotData(QVariantList data) { if(st_ == Fetching) { emit beginInsertRows(QModelIndex(), 0, data.length() - 1); this->data_ = data; emit endInsertRows(); setState(Complete); } }
NDArray::NDArray(const QVariantList &values) : NDArray(TypeMap<qreal>::type, {values.length()}, 0) { qreal* dptr = (qreal*)data(); // Copy in data from list for (int i=0; i<m_size; ++i) { // qDebug() << QString("%1: %2").arg(i).arg(values[i].toReal()); (*dptr++) = values[i].toReal(); } }
QList<double> MapPage::evalGetHistoryDists() const { QVariant result = this->mainFrame()->evaluateJavaScript("curRoute.getHistoryDists();"); QVariantList vpath = result.toList(); QList<double> historyDists; for (int i=0; i<vpath.length(); i++) { historyDists.push_back(vpath[i].toDouble()); } return historyDists; }
void Bb10Ui::deleteBuffer() { QVariantList index = m_channelListView->selected(); if (index.length() < 2) return; QModelIndex modelIndex = static_cast<DataModelAdapter*>(m_channelListView->dataModel())->getQModelIndex(index); BufferId bufId = modelIndex.data(NetworkModel::BufferIdRole).value<BufferId>(); Client::removeBuffer(bufId); }
int ResultsDataModel::childCount(const QVariantList &indexPath) { int retVal = 0; if (indexPath.length() == 0) { retVal = _internalDB.length(); } else { //No map in list has children; each just represents a song or album retVal = 0; } return retVal; }
bool TabRow::update(const QVariantList& args) const { if (args.length() == 0) { return true; // nothing to do } if ((args.length() % 2) != 0) { throw std::invalid_argument("Update row: Need an even number of arguments (column / value pairs)"); } // create the SQL statement QString sql = "UPDATE " + tabName + " SET "; // split the combined column/values list in "args" into a separate list of values QVariantList vals; QVariantList::const_iterator i = args.begin(); while (i != args.end()) { QString colName = (*i).toString(); if (colName == "id") { throw std::invalid_argument("Update row: can't alter value of the ID column!"); } sql += colName + " = ?, "; i++; vals << (*i); i++; } // remove the trailing ", " sql = sql.left(sql.length() - 2); // complete the statement sql += " WHERE id = ?"; vals << rowId; int result = db->execNonQuery(sql, vals); return (result == 1); }
/** * This slot is connected to the dataChanged signal of the FavoritesService and is executed * when the data in the service is changed. When the data is changed, we delete * all the data in the DataModel and insert the new data. * * @param favorites The data to be inserted in the datamodel. */ void FavoritesViewModel::favoritesDataChanged(const QVariantList &favorites) { // clear the data. this->dataModel->clear(); // repopulate the datamodel for(int i=0; i<favorites.length(); i++) { this->dataModel->insert(favorites[i].toMap()); } emit dataModelChanged(dataModel); }
void Bb10Ui::partChannel() { QVariantList index = m_channelListView->selected(); if (index.length() < 2) return; QModelIndex modelIndex = static_cast<DataModelAdapter*>(m_channelListView->dataModel())->getQModelIndex(index); BufferInfo bufInfo = modelIndex.data(NetworkModel::BufferInfoRole).value<BufferInfo>(); QString reason = Client::identity(Client::network(bufInfo.networkId())->identity())->partReason(); Client::userInput(bufInfo, QString("/PART %1").arg(reason)); }
void Bb10Ui::joinChannel() { QVariantList index = m_channelListView->selected(); if (index.length() < 2) return; QModelIndex modelIndex = static_cast<DataModelAdapter*>(m_channelListView->dataModel())->getQModelIndex(index); BufferInfo bufInfo = modelIndex.data(NetworkModel::BufferInfoRole).value<BufferInfo>(); QString bufferName = bufInfo.bufferName(); switchToOrJoinChat(bufferName, false); }
void StatisticsAPI::getAllProjectLangStats(const QString &projectSlug, const QVariantList &resources, int accountIdx) { if (resources.isEmpty()) { emit gotAllProjectLangStatsError(tr("No resources set.")); return; } getAllProjectLangStatsNm.setAccountIndex(accountIdx); projectLangStats.clear(); projectLangStatsCounter = resources.length(); for (int i = 0; i < resources.length(); ++i) { QUrl url = helper.buildUrl("/project/" + projectSlug + "/resource/" + resources.at(i).toString() + "/stats/", accountIdx); connect(&getAllProjectLangStatsNm, SIGNAL(finished(QNetworkReply*)), this, SLOT(getAllProjectLangStatsFinished(QNetworkReply*)), Qt::UniqueConnection); getAllProjectLangStatsNm.get(QNetworkRequest(url)); } }
void AudioPlayerControlRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { Q_UNUSED(context) QDBusInterface tracklist(QString::fromLatin1( "org.mpris.%1").arg(m_player), QLatin1String( "/TrackList" ), QLatin1String( "org.freedesktop.MediaPlayer" )); QVariantList data = match.data().value<QVariantList>(); /* Only Amarok part*/ QString url = data[2].toString(); int pos = posInPlaylist(url); kDebug() << "pos" << pos; QAction *a = match.selectedAction(); if (data[3].toString().compare(NONE)) { if (!a) { a = action(data[3].toString()); } if (a == action(QUEUE)) { KUrl::List list; list << KUrl(url); KRun::run(QLatin1String( "amarok --queue %u" ), list, 0); } else if (a == action(APPEND)) { if (!(pos > -1)) { tracklist.call(QDBus::NoBlock, QLatin1String( "AddTrack" ), url , false); } } else { //Action play was selected if (pos > -1) { tracklist.call(QDBus::NoBlock, QLatin1String( "PlayTrack" ), pos); } else { tracklist.call(QDBus::NoBlock, QLatin1String( "AddTrack" ), url, true); } } }/* Only Amarok part over */ else { if ((data[4].toString().compare(QLatin1String( "start" )) == 0)) { //The players's interface isn't available but it should be started if (!startPlayer()) { return; } } QDBusMessage msg = QDBusMessage::createMethodCall(QString::fromLatin1( "org.mpris.%1").arg(m_player),data[0].toString(), data[1].toString(), data[2].toString()); kDebug() << msg; QVariantList args; for (int i = 5;data.length() > i;++i) { args << data[i]; } msg.setArguments(args); QDBusConnection::sessionBus().call(msg, QDBus::NoBlock); } }
void XYSeries::addPoints(QVariantList data) { ChartPoint *point; for(int i=0;i<data.length();++i){ point = new ChartPoint(data.at(i).toMap(), this); dataList.append(point); connect(point, &ChartPoint::xChanged, this, &XYSeries::calculateDataRange); connect(point, &ChartPoint::yChanged, this, &XYSeries::calculateDataRange); } calculateDataRange(); emit dataChanged(); }
Client::EmailList Client::threads_get(const std::string& id) { QJsonDocument root; get({ "users", "me", "threads", id }, metadata_params(), root); EmailList result; QVariantMap variant = root.toVariant().toMap(); QVariantList messages = variant["messages"].toList(); int length = messages.length(); for (int i = length-1; i >= 0; i--) result.emplace_back(parse_email(messages[i])); return result; }
Client::EmailList Client::threads_get_batch(const ThreadList& threads) { QVariantList res_array; batch_get({ "users", "me", "threads" }, metadata_params(), threads, res_array); EmailList result; for (const QVariant& var : res_array) { QVariantList messages = var.toMap()["messages"].toList(); int length = messages.length(); for (int i = length-1; i >= 0; i--) result.emplace_back(parse_email(messages[i])); } return result; }