void tst_QMap::keys_values_uniqueKeys() { QMap<QString, int> map; QVERIFY(map.uniqueKeys().isEmpty()); QVERIFY(map.keys().isEmpty()); QVERIFY(map.values().isEmpty()); map.insertMulti("alpha", 1); QVERIFY(map.keys() == (QList<QString>() << "alpha")); QVERIFY(map.uniqueKeys() == map.keys()); QVERIFY(map.values() == (QList<int>() << 1)); map.insertMulti("beta", -2); QVERIFY(map.keys() == (QList<QString>() << "alpha" << "beta")); QVERIFY(map.keys() == map.uniqueKeys()); QVERIFY(map.values() == (QList<int>() << 1 << -2)); map.insertMulti("alpha", 2); QVERIFY(map.uniqueKeys() == (QList<QString>() << "alpha" << "beta")); QVERIFY(map.keys() == (QList<QString>() << "alpha" << "alpha" << "beta")); QVERIFY(map.values() == (QList<int>() << 2 << 1 << -2)); map.insertMulti("beta", 4); QVERIFY(map.uniqueKeys() == (QList<QString>() << "alpha" << "beta")); QVERIFY(map.keys() == (QList<QString>() << "alpha" << "alpha" << "beta" << "beta")); QVERIFY(map.values() == (QList<int>() << 2 << 1 << 4 << -2)); }
void neuron_branch_tip_count(V3DLONG &n_branch, V3DLONG &n_tip, const vector<V_NeuronSWC> & segment_list) { QMap <V_NeuronSWC_coord, V_NeuronSWC_unit> map; map.clear(); for (V3DLONG i=0; i<segment_list.size(); i++) { const V_NeuronSWC & seg = segment_list.at(i); for (V3DLONG j=0; j<seg.row.size(); j++) { V_NeuronSWC_unit node = seg.row.at(j); V_NeuronSWC_coord key = node; map.insertMulti(key, node); } } n_branch = 0; n_tip = 2*segment_list.size(); QList <V_NeuronSWC_coord> keys = map.uniqueKeys(); for (V3DLONG i=0; i<keys.size(); i++) { V_NeuronSWC_coord key = keys.at(i); int nkey = map.count(key); if (nkey >= 3) { n_branch ++; } if (nkey >= 2) { n_tip -= nkey; } } }
void SkyNet::timerEvent(QTimerEvent *e) { if (self_aware) { if (write_mutex.tryLock(10)) { QMap<QByteArray, QList<QString> > queues = msgqueues; queues.unite(sndfilequeues); QList<QByteArray> c2c_peer_ids = queues.uniqueKeys(); c2c_peer_ids = filter_existing_chans(c2c_peer_ids); for (int i = 0; i < c2c_peer_ids.size(); i++) { int ret; struct PICA_chaninfo *chan = NULL; ret = PICA_create_channel(nodelink, (const unsigned char*)c2c_peer_ids[i].constData(), &chan); qDebug()<<"restoring channel to "<<c2c_peer_ids[i]<<" ret ="<<ret<<" in timer event\n"; } write_mutex.unlock(); } } else { killTimer(e->timerId()); Accounts::AccountRecord acc = this->CurrentAccount(); Join(acc); } }
void TestReportHistory::verify_table(ReportTable *table_under_test, QMap<int, QStringList> &allowed_values) { QCOMPARE(table_under_test->get_field_names().count(), allowed_values.uniqueKeys().count()); for (auto &row : table_under_test->get_rows()) { for (int allowed_key : allowed_values.keys()) { QString col_str; QVariant col = row.row_m.value(allowed_key); if (col.canConvert<DataEngineDateTime>()) { col_str = col.value<DataEngineDateTime>().str(); } else { col_str = col.toString(); } //qDebug() << col_str; // qDebug() << allowed_values.value(allowed_key); QStringList allowed_value_per_col = allowed_values.value(allowed_key); if (allowed_value_per_col.count() == 0) { QCOMPARE(col_str, QString()); } else { QVERIFY(allowed_value_per_col.contains(col_str)); allowed_value_per_col.removeOne(col_str); } allowed_values.insert(allowed_key, allowed_value_per_col); } } for (int allowed_key : allowed_values.keys()) { QStringList allowed_value_per_col = allowed_values.value(allowed_key); QVERIFY(allowed_value_per_col.count() == 0); //qDebug() << allowed_values.value(allowed_key); } }
QStringList Config::LauncherSettings::subKeys(const QString &key) { QMap<QString, QString> settings = SettingsBase::getSettings(); QStringList keys = settings.uniqueKeys(); qDebug() << keys; QRegExp keyRe("(.+)/"); QStringList result; foreach (const QString ¤tKey, keys) { if (keyRe.indexIn(currentKey) != -1) { QString prefixedKey = keyRe.cap(1); if(prefixedKey.startsWith(key)) { QString subKey = prefixedKey.remove(key); if (!subKey.isEmpty()) result.append(subKey); } } } result.removeDuplicates(); return result; }
std::string BuyoutManager::Serialize(const QMap<QString, Buyout> &buyouts) { QJsonDocument doc; QJsonObject root; for (QString hash : buyouts.uniqueKeys()) { Buyout buyout = buyouts.value(hash); if (buyout.type != BUYOUT_TYPE_NO_PRICE && (buyout.currency == CURRENCY_NONE || buyout.type == BUYOUT_TYPE_NONE)) continue; if (buyout.type >= BuyoutTypeAsTag.size() || buyout.currency >= CurrencyAsTag.size()) { QLOG_WARN() << "Ignoring invalid buyout, type:" << buyout.type << "currency:" << buyout.currency; continue; } QJsonObject value; value.insert("value", buyout.value); value.insert("set_by", buyout.set_by); if (!buyout.last_update.isNull()){ value.insert("last_update", (int) buyout.last_update.toTime_t()); } else { // If last_update is null, set as the actual time value.insert("last_update", (int) QDateTime::currentDateTime().toTime_t()); } value.insert("type", QString::fromStdString(BuyoutTypeAsTag[buyout.type])); value.insert("currency", QString::fromStdString(CurrencyAsTag[buyout.currency])); root.insert(hash, value); } doc.setObject(root); QByteArray result = doc.toJson(); return result.toStdString(); }
void SkyNet::nodethread_connected(QString addr, quint16 port, NodeThread *thread) { if (self_aware) { emit BecameSelfAware(); //restore old peer connections, if any QList<QByteArray> c2c_peer_ids; //load undelivered messages from history if (msgqueues.isEmpty()) { History h(config_dbname, Accounts::GetCurrentAccount().id); msgqueues = h.GetUndeliveredMessages(); } //load file transfers to be completed // sndfilequeues = ... QMap<QByteArray, QList<QString> > queues = msgqueues; queues.unite(sndfilequeues); c2c_peer_ids = queues.uniqueKeys(); for (int i = 0; i < c2c_peer_ids.size(); i++) { int ret; write_mutex.lock(); struct PICA_chaninfo *chan = NULL; ret = PICA_create_channel(nodelink, (const unsigned char*)c2c_peer_ids[i].constData(), &chan); qDebug()<<"restoring channel to "<<c2c_peer_ids[i]<<" ret ="<<ret<<"\n"; write_mutex.unlock(); } //start timer timer_id = startTimer(10000); } }
void MarksDB::deleteLesson(int lessonId) { QList<QString> listStudents = markMap.uniqueKeys(); for (int i=0; i<listStudents.size(); i++) { QString name = listStudents.at(i); QMap<int,int> tempMap = markMap.take(name); if (tempMap.contains(lessonId)) { tempMap.remove(lessonId); } if (tempMap.size() > 0) { markMap.insert(name,tempMap); } } }
void TextEditorOverlay::mapEquivalentSelections() { m_equivalentSelections.clear(); m_equivalentSelections.resize(m_selections.size()); QMap<QString, int> all; for (int i = 0; i < m_selections.size(); ++i) all.insertMulti(selectionText(i).toLower(), i); const QList<QString> &uniqueKeys = all.uniqueKeys(); foreach (const QString &key, uniqueKeys) { QList<int> indexes; QMap<QString, int>::const_iterator lbit = all.lowerBound(key); QMap<QString, int>::const_iterator ubit = all.upperBound(key); while (lbit != ubit) { indexes.append(lbit.value()); ++lbit; } foreach (int index, indexes) m_equivalentSelections[index] = indexes; }
QStringList REPL::_enumerateCompletions(QObject* obj) const { const QMetaObject* meta = obj->metaObject(); QMap<QString, bool> completions; // List up slots, signals, and invokable methods const int methodOffset = meta->methodOffset(); const int methodCount = meta->methodCount(); for (int i = methodOffset; i < methodCount; i++) { const QString name = QString::fromLatin1(meta->method(i).methodSignature()); // Ignore methods starting with underscores if (name.startsWith('_')) { continue; } // Keep only up to, but not including, first paren const int cutoff = name.indexOf('('); completions.insert((0 < cutoff ? name.left(cutoff) : name), true); } // List up properties const int propertyOffset = meta->propertyOffset(); const int propertyCount = meta->propertyCount(); for (int i = propertyOffset; i < propertyCount; i++) { const QMetaProperty prop = meta->property(i); // Ignore non-scriptable properties if (!prop.isScriptable()) { continue; } const QString name = QString::fromLatin1(prop.name()); // Ignore properties starting with underscores if (name.startsWith('_')) { continue; } completions.insert(name, true); } return completions.uniqueKeys(); }
void QgsBrowserModel::addRootItems() { updateProjectHome(); // give the home directory a prominent third place QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, tr( "Home" ), QDir::homePath(), QStringLiteral( HOME_PREFIX ) + QDir::homePath() ); item->setSortKey( QStringLiteral( " 2" ) ); setupItemConnections( item ); mRootItems << item; // add favorite directories mFavorites = new QgsFavoritesItem( nullptr, tr( "Favorites" ) ); if ( mFavorites ) { setupItemConnections( mFavorites ); mRootItems << mFavorites; } // add drives const auto drives { QDir::drives() }; for ( const QFileInfo &drive : drives ) { const QString path = drive.absolutePath(); if ( QgsDirectoryItem::hiddenPath( path ) ) continue; QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, path, path ); item->setSortKey( QStringLiteral( " 3 %1" ).arg( path ) ); mDriveItems.insert( path, item ); setupItemConnections( item ); mRootItems << item; } #ifdef Q_OS_MAC QString path = QString( "/Volumes" ); QgsDirectoryItem *vols = new QgsDirectoryItem( nullptr, path, path ); mRootItems << vols; #endif // container for displaying providers as sorted groups (by QgsDataProvider::DataCapability enum) QMap<int, QgsDataItem *> providerMap; const auto constProviders = QgsApplication::dataItemProviderRegistry()->providers(); for ( QgsDataItemProvider *pr : constProviders ) { int capabilities = pr->capabilities(); if ( capabilities == QgsDataProvider::NoDataCapabilities ) { QgsDebugMsgLevel( pr->name() + " does not have any dataCapabilities", 4 ); continue; } QgsDataItem *item = pr->createDataItem( QString(), nullptr ); // empty path -> top level if ( item ) { // Forward the signal from the root items to the model (and then to the app) connect( item, &QgsDataItem::connectionsChanged, this, &QgsBrowserModel::connectionsChanged ); QgsDebugMsgLevel( "Add new top level item : " + item->name(), 4 ); setupItemConnections( item ); providerMap.insertMulti( capabilities, item ); } } // add as sorted groups by QgsDataProvider::DataCapability enum const auto constUniqueKeys = providerMap.uniqueKeys(); for ( int key : constUniqueKeys ) { QList<QgsDataItem *> providerGroup = providerMap.values( key ); if ( providerGroup.size() > 1 ) { std::sort( providerGroup.begin(), providerGroup.end(), cmpByDataItemName_ ); } const auto constProviderGroup = providerGroup; for ( QgsDataItem *ditem : constProviderGroup ) { mRootItems << ditem; } } }
void Config::setDevices() { // setup devices table qDebug() << "[Config] setting up devices list"; QStringList platformList; if(ui.showDisabled->isChecked()) platformList = SystemInfo::platforms(SystemInfo::PlatformAllDisabled); else platformList = SystemInfo::platforms(SystemInfo::PlatformAll); QMap <QString, QString> manuf; for(int it = 0; it < platformList.size(); it++) { QString curbrand = SystemInfo::platformValue(platformList.at(it), SystemInfo::CurBrand).toString(); manuf.insertMulti(curbrand, platformList.at(it)); } // set up devices table ui.treeDevices->header()->hide(); ui.treeDevices->expandAll(); ui.treeDevices->setColumnCount(1); QList<QTreeWidgetItem *> items; // get manufacturers QStringList brands = manuf.uniqueKeys(); QTreeWidgetItem *w; QTreeWidgetItem *w2; QTreeWidgetItem *w3 = 0; QString selected = RbSettings::value(RbSettings::Platform).toString(); for(int c = 0; c < brands.size(); c++) { w = new QTreeWidgetItem(); w->setFlags(Qt::ItemIsEnabled); w->setText(0, brands.at(c)); items.append(w); // go through platforms and add all players matching the current brand for(int it = 0; it < platformList.size(); it++) { // skip if not current brand if(!manuf.values(brands.at(c)).contains(platformList.at(it))) continue; // construct display name QString curname = SystemInfo::platformValue(platformList.at(it), SystemInfo::CurName).toString() + " (" +ServerInfo::platformValue(platformList.at(it), ServerInfo::CurStatus).toString() +")"; qDebug() << "[Config] add supported device:" << brands.at(c) << curname; w2 = new QTreeWidgetItem(w, QStringList(curname)); w2->setData(0, Qt::UserRole, platformList.at(it)); if(platformList.at(it) == selected) { w2->setSelected(true); w->setExpanded(true); w3 = w2; // save pointer to hilight old selection } items.append(w2); } } // remove any old items in list QTreeWidgetItem* widgetitem; do { widgetitem = ui.treeDevices->takeTopLevelItem(0); delete widgetitem; } while(widgetitem); // add new items ui.treeDevices->insertTopLevelItems(0, items); if(w3 != 0) { ui.treeDevices->setCurrentItem(w3); // hilight old selection ui.treeDevices->scrollToItem(w3); } // tts / encoder tab //encoders updateEncState(); //tts QStringList ttslist = TTSBase::getTTSList(); for(int a = 0; a < ttslist.size(); a++) ui.comboTts->addItem(TTSBase::getTTSName(ttslist.at(a)), ttslist.at(a)); //update index of combobox int index = ui.comboTts->findData(RbSettings::value(RbSettings::Tts).toString()); if(index < 0) index = 0; ui.comboTts->setCurrentIndex(index); updateTtsState(index); }
} Q_ASSERT(false); return false; } //Retrieve field types QMap<QString,QVariant::Type> columnTypeMap = getColumnTypeMap(); QMap<QString,QVariant::Type> datumTypeMap = _exampleDatum->getFieldTypeMap(); //TODO: Simplify type names //Validate types QMap<QString,QVariant::Type> typeMap = columnTypeMap.unite(datumTypeMap); QList<QString> fieldNames = typeMap.uniqueKeys(); //Verify we have two entries per fieldName for(int i=0; i<fieldNames.length(); i++){ QString name = fieldNames[i]; //Field present in database table? if(!columnTypeMap.contains(name)){ DEBUG_MSG() << "Field[" << name << "] not present in existing table[" << _tableName << "]"; success = false; break; }
void AddTestCasesWizard::searchMatchedFiles() { QStringList inputFiles, outputFiles; getFiles(Settings::dataPath(), "", inputFiles); getFiles(Settings::dataPath(), "", outputFiles); QString regExp = getFullRegExp(inputFilesPattern); for (int i = 0; i < inputFiles.size(); i ++) { if (! QRegExp(regExp).exactMatch(inputFiles[i])) { inputFiles.removeAt(i); i --; } } regExp = getFullRegExp(outputFilesPattern); for (int i = 0; i < outputFiles.size(); i ++) { if (! QRegExp(regExp).exactMatch(outputFiles[i])) { outputFiles.removeAt(i); i --; } } qSort(inputFiles.begin(), inputFiles.end(), compareFileName); qSort(outputFiles.begin(), outputFiles.end(), compareFileName); QList<QStringList> inputFilesMatchedPart; QList<QStringList> outputFilesMatchedPart; for (int i = 0; i < inputFiles.size(); i ++) { inputFilesMatchedPart.append(getMatchedPart(inputFiles[i], inputFilesPattern)); } for (int i = 0; i < outputFiles.size(); i ++) { outputFilesMatchedPart.append(getMatchedPart(outputFiles[i], outputFilesPattern)); } QMap<QString, int> loc; QList< QPair<QString, QString> > singleCases; QList< QStringList > matchedPart; for (int i = 0; i < inputFiles.size(); i ++) { loc[inputFilesMatchedPart[i].join("*")] = i; } for (int i = 0; i < outputFiles.size(); i ++) { if (loc.count(outputFilesMatchedPart[i].join("*")) > 0) { int partner = loc[outputFilesMatchedPart[i].join("*")]; singleCases.append(qMakePair(inputFiles[partner], outputFiles[i])); matchedPart.append(outputFilesMatchedPart[i]); } } loc.clear(); for (int i = 0; i < singleCases.size(); i ++) { QStringList key; for (int j = 0; j < ui->argumentList->rowCount(); j ++) { if (ui->argumentList->item(j, 0)->checkState() == Qt::Checked) { key.append(matchedPart[i][j]); } } loc.insertMulti(key.join("*"), i); } matchedInputFiles.clear(); matchedOutputFiles.clear(); ui->testCasesViewer->clear(); QList<QString> keys = loc.uniqueKeys(); qSort(keys.begin(), keys.end(), compareFileName); for (int i = 0; i < keys.size(); i ++) { QList<int> values = loc.values(keys[i]); qSort(values.begin(), values.end()); QStringList inputFiles, outputFiles; QTreeWidgetItem *item = new QTreeWidgetItem(ui->testCasesViewer); item->setText(0, tr("Test Case #%1").arg(i + 1)); for (int j = 0; j < values.size(); j ++) { inputFiles.append(singleCases[values[j]].first); outputFiles.append(singleCases[values[j]].second); QTreeWidgetItem *child = new QTreeWidgetItem(item); child->setText(0, singleCases[values[j]].first); child->setText(1, singleCases[values[j]].second); } matchedInputFiles.append(inputFiles); matchedOutputFiles.append(outputFiles); } ui->testCasesViewer->resizeColumnToContents(0); ui->testCasesViewer->resizeColumnToContents(1); }