int commandtool::umount_part(const blockdevice *block) { QMap<QString, dfentry> entries; df(entries); QMap<QString,dfentry>::const_iterator i = entries.constFind(block->device); if (i == entries.constEnd()) { util::log(QString("device %1 already umounted").arg(block->device)); return 0; } QString result; QStringList args; args << block->device; int r, trys; trys = 0; while (true) { r = exec(COMMAND_UMOUNT, args, result); if (r != 0) { sleep(1); if (++trys >= 3) break; //try again } else { break; } } return (r == 0) ? 0 : -1; }
std::shared_ptr<OsmAnd::RoutePlannerContext::RouteCalculationSegment> OsmAnd::RoutePlannerContext::RoutingSubsectionContext::loadRouteCalculationSegment( uint32_t x31, uint32_t y31, QMap<uint64_t, std::shared_ptr<const Model::Road> >& processed, const std::shared_ptr<RouteCalculationSegment>& original_) { uint64_t id = (static_cast<uint64_t>(x31) << 31) | y31; auto itSegment = _roadSegments.constFind(id); if(itSegment == _roadSegments.cend()) return original_; this->_access++; auto original = original_; auto segment = *itSegment; while(segment) { auto road = segment->road; auto roadPointId = RoutePlanner::encodeRoutePointId(road, segment->pointIndex); auto itOtherRoad = processed.constFind(roadPointId); if(itOtherRoad == processed.cend() || (*itOtherRoad)->points.size() < road->points.size()) { processed.insert(roadPointId, road); std::shared_ptr<RouteCalculationSegment> newSegment(new RouteCalculationSegment(road, segment->pointIndex)); newSegment->_next = original; original = newSegment; } segment = segment->next; } return original; }
// update pages which have a duplicate master page foreach (KoPAPage * page, pages) { KoPAPage * p = dynamic_cast<KoPAPage*>(page); Q_ASSERT(p); if (p) { KoPAMasterPage * masterPage(p->masterPage()); QMap<KoPAMasterPage*, KoPAMasterPage*>::const_iterator pageIt(updateMasterPage.constFind(masterPage)); if (pageIt != updateMasterPage.constEnd()) { p->setMasterPage(pageIt.value()); } } }
/*! \brief Call the stored method with the arguments passed in via Queries. * * \note Invoke is not thread safe and any method exposed using this class MUST ensure thread safety. */ QVariant Invoke(QObject *Object, const QMap<QString,QString> &Queries, QString &ReturnType, bool &VoidResult) { // this may be called by multiple threads simultaneously, so we need to create our own paramaters instance. // N.B. QMetaObject::invokeMethod only supports up to 10 arguments (plus a return value) void* parameters[11]; memset(parameters, 0, 11 * sizeof(void*)); int size = qMin(11, m_types.size()); // check parameter count if (Queries.size() != size - 1) { LOG(VB_GENERAL, LOG_ERR, QString("Method '%1' expects %2 parameters, sent %3") .arg(m_names[0].data()).arg(size - 1).arg(Queries.size())); return QVariant(); } // populate parameters from query and ensure each parameter is listed QMap<QString,QString>::const_iterator it; for (int i = 0; i < size; ++i) { parameters[i] = QMetaType::create(m_types[i]); if (i) { it = Queries.constFind(m_names[i]); if (it == Queries.end()) { LOG(VB_GENERAL, LOG_ERR, QString("Parameter '%1' for method '%2' is missing") .arg(m_names[i].data()).arg(m_names[0].data())); return QVariant(); } SetValue(parameters[i], it.value(), m_types[i]); } } if (Object->qt_metacall(QMetaObject::InvokeMetaMethod, m_index, parameters) > -1) LOG(VB_GENERAL, LOG_ERR, "qt_metacall error"); // we cannot create a QVariant that is void and an invalid QVariant signals an error state, // so flag directly VoidResult = m_types[0] == QMetaType::Void; QVariant result = m_types[0] == QMetaType::Void ? QVariant() : QVariant(m_types[0], parameters[0]); // free allocated parameters for (int i = 0; i < size; ++i) if (parameters[i]) QMetaType::destroy(m_types.data()[i], parameters[i]); ReturnType = m_returnType; return result; }
int ScriptInfo::lineOffset(int lineNumber) { QMap<int, int>::const_iterator it = m_lineOffsets.constFind(lineNumber); if (it != m_lineOffsets.constEnd()) return it.value(); int offset; it = m_lineOffsets.constFind(lineNumber - 1); if (it != m_lineOffsets.constEnd()) { offset = it.value(); offset = m_code.indexOf(QLatin1Char('\n'), offset); if (offset != -1) ++offset; m_lineOffsets.insert(lineNumber, offset); } else { int index; it = m_lineOffsets.lowerBound(lineNumber); --it; if (it != m_lineOffsets.constBegin()) { index = it.key(); offset = it.value(); } else { index = m_lineNumber; offset = 0; } int j = index; for ( ; j < lineNumber; ++j) { m_lineOffsets.insert(j, offset); offset = m_code.indexOf(QLatin1Char('\n'), offset); if (offset == -1) break; ++offset; } m_lineOffsets.insert(j, offset); } return offset; }
QString mapiTagString( int key ) { if ( MAPI_TagMap.count() == 0 ) { for ( int i=0; MAPI_TagStrings[ i ].str; i++ ) { MAPI_TagMap[ MAPI_TagStrings[ i ].tag ] = i18n( MAPI_TagStrings[ i ].str ); } } QMap<int,QString>::ConstIterator it = MAPI_TagMap.constFind( key ); if ( it == MAPI_TagMap.constEnd() ) { return QString().sprintf( "0x%04X", key ); } else { return QString().sprintf( "0x%04X ________: ", key ) + *it; } }
// Takes care that there may be multiple values of attribute in identity's attributes bool RecognitionDatabase::Private::identityContains(const Identity& identity, const QString& attribute, const QString& value) const { const QMap<QString, QString> map = identity.attributesMap(); QMap<QString, QString>::const_iterator it = map.constFind(attribute); for (; it != map.constEnd() && it.key() == attribute; ++it) { if (it.value() == value) { return true; } } return false; }
void FileOperation::openFilesWithDefaultApplication(const QList<QUrl>& urls, QWidget* const parentWidget) { if (urls.isEmpty()) { return; } // Create a map of service depending of type mimes to route and start only one instance of relevant application with all same type mime files. QMap<KService::Ptr, QList<QUrl>> servicesMap; foreach (const QUrl& url, urls) { const QString mimeType = QMimeDatabase().mimeTypeForFile(url.path(), QMimeDatabase::MatchExtension).name(); KService::List offers = KMimeTypeTrader::self()->query(mimeType, QLatin1String("Application")); if (offers.isEmpty()) { return; } KService::Ptr ptr = offers.first(); QMap<KService::Ptr, QList<QUrl>>::const_iterator it = servicesMap.constFind(ptr); if (it != servicesMap.constEnd()) { servicesMap[ptr] << url; } else { servicesMap.insert(ptr, QList<QUrl>() << url); } } for (QMap<KService::Ptr, QList<QUrl>>::const_iterator it = servicesMap.constBegin(); it != servicesMap.constEnd(); ++it) { // Run the dedicated app to open the item. #if KIO_VERSION < QT_VERSION_CHECK(5,6,0) KRun::run(*it.key(), it.value(), parentWidget); #else KRun::runService(*it.key(), it.value(), parentWidget); #endif } }
void MainWindow::setimagelabel( QMap<QString, Card*> Deck ,QString id) { QMap<QString, Card*>::const_iterator i=Deck.constFind(id); Card* n=new Card(""); if(i!=Deck.begin())i--; n=(Card*)i.value(); ui->label->setPixmap(QPixmap::fromImage(n->Picture, Qt::AutoColor)); ui->label_2->setText(n->Name); ui->label_3->setText(n->Description); // i++; // n=(Card*)i.value(); // ui->label_2->setPixmap(QPixmap::fromImage(n->Picture, Qt::AutoColor)); // i++; // n=(Card*)i.value(); // ui->label_3->setPixmap(QPixmap::fromImage(n->Picture, Qt::AutoColor)); }
bool OsmAnd::MapStyleEvaluator_P::evaluate( const std::shared_ptr<const Model::MapObject>& mapObject, const QMap< uint64_t, std::shared_ptr<MapStyleRule> >& rules, const uint32_t tagKey, const uint32_t valueKey, MapStyleEvaluationResult* const outResultStorage, bool evaluateChildren) { _inputValues[_builtinValueDefs->id_INPUT_TAG].asUInt = tagKey; _inputValues[_builtinValueDefs->id_INPUT_VALUE].asUInt = valueKey; const auto ruleId = MapStyle_P::encodeRuleId(tagKey, valueKey); auto itRule = rules.constFind(ruleId); if(itRule == rules.cend()) return false; return evaluate(mapObject.get(), *itRule, outResultStorage, evaluateChildren); }
/** @short Decode RFC2231-style eextended parameter values into a real Unicode string */ QString extractRfc2231Param(const QMap<QByteArray, QByteArray> ¶meters, const QByteArray &key) { QMap<QByteArray, QByteArray>::const_iterator it = parameters.constFind(key); if (it != parameters.constEnd()) { // This parameter is not using the RFC 2231 syntax for extended parameters. // I have no idea whether this is correct, but I *guess* that trying to use RFC2047 is not going to hurt. return decodeRFC2047String(*it); } if (parameters.constFind(key + "*0") != parameters.constEnd()) { // There's a 2231-style continuation *without* the language/charset extension QByteArray raw; int num = 0; while ((it = parameters.constFind(key + '*' + QByteArray::number(num++))) != parameters.constEnd()) { raw += *it; } return decodeRFC2047String(raw); } QByteArray raw; if ((it = parameters.constFind(key + '*')) != parameters.constEnd()) { // No continuation, but language/charset is present raw = *it; } else if (parameters.constFind(key + "*0*") != parameters.constEnd()) { // Both continuation *and* the lang/charset extension are in there int num = 0; // The funny thing is that the other values might or might not end with the trailing star, // at least according to the example in the RFC do { if ((it = parameters.constFind(key + '*' + QByteArray::number(num))) != parameters.constEnd()) raw += *it; else if ((it = parameters.constFind(key + '*' + QByteArray::number(num) + '*')) != parameters.constEnd()) raw += *it; ++num; } while (it != parameters.constEnd()); } // Process 2231-style language/charset continuation, if present int pos1 = raw.indexOf('\'', 0); int pos2 = raw.indexOf('\'', qMax(1, pos1 + 1)); if (pos1 != -1 && pos2 != -1) { return decodeByteArray(translatePercentToBin(raw.mid(pos2 + 1)), raw.left(pos1)); } // Fallback: it could be empty, or otherwise malformed. Just treat it as UTF-8 for compatibility return QString::fromUtf8(raw); }
QDomElement Reference::applyElement( const QDomElement &context ) const { kDebug() <<"Reference::applyElement()" << toString() <<"Context:" << context.tagName(); QDomElement result = context; if ( mSegments.count() == 1 && lastSegment().name() == "." ) return result; Reference::Segment::List::ConstIterator it; for( it = mSegments.constBegin(); it != mSegments.constEnd(); ++it ) { Reference::Segment segment = *it; // kDebug() <<" Segment:" << segment.toString() <<"Count:" << // segment.count(); QMap<QString, int> counts; QDomNode n; for( n = result.firstChild(); !n.isNull(); n = n.nextSibling() ) { QDomElement e = n.toElement(); // kDebug() <<" E:" << e.tagName(); int count = 1; QMap<QString, int>::ConstIterator itCount = counts.constFind( e.tagName() ); if ( itCount != counts.constEnd() ) count = itCount.value(); // kDebug() <<" COUNT:" << count; if ( e.tagName() == segment.name() && count == segment.count() ) { result = e; break; } counts.insert( e.tagName(), ++count ); } if ( n.isNull() ) { kError() <<"Reference::apply(): Unable to find element '" << segment.toString() << "'"; return QDomElement(); } } return result; }
QDomElement Reference::apply( const QDomDocument &doc ) const { QDomElement result; Reference::Segment::List::ConstIterator it; for( it = mSegments.constBegin(); it != mSegments.constEnd(); ++it ) { Reference::Segment segment = *it; if ( result.isNull() ) { kDebug() <<"ROOT"; if ( doc.documentElement().tagName() == segment.name() ) { result = doc.documentElement(); continue; } else { kError() <<"Document element '" << doc.documentElement().tagName() << "' isn't '" << segment.name() << "'"; return QDomElement(); } } QMap<QString, int> counts; QDomNode n; for( n = result.firstChild(); !n.isNull(); n = n.nextSibling() ) { QDomElement e = n.toElement(); int count = 1; QMap<QString, int>::ConstIterator itCount = counts.constFind( e.tagName() ); if ( itCount != counts.constEnd() ) count = itCount.value(); if ( e.tagName() == segment.name() && count == segment.count() ) { result = e; break; } counts.insert( e.tagName(), ++count ); } if ( n.isNull() ) { kError() <<"Reference::apply(): Unable to find element '" << segment.toString() << "'"; return QDomElement(); } } return result; }
QList<ToolChain *> AndroidToolChainFactory::createToolChainsForNdk(const Utils::FileName &ndkPath) { QList<ToolChain *> result; if (ndkPath.isEmpty()) return result; QRegExp versionRegExp(NDKGccVersionRegExp); FileName path = ndkPath; QDirIterator it(path.appendPath(QLatin1String("toolchains")).toString(), QStringList() << QLatin1String("*"), QDir::Dirs); QMap<Abi::Architecture, AndroidToolChain *> newestToolChainForArch; while (it.hasNext()) { const QString &fileName = QFileInfo(it.next()).fileName(); int idx = versionRegExp.indexIn(fileName); if (idx == -1) continue; QString version = fileName.mid(idx + 1); QString platform = fileName.left(idx); Abi::Architecture arch = AndroidConfig::architectureForToolChainPrefix(platform); if (arch == Abi::UnknownArchitecture) // e.g. mipsel which is not yet supported continue; AndroidToolChain *tc = new AndroidToolChain(arch, version, ToolChain::AutoDetection); FileName compilerPath = AndroidConfigurations::currentConfig().gccPath(arch, version); tc->setCompilerCommand(compilerPath); result.append(tc); QMap<Abi::Architecture, AndroidToolChain *>::const_iterator it = newestToolChainForArch.constFind(arch); if (it == newestToolChainForArch.constEnd()) newestToolChainForArch.insert(arch, tc); else if (versionCompareLess(it.value(), tc)) newestToolChainForArch[arch] = tc; } foreach (ToolChain *tc, result) { AndroidToolChain *atc = static_cast<AndroidToolChain *>(tc); if (newestToolChainForArch.value(atc->targetAbi().architecture()) != atc) atc->setSecondaryToolChain(true); }
void DateAlbumModel::setYearMonthMap(const QMap<YearMonth, int>& yearMonthMap) { AlbumIterator it(rootAlbum()); QMap<int, int> albumToCountMap; while (it.current()) { DAlbum* const dalbum = static_cast<DAlbum*>(*it); QDate date = dalbum->date(); switch (dalbum->range()) { case DAlbum::Month: { QMap<YearMonth, int>::const_iterator it2 = yearMonthMap.constFind(YearMonth(date.year(), date.month())); if ( it2 != yearMonthMap.constEnd() ) { albumToCountMap.insert((*it)->id(), it2.value()); } break; } case DAlbum::Year: // a year itself cannot contain images and therefore always has count 0 albumToCountMap.insert((*it)->id(), 0); break; default: qCDebug(DIGIKAM_GENERAL_LOG) << "Untreated DAlbum range " << dalbum->range(); albumToCountMap.insert((*it)->id(), 0); break; } ++it; } setCountMap(albumToCountMap); }
void PropertyEditor::setObject(QObject *object) { QDesignerFormWindowInterface *oldFormWindow = QDesignerFormWindowInterface::findFormWindow(m_object); // In the first setObject() call following the addition of a dynamic property, focus and edit it. const bool editNewDynamicProperty = object != 0 && m_object == object && !m_recentlyAddedDynamicProperty.isEmpty(); m_object = object; m_propertyManager->setObject(object); QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(m_object); FormWindowBase *fwb = qobject_cast<FormWindowBase *>(formWindow); m_treeFactory->setFormWindowBase(fwb); m_groupFactory->setFormWindowBase(fwb); storeExpansionState(); UpdateBlocker ub(this); updateToolBarLabel(); QMap<QString, QtVariantProperty *> toRemove = m_nameToProperty; const QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(m_core->extensionManager(), m_object); const QDesignerPropertySheet *sheet = qobject_cast<QDesignerPropertySheet*>(m_core->extensionManager()->extension(m_object, Q_TYPEID(QDesignerPropertySheetExtension))); // Optimizization: Instead of rebuilding the complete list every time, compile a list of properties to remove, // remove them, traverse the sheet, in case property exists just set a value, otherwise - create it. QExtensionManager *m = m_core->extensionManager(); m_propertySheet = qobject_cast<QDesignerPropertySheetExtension*>(m->extension(object, Q_TYPEID(QDesignerPropertySheetExtension))); if (m_propertySheet) { const int propertyCount = m_propertySheet->count(); for (int i = 0; i < propertyCount; ++i) { if (!m_propertySheet->isVisible(i)) continue; const QString propertyName = m_propertySheet->propertyName(i); if (m_propertySheet->indexOf(propertyName) != i) continue; const QString groupName = m_propertySheet->propertyGroup(i); const QMap<QString, QtVariantProperty *>::const_iterator rit = toRemove.constFind(propertyName); if (rit != toRemove.constEnd()) { QtVariantProperty *property = rit.value(); if (m_propertyToGroup.value(property) == groupName && toBrowserType(m_propertySheet->property(i), propertyName) == property->propertyType()) toRemove.remove(propertyName); } } } QMapIterator<QString, QtVariantProperty *> itRemove(toRemove); while (itRemove.hasNext()) { itRemove.next(); QtVariantProperty *property = itRemove.value(); m_nameToProperty.remove(itRemove.key()); m_propertyToGroup.remove(property); delete property; } if (oldFormWindow != formWindow) reloadResourceProperties(); bool isMainContainer = false; if (QWidget *widget = qobject_cast<QWidget*>(object)) { if (QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(widget)) { isMainContainer = (fw->mainContainer() == widget); } } m_groups.clear(); if (m_propertySheet) { QtProperty *lastProperty = 0; QtProperty *lastGroup = 0; const int propertyCount = m_propertySheet->count(); for (int i = 0; i < propertyCount; ++i) { if (!m_propertySheet->isVisible(i)) continue; const QString propertyName = m_propertySheet->propertyName(i); if (m_propertySheet->indexOf(propertyName) != i) continue; const QVariant value = m_propertySheet->property(i); const int type = toBrowserType(value, propertyName); QtVariantProperty *property = m_nameToProperty.value(propertyName, 0); bool newProperty = property == 0; if (newProperty) { property = m_propertyManager->addProperty(type, propertyName); if (property) { newProperty = true; if (type == DesignerPropertyManager::enumTypeId()) { const PropertySheetEnumValue e = qvariant_cast<PropertySheetEnumValue>(value); QStringList names; QStringListIterator it(e.metaEnum.keys()); while (it.hasNext()) names.append(it.next()); m_updatingBrowser = true; property->setAttribute(m_strings.m_enumNamesAttribute, names); m_updatingBrowser = false; } else if (type == DesignerPropertyManager::designerFlagTypeId()) { const PropertySheetFlagValue f = qvariant_cast<PropertySheetFlagValue>(value); QList<QPair<QString, uint> > flags; QStringListIterator it(f.metaFlags.keys()); while (it.hasNext()) { const QString name = it.next(); const uint val = f.metaFlags.keyToValue(name); flags.append(qMakePair(name, val)); } m_updatingBrowser = true; QVariant v; qVariantSetValue(v, flags); property->setAttribute(m_strings.m_flagsAttribute, v); m_updatingBrowser = false; } } } if (property != 0) { const bool dynamicProperty = (dynamicSheet && dynamicSheet->isDynamicProperty(i)) || (sheet && sheet->isDefaultDynamicProperty(i)); switch (type) { case QVariant::Palette: setupPaletteProperty(property); break; case QVariant::KeySequence: //addCommentProperty(property, propertyName); break; default: break; } if (type == QVariant::String || type == qMetaTypeId<PropertySheetStringValue>()) setupStringProperty(property, isMainContainer); property->setAttribute(m_strings.m_resettableAttribute, m_propertySheet->hasReset(i)); const QString groupName = m_propertySheet->propertyGroup(i); QtVariantProperty *groupProperty = 0; if (newProperty) { QMap<QString, QtVariantProperty*>::const_iterator itPrev = m_nameToProperty.insert(propertyName, property); m_propertyToGroup[property] = groupName; if (m_sorting) { QtProperty *previous = 0; if (itPrev != m_nameToProperty.constBegin()) previous = (--itPrev).value(); m_currentBrowser->insertProperty(property, previous); } } const QMap<QString, QtVariantProperty*>::const_iterator gnit = m_nameToGroup.constFind(groupName); if (gnit != m_nameToGroup.constEnd()) { groupProperty = gnit.value(); } else { groupProperty = m_propertyManager->addProperty(QtVariantPropertyManager::groupTypeId(), groupName); QtBrowserItem *item = 0; if (!m_sorting) item = m_currentBrowser->insertProperty(groupProperty, lastGroup); m_nameToGroup[groupName] = groupProperty; m_groups.append(groupProperty); if (dynamicProperty) m_dynamicGroup = groupProperty; if (m_currentBrowser == m_treeBrowser && item) { m_treeBrowser->setBackgroundColor(item, propertyColor(groupProperty)); groupProperty->setModified(true); } } /* Group changed or new group. Append to last subproperty of * that group. Note that there are cases in which a derived * property sheet appends fake properties for the class * which will appear after the layout group properties * (QWizardPage). To make them appear at the end of the * actual class group, goto last element. */ if (lastGroup != groupProperty) { lastGroup = groupProperty; lastProperty = 0; // Append at end const QList<QtProperty*> subProperties = lastGroup->subProperties(); if (!subProperties.empty()) lastProperty = subProperties.back(); lastGroup = groupProperty; } if (!m_groups.contains(groupProperty)) m_groups.append(groupProperty); if (newProperty) groupProperty->insertSubProperty(property, lastProperty); lastProperty = property; updateBrowserValue(property, value); property->setModified(m_propertySheet->isChanged(i)); if (propertyName == QLatin1String("geometry") && type == QVariant::Rect) { QList<QtProperty *> subProperties = property->subProperties(); foreach (QtProperty *subProperty, subProperties) { const QString subPropertyName = subProperty->propertyName(); if (subPropertyName == QLatin1String("X") || subPropertyName == QLatin1String("Y")) subProperty->setEnabled(!isMainContainer); } } } else { qWarning("%s", qPrintable(msgUnsupportedType(propertyName, type))); } }
void QtResourceViewPrivate::filterOutResources() { QMap<QString, bool> pathToMatchingContents; // true means the path has any matching contents QMap<QString, bool> pathToVisible; // true means the path has to be shown // 1) we go from root path recursively. // 2) we check every path if it contains at least one matching resource - if empty we add it // to pathToMatchingContents and pathToVisible with false, if non empty // we add it with true and change every parent path in pathToVisible to true. // 3) we hide these items which has pathToVisible value false. const bool matchAll = m_filterPattern.isEmpty(); const QString root(QLatin1Char(':')); QQueue<QString> pathQueue; pathQueue.enqueue(root); while (!pathQueue.isEmpty()) { const QString path = pathQueue.dequeue(); QStringList fileNames = m_pathToContents.value(path); QStringListIterator it(fileNames); bool hasContents = matchAll; if (!matchAll) { // the case filter is not empty - we check if the path contains anything while (it.hasNext()) { QString fileName = it.next(); hasContents = fileName.contains(m_filterPattern, Qt::CaseInsensitive); if (hasContents) // the path contains at least one resource which matches the filter break; } } pathToMatchingContents[path] = hasContents; pathToVisible[path] = hasContents; if (hasContents) { // if the path is going to be shown we need to show all its parent paths QString parentPath = m_pathToParentPath.value(path); while (!parentPath.isEmpty()) { QString p = parentPath; if (pathToVisible.value(p)) // parent path is already shown, we break the loop break; pathToVisible[p] = true; parentPath = m_pathToParentPath.value(p); } } QStringList subPaths = m_pathToSubPaths.value(path); // we do the same for children paths QStringListIterator itSubPaths(subPaths); while (itSubPaths.hasNext()) pathQueue.enqueue(itSubPaths.next()); } // we setup here new path and resource to be activated const QString currentPath = m_itemToPath.value(m_treeWidget->currentItem()); QString newCurrentPath = currentPath; QString currentResource = m_itemToResource.value(m_listWidget->currentItem()); if (!matchAll) { bool searchForNewPathWithContents = true; if (!currentPath.isEmpty()) { // if the currentPath is empty we will search for a new path too QMap<QString, bool>::ConstIterator it = pathToMatchingContents.constFind(currentPath); if (it != pathToMatchingContents.constEnd() && it.value()) // the current item has contents, we don't need to search for another path searchForNewPathWithContents = false; } if (searchForNewPathWithContents) { // we find the first path with the matching contents QMap<QString, bool>::ConstIterator itContents = pathToMatchingContents.constBegin(); while (itContents != pathToMatchingContents.constEnd()) { if (itContents.value()) { newCurrentPath = itContents.key(); // the new path will be activated break; } itContents++; } } QFileInfo fi(currentResource); if (!fi.fileName().contains(m_filterPattern, Qt::CaseInsensitive)) { // the case when the current resource is filtered out const QStringList fileNames = m_pathToContents.value(newCurrentPath); QStringListIterator it(fileNames); while (it.hasNext()) { // we try to select the first matching resource from the newCurrentPath QString fileName = it.next(); if (fileName.contains(m_filterPattern, Qt::CaseInsensitive)) { QDir dirPath(newCurrentPath); currentResource = dirPath.absoluteFilePath(fileName); // the new resource inside newCurrentPath will be activated break; } } } } QTreeWidgetItem *newCurrentItem = m_pathToItem.value(newCurrentPath); if (currentPath != newCurrentPath) m_treeWidget->setCurrentItem(newCurrentItem); else slotCurrentPathChanged(newCurrentItem); // trigger filtering on the current path QListWidgetItem *currentResourceItem = m_resourceToItem.value(currentResource); if (currentResourceItem) { m_listWidget->setCurrentItem(currentResourceItem); m_listWidget->scrollToItem(currentResourceItem); } QMapIterator<QString, bool> it(pathToVisible); // hide all paths filtered out while (it.hasNext()) { const QString path = it.next().key(); QTreeWidgetItem *item = m_pathToItem.value(path); if (item) item->setHidden(!it.value()); } }