void StatOverview::loadAllStat(){ QFile file("etc/total_stat.txt"); if(file.open(QIODevice::ReadOnly)){ QTextStream stream(&file); QHash<QString, QHash<QString, int> > total_stat; QHash<QString, int> stat; QStringList items = Sanguosha->getStatItems(); int i = 0; while(!stream.atEnd()){ QString general_name; stream >> general_name; stat.empty(); foreach(QString item, items) { int value; stream >> value; stat.insert(item, value); } total_stat.insert(general_name, stat); i++; }
int main () { QHash<int, int> myQHash; QHash<int, int> :: iterator it; myQHash[1] = 500; myQHash[2] = 300; myQHash[3] = 100; it = myQHash.begin(); it = myQHash.find(1); if (it.value() == 500) { it = myQHash.erase(it); } it = myQHash.find(2); if (it.value() == 300) { it = myQHash.erase(it); } assert(!(myQHash.empty())); return 0; }
const QHash<Carton::Faces, QVector<Carton::Vertices> > &Carton::facesVerticesHash() { static const struct { const Faces face; const Vertices vertices[4]; //topLeft, topRight, bottomRight, BottomLeft } verticesOfFaces[] = { {Front, {LeftTopFront, RightTopFront, RightBottomFront, LeftBottomFront}}, {Left, {LeftTopBack, LeftTopFront, LeftBottomFront, LeftBottomBack}}, {Right, {RightTopFront, RightTopBack, RightBottomBack, RightBottomFront}}, {Back, {RightTopBack, LeftTopBack, LeftBottomBack, RightBottomBack}}, {Top, {LeftTopBack, RightTopBack, RightTopFront, LeftTopFront}}, {Bottom, {LeftBottomBack, RightBottomBack, RightBottomFront, LeftBottomFront}}, {FrontReflection, {LeftSubFront, RightSubFront, RightBottomFront, LeftBottomFront}}, {LeftReflection, {LeftSubBack, LeftSubFront, LeftBottomFront, LeftBottomBack}}, {RightReflection, {RightSubFront, RightSubBack, RightBottomBack, RightBottomFront}}, {BackReflection, {RightSubBack, LeftSubBack, LeftBottomBack, RightBottomBack}} }; static const size_t facesCount = sizeof(verticesOfFaces)/sizeof(verticesOfFaces[0]); static const size_t verticesPerFaceCount = sizeof(verticesOfFaces[0].vertices)/sizeof(verticesOfFaces[0].vertices[0]); static QHash<Faces, QVector<Vertices> > result; if (result.empty()) { for (size_t faceIndex = 0; faceIndex < facesCount; faceIndex++) { QVector<Vertices> vertices(verticesPerFaceCount); for (size_t vertexIndex = 0; vertexIndex < verticesPerFaceCount; vertexIndex++) vertices[vertexIndex] = verticesOfFaces[faceIndex].vertices[vertexIndex]; result[verticesOfFaces[faceIndex].face] = vertices; } } return result; }
BattlePStorage::BattlePStorage(BattlePlugin *p) { for (int i = 0; i < lastEnum; i++) { calls[i] = NULL; } QHash<QString, Hook> functions = p->getHooks(); if (functions.contains("battleStarting(BattleInterface&)")) { calls[battleStarting] = functions.value("battleStarting(BattleInterface&)"); functions.remove("battleStarting(BattleInterface&)"); } if (functions.contains("emitCommand(BattleInterface&,int,int,QByteArray)")) { calls[emitCommand] = functions.value("emitCommand(BattleInterface&,int,int,QByteArray)"); functions.remove("emitCommand(BattleInterface&,int,int,QByteArray)"); } if (!functions.empty()) { /* To Do: Some way to propagate an error about unreckognized stuff, maybe cancel the plugin entirely */ } plugin = p; }
QHash<int, QByteArray> QObjectListModel::roleNames() const { static QHash<int, QByteArray> roles; if(roles.empty()) { roles[Qt::UserRole + 1] = "object"; } return roles; }
static const QHash<QString, LayoutInfo::Type> &layoutNameTypeMap() { static QHash<QString, LayoutInfo::Type> nameTypeMap; if (nameTypeMap.empty()) { nameTypeMap.insert(QLatin1String("QVBoxLayout"), LayoutInfo::VBox); nameTypeMap.insert(QLatin1String("QHBoxLayout"), LayoutInfo::HBox); nameTypeMap.insert(QLatin1String("QGridLayout"), LayoutInfo::Grid); nameTypeMap.insert(QLatin1String("QFormLayout"), LayoutInfo::Form); } return nameTypeMap; }
LayoutInfo::Type LayoutInfo::layoutType(const QString &typeName) { static QHash<QString, Type> nameTypeMap; if (nameTypeMap.empty()) { nameTypeMap.insert(QLatin1String("QVBoxLayout"), VBox); nameTypeMap.insert(QLatin1String("QHBoxLayout"), HBox); nameTypeMap.insert(QLatin1String("QGridLayout"), Grid); nameTypeMap.insert(QLatin1String("QFormLayout"), Form); } return nameTypeMap.value(typeName, NoLayout); }
// open() button uses this void PlaylistModel::addMedia(const QStringList& fileNames) { // append media to end of m_data int start = m_data.size(); foreach(QString const &path, fileNames) { QHash<QString, QString> hash; u->get_metaData(path, hash); if (!hash.empty()) { beginInsertRows(QModelIndex(), start, start); m_data.append(hash); start = start+1; emit(mediaAddedToPlaylist(hash["absFilePath"])); endInsertRows(); } }
// Quick lookup by name static LayoutPropertyType layoutPropertyType(const QString &name) { static QHash<QString, LayoutPropertyType> namePropertyMap; if (namePropertyMap.empty()) { namePropertyMap.insert(QLatin1String(leftMargin), LayoutPropertyLeftMargin); namePropertyMap.insert(QLatin1String(topMargin), LayoutPropertyTopMargin); namePropertyMap.insert(QLatin1String(rightMargin), LayoutPropertyRightMargin); namePropertyMap.insert(QLatin1String(bottomMargin), LayoutPropertyBottomMargin); namePropertyMap.insert(QLatin1String(horizontalSpacing), LayoutPropertyHorizontalSpacing); namePropertyMap.insert(QLatin1String(verticalSpacing), LayoutPropertyVerticalSpacing); namePropertyMap.insert(QLatin1String(spacing), LayoutPropertySpacing); namePropertyMap.insert(QLatin1String(margin), LayoutPropertyMargin); namePropertyMap.insert(QLatin1String(sizeConstraint), LayoutPropertySizeConstraint); } return namePropertyMap.value(name, LayoutPropertyNone); }
const QHash<QString, QSizeF> &Types::paperFormats() { static QHash<QString, QSizeF> formats; if (formats.empty()) { static const struct { QString name; qreal width; qreal height; } paperFormats[] = { {QLatin1String("DIN A4"), 21.0, 29.7}, {QLatin1String("DIN A3"), 29.7, 42.0}, {QLatin1String("Legal"), 21.6, 35.6}, {QLatin1String("Letter"), 21.6, 27.9}, {QLatin1String("Tabloid"), 27.9, 43.2} }; static const int paperFormatsCount = int(sizeof paperFormats / sizeof paperFormats[0]); for (int i = 0; i < paperFormatsCount; i++) formats.insert(paperFormats[i].name, QSizeF(paperFormats[i].width, paperFormats[i].height)); } return formats; }
const QHash<Types::UnitsOfLength, QPair<QString, qreal> > &Types::unitsOfLength() { static QHash<UnitsOfLength, QPair<QString, qreal> > units; if (units.empty()) { static const struct { UnitsOfLength unit; QString name; qreal cm; } unitsOfLength[] = { {UnitOfLengthMeter, QLatin1String("m"), 100.00}, {UnitOfLengthMillimeter, QLatin1String("mm"), 0.10}, {UnitOfLengthCentimeter, QLatin1String("cm"), 1.00}, {UnitOfLengthInch, QLatin1String("in"), 2.54}, {UnitOfLengthFeet, QLatin1String("ft"), 2.54 * 12.00}, {UnitOfLengthPoints, QLatin1String("pt"), 2.54 / 72.00} }; static const int unitsOfLengthCount = int(sizeof unitsOfLength / sizeof unitsOfLength[0]); for (int i = 0; i < unitsOfLengthCount; i++) units.insert(unitsOfLength[i].unit, QPair<QString, qreal> (unitsOfLength[i].name, unitsOfLength[i].cm)); } return units; }
void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit ) { QHash< QgsSymbol *, QList<QgsFeature> > features; // key = symbol, value = array of features QgsSingleSymbolRenderer *selRenderer = nullptr; if ( !mSelectedFeatureIds.isEmpty() ) { selRenderer = new QgsSingleSymbolRenderer( QgsSymbol::defaultSymbol( mGeometryType ) ); selRenderer->symbol()->setColor( mContext.selectionColor() ); selRenderer->setVertexMarkerAppearance( mVertexMarkerStyle, mVertexMarkerSize ); selRenderer->startRender( mContext, mFields ); } QgsExpressionContextScope *symbolScope = QgsExpressionContextUtils::updateSymbolScope( nullptr, new QgsExpressionContextScope() ); mContext.expressionContext().appendScope( symbolScope ); // 1. fetch features QgsFeature fet; while ( fit.nextFeature( fet ) ) { if ( mContext.renderingStopped() ) { qDebug( "rendering stop!" ); stopRenderer( selRenderer ); delete mContext.expressionContext().popScope(); return; } if ( !fet.hasGeometry() ) continue; // skip features without geometry mContext.expressionContext().setFeature( fet ); QgsSymbol *sym = mRenderer->symbolForFeature( fet, mContext ); if ( !sym ) { continue; } if ( !features.contains( sym ) ) { features.insert( sym, QList<QgsFeature>() ); } features[sym].append( fet ); // new labeling engine if ( mContext.labelingEngine() ) { QgsGeometry obstacleGeometry; QgsSymbolList symbols = mRenderer->originalSymbolsForFeature( fet, mContext ); if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry ) { obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ); } if ( !symbols.isEmpty() ) { QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope ); } if ( mLabelProvider ) { mLabelProvider->registerFeature( fet, mContext, obstacleGeometry ); } if ( mDiagramProvider ) { mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry ); } } } delete mContext.expressionContext().popScope(); if ( features.empty() ) { // nothing to draw stopRenderer( selRenderer ); return; } // find out the order QgsSymbolLevelOrder levels; QgsSymbolList symbols = mRenderer->symbols( mContext ); for ( int i = 0; i < symbols.count(); i++ ) { QgsSymbol *sym = symbols[i]; for ( int j = 0; j < sym->symbolLayerCount(); j++ ) { int level = sym->symbolLayer( j )->renderingPass(); if ( level < 0 || level >= 1000 ) // ignore invalid levels continue; QgsSymbolLevelItem item( sym, j ); while ( level >= levels.count() ) // append new empty levels levels.append( QgsSymbolLevel() ); levels[level].append( item ); } } // 2. draw features in correct order for ( int l = 0; l < levels.count(); l++ ) { QgsSymbolLevel &level = levels[l]; for ( int i = 0; i < level.count(); i++ ) { QgsSymbolLevelItem &item = level[i]; if ( !features.contains( item.symbol() ) ) { QgsDebugMsg( QStringLiteral( "level item's symbol not found!" ) ); continue; } int layer = item.layer(); QList<QgsFeature> &lst = features[item.symbol()]; QList<QgsFeature>::iterator fit; for ( fit = lst.begin(); fit != lst.end(); ++fit ) { if ( mContext.renderingStopped() ) { stopRenderer( selRenderer ); return; } bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fit->id() ); // maybe vertex markers should be drawn only during the last pass... bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) ); mContext.expressionContext().setFeature( *fit ); try { mRenderer->renderFeature( *fit, mContext, layer, sel, drawMarker ); } catch ( const QgsCsException &cse ) { Q_UNUSED( cse ); QgsDebugMsg( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" ) .arg( fet.id() ).arg( cse.what() ) ); } } } } stopRenderer( selRenderer ); }
void CDspVmAutoTaskManagerBase::timerEvent(QTimerEvent* te) { if (!IsInitialized()) { WRITE_TRACE( DBG_WARNING, "Timer event on unitialized %s manager", getManagerName() ); return; } // Looking for proper VM ident. bool bRestartTimer = false; TimerInfo timerInfo; CVmIdent vmIdent; { QMutexLocker locker(&m_lockVmIdents); QMap<CVmIdent, TimerInfo >::iterator it; for(it = m_mapVmIdents.begin(); it != m_mapVmIdents.end(); ++it) { timerInfo = it.value(); if (timerInfo.iTimerId == te->timerId()) break; } if ( it == m_mapVmIdents.end() || timerInfo.bTaskInUse) return; vmIdent = it.key(); bRestartTimer = (timerInfo.iPeriod != timerInfo.iOriginalPeriod); if (bRestartTimer) { emit killVmTimerSignal(timerInfo.iTimerId); m_mapVmIdents.remove(vmIdent); } } if (bRestartTimer) { emit startVmTimerSignal(vmIdent, timerInfo.iOriginalPeriod, timerInfo.iOriginalPeriod); } // Store timestamp { CDspLockedPointer<QSettings> pQSettings = CDspService::instance()->getQSettings(); QString qsGroup = getSettingsGroupKey(vmIdent); pQSettings->beginGroup(qsGroup); pQSettings->setValue(getSettingsKeyTimestamp(), QVariant(QDateTime::currentDateTime())); pQSettings->endGroup(); } // Get client QHash< IOSender::Handle, SmartPtr<CDspClient> > hashClients = CDspService::instance()->getClientManager().getSessionListByVm( vmIdent.second, vmIdent.first, CDspAccessManager::VmAccessRights::makeModeRWX() ); if ( hashClients.empty() ) { WRITE_TRACE(DBG_FATAL, "No clients connect to VM %s with required permissions", QSTR2UTF8(vmIdent.first) ); return; } // Start auto task if ( ! updateTaskState(vmIdent, true) ) return; // Fake client SmartPtr<CDspClient> pClient( new CDspClient(IOSender::Handle()) ); pClient->getAuthHelper().AuthUserBySelfProcessOwner(); pClient->setVmDirectoryUuid(vmIdent.second); startTask( pClient, vmIdent ); }
bool Args::parse(int argc, char **argv){ /* Simple class to parse some commandline arguments */ QTextStream qerr(stderr, QIODevice::WriteOnly); QHash<QString, QString> args; /* to accept parameters like -f=spam-eggs */ QRegExp short_key_value_re("-([^=-])=(.+)"); /* to accept parameters like -f */ QRegExp short_key_re("-([^=-]+)"); /* to accept parameters like --foo-bar=spam-eggs */ QRegExp key_value_re("--([^=]+)=(.+)"); /* to accept parameters like --foo-bar */ QRegExp key_re("--([^=]+)"); /* to accept values for space separated parameters */ QRegExp value_re("([^-]+.*|.)"); /* Using argc/argv so all parameters work, not just the ones not filtered out by Qt */ program = QString(argv[0]); for(int i=1; i<argc; i++){ int j; QString key; QString value; QString tmp = QString(argv[i]); if(short_key_value_re.exactMatch(tmp)){ key = short_key_value_re.cap(1); value = short_key_value_re.cap(2); if(key.length() > 1){ qerr << "Can't have multiple short arguments with values." \ << endl; qerr << "Did you forget a '-'? Try --" << key << "=" \ << value << " instead" << endl; return false; } }else if(short_key_re.exactMatch(tmp)){ key = short_key_re.cap(1); if(short_key_re.cap(1).length() != 1){ j = short_key_re.cap(1).length(); while(j--){ args.insert(QString(key[j]), value); } continue; } }else if(key_value_re.exactMatch(tmp)){ key = key_value_re.cap(1); value = key_value_re.cap(2); }else if(key_re.exactMatch(tmp)){ key = key_re.cap(1); } if(i+1 < argc){ tmp = QString(argv[i+1]); if(value == NULL && value_re.exactMatch(tmp)){ i++; value = value_re.cap(1); } } args.insert(key, value); } QHashIterator<QString, Arg*> j(this->args); while(j.hasNext()){ j.next(); Arg arg = *j.value(); if(args.contains(arg.getName())){ /* Called help, exiting to display help */ if(arg.getName() == "help"){ return false; } insert(arg.getName(), arg.callback(args.take(arg.getName()))); }else if(args.contains(arg.getShortname())){ /* Called help, exiting to display help */ if(arg.getName() == "help"){ return false; } insert(arg.getName(), arg.callback(args.take(arg.getShortname()))); }else if(arg.getRequired()){ qerr << "Argument '" << j.key() \ << "' is required and not given." << endl; return false; }else{ insert(arg.getName(), arg.getDefault()); } } if(!args.empty()){ qerr << "The following unsupported arguments were found:" << endl; QHashIterator<QString, QString> j(args); while(j.hasNext()){ j.next(); if(j.key().length() == 1){ qerr << "\t-"; }else{ qerr << "\t--"; } qerr << j.key(); if(j.value() != ""){ qerr << " with value: " << j.value(); } qerr << endl; } return false; } return true; }
static QHash<QString, Key> getMap(KeyMap::Model model, KeyMap::Layout layout){ if(model < 0 || layout < 0 || model >= N_MODELS || layout >= N_LAYOUTS) return QHash<QString, Key>(); // Return the map if it's already filled out QHash<QString, Key>& map = standardMaps[model][layout]; if(!map.empty()) return map; // Otherwise, create it switch(model){ case KeyMap::K95:{ // The K95 maps serve as bases for all the other keyboards // Fetch the master map, or create it if not yet done if(K95BaseMap.empty()){ for(const Key* key = K95Keys; key < K95Keys + KEYCOUNT_K95; key++) K95BaseMap[key->name] = *key; } map = K95BaseMap; // Patch the map for the layout switch(layout){ case KeyMap::FR: patch(map, patchFR); break; case KeyMap::DE: patch(map, patchDE); break; case KeyMap::ES: patch(map, patchES); break; case KeyMap::SE: patch(map, patchSE); break; case KeyMap::GB_DVORAK: case KeyMap::US_DVORAK: patch(map, patchDvorak); break; default:; // English QWERTY - no patch needed } if(KeyMap::isISO(layout)) patchISO(map); else patchANSI(map); // Done! return the map break; } case KeyMap::K70:{ // The K70 maps are based on the K95 maps. However all the keys are shifted left and the G keys are removed map = getMap(KeyMap::K95, layout); QMutableHashIterator<QString, Key> i(map); while(i.hasNext()){ i.next(); // Move key to left. Remove it if it fell off the edge if((i.value().x -= K70_X_START) < 0) i.remove(); } // Remove the M buttons as well map.remove("mr"); map.remove("m1"); map.remove("m2"); map.remove("m3"); // Done! break; } case KeyMap::K65:{ // The K65 maps additionally remove the numpad and have a modified top row map = getMap(KeyMap::K70, layout); QMutableHashIterator<QString, Key> i(map); while(i.hasNext()){ i.next(); if(i.value().x >= K65_WIDTH) i.remove(); } for(const Key* key = K65TopRow; key < K65TopRow + K65_TOP_COUNT; key++) map[key->name] = *key; // Done! break; } case KeyMap::M65:{ // M65 isn't a keyboard; it has its own base for(const Key* key = M65Keys; key < M65Keys + KEYCOUNT_M65; key++){ // Keyboard keys are written from the center because that's where the LEDs are, but the mouse buttons are odd shapes so they're // written from the upper left Key translatedKey = *key; translatedKey.x += translatedKey.width / 2; translatedKey.y += translatedKey.height / 2; M65BaseMap[key->name] = translatedKey; } map = M65BaseMap; // Mice have no layout patches - no other changes necessary break; } default:; // <- stop GCC from complaining } // Map is finished, return result return map; }
ParameterizedCommand::Pointer ParameterizedCommand::GenerateCommand(const SmartPointer<Command> command, const QHash<QString, Object::Pointer>& parameters) { // no parameters if (parameters.empty()) { ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command, QList<Parameterization>())); return pCmd; } try { QList<Parameterization> parms; // iterate over given parameters for (QHash<QString, Object::Pointer>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) { QString key(i.key()); // get the parameter from the command IParameter::Pointer parameter(command->GetParameter(key)); // if the parameter is defined add it to the parameter list if (!parameter) { return ParameterizedCommand::Pointer(0); } ParameterType::Pointer parameterType(command->GetParameterType(key)); if (!parameterType) { QString val = i.value()->ToString(); parms.push_back(Parameterization(parameter, val)); } else { IParameterValueConverter* valueConverter(parameterType->GetValueConverter()); if (valueConverter) { QString val(valueConverter->ConvertToString(i.value())); parms.push_back(Parameterization(parameter, val)); } else { QString val = i.value()->ToString(); parms.push_back(Parameterization(parameter, val)); } } } // convert the parameters to an Parameterization array and create // the command ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command, parms)); return pCmd; } catch (const NotDefinedException* /*e*/) { } catch (const ParameterValueConversionException* /*e*/) { } return ParameterizedCommand::Pointer(0); }