/*! Removes the mapping from application \a app to its process id. \internal */ void OomPrivate::remove(const QString& app) { if (app.isEmpty()) return; int pid = 0; QMap<QString,int>::iterator i; i = important_procs_.find(app); if (i != important_procs_.end()) { pid = i.value(); important_procs_.erase(i); qLog(OOM) << "Removed important proc:" << app << pid; return; } i = critical_procs_.find(app); if (i != critical_procs_.end()) { pid = i.value(); critical_procs_.erase(i); qLog(OOM) << "Removed critical proc:" << app << pid; return; } i = expendable_procs_.find(app); if (i != expendable_procs_.end()) { pid = i.value(); expendable_procs_.erase(i); qLog(OOM) << "Removed expendable proc:" << app << pid; return; } }
ConfCertDialog::~ConfCertDialog() { QMap<RsPeerId, ConfCertDialog*>::iterator it = instances_ssl.find(peerId); if (it != instances_ssl.end()) instances_ssl.erase(it); QMap<RsPgpId, ConfCertDialog*>::iterator it2 = instances_pgp.find(pgpId); if (it2 != instances_pgp.end()) instances_pgp.erase(it2); }
ConfCertDialog::~ConfCertDialog() { // if(peerId.isNull()) { QMap<RsPeerId, ConfCertDialog*>::iterator it = instances_ssl.find(peerId); if (it != instances_ssl.end()) instances_ssl.erase(it); } // else { QMap<RsPgpId, ConfCertDialog*>::iterator it = instances_pgp.find(pgpId); if (it != instances_pgp.end()) instances_pgp.erase(it); } }
void ConfigurationScreens::prepareScreens(QMap<int, OutputScreen *> & screens) { BackendConfiguration * config = BackendConfigurations::self()->activeBackendConfiguration(); if (! config) { return; } if (config->name() == "external") { screens.clear(); return; } QMap<int, QRect> layout = config->realLayout(); for (QMap<int, QRect>::const_iterator i = layout.constBegin(); i != layout.constEnd(); ++i) { if (screens.contains(i.key())) { screens[i.key()]->_setGeom(i.value()); } else { OutputScreen * screen = new OutputScreen(this); screen->_setId(i.key()); screen->_setGeom(i.value()); screens.insert(screen->id(), screen); } } for (QMap<int, OutputScreen *>::iterator i = screens.begin(); i != screens.end();) { if (! layout.contains(i.key())) { i = screens.erase(i); } else { ++i; } } }
ConfCertDialog::~ConfCertDialog() { QMap<std::string, ConfCertDialog*>::iterator it = instances.find(mId); if (it != instances.end()) { instances.erase(it); } }
/*! Convenience function that attempts to unlock the file with identifier \a id that was locked by \c QMail::fileLock. Returns \c true for success or \c false otherwise. \sa QMail::fileLock() */ bool QMail::fileUnlock(int id) { #ifdef Q_OS_WIN QMap<int, HANDLE>::iterator it = lockedFiles.find(id); if (it != lockedFiles.end()) { if (::UnlockFile(it.value(), 0, 0, 1, 0) == FALSE) { qWarning() << "Unable to unlock file:" << lastSystemErrorMessage(); } else { if (::CloseHandle(it.value()) == FALSE) { qWarning() << "Unable to close handle:" << lastSystemErrorMessage(); } lockedFiles.erase(it); return true; } } return false; #else int result = -1; result = ::close(id); if (result == -1) return false; return true; #endif }
extern "C" void qtns_destroy(QtNPInstance *This) { QMap<QtNPInstance *, QX11EmbedWidget *>::iterator it = clients.find(This); if (it == clients.end()) return; delete it.value(); clients.erase(it); }
bool Injector::addTranslator(QString fn) { if (_repMap.contains(fn)) _repMap.erase(_repMap.find(fn)); if (!_newTrans.contains(fn)) _newTrans[fn] = (new QTranslator()); return Injector::instance().Wrapper->Call_QTranslator_load(_newTrans[fn], fn, QString(), QString(), QString()); }
void removeCustomField(const QString &name) { QMap<QString, QString>::iterator it = _customFields.find(name); if (it != _customFields.end()) { _customFields.erase(it); _customFieldsModified = true; } }
static void clear(QMap<int, T*> &temp) { QMap<int, T*> clearMap = temp; typename QMap<int, T*>::iterator it; for(it = clearMap.begin(); it != clearMap.end(); ) { SAFE_DELETE(it.value()); clearMap.erase(it++); } clearMap.clear(); }
ReferenceCounter::~ReferenceCounter(void) { if (0 != m_referenceCount) { LOG(VB_GENERAL, LOG_ERR, "Object deleted with non-zero reference count!"); } #ifdef LEAK_DEBUG QWriteLocker locker(&leakLock); leakMap.erase(leakMap.find(this)); #endif }
ReferenceCounter::~ReferenceCounter(void) { if (m_referenceCount.fetchAndAddRelaxed(0) > 1) { LOG(VB_GENERAL, LOG_ERR, "Object deleted with non-zero or one reference count!"); } #ifdef LEAK_DEBUG QWriteLocker locker(&leakLock); leakMap.erase(leakMap.find(this)); #endif }
static void foldNode(QDomElement &docElem, QDomElement &e, QMap<QString,QDomElement> &dupeList, QString s=QString()) //krazy:exclude=passbyvalue { if (s.isEmpty()) s = e.text(); QMap<QString,QDomElement>::iterator it = dupeList.find(s); if (it != dupeList.end()) { kDebug(7021) << e.tagName() << "and" << s << "requires combining!"; docElem.removeChild(*it); dupeList.erase(it); } dupeList.insert(s, e); }
void FdoSelectionManager::removeDamageWatch(QWidget *container) { #if defined(HAVE_XFIXES) && defined(HAVE_XDAMAGE) && defined(HAVE_XCOMPOSITE) for (QMap<WId, DamageWatch*>::Iterator it = damageWatches.begin(); it != damageWatches.end(); ++it) { DamageWatch *damage = *(it); if (damage->container == container) { XDamageDestroy(QX11Info::display(), damage->damage); damageWatches.erase(it); delete damage; break; } } #endif }
int main () { QMap<char,int> myQMap; myQMap['a']=10; myQMap['b']=20; myQMap['c']=30; while (!myQMap.empty()) { cout << myQMap.begin().key() << " => "; cout << myQMap.begin().value() << endl; myQMap.erase(myQMap.begin()); } assert(!myQMap.empty()); return 0; }
/*! Convenience function that attempts to unlock the file with identifier \a id that was locked by \c QMail::fileLock. Returns \c true for success or \c false otherwise. \sa QMail::fileLock() */ bool QMail::fileUnlock(int id) { #ifdef Q_OS_WIN QMap<int, HANDLE>::iterator it = lockedFiles.find(id); if (it != lockedFiles.end()) { if (::UnlockFile(it.value(), 0, 0, 1, 0) == FALSE) { qWarning() << "Unable to unlock file:" << lastSystemErrorMessage(); } else { if (::CloseHandle(it.value()) == FALSE) { qWarning() << "Unable to close handle:" << lastSystemErrorMessage(); } lockedFiles.erase(it); return true; } } return false; #else struct flock fl; fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; int result = -1; if((result = ::fcntl(id,F_SETLK, &fl)) == -1) return false; if((result = ::close(id)) == -1) return false; return true; #endif }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindNeighbors::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName()); size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); size_t totalFeatures = m_NumNeighborsPtr.lock()->getNumberOfTuples(); size_t udims[3] = { 0, 0, 0 }; m->getGeometryAs<ImageGeom>()->getDimensions(udims); #if (CMP_SIZEOF_SIZE_T == 4) typedef int32_t DimType; #else typedef int64_t DimType; #endif DimType dims[3] = { static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), }; DimType neighpoints[6] = { 0, 0, 0, 0, 0, 0 }; neighpoints[0] = -dims[0] * dims[1]; neighpoints[1] = -dims[0]; neighpoints[2] = -1; neighpoints[3] = 1; neighpoints[4] = dims[0]; neighpoints[5] = dims[0] * dims[1]; DimType column = 0, row = 0, plane = 0; int32_t feature = 0; int32_t nnum = 0; int8_t onsurf = 0; bool good = false; DimType neighbor = 0; std::vector<std::vector<int32_t> > neighborlist; std::vector<std::vector<float> > neighborsurfacearealist; int32_t nListSize = 100; neighborlist.resize(totalFeatures); neighborsurfacearealist.resize(totalFeatures); uint64_t millis = QDateTime::currentMSecsSinceEpoch(); uint64_t currentMillis = millis; for (size_t i = 1; i < totalFeatures; i++) { currentMillis = QDateTime::currentMSecsSinceEpoch(); if (currentMillis - millis > 1000) { QString ss = QObject::tr("Finding Neighbors || Initializing Neighbor Lists || %1% Complete").arg((static_cast<float>(i) / totalFeatures) * 100); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); millis = QDateTime::currentMSecsSinceEpoch(); } if (getCancel() == true) { return; } m_NumNeighbors[i] = 0; neighborlist[i].resize(nListSize); neighborsurfacearealist[i].assign(nListSize, -1.0f); if (m_StoreSurfaceFeatures == true) { m_SurfaceFeatures[i] = false; } } for (size_t j = 0; j < totalPoints; j++) { currentMillis = QDateTime::currentMSecsSinceEpoch(); if (currentMillis - millis > 1000) { QString ss = QObject::tr("Finding Neighbors || Determining Neighbor Lists || %1% Complete").arg((static_cast<float>(j) / totalPoints) * 100); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); millis = QDateTime::currentMSecsSinceEpoch(); } if (getCancel() == true) { return; } onsurf = 0; feature = m_FeatureIds[j]; if (feature > 0) { column = static_cast<DimType>( j % m->getGeometryAs<ImageGeom>()->getXPoints() ); row = static_cast<DimType>( (j / m->getGeometryAs<ImageGeom>()->getXPoints()) % m->getGeometryAs<ImageGeom>()->getYPoints() ); plane = static_cast<DimType>( j / (m->getGeometryAs<ImageGeom>()->getXPoints() * m->getGeometryAs<ImageGeom>()->getYPoints()) ); if (m_StoreSurfaceFeatures == true) { if ((column == 0 || column == DimType((m->getGeometryAs<ImageGeom>()->getXPoints() - 1)) || row == 0 || row == DimType((m->getGeometryAs<ImageGeom>()->getYPoints()) - 1) || plane == 0 || plane == DimType((m->getGeometryAs<ImageGeom>()->getZPoints() - 1))) && m->getGeometryAs<ImageGeom>()->getZPoints() != 1) { m_SurfaceFeatures[feature] = true; } if ((column == 0 || column == DimType((m->getGeometryAs<ImageGeom>()->getXPoints() - 1)) || row == 0 || row == DimType((m->getGeometryAs<ImageGeom>()->getYPoints() - 1))) && m->getGeometryAs<ImageGeom>()->getZPoints() == 1) { m_SurfaceFeatures[feature] = true; } } for (int32_t k = 0; k < 6; k++) { good = true; neighbor = static_cast<DimType>( j + neighpoints[k] ); if (k == 0 && plane == 0) { good = false; } if (k == 5 && plane == (m->getGeometryAs<ImageGeom>()->getZPoints() - 1)) { good = false; } if (k == 1 && row == 0) { good = false; } if (k == 4 && row == (m->getGeometryAs<ImageGeom>()->getYPoints() - 1)) { good = false; } if (k == 2 && column == 0) { good = false; } if (k == 3 && column == (m->getGeometryAs<ImageGeom>()->getXPoints() - 1)) { good = false; } if (good == true && m_FeatureIds[neighbor] != feature && m_FeatureIds[neighbor] > 0) { onsurf++; nnum = m_NumNeighbors[feature]; neighborlist[feature].push_back(m_FeatureIds[neighbor]); nnum++; m_NumNeighbors[feature] = nnum; } } } if (m_StoreBoundaryCells == true) { m_BoundaryCells[j] = onsurf; } } // We do this to create new set of NeighborList objects for (size_t i = 1; i < totalFeatures; i++) { currentMillis = QDateTime::currentMSecsSinceEpoch(); if (currentMillis - millis > 1000) { QString ss = QObject::tr("Finding Neighbors || Calculating Surface Areas || %1% Complete").arg(((float)i / totalFeatures) * 100); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); millis = QDateTime::currentMSecsSinceEpoch(); } if(getCancel() == true) { return; } QMap<int32_t, int32_t> neighToCount; int32_t numneighs = static_cast<int32_t>( neighborlist[i].size() ); // this increments the voxel counts for each feature for (int32_t j = 0; j < numneighs; j++) { neighToCount[neighborlist[i][j]]++; } QMap<int32_t, int32_t>::Iterator neighiter = neighToCount.find(0); neighToCount.erase(neighiter); neighiter = neighToCount.find(-1); neighToCount.erase(neighiter); // Resize the features neighbor list to zero neighborlist[i].resize(0); neighborsurfacearealist[i].resize(0); for (QMap<int32_t, int32_t>::iterator iter = neighToCount.begin(); iter != neighToCount.end(); ++iter) { int32_t neigh = iter.key(); // get the neighbor feature int32_t number = iter.value(); // get the number of voxels float area = float(number) * m->getGeometryAs<ImageGeom>()->getXRes() * m->getGeometryAs<ImageGeom>()->getYRes(); // Push the neighbor feature id back onto the list so we stay synced up neighborlist[i].push_back(neigh); neighborsurfacearealist[i].push_back(area); } m_NumNeighbors[i] = int32_t(neighborlist[i].size()); // Set the vector for each list into the NeighborList Object NeighborList<int32_t>::SharedVectorType sharedNeiLst(new std::vector<int32_t>); sharedNeiLst->assign(neighborlist[i].begin(), neighborlist[i].end()); m_NeighborList.lock()->setList(static_cast<int32_t>(i), sharedNeiLst); NeighborList<float>::SharedVectorType sharedSAL(new std::vector<float>); sharedSAL->assign(neighborsurfacearealist[i].begin(), neighborsurfacearealist[i].end()); m_SharedSurfaceAreaList.lock()->setList(static_cast<int32_t>(i), sharedSAL); } notifyStatusMessage(getHumanLabel(), "Complete"); }
void KstEditViewObjectDialogI::updateWidgets() { // clear all the current widgets from the grid clearWidgets(); // get the qt properties of the viewobject if (_viewObject) { _customWidget = _viewObject->configWidget(); if (_customWidget) { _grid = new QGridLayout(_propertiesFrame, 1, 1); _customWidget->reparent(_propertiesFrame, QPoint(0, 0)); _grid->addWidget(_customWidget, 0, 0); _viewObject->fillConfigWidget(_customWidget, _isNew); resize(minimumSizeHint()); return; } //--------------------------------------------------------------- // NOTE: due to Early return, nothing after this line is executed // if the view object provides a custom widget. int numProperties = _viewObject->metaObject()->numProperties(true); // create a new grid _grid = new QGridLayout(_propertiesFrame, numProperties, 2, 0, 8); _grid->setColStretch(0,0); _grid->setColStretch(1,1); // get the property names and types for (int i = 0; i < numProperties; i++) { const QMetaProperty* property = _viewObject->metaObject()->property(i, true); QString propertyType(property->type()); QString propertyName(property->name()); // for this property, get the meta-data map QMap<QString, QVariant> metaData = _viewObject->widgetHints(propertyName); if (!metaData.empty()) { QString friendlyName = metaData["_kst_label"].toString(); QString widgetType = metaData["_kst_widgetType"].toString(); metaData.erase("_kst_label"); metaData.erase("_kst_widgetType"); // use friendly name for label QLabel* propertyLabel = new QLabel(_propertiesFrame, "label-"+i); propertyLabel->setText(friendlyName); _grid->addWidget(propertyLabel,i,0); _widgets.append(propertyLabel); propertyLabel->show(); // display different types of widgets depending on what dialogData specifies QWidget* propertyWidget = 0L; if (widgetType == "QSpinBox") { // insert a spinbox propertyWidget = new QSpinBox(_propertiesFrame, (propertyName+","+"value").latin1()); propertyWidget->setProperty("value", _viewObject->property(property->name())); } else if (widgetType == "KColorButton") { // insert a colorbutton propertyWidget = new KColorButton(_propertiesFrame, (propertyName+","+"color").latin1()); propertyWidget->setProperty("color", _viewObject->property(property->name())); } else if (widgetType == "QLineEdit") { // insert a text field propertyWidget = new QLineEdit(_propertiesFrame, (propertyName+","+"text").latin1()); propertyWidget->setProperty("text", _viewObject->property(property->name())); } else if (widgetType == "KURLRequester") { // insert a url requester propertyWidget = new KURLRequester(_propertiesFrame, (propertyName+","+"url").latin1()); propertyWidget->setProperty("url", _viewObject->property(property->name())); } else if (widgetType == "PenStyleWidget") { // insert a combobox with QT pen styles QComboBox* combo = new QComboBox(_propertiesFrame, (propertyName+","+"currentItem").latin1()); fillPenStyleWidget(combo); propertyWidget = combo; propertyWidget->setProperty("currentItem", _viewObject->property(property->name())); } else if (widgetType == "QCheckBox") { // insert a checkbox propertyWidget = new QCheckBox(_propertiesFrame, (propertyName+","+"checked").latin1()); propertyWidget->setProperty("checked", _viewObject->property(property->name())); } else if (widgetType == "KDoubleSpinBox") { // insert a double num spinbox KDoubleSpinBox* input = new KDoubleSpinBox(_propertiesFrame, (propertyName+","+"value").latin1()); // need this so that setValue later works input->setMinValue(metaData["minValue"].toDouble()); input->setMaxValue(metaData["maxValue"].toDouble()); input->setLineStep(metaData["lineStep"].toDouble()); metaData.erase("minValue"); metaData.erase("maxValue"); metaData.erase("lineStep"); propertyWidget = input; propertyWidget->setProperty("value", _viewObject->property(property->name())); } else if (widgetType == "KFontCombo") { // insert a font combo box propertyWidget = new KFontCombo(_propertiesFrame, (propertyName+","+"currentText").latin1()); propertyWidget->setProperty("currentText", _viewObject->property(property->name())); } else if (widgetType == "HJustifyCombo") { // insert a combo box filled with horizontal justifications QComboBox* combo = new QComboBox(_propertiesFrame, (propertyName+","+"currentItem").latin1()); fillHJustifyWidget(combo); propertyWidget = combo; propertyWidget->setProperty("currentItem", _viewObject->property(property->name())); } else if (widgetType == "VJustifyCombo") { // insert a combo box filled with vertical justifications QComboBox* combo = new QComboBox(_propertiesFrame, (propertyName+","+"currentItem").latin1()); fillVJustifyWidget(combo); propertyWidget = combo; propertyWidget->setProperty("currentItem", _viewObject->property(property->name())); } // also set any additional properties specified by metaData for (QMap<QString, QVariant>::ConstIterator it = metaData.begin(); it != metaData.end(); ++it) { propertyWidget->setProperty(it.key().latin1(), it.data()); } _grid->addWidget(propertyWidget, i, 1); _inputWidgets.append(propertyWidget); propertyWidget->show(); } } // geometry cleanup resize(minimumSizeHint()); //setFixedHeight(height()); } }
void KstEditViewObjectDialogI::updateWidgets() { // clear all the current widgets from the grid clearWidgets(); // get the qt properties of the viewobject if (_viewObject) { _customWidget = _viewObject->configWidget(); if (_customWidget) { _grid = new QGridLayout(_propertiesFrame, 1, 1); _customWidget->reparent(_propertiesFrame, QPoint(0, 0)); _grid->addWidget(_customWidget, 0, 0); _viewObject->fillConfigWidget(_customWidget, _isNew); if (!_isNew) { _viewObject->connectConfigWidget(this, _customWidget); } resize(minimumSizeHint()); return; } //--------------------------------------------------------------- // NOTE: due to Early return, nothing after this line is executed // if the view object provides a custom widget. int numProperties = _viewObject->metaObject()->numProperties(true); // create a new grid _grid = new QGridLayout(_propertiesFrame, numProperties, 2, 0, 8); _grid->setColStretch(0,0); _grid->setColStretch(1,1); // get the property names and types for (int i = 0; i < numProperties; i++) { const QMetaProperty* property = _viewObject->metaObject()->property(i, true); QString propertyType(property->type()); QString propertyName(property->name()); // for this property, get the meta-data map QMap<QString, QVariant> metaData = _viewObject->widgetHints(propertyName); if (!metaData.empty()) { QString friendlyName = metaData["_kst_label"].toString(); QString widgetType = metaData["_kst_widgetType"].toString(); metaData.erase("_kst_label"); metaData.erase("_kst_widgetType"); // use friendly name for label QLabel* propertyLabel = new QLabel(_propertiesFrame, "label-"+i); propertyLabel->setText(friendlyName); _grid->addWidget(propertyLabel,i,0); _widgets.append(propertyLabel); propertyLabel->show(); // display different types of widgets depending on what dialogData specifies QWidget* propertyWidget = 0L; if (widgetType == "QSpinBox") { // insert a spinbox propertyWidget = new QSpinBox(_propertiesFrame, (propertyName+","+"value").latin1()); propertyWidget->setProperty("value", _viewObject->property(property->name())); if (!_isNew) { connect(propertyWidget, SIGNAL(valueChanged(const QString&)), this, SLOT(modified())); connect(propertyWidget->child("qt_spinbox_edit"), SIGNAL(textChanged(const QString&)), this, SLOT(modified())); } } else if (widgetType == "KColorButton") {
DTC::ProgramList* Dvr::GetRecordedList( bool bDescending, int nStartIndex, int nCount, const QString &sTitleRegEx, const QString &sRecGroup, const QString &sStorageGroup ) { QMap< QString, ProgramInfo* > recMap; if (gCoreContext->GetScheduler()) recMap = gCoreContext->GetScheduler()->GetRecording(); QMap< QString, uint32_t > inUseMap = ProgramInfo::QueryInUseMap(); QMap< QString, bool > isJobRunning= ProgramInfo::QueryJobsRunning(JOB_COMMFLAG); ProgramList progList; int desc = 1; if (bDescending) desc = -1; LoadFromRecorded( progList, false, inUseMap, isJobRunning, recMap, desc ); QMap< QString, ProgramInfo* >::iterator mit = recMap.begin(); for (; mit != recMap.end(); mit = recMap.erase(mit)) delete *mit; // ---------------------------------------------------------------------- // Build Response // ---------------------------------------------------------------------- DTC::ProgramList *pPrograms = new DTC::ProgramList(); int nAvailable = 0; int nMax = (nCount > 0) ? nCount : progList.size(); nAvailable = 0; nCount = 0; QRegExp rTitleRegEx = QRegExp(sTitleRegEx, Qt::CaseInsensitive); for( unsigned int n = 0; n < progList.size(); n++) { ProgramInfo *pInfo = progList[ n ]; if (pInfo->IsDeletePending() || (!sTitleRegEx.isEmpty() && !pInfo->GetTitle().contains(rTitleRegEx)) || (!sRecGroup.isEmpty() && sRecGroup != pInfo->GetRecordingGroup()) || (!sStorageGroup.isEmpty() && sStorageGroup != pInfo->GetStorageGroup())) continue; if ((nAvailable < nStartIndex) || (nCount >= nMax)) { ++nAvailable; continue; } ++nAvailable; ++nCount; DTC::Program *pProgram = pPrograms->AddNewProgram(); FillProgramInfo( pProgram, pInfo, true ); } // ---------------------------------------------------------------------- pPrograms->setStartIndex ( nStartIndex ); pPrograms->setCount ( nCount ); pPrograms->setTotalAvailable( nAvailable ); pPrograms->setAsOf ( MythDate::current() ); pPrograms->setVersion ( MYTH_BINARY_VERSION ); pPrograms->setProtoVer ( MYTH_PROTO_VERSION ); return pPrograms; }
/** * Set entries to a variable. Will set the variables to the existing line, removing duplicates * Will preserve += constructs and make sure that the variable only has one copy of the value across * all += constructs * Adds line if it does not exist. * @param fileName * @param variables key=value string of entries to add */ void AutoProjectTool::setMakefileam ( const QString &fileName, QMap<QString, QString> variables ) { for ( QMap<QString, QString>::Iterator it0 = variables.begin(); it0 != variables.end(); ++it0 ) { kdDebug ( 9020 ) << "key (set): " << it0.key() << "=" << it0.data() << endl; } // input file reading QFile fin ( fileName ); if ( !fin.open ( IO_ReadOnly ) ) { return ; } QTextStream ins ( &fin ); // output file writing. QFile fout ( fileName + "#" ); if ( !fout.open ( IO_WriteOnly ) ) { fin.close(); return ; } QTextStream outs ( &fout ); // variables QRegExp re ( "^(#kdevelop:[ \t]*)?([A-Za-z][@A-Za-z0-9_]*)[ \t]*([:\\+]?=)[ \t]*(.*)$" ); bool multiLine = false; QString lastLhs; QMap<QString, QString> seenLhs; while ( !fin.atEnd() ) { QString s = ins.readLine(); if ( re.exactMatch ( s ) ) { QString lhs = re.cap ( 2 ); bool notFound = ( variables.find ( lhs ) == variables.end() ); if ( notFound ) { if ( seenLhs.find ( lhs ) == seenLhs.end() ) { // not interested in this line at all // write it out as is.. outs << s << endl; } // we have seen this variable, but since we are setting the // whole line - we skip this as it will be a += line. } else { // we are interested in this line.. QString rhs = re.cap ( 4 ).stripWhiteSpace(); if ( rhs[ rhs.length() - 1 ] == '\\' ) { // save it for when we have the whole line.. multiLine = true; lastLhs = lhs; } else { // deal with it now - a single line // we are adding our interested values to this line and writing it // now write the line out if it is not going to be empty. QString newLine ( lhs ); newLine += " = "; bool added = false; int len = newLine.length(); QStringList variableList = QStringList::split ( ' ', variables[lhs] ); for ( uint count = 0; count < variableList.size(); count++ ) { len += variableList[count].length() + 1; if ( len > 80 ) { newLine += "\\\n\t"; len = 8; } newLine += variableList[count]; newLine += ' '; added = true; } // only print it out if there was a value to add.. if ( added ) { newLine.setLength ( newLine.length() - 1 ); outs << newLine << endl; } seenLhs[lhs] = "done"; variables.erase ( lhs ); } } } else if ( multiLine ) { s = s.stripWhiteSpace(); // we are only here if were interested in this line.. if ( s[s.length()-1] == '\\' ) { s.setLength ( s.length() - 1 ); // still more multi line we wait for.. } else { // end of the multi line.. multiLine = false; } if ( !multiLine ) { // we are adding our interested values to this line and writing it // now write the line out if it is not going to be empty. QString newLine ( lastLhs ); newLine += " = "; bool added = false; int len = newLine.length(); QStringList variableList = QStringList::split ( ' ', variables[lastLhs] ); for ( uint count = 0; count < variableList.size(); count++ ) { len += variableList[count].length() + 1; if ( len > 80 ) { newLine += "\\\n\t"; len = 8; } newLine += variableList[count]; newLine += ' '; added = true; } // only print it out if there was a value to add.. if ( added ) { newLine.setLength ( newLine.length() - 1 ); outs << newLine << endl; } seenLhs[lastLhs] = "done"; variables.erase ( lastLhs ); lastLhs.setLength ( 0 ); } } else { // can write this line out.. // not a match, not a multi line, outs << s << endl; } } for ( QMap<QString, QString>::Iterator it0 = variables.begin(); it0 != variables.end(); ++it0 ) { QString newLine ( it0.key() ); newLine += " = "; bool added = false; int len = newLine.length(); QStringList variableList = QStringList::split ( ' ', it0.data() ); for ( uint count = 0; count < variableList.size(); count++ ) { len += variableList[count].length() + 1; if ( len > 80 ) { newLine += "\\\n\t"; len = 8; } newLine += variableList[count]; newLine += ' '; added = true; } // only print it out if there was a value to add.. if ( added ) { newLine.setLength ( newLine.length() - 1 ); outs << newLine << endl; } } fin.close(); fout.close(); QDir().rename ( fileName + "#", fileName ); }
virtual void timerEvent(QTimerEvent * event) { static int fireCounter = 0; #ifdef USE_SDL SDL_JoystickUpdate(); doDumpFrames = false; for (int i = 0; i < joysticks.size(); ++i) { EPuck* epuck = epucks[i]; if (world->hasGroundTexture()) cout << "Robot " << i << " is on ground of colour " << world->getGroundColor(epuck->pos) << endl; #define SPEED_MAX 13. //cout << "S " << epuck->infraredSensor2.getRayDist(0) << " " << epuck->infraredSensor2.getRayDist(1) << " " << epuck->infraredSensor2.getRayDist(2) << endl; #if 0 epuck->leftSpeed = - SDL_JoystickGetAxis(joysticks[i], 1) / (32767. / SPEED_MAX); epuck->rightSpeed = - SDL_JoystickGetAxis(joysticks[i], 4) / (32767. / SPEED_MAX); #else double x = SDL_JoystickGetAxis(joysticks[i], 0) / (32767. / SPEED_MAX); double y = -SDL_JoystickGetAxis(joysticks[i], 1) / (32767. / SPEED_MAX); epuck->leftSpeed = y + x; epuck->rightSpeed = y - x; #endif if ((SDL_JoystickGetButton(joysticks[i], 6) || SDL_JoystickGetButton(joysticks[i], 7)) && (++fireCounter % 2) == 0) { PhysicalObject* o = new PhysicalObject; Vector delta(cos(epuck->angle), sin(epuck->angle)); o->pos = epuck->pos + delta * 6; o->speed = epuck->speed + delta * 10; o->setCylindric(0.5, 0.5, 10); o->dryFrictionCoefficient = 0.01; o->setColor(Color(0.4, 0, 0)); o->collisionElasticity = 1; bullets[o] = 300; world->addObject(o); } doDumpFrames |= SDL_JoystickGetButton(joysticks[i], 0); } if (joysticks.size() > 0 && subjectiveView) { const EPuck* epuck = epucks[0]; Vector p(epuck->pos); camera.pos.setX(p.x+cos(camera.yaw)*7); camera.pos.setY(p.y+sin(camera.yaw)*7); camera.yaw = epuck->angle; camera.altitude = 11; } #endif QMap<PhysicalObject*, int>::iterator i = bullets.begin(); while (i != bullets.end()) { QMap<PhysicalObject*, int>::iterator oi = i; ++i; if (oi.value()) { oi.value()--; } else { PhysicalObject* o = oi.key(); world->removeObject(o); bullets.erase(oi); delete o; } } ViewerWidget::timerEvent(event); }
int main(int argc, char **argv) { if (argc > 1 && argv[1][0] != '-') { QCoreApplication a(argc, argv); if (qstrcmp(argv[1], "import")) { qWarning("unknown command \"%s\"", argv[1]); return 1; } if (argc == 2) { qWarning("you must specify an address string to import, eg.\n" "%s import \"Joe User <*****@*****.**>\"", argv[0]); return 2; } QMap<QString, QString> imports; for (int i = 2; i < argc; ++i) { QString arg = QString::fromLocal8Bit(argv[i]); QString mail, name; QStringList contact = arg.split(QLatin1String(" "), QString::SkipEmptyParts); foreach (const QString &token, contact) { if (token.contains(QLatin1Char('@'))) mail = token; else name = name.isEmpty() ? token : name + QLatin1String(" ") + token; } if (mail.isEmpty()) { qWarning("error, \"%s\" does not seem to contain a mail address", arg.toLocal8Bit().data()); continue; } mail.remove(QLatin1Char('<')); mail.remove(QLatin1Char('>')); if (name.isEmpty()) name = mail; imports.insert(name, mail); } if (imports.isEmpty()) { qWarning("nothing to import"); return 2; } int lastContact = -1, updates = 0, adds = 0; QSettings abook(QDir::homePath() + QLatin1String("/.abook/addressbook"), QSettings::IniFormat); abook.setIniCodec("UTF-8"); QStringList contacts = abook.childGroups(); foreach (const QString &contact, contacts) { Common::SettingsCategoryGuard guard(&abook, contact); int id = contact.toInt(); if (id > lastContact) lastContact = id; const QString name = abook.value(QLatin1String("name"), QString()).toString(); QMap<QString,QString>::iterator it = imports.begin(), end = imports.end(); while (it != end) { if (it.key() == name) { QStringList mails = abook.value(QLatin1String("email"), QString()).toStringList(); if (!mails.contains(it.value())) { ++updates; mails << it.value(); abook.setValue(QLatin1String("email"), mails); } it = imports.erase(it); continue; } else ++it; } }
void MythUIHelper::ClearOldImageCache(void) { QString cachedirname = GetConfDir() + "/cache/themecache/"; d->themecachedir = GetThemeCacheDir(); QDir dir(cachedirname); if (!dir.exists()) dir.mkdir(cachedirname); QString themecachedir = d->themecachedir; d->themecachedir += '/'; dir.setPath(themecachedir); if (!dir.exists()) dir.mkdir(themecachedir); dir.setPath(cachedirname); dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); QFileInfoList list = dir.entryInfoList(); QFileInfoList::const_iterator it = list.begin(); QMap<QDateTime, QString> dirtimes; const QFileInfo *fi; while (it != list.end()) { fi = &(*it++); if (fi->isDir() && !fi->isSymLink()) { if (fi->absoluteFilePath() == themecachedir) continue; dirtimes[fi->lastModified()] = fi->absoluteFilePath(); } } // Cache two themes/resolutions to allow sampling other themes without // incurring a penalty. Especially for those writing new themes or testing // changes of an existing theme. The space used is neglible when compared // against the average video while ((size_t)dirtimes.size() >= 2) { LOG(VB_GUI | VB_FILE, LOG_INFO, LOC + QString("Removing cache dir: %1") .arg(dirtimes.begin().value())); RemoveCacheDir(dirtimes.begin().value()); dirtimes.erase(dirtimes.begin()); } QMap<QDateTime, QString>::const_iterator dit = dirtimes.begin(); for (; dit != dirtimes.end(); ++dit) { LOG(VB_GUI | VB_FILE, LOG_INFO, LOC + QString("Keeping cache dir: %1").arg(*dit)); } }