void KreCategoriesListWidget::load( int limit, int offset )
{
	CategoryTree categoryTree;
	CategoryTree * pCategoryTree = &categoryTree;
	m_sourceModel->setRowCount( 0 );
	m_database->loadCachedCategories( &pCategoryTree, limit, offset, -1, true );

        for ( CategoryTree * child_it = pCategoryTree->firstChild(); child_it; child_it = child_it->nextSibling() ) {
		//The "Id" item.
		QStandardItem *itemId = new QStandardItem;
		itemId->setData( QVariant(child_it->category.id), Qt::EditRole );
		itemId->setEditable( false );

		//The "Category" item.
		QStandardItem *itemCategory = new QStandardItem( child_it->category.name );
		itemCategory->setEditable( true );

		//Insert the items in the model.
		QList<QStandardItem*> items;
		items << itemCategory << itemId;
		m_sourceModel->appendRow( items );

		//Populate the current element.
		populate( itemCategory, child_it->category.id );
        }

	emit loadFinishedPrivate();
}
Beispiel #2
0
void KrePropertyListWidget::load(int limit, int offset)
{
	//We are not using limits here because usually the number of properties
	//in the database will be low, even for large databases.
	Q_UNUSED(limit)
	Q_UNUSED(offset)

	IngredientPropertyList propList;
	int numberOfProps = m_database->loadProperties( &propList );
	m_sourceModel->setRowCount( numberOfProps );

	KConfigGroup config( KGlobal::config(), "Formatting");
	QStringList hiddenList = config.readEntry("HiddenProperties", QStringList());

	//PropDisplayedDelegate * propDisplayedDelegate = new PropDisplayedDelegate;
	//ui->m_treeView->setItemDelegateForColumn(5, propDisplayedDelegate);
	kDebug() << hiddenList;

	int current_row = 0;
	QModelIndex index;
	for ( IngredientPropertyList::const_iterator it = propList.constBegin(); it != propList.constEnd(); ++it ) {
		// Write the database id in the model.
		index = m_sourceModel->index( current_row, 0 );
		m_sourceModel->setData( index, QVariant(it->id), Qt::EditRole );
		m_sourceModel->itemFromIndex( index )->setEditable( false );
		// Write the name of the property in the model.
		index = m_sourceModel->index( current_row, 1 );
		m_sourceModel->setData( index, QVariant(it->name), Qt::EditRole );
		m_sourceModel->itemFromIndex( index )->setEditable( true );
		// Write the units the property is using in the model.
		index = m_sourceModel->index( current_row, 2 );
		m_sourceModel->setData( index, QVariant(it->units), Qt::EditRole );
		//FIXME: Property units cannot be edited, this is a bug the database design.
		m_sourceModel->itemFromIndex( index )->setEditable( false );
		// Item showing if the property is displayed in "show recipe" and printing
		QStandardItem * checkItem = new QStandardItem;
		checkItem->setCheckable( true );
		if ( hiddenList.contains(it->name) ) {
			checkItem->setCheckState( Qt::Unchecked );
		} else {
			checkItem->setCheckState( Qt::Checked );
		}
		m_sourceModel->setItem( current_row, 3, checkItem );
		// Increment the row counter.
		++current_row;
	}

	//For some reason the list isn't ordered after adding that QStandardItem's
	//to the model (see above).
	m_proxyModel->sort(1);

	emit loadFinishedPrivate();

}
Beispiel #3
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();
}