QString XCursorThemeData::findAlternative (const QString &name) const { if (alternatives.isEmpty()) { alternatives.reserve(18); // Qt uses non-standard names for some core cursors. // If Xcursor fails to load the cursor, Qt creates it with the correct name using the // core protcol instead (which in turn calls Xcursor). We emulate that process here. // Note that there's a core cursor called cross, but it's not the one Qt expects. alternatives.insert("cross", "crosshair"); alternatives.insert("up_arrow", "center_ptr"); alternatives.insert("wait", "watch"); alternatives.insert("ibeam", "xterm"); alternatives.insert("size_all", "fleur"); alternatives.insert("pointing_hand", "hand2"); // Precomputed MD5 hashes for the hardcoded bitmap cursors in Qt and KDE. // Note that the MD5 hash for left_ptr_watch is for the KDE version of that cursor. alternatives.insert("size_ver", "00008160000006810000408080010102"); alternatives.insert("size_hor", "028006030e0e7ebffc7f7070c0600140"); alternatives.insert("size_bdiag", "c7088f0f3e6c8088236ef8e1e3e70000"); alternatives.insert("size_fdiag", "fcf1c3c7cd4491d801f1e1c78f100000"); alternatives.insert("whats_this", "d9ce0ab605698f320427677b458ad60b"); alternatives.insert("split_h", "14fef782d02440884392942c11205230"); alternatives.insert("split_v", "2870a09082c103050810ffdffffe0204"); alternatives.insert("forbidden", "03b6e0fcb3499374a867c041f52298f0"); alternatives.insert("left_ptr_watch", "3ecb610c1bf2410f44200f48c40d3599"); alternatives.insert("hand2", "e29285e634086352946a0e7090d73106"); alternatives.insert("openhand", "9141b49c8149039304290b508d208c40"); alternatives.insert("closedhand", "05e88622050804100c20044008402080"); } return alternatives.value(name, QString()); }
void OsmAnd::RasterizerEnvironment_P::setSettings(const QHash< QString, QString >& newSettings) { QHash< std::shared_ptr<const MapStyleValueDefinition>, MapStyleValue > resolvedSettings; resolvedSettings.reserve(newSettings.size()); for(const auto& itSetting : rangeOf(newSettings)) { const auto& name = itSetting.key(); const auto& value = itSetting.value(); // Resolve input-value definition by name std::shared_ptr<const MapStyleValueDefinition> inputValueDef; if(!owner->style->resolveValueDefinition(name, inputValueDef)) { LogPrintf(LogSeverityLevel::Warning, "Setting of '%s' to '%s' impossible: failed to resolve input value definition failed with such name"); continue; } // Parse value MapStyleValue parsedValue; if(!owner->style->_p->parseValue(inputValueDef, value, parsedValue)) { LogPrintf(LogSeverityLevel::Warning, "Setting of '%s' to '%s' impossible: failed to parse value"); continue; } resolvedSettings.insert(inputValueDef, parsedValue); } setSettings(resolvedSettings); }
static QHash<QString, QObject*> createObjects(QObject *parent) { const int num = 100; QHash<QString, QObject*> objects; objects.reserve(num); for (int i = 0; i < num; ++i) { objects[QStringLiteral("obj%1").arg(i)] = new BenchObject(parent); } return objects; }
void tst_QScriptValueGenerated::qscriptvalue_castqint32_makeData(const char* expr) { static QHash<QString, qint32> value; if (value.isEmpty()) { value.reserve(148); for (unsigned i = 0; i < 148; ++i) value.insert(qscriptvalue_castqint32_tagArray[i], qscriptvalue_castqint32_valueArray[i]); } newRow(expr) << value.value(expr); }
QHash<int, ListDigraph::Node> ProcessModel::opID2Node() { QHash<int, ListDigraph::Node> res; res.reserve(countNodes(graph)); // Iterate over all nodes of the graph for (ListDigraph::NodeIt it(graph); it != INVALID; ++it) { res[ops[it]->ID] = it; } return res; }
inline void defineCamlClassNames( Smoke *sm ) { camlPolyvarClasses.reserve( camlPolyvarClasses.size() + sm->numClasses + 1 ); const char *s; for ( Smoke::Index i = 0; i < sm->numClasses; ++i ) { s = sm->classes[ i ].className; qDebug() << &( sm->classes[ i ] ) << &s << s; camlPolyvarClasses[ caml_hash_variant( s ) ] = s; } }
QHash<int, QByteArray> roleNames() const { // TODO this is not optimal, but happen once, do we want to do something about it? QHash<int, QByteArray> roles; roles.reserve(_roles.count()); for (QHash<int, QString>::const_iterator i = _roles.constBegin(); i != _roles.constEnd(); ++i) { roles.insert(i.key(), i.value().toUtf8()); } return roles; }
void OsmAnd::MapPresentationEnvironment_P::setSettings(const QHash< QString, QString >& newSettings) { QHash< ResolvedMapStyle::ValueDefinitionId, MapStyleConstantValue > resolvedSettings; resolvedSettings.reserve(newSettings.size()); for (const auto& itSetting : rangeOf(newSettings)) { const auto& name = itSetting.key(); const auto& value = itSetting.value(); // Resolve input-value definition by name const auto valueDefId = owner->resolvedStyle->getValueDefinitionIdByName(name); const auto valueDef = owner->resolvedStyle->getValueDefinitionById(valueDefId); if (!valueDef || valueDef->valueClass != MapStyleValueDefinition::Class::Input) { LogPrintf(LogSeverityLevel::Warning, "Setting of '%s' to '%s' impossible: failed to resolve input value definition failed with such name", qPrintable(name), qPrintable(value)); continue; } // Parse value MapStyleConstantValue parsedValue; if (!owner->resolvedStyle->parseValue(value, valueDef, parsedValue)) { LogPrintf(LogSeverityLevel::Warning, "Setting of '%s' to '%s' impossible: failed to parse value", qPrintable(name), qPrintable(value)); continue; } // Special case for night mode if (valueDefId == MapStyleBuiltinValueDefinitions::get()->id_INPUT_NIGHT_MODE) { _desiredStubsStyle = (parsedValue.asSimple.asInt == 1) ? MapStubStyle::Dark : MapStubStyle::Light; } resolvedSettings.insert(valueDefId, parsedValue); } setSettings(resolvedSettings); }
int numberOfColors(const QImage& image) { const int width = image.width(); const int height = image.height(); // a hash is faster than a set here QHash<QRgb, char> usedColors; // this is about the smallest estimate of any of the actual values // I computed, so it should be an underestimate, but will still // help usedColors.reserve(qMin(static_cast<int>(width*height*.01), 500000)); const char c(' '); // QSet<QRgb> usedColors; for (int j = 0; j < height; ++j) { for (int i = 0; i < width; ++i) { // don't do look ahead - it's slower on photos usedColors[image.pixel(i, j)] = c; } } return usedColors.keys().size(); }
void DataOutputWidget::exportData(QTextStream &stream, const QChar stringsQuoteChar, const QChar numbersQuoteChar, const QString fieldDelimiter, const Options opt) { QItemSelectionModel *selectionModel = m_view->selectionModel(); if (!selectionModel->hasSelection()) return; QString fixedFieldDelimiter = fieldDelimiter; /// FIXME: ugly workaround... fixedFieldDelimiter = fixedFieldDelimiter.replace("\\t", "\t"); fixedFieldDelimiter = fixedFieldDelimiter.replace("\\r", "\r"); fixedFieldDelimiter = fixedFieldDelimiter.replace("\\n", "\n"); QTime t; t.start(); QSet<int> columns; QSet<int> rows; QHash<QPair<int,int>,QString> snapshot; const QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); snapshot.reserve(selectedIndexes.count()); foreach (const QModelIndex& index, selectedIndexes) { const QVariant data = index.data(Qt::UserRole); const int col = index.column(); const int row = index.row(); if (!columns.contains(col)) columns.insert(col); if (!rows.contains(row)) rows.insert(row); if (data.type() < 7) // is numeric or boolean { if (numbersQuoteChar != '\0') snapshot[qMakePair(row,col)] = numbersQuoteChar + data.toString() + numbersQuoteChar; else snapshot[qMakePair(row,col)] = data.toString(); } else { if (stringsQuoteChar != '\0') snapshot[qMakePair(row,col)] = stringsQuoteChar + data.toString() + stringsQuoteChar; else snapshot[qMakePair(row,col)] = data.toString(); } } if (opt.testFlag(ExportColumnNames)) { if (opt.testFlag(ExportLineNumbers)) stream << fixedFieldDelimiter; QSetIterator<int> j(columns); while (j.hasNext()) { const QVariant data = m_model->headerData(j.next(), Qt::Horizontal); if (stringsQuoteChar != '\0') stream << stringsQuoteChar + data.toString() + stringsQuoteChar; else stream << data.toString(); if (j.hasNext()) stream << fixedFieldDelimiter; } stream << "\n"; } foreach(const int row, rows) { if (opt.testFlag(ExportLineNumbers)) stream << row + 1 << fixedFieldDelimiter; QSetIterator<int> j(columns); while (j.hasNext()) { stream << snapshot.value(qMakePair(row,j.next())); if (j.hasNext()) stream << fixedFieldDelimiter; } stream << "\n"; } kDebug() << "Export in" << t.elapsed() << "msecs"; }