void DisplayFlagWidget::findChildren(Q3CheckListItem *item, std::vector<Q3CheckListItem* > &children)
{
    Q3CheckListItem * child = (Q3CheckListItem * )item->firstChild();
    while(child)
    {
        children.push_back(child);
        findChildren(child,children);
        child = (Q3CheckListItem * )child->nextSibling();
    }
}
Пример #2
0
void RecipeImportDialog::loadListView()
{
    CustomCheckListItem * head_item = new CustomCheckListItem( kListView, i18nc( "@item:inlistbox All items", "All (%1)", list_copy.count() ), Q3CheckListItem::CheckBox );
    head_item->setOpen( true );

    //get all categories
    QStringList categoryList;

    RecipeList::const_iterator recipe_it;
    for ( recipe_it = list_copy.begin(); recipe_it != list_copy.end(); ++recipe_it ) {
        for ( ElementList::const_iterator cat_it = ( *recipe_it ).categoryList.begin(); cat_it != ( *recipe_it ).categoryList.end(); ++cat_it ) {
            if ( categoryList.contains( ( *cat_it ).name ) == false )
                categoryList << ( *cat_it ).name;
        }
    }

    //create all category check list items
    Q3Dict<CustomCheckListItem> all_categories;

    QStringList::iterator it;
    for ( it = categoryList.begin(); it != categoryList.end(); ++it ) {
        CustomCheckListItem *category_item = new CustomCheckListItem( head_item, *it, Q3CheckListItem::CheckBox );
        //category_item->setOpen(true);

        all_categories.insert( *it, category_item );
    }

    //add recipes to category check list items
    recipe_items = new QMap<CustomCheckListItem*, RecipeList::const_iterator>; //we won't be able to identify a recipe later if we  just put a value in here. The iterator will be unique so we'll use it.  This is safe since the list is constant (iterators won't become invlalid).

    CustomCheckListItem *item = 0;
    CustomCheckListItem *category_item = 0;

    for ( recipe_it = list_copy.begin(); recipe_it != list_copy.end(); ++recipe_it ) {
        if ( ( *recipe_it ).categoryList.count() == 0 ) {
            if ( !category_item )  //don't create this until there are recipes to put in it
            {
                category_item = new CustomCheckListItem( head_item, i18nc( "@item", "Uncategorized" ), Q3CheckListItem::CheckBox );
                all_categories.insert( i18nc( "@item", "Uncategorized" ), category_item );
            }
            CustomCheckListItem *item = new CustomCheckListItem( category_item, ( *recipe_it ).title, Q3CheckListItem::CheckBox );
            recipe_items->insert( item, recipe_it );
        }
        else {
            for ( ElementList::const_iterator cat_it = ( *recipe_it ).categoryList.begin(); cat_it != ( *recipe_it ).categoryList.end(); ++cat_it ) {

                CustomCheckListItem *category_item = all_categories[ ( *cat_it ).name ];

                item = new CustomCheckListItem( category_item, item, ( *recipe_it ).title, Q3CheckListItem::CheckBox );
                recipe_items->insert( item, recipe_it );
            }
        }
    }

    //append the number of recipes in each category to the check list item text
    Q3DictIterator<CustomCheckListItem> categories_it( all_categories );
    for ( ; categories_it.current(); ++categories_it ) {
        int count = 0;
        for ( Q3CheckListItem * it = static_cast<Q3CheckListItem*>( categories_it.current() ->firstChild() ); it; it = static_cast<Q3CheckListItem*>( it->nextSibling() ) ) {
            count++;
        }
        categories_it.current() ->setText( 0, categories_it.current() ->text( 0 ) + QString( " (%1)" ).arg( count ) );
    }

    head_item->setOn( true ); //this will check all recipes
}
Пример #3
0
void CustomCheckListItem::stateChange( bool on )
{
    if ( !m_locked ) {
        for ( Q3CheckListItem * it = static_cast<Q3CheckListItem*>( firstChild() ); it; it = static_cast<Q3CheckListItem*>( it->nextSibling() ) ) {
            it->setOn( on );
        }
    }

    if ( !on ) {
        Q3ListViewItem * parent = this->parent();
        if ( parent && ( parent->rtti() == 1 ) ) {
            CustomCheckListItem * item = static_cast<CustomCheckListItem*>( parent );
            item->setLocked( true );
            item->setOn( on );
            item->setLocked( false );
        }
    }

    QString thisText = text(0);
    Q3ListViewItemIterator it( listView() );
    while ( it.current() ) {
        if ( it.current()->rtti() == 1 && it.current()->text(0) == thisText ) {
            CustomCheckListItem * item = static_cast<CustomCheckListItem*>( it.current() );
            item->setOn( on );
        }
        ++it;
    }
}