Esempio n. 1
0
QList<int> RecipeActionsHandler::getAllVisibleItems()
{
	QList<int> ids;

	Q3ListViewItemIterator iterator( parentListView );
	while ( iterator.current() ) {
		if ( iterator.current() ->isVisible() ) {
			if ( iterator.current() ->rtti() == RECIPELISTITEM_RTTI ) {
				RecipeListItem * recipe_it = ( RecipeListItem* ) iterator.current();
				int recipe_id = recipe_it->recipeID();
	
				if ( ids.indexOf( recipe_id ) == -1 )
					ids.append( recipe_id );
			}
			//it is a category item and isn't populated, so get the unpopulated data from the database
			else if ( iterator.current()->rtti() == CATEGORYLISTITEM_RTTI && !iterator.current()->firstChild() ) {
				int cat_id = (( CategoryListItem* ) iterator.current())->element().id;
				ElementList list;
				database->loadRecipeList( &list, cat_id, true );
		
				for ( ElementList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it ) {
					if ( ids.indexOf( (*it).id ) == -1 )
						ids << (*it).id;
				}
			}
		}

		++iterator;
	}

	return ids;
}
Esempio n. 2
0
QList<int> RecipeActionsHandler::recipeIDs( const QList<Q3ListViewItem *> &items ) const
{
	QList<int> ids;

	QListIterator<Q3ListViewItem *> it(items);
	const Q3ListViewItem *item;
	while ( it.hasNext() ) {
		item = it.next();
		if ( item->rtti() == 1000 ) { //RecipeListItem
			RecipeListItem * recipe_it = ( RecipeListItem* ) item;
			if ( ids.indexOf( recipe_it->recipeID() ) == -1 )
				ids << recipe_it->recipeID();
		}
		else if ( item->rtti() == 1001 ) {
			CategoryListItem *cat_it = ( CategoryListItem* ) item;
			ElementList list;
			database->loadRecipeList( &list, cat_it->element().id, true );
	
			for ( ElementList::const_iterator cat_it = list.constBegin(); cat_it != list.constEnd(); ++cat_it ) {
				if ( ids.indexOf( (*cat_it).id ) == -1 )
					ids << (*cat_it).id;
			}
		}
	}

	return ids;
}
Esempio n. 3
0
void IngredientComboBox::reload()
{
	QString remember_text;
	if ( isEditable() )
		remember_text = lineEdit()->text();

	ElementList ingredientList;
	database->loadIngredients( &ingredientList );

	clear();
	ingredientComboRows.clear();

	int row = 0;
	if ( !m_specialItem.isEmpty() ) {
		insertItem( count(), m_specialItem );
		ingredientComboRows.insert( row, -1 );
		row++;
	}
	for ( ElementList::const_iterator it = ingredientList.constBegin(); it != ingredientList.constEnd(); ++it, ++row ) {
		insertItem( count(), (*it).name );
		completionObject()->addItem((*it).name);
		ingredientComboRows.insert( row, (*it).id );
	}

	if ( isEditable() )
		setEditText( remember_text );

	database->disconnect( this );
	connect( database, SIGNAL( ingredientCreated( const Element & ) ), SLOT( createIngredient( const Element & ) ) );
	connect( database, SIGNAL( ingredientRemoved( int ) ), SLOT( removeIngredient( int ) ) );
}
Esempio n. 4
0
void IngredientListView::load( int limit, int offset )
{
	ElementList ingredientList;
	database->loadIngredients( &ingredientList, limit, offset );

	setTotalItems(ingredientList.count());

	for ( ElementList::const_iterator ing_it = ingredientList.constBegin(); ing_it != ingredientList.constEnd(); ++ing_it )
		createIngredient( *ing_it );
}
Esempio n. 5
0
void IngredientComboBox::loadMore()
{
	if ( loading_at >= ing_count-1 ) {
		endLoad();
		return;
	}

	ElementList ingredientList;
	database->loadIngredients( &ingredientList, load_limit, loading_at );

	for ( ElementList::const_iterator it = ingredientList.constBegin(); it != ingredientList.constEnd(); ++it, ++loading_at ) {
		insertItem( count(), (*it).name );
		completionObject()->addItem((*it).name);
		ingredientComboRows.insert( loading_at, (*it).id );
	}
}
Esempio n. 6
0
void KreAuthorListWidget::queryFinished(const ElementList & authorList, int authorsLoaded)
{
	kDebug() << "Thread done, I'm in" << (size_t)QThread::currentThreadId();
	m_sourceModel->setRowCount( authorsLoaded );
	ElementList::const_iterator author_it;
	int current_row = 0;
	QModelIndex index;
        for ( author_it = authorList.constBegin(); author_it != authorList.constEnd(); ++author_it ) {
		// Write the database id in the model.
		index = m_sourceModel->index( current_row, 0 );
                m_sourceModel->setData( index, QVariant(author_it->id), Qt::EditRole );
                m_sourceModel->itemFromIndex( index )->setEditable( false );
		// Write the name of the author in the model.
		index = m_sourceModel->index( current_row, 1 );
                m_sourceModel->setData( index, QVariant(author_it->name), Qt::EditRole );
                m_sourceModel->itemFromIndex( index )->setEditable( true );
		// Increment the row counter.
		++current_row;
	}
	
	m_thread->disconnect();
	emit loadFinishedPrivate();
}