uint getIdByElement(Element * element) const { if ( element->isNode() ) { Node * node; node = static_cast<Node *>(element); return nodes.key(node); } else if ( element->isStore() ) { Store * store; store = static_cast<Store *>(element); return stores.key(store); } else if ( element->isSwitch() ) { Switch * aswitch; aswitch = static_cast<Switch *>(element); return switches.key(aswitch); } else { return (uint)-1; } }
void radeon_profile::adjustFanSpeed() { if (device.gpuTemeperatureData.current != device.gpuTemeperatureData.currentBefore) { if (currentFanProfile.contains(device.gpuTemeperatureData.current)) { // Exact match device.setPwmValue(device.features.pwmMaxSpeed * currentFanProfile.value(device.gpuTemeperatureData.current) / 100); return; } // find bounds of current temperature const QMap<int,unsigned int>::const_iterator high = currentFanProfile.upperBound(device.gpuTemeperatureData.current), low = high - 1; int hSpeed = high.value(), lSpeed = low.value(); if (high == currentFanProfile.constBegin()) { device.setPwmValue(device.features.pwmMaxSpeed * hSpeed / 100); return; } if (low == currentFanProfile.constEnd()) { device.setPwmValue(device.features.pwmMaxSpeed * lSpeed / 100); return; } // calculate two point stright line equation based on boundaries of current temperature // y = mx + b = (y2-y1)/(x2-x1)*(x-x1)+y1 int hTemperature = high.key(), lTemperature = low.key(); float speed = (float)((hSpeed - lSpeed) / (hTemperature - lTemperature) * (device.gpuTemeperatureData.current - lTemperature)) + lSpeed; device.setPwmValue(device.features.pwmMaxSpeed * speed / 100); } }
static QString fromEscapedString(const QString & val) { QString ret(val); foreach(const QString & val, escapeCharacters.values()) { ret.replace(val, escapeCharacters.key(val)); } return ret; }
Solid::OpticalDisc::DiscType OpticalDisc::discType() const { const QString discType = m_device->prop("DriveMedia").toString(); QMap<Solid::OpticalDisc::DiscType, QString> map; map[Solid::OpticalDisc::CdRom] = "optical_cd"; map[Solid::OpticalDisc::CdRecordable] = "optical_cd_r"; map[Solid::OpticalDisc::CdRewritable] = "optical_cd_rw"; map[Solid::OpticalDisc::DvdRom] = "optical_dvd"; map[Solid::OpticalDisc::DvdRecordable] = "optical_dvd_r"; map[Solid::OpticalDisc::DvdRewritable] ="optical_dvd_rw"; map[Solid::OpticalDisc::DvdRam] ="optical_dvd_ram"; map[Solid::OpticalDisc::DvdPlusRecordable] ="optical_dvd_plus_r"; map[Solid::OpticalDisc::DvdPlusRewritable] ="optical_dvd_plus_rw"; map[Solid::OpticalDisc::DvdPlusRecordableDuallayer] ="optical_dvd_plus_r_dl"; map[Solid::OpticalDisc::DvdPlusRewritableDuallayer] ="optical_dvd_plus_rw_dl"; map[Solid::OpticalDisc::BluRayRom] ="optical_bd"; map[Solid::OpticalDisc::BluRayRecordable] ="optical_bd_r"; map[Solid::OpticalDisc::BluRayRewritable] ="optical_bd_re"; map[Solid::OpticalDisc::HdDvdRom] ="optical_hddvd"; map[Solid::OpticalDisc::HdDvdRecordable] ="optical_hddvd_r"; map[Solid::OpticalDisc::HdDvdRewritable] ="optical_hddvd_rw"; // TODO add these to Solid //map[Solid::OpticalDisc::MagnetoOptical] ="optical_mo"; //map[Solid::OpticalDisc::MountRainer] ="optical_mrw"; //map[Solid::OpticalDisc::MountRainerWritable] ="optical_mrw_w"; return map.key( discType, Solid::OpticalDisc::UnknownDiscType ); }
void MsgAudioSelectionEngine::HandleQueryCompletedL(CMdEQuery& aQuery, TInt aError) { iNameList.clear(); iUriList.clear(); if (aError == KErrCancel) { emit queryError(aError); return; } else { QMap<QString,QString> nameUriList; CMdEObjectQuery* query = static_cast<CMdEObjectQuery*> (&aQuery); TInt count = query->Count(); for (TInt i = 0; i < count; ++i) { CMdEObject* object = (CMdEObject*) query->TakeOwnershipOfResult(i); CleanupStack::PushL(object); CMdEPropertyDef& propDef = MsgAudioSelectionEngine::PropertyDefL( iSession, MsgAudioSelectionEngine::EAttrFileName); CMdEProperty* property = 0; TInt err = object->Property(propDef, property, 0); if (err != KErrNotFound && property) { QString songName(XQConversions::s60DescToQString( property->TextValueL())); QString uriValue(XQConversions::s60DescToQString( object->Uri())); //insert into the map nameUriList.insertMulti(uriValue, songName); } CleanupStack::PopAndDestroy(object); } //now get all the song names and sort them iNameList = nameUriList.values(); iNameList.sort(); // go through the song list and get the associated uri // insert into the uri list int nameListTotal = iNameList.count(); for(int nameListCount = 0; nameListCount<nameListTotal; nameListCount++) { QString key = nameUriList.key(iNameList.at(nameListCount)); iUriList.append(key); nameUriList.remove(key); } // emit the list to the model emit queryComplete(iNameList, iUriList); } }
QVariant NumberCompletionModel::data(const QModelIndex& index, int role ) const { if (!index.isValid()) return QVariant(); const QMap<int,PhoneNumber*>::iterator i = const_cast<NumberCompletionModel*>(this)->m_hNumbers.end()-1-index.row(); const PhoneNumber* n = i.value(); const int weight = i.key (); bool needAcc = (role>=100 || role == Qt::UserRole) && n->account() && n->account() != AccountListModel::instance()->currentAccount() && n->account()->alias() != Account::ProtocolName::IP2IP; switch (static_cast<NumberCompletionModel::Columns>(index.column())) { case NumberCompletionModel::Columns::CONTENT: switch (role) { case Qt::DisplayRole: return n->uri(); break; case Qt::ToolTipRole: return QString("<table><tr><td>%1</td></tr><tr><td>%2</td></tr></table>").arg(n->primaryName()).arg(n->category()->name()); break; case Qt::DecorationRole: return n->icon(); break; case NumberCompletionModel::Role::ALTERNATE_ACCOUNT: case Qt::UserRole: if (needAcc) return n->account()->alias(); else return QString(); case NumberCompletionModel::Role::FORCE_ACCOUNT: return needAcc; case NumberCompletionModel::Role::ACCOUNT: if (needAcc) return QVariant::fromValue(const_cast<Account*>(n->account())); break; }; break; case NumberCompletionModel::Columns::NAME: switch (role) { case Qt::DisplayRole: return n->primaryName(); }; break; case NumberCompletionModel::Columns::ACCOUNT: switch (role) { case Qt::DisplayRole: return n->account()?n->account()->id():AccountListModel::instance()->currentAccount()->id(); }; break; case NumberCompletionModel::Columns::WEIGHT: switch (role) { case Qt::DisplayRole: return weight; }; break; }; return QVariant(); }
void JoCASSViewer::createViewerForType(QMap<QString,DataViewer*>::iterator view, Result<float>::shared_pointer result) { //qDebug()<<"create viewer"<<view.key()<<result->dim(); switch (result->dim()) { case 0: view.value() = new ZeroDViewer(view.key(),this); break; case 1: view.value() = new OneDViewer(view.key(),this); break; case 2: view.value() = new TwoDViewer(view.key(),this); break; } view.value()->show(); connect(view.value(),SIGNAL(viewerClosed(DataViewer*)), this,SLOT(removeViewer(DataViewer*))); //qDebug()<<"created viewer"<<view.key()<<result->dim(); }
int BookViewPreview::GetSelectionOffset(const QMap<int, QString> &node_offsets, Searchable::Direction search_direction) { QList<ViewEditor::ElementIndex> cl = GetCaretLocation(); // remove final #text node if it exists if (cl.at(cl.count()-1).name == "#text") { cl.removeLast(); } QString caret_node = ConvertHierarchyToQWebPath(cl); bool searching_down = search_direction == Searchable::Direction_Down ? true : false; int local_offset = GetLocalSelectionOffset(!searching_down); int search_start = node_offsets.key(caret_node) + local_offset; return search_start; }
void Plugin::_loadConfiguration() { QMap<QString, gnutls_sec_param_t> secParams; int expiration; int i; secParams.insert("LOW", GNUTLS_SEC_PARAM_LOW); secParams.insert("LEGACY", GNUTLS_SEC_PARAM_LEGACY); secParams.insert("NORMAL", GNUTLS_SEC_PARAM_NORMAL); secParams.insert("HIGH", GNUTLS_SEC_PARAM_HIGH); secParams.insert("ULTRA", GNUTLS_SEC_PARAM_ULTRA); if ((this->priorityStrings = this->api->configuration(true).get("priority_strings").toLatin1()).isEmpty()) this->priorityStrings = "SECURE128:-VERS-SSL3.0"; if ((this->crtFile = this->api->configuration(true).get("crt")).isEmpty()) this->crtFile = "crt.pem"; if ((this->keyFile = this->api->configuration(true).get("key")).isEmpty()) this->keyFile = "key.pem"; if ((this->dhParamsFile = this->api->configuration(true).get("dh_params")).isEmpty()) this->dhParamsFile = "dh_params.pem"; if (!(this->secParam = secParams.value(this->api->configuration(true).get("sec_param").toUpper()))) this->secParam = GNUTLS_SEC_PARAM_HIGH; if (!(expiration = this->api->configuration(true).get("dh_params_expiration").toUInt())) expiration = 90; if (!(this->handshakeTimeout = this->api->configuration(true).get("handshake_timeout").toInt())) this->handshakeTimeout = 5000; if ((this->keyPassword = this->api->configuration(true).get("private_key_password").toLatin1()).isEmpty()) this->api->configuration(true).set("private_key_password", (this->keyPassword = this->_generatePassword())).save(); this->dhParamsExpiration = QDateTime::currentDateTime().addDays(-expiration); this->crtFile.prepend(this->api->getPluginPath()); this->keyFile.prepend(this->api->getPluginPath()); this->dhParamsFile.prepend(this->api->getPluginPath()); // Appends the sec param to the file name if ((i = this->dhParamsFile.lastIndexOf('.')) >= 0) this->dhParamsFile.insert(i, "." + secParams.key(this->secParam).toLower()); else this->dhParamsFile.append("." + secParams.key(this->secParam).toLower()); }
int BookViewPreview::GetSelectionOffset(const QMap<int, QString> &node_offsets, Searchable::Direction search_direction) { QList<ViewEditor::ElementIndex> cl = GetCaretLocation(); // remove final #text node if it exists // Some BookView tabs with only SVG images report a cl.count of 0 // meaning there is no cursor, so test for that case if ((cl.count() > 0) && (cl.at(cl.count()-1).name == "#text")) { cl.removeLast(); } QString caret_node = ConvertHierarchyToQWebPath(cl); bool searching_down = search_direction == Searchable::Direction_Down ? true : false; int local_offset = GetLocalSelectionOffset(!searching_down); int search_start = node_offsets.key(caret_node) + local_offset; return search_start; }
void CP2PServers::SyncServers(const QVariantMap& Response) { QMap<QString, SServer*> OldServers = m_Servers; foreach (const QVariant& vServer,Response["Servers"].toList()) { QVariantMap Server = vServer.toMap(); QString Url = Server["Url"].toString(); SServer* pServer = OldServers.take(Url); if(!pServer) { pServer = new SServer(); pServer->pItem = new QTreeWidgetItem(); m_pServerTree->addTopLevelItem(pServer->pItem); pServer->pItem->setText(eUrl, Url); m_Servers.insert(Url, pServer); } QFont Font = pServer->pItem->font(eUrl); if(Font.bold() != Server["IsStatic"].toBool()) { Font.setBold(Server["IsStatic"].toBool()); pServer->pItem->setFont(eUrl, Font); } pServer->pItem->setText(eName, Server["Name"].toString()); pServer->pItem->setData(eName, Qt::UserRole, Server["IsStatic"]); pServer->pItem->setText(eVersion, Server["Version"].toString()); pServer->pItem->setText(eStatus, Server["Status"].toString()); pServer->pItem->setData(eStatus, Qt::UserRole, Server["Status"]); pServer->pItem->setText(eUsers, Server["UserCount"].toString() + "(" + Server["LowIDCount"].toString() + ")/" + Server["UserLimit"].toString()); pServer->pItem->setText(eFiles, Server["FileCount"].toString() + "|" + Server["HardLimit"].toString() + "(" + Server["SoftLimit"].toString() + ")"); pServer->pItem->setText(eDescription, Server["Description"].toString()); } foreach(SServer* pServer, OldServers) { m_Servers.remove(OldServers.key(pServer)); delete pServer->pItem; delete pServer; }
//read sum rule file to generate CNF file void generateSumCnfFlie() { QFile file(ruleFileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "cannot open file"; return; } QTextStream stream(&file); QFile clauseFile(cnfFileName); if (!clauseFile.open(QIODevice::WriteOnly | QIODevice::Text)) { qDebug() << "cannot open file"; return; } QTextStream cnfStream(&clauseFile); QString resultCnfClause = ""; int numberOfClause = 0; while (!stream.atEnd()) { QString line = stream.readLine(); QStringList elements = line.split(" || "); // qDebug() << "elements:" << elements; QString cnfLine = ""; foreach (QString ele, elements) { bool isNOT = false; QString varLogical = ele.trimmed(); if (ele.contains("!")) { varLogical = varLogical.split("!").at(1); isNOT = true; } if (!mapVariables.values().contains(varLogical)) { mapVariables.insert(globalIndex++,varLogical); } cnfLine.append(QString("%1 ").arg(isNOT ? - mapVariables.key(varLogical) : mapVariables.key(varLogical))); } cnfLine.append("0"); numberOfClause++; resultCnfClause.append(cnfLine).append("\n"); }
void MainForm::handleGpuChange(const QString& type) { QString prev = comboFSAA->currentText(); QList<int> caps = g_mapGPUCaps[type]; int gindex = comboGpuType->currentIndex(); int newindex = 0; comboFSAA->clear(); for(int i=0;i<caps.size();i++) { QString name = g_mapAATypes.key(caps[i]); comboFSAA->addItem(name); if(name == prev) newindex = i; } comboFSAA->setCurrentIndex(newindex); newindex = comboAniso->currentIndex(); comboAniso->clear(); QStringList list; list << "<default>" << "Disabled" << "2x anisotropic filtering"; if(gindex >= 2) { list << "4x anisotropic filtering" << "8x anisotropic filtering"; if(gindex >= 3) list << "16x anisotropic filtering"; } if(newindex > list.size()-1) newindex = list.size()-1; else if(newindex < 0) newindex = 0; comboAniso->addItems(list); comboAniso->setCurrentIndex(newindex); }
void PopupEnumeratedValue::populateRadioButtons(QMap<QString, int> enumeratedValue, bool init) { group = new QButtonGroup(); foreach (int val, enumeratedValue.values()) { QRadioButton *radio = new QRadioButton(enumeratedValue.key(val)); group->addButton(radio); group->setId(radio, val); if(init) { if(m_attribute->defaultValue() == val) radio->setChecked(true); } else { if(m_attribute->currentValue() == val) radio->setChecked(true); } ui->verticalGroupBox->layout()->addWidget(radio); } }
void GraphicsView::scalePixmap() { this->scene()->clear(); int h = pixmap.height() * freqZoomFactor; int w = pixmap.width() * timeZoomFactor; graphicsPixmapItem = this->scene()->addPixmap( pixmap.scaled(w,h,Qt::IgnoreAspectRatio,Qt::SmoothTransformation) ); this->scene()->setSceneRect(0,0,w,h); QMap<QGraphicsItem*,MarkerPoint> tempMap (markerPointMap); markerPointMap.clear(); MarkerPoint::setMaxX( sceneRect().width() ); MarkerPoint::setMaxY( sceneRect().height() ); MarkerPoint marker; foreach (marker,tempMap) { bool selected = ( tempMap.key(marker) == selectedMarker ); marker.refresh(); if (selected) selectedMarker = addItem(marker, markerPointSelectedRadius); else addItem(marker, markerPointRadius); }
bool KEntryMap::getEntryOption(const QMap< KEntryKey, KEntry >::ConstIterator& it, KEntryMap::EntryOption option) const { if (it != constEnd()) { switch (option) { case EntryDirty: return it->bDirty; case EntryLocalized: return it.key().bLocal; case EntryGlobal: return it->bGlobal; case EntryImmutable: return it->bImmutable; case EntryDeleted: return it->bDeleted; case EntryExpansion: return it->bExpand; default: break; // fall through } } return false; }
TimeStepMethod timeStepMethodFromStringKey(const QString &timeStepMethod) { return timeStepMethodList.key(timeStepMethod); }
Hermes::Hermes2D::NormType adaptivityNormTypeFromStringKey(const QString &adaptivityNormType) { return adaptivityNormTypeList.key(adaptivityNormType); }
AdaptivityStoppingCriterionType adaptivityStoppingCriterionFromStringKey(const QString &adaptivityStoppingCriterionType) { return adaptivityStoppingCriterionTypeList.key(adaptivityStoppingCriterionType); }
AdaptivityType adaptivityTypeFromStringKey(const QString &adaptivityType) { return adaptivityTypeList.key(adaptivityType); }
PhysicFieldVariableComp physicFieldVariableCompFromStringKey(const QString &physicFieldVariableComp) { return physicFieldVariableCompList.key(physicFieldVariableComp); }
MeshType meshTypeFromStringKey(const QString &meshType) { return meshTypeList.key(meshType); }
CoordinateType coordinateTypeFromStringKey(const QString &coordinateType) { return coordinateTypeList.key(coordinateType); }
Hermes::Solvers::PreconditionerType iterLinearSolverPreconditionerTypeFromStringKey(const QString &type) { return iterLinearSolverPreconditionerTypeList.key(type); }
QByteArray QGithubMarkdown::write(QTextDocument *source) { QStringList output; bool wasInList = false; bool inCodeBlock = false; auto endCodeBlock = [&]() { if (inCodeBlock) { output.append("```\n"); } inCodeBlock = false; }; auto formatForPos = [&](const QTextBlock &block, const int pos) -> QTextCharFormat { for (const auto fmtRange : block.textFormats()) { if (fmtRange.start <= pos && pos <= (fmtRange.start + fmtRange.length)) { return fmtRange.format; } } Q_ASSERT(false); return QTextCharFormat(); }; auto blockToMarkdown = [&](const QTextBlock &block, const int offset = 0) -> QString { QString out; bool inBold = false; bool inItalic = false; QString currentLink; for (int i = offset; i < block.text().size(); ++i) { const QChar c = block.text().at(i); const QTextCharFormat fmt = formatForPos(block, i); if (fmt.fontItalic() != inItalic) { out.insert(out.size() - 1, '_'); inItalic = !inItalic; } if ((fmt.fontWeight() == QFont::Bold) != inBold) { out.insert(out.size() - 1, "**"); inBold = !inBold; } if (fmt.anchorHref().isEmpty() && !currentLink.isNull()) { out.insert(out.size() - 1, "](" + currentLink + ")"); } else if (!fmt.anchorHref().isEmpty() && currentLink.isNull()) { out.insert(out.size() - 1, "["); currentLink = fmt.anchorHref(); } // FIXME images out.append(c); } return out; }; for (QTextBlock block = source->begin(); block != source->end(); block = block.next()) { // heading if (block.charFormat().toolTip() == block.text()) { endCodeBlock(); output.append(QString(sizeMap.key(block.charFormat().fontPointSize()), '#') + " " + block.text() + "\n"); } else { // list if (QTextList *list = block.textList()) { endCodeBlock(); const QString indent = QString((list->format().indent()-1) * 2, ' '); if (list->format().style() == QTextListFormat::ListDisc) { output.append(indent + "* " + blockToMarkdown(block)); } else { output.append(indent + QString::number(list->itemNumber(block) + 1) + ". " + blockToMarkdown(block)); } wasInList = true; } else { if (wasInList) { output.append(""); wasInList = false; } if (block.charFormat().fontFamily() == "Monospace") { if (!inCodeBlock) { inCodeBlock = true; output.insert(output.size() - 1, "```"); } output.append(block.text().remove("\n")); } else { endCodeBlock(); output.append(blockToMarkdown(block) + "\n"); } } } } QString string = output.join("\n"); return string.trimmed().toUtf8(); }
WeakFormKind weakFormFromStringKey(const QString &weakForm) { return weakFormList.key(weakForm); }
AnalysisType analysisTypeFromStringKey(const QString &analysisType) { return analysisTypeList.key(analysisType); }
WeakFormVariant weakFormVariantFromStringKey(const QString &weakFormVariant) { return weakFormVariantList.key(weakFormVariant); }
void LanguageSelection::Load(void) { MythLocale *locale = new MythLocale(); QString langCode; if (gCoreContext->GetLocale()) { // If the global MythLocale instance exists, then we should use it // since it's informed by previously chosen values from the // database. *locale = *gCoreContext->GetLocale(); } else { // If no global MythLocale instance exists then we're probably // bootstrapping before the database is available, in that case // we want to load language from the locale XML defaults if they // exist. // e.g. the locale defaults might define en_GB for Australia which has // no translation of it's own. We can't automatically derive en_GB // from en_AU which MythLocale will arrive at and there is no 'en' // translation. langCode = locale->GetLocaleSetting("Language"); } if (langCode.isEmpty()) langCode = locale->GetLanguageCode(); QString localeCode = locale->GetLocaleCode(); QString countryCode = locale->GetCountryCode(); LOG(VB_GENERAL, LOG_INFO, QString("System Locale (%1), Country (%2), Language (%3)") .arg(localeCode).arg(countryCode).arg(langCode)); QMap<QString,QString> langMap = MythTranslation::getLanguages(); QStringList langs = langMap.values(); langs.sort(); MythUIButtonListItem *item; bool foundLanguage = false; for (QStringList::Iterator it = langs.begin(); it != langs.end(); ++it) { QString nativeLang = *it; QString code = langMap.key(nativeLang); // Slow, but map is small QString language = GetISO639EnglishLanguageName(code); item = new MythUIButtonListItem(m_languageList, nativeLang); item->SetText(language, "language"); item->SetText(nativeLang, "nativelanguage"); item->SetData(code); // We have to compare against locale for languages like en_GB if (code.toLower() == m_language.toLower() || code == langCode || code == localeCode) { m_languageList->SetItemCurrent(item); foundLanguage = true; } } if (m_languageList->IsEmpty()) { LOG(VB_GUI, LOG_ERR, "ERROR - Failed to load translations, at least " "one translation file MUST be installed."); item = new MythUIButtonListItem(m_languageList, "English (United States)"); item->SetText("English (United States)", "language"); item->SetText("English (United States)", "nativelanguage"); item->SetData("en_US"); } if (!foundLanguage) m_languageList->SetValueByData("en_US"); ISO3166ToNameMap localesMap = GetISO3166EnglishCountryMap(); QStringList locales = localesMap.values(); locales.sort(); for (QStringList::Iterator it = locales.begin(); it != locales.end(); ++it) { QString country = *it; QString code = localesMap.key(country); // Slow, but map is small QString nativeCountry = GetISO3166CountryName(code); item = new MythUIButtonListItem(m_countryList, country); item->SetData(code); item->SetText(country, "country"); item->SetText(nativeCountry, "nativecountry"); item->SetImage(QString("locale/%1.png").arg(code.toLower())); if (code == m_country || code == countryCode) m_countryList->SetItemCurrent(item); } delete locale; }
CouplingType couplingTypeFromStringKey(const QString &couplingType) { return couplingTypeList.key(couplingType); }