Exemplo n.º 1
0
CatItem CatBuilder::updateItem(CatItem& it, int childDepth, UserEvent::LoadType lt) {
    if(!it.shouldUpdate(childDepth, lt)) {
        return it;
    }

    CatItem realItem;
    QList<int> matches = it.getMatchIndex();

    if(!it.getIsTempItem()) {
        QString path = it.getPath();
        realItem = getItem(path, childDepth);
        addSynonymChildren(realItem);

        //Our plugins can return items not in the database
        if(!realItem.isEmpty()) {
            //realItem.merge(it);
            it.merge(realItem);
        }
        if(lt!=UserEvent::IGNORE) {
            for(int i=0; i<childDepth; i++) {
                //avoiding address of reference of smart-pointer itme
                CatItem holder = it;
                if(plugins_ptr->itemLoading(&holder,lt)) {
                    cat->addItem(holder);
                    it = holder;
                }
            }
        }
    }
    it.setMatchIndex(matches);
    return it;
}
Exemplo n.º 2
0
bool TrieNode::breadthSearch(QHash<qint32,CatItem>& alreadyFound, QString matchString,
                    int desired, int depth, int digDepth, int skipDepth, ItemFilter* filter){


    bool worthLookingFurther = (digDepth >0);
    if(skipDepth<=0){
        worthLookingFurther = true;

        QLinkedList<ItemRep>::iterator i = m_bestItems.begin();
        for(;i != m_bestItems.end();i++){

            //This step optimizes - skip what you know is wrong before paying for a full check
            QList<int> outIndex;
            CatItem it_approx((*i).getName(),(*i).getName());
            if(!matchString.isEmpty() && !userkey_match(it_approx,matchString, &outIndex))
                { continue; }

            CatItem::ItemType mt = (*i).getItemType();
            if(!CatItem::matchOrganizingTypes(filter->getOrganizeingType(),mt))
                {continue;}

            //Now the "real" matching
            CatItem it = mp_container->getByInternalIdProtectMe((*i).getInternalId());
            outIndex.clear();

            //We want to allow names that are parts of the main name...
            if(!matchString.isEmpty() && !userkey_match(it,matchString, &outIndex)){
                if(matchString.length() < MIN_SUBSTR_MATCH_LEN)
                    { continue; }
                if(!it.getName().contains(matchString))
                    { continue; }
            }

            if (!filter || filter->acceptItem(&(it) )){
                worthLookingFurther =true;
                if(outIndex.length() > 0){
                    it.setMatchIndex(outIndex);
                }
                //it.setMatchIndex((*i).getMatchIndex());
                alreadyFound[it.getItemId()] = it;
            }
            if(alreadyFound.count() > desired){ return false; }
        }
    }


    if(depth<=0){ return true; }

    if(worthLookingFurther || matchString.length() <=BROAD_KEYSEARCH_MAXLEN ||
       (skipDepth) > 0) {
        for(int i=0;i < m_entries.count();i++){
            if(!m_entries[i]){continue;}
            m_entries[i]->breadthSearch(alreadyFound, matchString, desired, depth-1,
                                      digDepth-1,
                                      skipDepth-1, filter);
            if(alreadyFound.count() > desired){ return false; }
        }
    }

    return worthLookingFurther;
}
Exemplo n.º 3
0
QList<CatItem> Catalog::expandStubs(QString userKeys, QList<CatItem>* inList){

    QList<CatItem> stubs; QList<CatItem> oldStubs;
    QList<CatItem>* workingList = inList;
    QList<CatItem> res;
    bool refreshNeeded =false;
    int rep=0;

    QSet<QString> updated;
    while((workingList->length()>0)) {
        cat_store.beginAddGroup();
        for(int i=0; i<workingList->count();i++){
            CatItem toAdd = workingList->at(i);
            bool atStub = toAdd.isStub();
            if(plugins.itemLoading(&toAdd, UserEvent::BECOMING_VISIBLE)){
                if(toAdd.isForDelete()) {
                    cat_store.removeItem(workingList->at(i));
                    continue;
                }
                if(atStub) {
                    refreshNeeded = true;
                    //toAdd.setStub(false);
                    cat_store.addItemInGroup(toAdd);
                }
            }
            QList<CatItem> newStubs = extractStubs(toAdd);
            for(int j=0; j<newStubs.count(); j++){
                if(!updated.contains(newStubs[j].getPath())){
                    updated.insert(newStubs[j].getPath());
                    stubs.append(newStubs[j]);
                }
            }
        }
        oldStubs = stubs;
        workingList = &oldStubs;
        cat_store.endAddGroup();
        stubs.clear();
        Q_ASSERT(workingList->count() <1000);
        rep++;
        Q_ASSERT(rep<10);
    }

    cat_store.beginAddGroup();
    for(int i=0; i<inList->count();i++){
        CatItem toAdd = inList->at(i);
        if(toAdd.isForDBInsertOnly()){
            cat_store.addItemInGroup(toAdd);
            continue;
        }
        if(userKeys.isEmpty() || matches(&toAdd, userKeys) || toAdd.getTakesAnykeys()) {
            if(refreshNeeded){
                CatItem refreshed = cat_store.getItemByPath(toAdd.getPath());
                if(!refreshed.isEmpty()){
                    toAdd.mergeItem(refreshed,true);
                }
                toAdd.setMatchIndex(QList<int>());
            }
            if(!toAdd.hasLabel(BUILTIN))
                { res.append(toAdd);}
        }}
    cat_store.endAddGroup();
    return res;
}