void tst_QStandardItem::takeChild() { QList<QStandardItem*> itemList; for (int i = 0; i < 10; ++i) itemList.append(new QStandardItem); QStandardItem item; item.appendColumn(itemList); for (int i = 0; i < item.rowCount(); ++i) { QCOMPARE(item.takeChild(i), itemList.at(i)); QCOMPARE(item.takeChild(0, 0), static_cast<QStandardItem*>(0)); for (int j = i + 1; j < item.rowCount(); ++j) QCOMPARE(item.child(j), itemList.at(j)); } qDeleteAll(itemList); }
void list_handling::compare_downloads(QModelIndex &index, std::vector<package>::iterator &new_it, std::vector<package>::iterator &old_it, vector<view_info> &info){ int dl_line = 0; vector<download>::iterator old_dit = old_it->dls.begin(); vector<download>::iterator new_dit = new_it->dls.begin(); vector<view_info>::iterator vit; QStandardItem *pkg; QStandardItem *dl; pkg = list_model->itemFromIndex(index); if(pkg == NULL) return; // compare every single download of the package while((old_dit != old_it->dls.end()) && (new_dit != new_it->dls.end())){ compare_one_download(*new_dit, *old_dit, pkg, dl_line); // recreate selection if existed for(vit = info.begin(); vit != info.end(); ++vit){ if((vit->id == new_dit->id) && !(vit->package)){ if(vit->selected){ // download is selected for(int i=0; i<5; ++i) selection_model->select(index.child(dl_line, i), QItemSelectionModel::Select); selected_downloads_size += (double)new_dit->size / 1048576; ++selected_downloads_count; break; } } } ++old_dit; ++new_dit; ++dl_line; } if(old_dit != old_it->dls.end()){ // there are more old lines than new ones while(old_dit != old_it->dls.end()){ // delete packages out of model for(int i=0; i<5; ++i){ dl = pkg->takeChild(dl_line, i); delete dl; } pkg->takeRow(dl_line); ++old_dit; } }else if(new_dit != new_it->dls.end()){ // there are more new lines than old ones while(new_dit != new_it->dls.end()){ // insert new download linkes create_new_download(*new_dit, pkg, dl_line); ++dl_line; ++new_dit; } list->collapse(index); list->expand(index); } }