// Now add all the categories into a big list
for( b = 0; b < catsToDisplay; b++ ) {
id = mainCatList.at( b ).firstChildElement( "categoryId" ).text();
//qDebug() << "id =" << id;
catItem->setText( 0, decodeXmlEntities( mainCatList.at( b ).firstChildElement( "categoryName" ).text() ) );
description = decodeXmlEntities( mainCatList.at( b ).firstChildElement( "description" ).text() );
if( !description.isEmpty() )
catItem->setStatusTip( 0, description );
catItem
->setData
( 0, Qt
::UserRole,
QVariant( id
) );
catItem
->setData
( 0,
33,
QVariant( false ) );
// i.e. not primary category until required catItems[id] = catItem;
}
qDebug() << "done the top-level categories";
// Now assign each category to its respective parent, and make a list of
// top-level items
thisId = item->data( 0, Qt::UserRole ).toString();
qDebug() << "now doing" << thisId;
if( thisId != "0" && catItems.contains( thisId ) ) {
qDebug() << "not a top-level";
thisItem = catItems[thisId];
qDebug() << "got item" << thisItem->data( 0, Qt::UserRole ).toString();
Q_ASSERT( thisItem != 0 );
thisItem->addChild( item );
}
if( thisId == "0" ) {
qDebug() << "top-level";
topLevelCatItems.append( item );
}
qDebug() << "have now done" << thisId;
}
// Now add all the categories into a big list
for( b = 0; b < catsToDisplay; b++ ) {
catItem = new QTreeWidgetItem;
id = mainCatList.at( b ).firstChildElement( "categoryId" ).text();
//qDebug() << "id =" << id;
catItem->setText( 0, decodeXmlEntities( mainCatList.at( b ).firstChildElement( "categoryName" ).text() ) );
description = decodeXmlEntities( mainCatList.at( b ).firstChildElement( "description" ).text() );
if( !description.isEmpty() )
catItem->setStatusTip( 0, description );
catItem->setData( 0, Qt::UserRole, QVariant( id ) );
catItem->setData( 0, 33, QVariant( false ) ); // i.e. not primary category until required
catItems[id] = catItem;
}
qDebug() << "done the top-level categories";
// Now assign each category to its respective parent, and make a list of
// top-level items
Q_FOREACH( QTreeWidgetItem *item, catItems ) {
thisId = item->data( 0, Qt::UserRole ).toString();
qDebug() << "now doing" << thisId;
if( thisId != "0" && catItems.contains( thisId ) ) {
qDebug() << "not a top-level";
thisItem = catItems[thisId];
qDebug() << "got item" << thisItem->data( 0, Qt::UserRole ).toString();
Q_ASSERT( thisItem != 0 );
thisItem->addChild( item );
}
if( thisId == "0" ) {
qDebug() << "top-level";
topLevelCatItems.append( item );
}
qDebug() << "have now done" << thisId;
}
To copy to clipboard, switch view to plain text mode
Bookmarks