void QDeclarativeDownloadListModel::updateItem_(TorrentState const& info, ParamsMap_t)
{
qDebug() << Q_FUNC_INFO << " enter";
- /*
- item->setData(2, Qt::DisplayRole,
- QVariant(GetStatusString((TorrentStatus::Id)info.state)));
- item->setData(3, Qt::DisplayRole,
- QVariant(formatProgress(info.progress)));
- item->setData(4, Qt::DisplayRole,
- QVariant(formatSize(info.down_rate)));
- item->setData(5, Qt::DisplayRole,
- QVariant(formatSize(info.up_rate)));
- item->setData(6, Qt::DisplayRole,
- QString::number(info.seeds) + "/" + QString::number(info.leeches));
- item->setData(7, Qt::DisplayRole, QString::number(info.ratio));
-
- // Calculate ETA
- if (info.down_rate > 0) {
- qulonglong eta = (info.total_size - info.total_done) / info.down_rate;
- item->setData(8, Qt::DisplayRole, formatElapsedTime(eta));
- } else {
- item->setData(8, Qt::DisplayRole, "N/A");
+
+ // Check if we even have the item in model. At this point we should...
+ if (!d->items_.contains(info.hash)) {
+ qWarning() << Q_FUNC_INFO << " torrent with hash \'"
+ << info.hash << "\' not in model";
+ return;
}
-*/
- // TODO: Update items data & Emit data changed.
-/*
- // Set color for status text
- QBrush brushTmp(GetStatusColor((TorrentStatus::Id)info.state));
- item->setForeground(2, brushTmp);
- */
+ int row = 0;
+ ItemIndex_t::iterator iterBegin = d->itemIndexes_.begin();
+ ItemIndex_t::iterator iterEnd = d->itemIndexes_.end();
+ while (iterBegin != iterEnd) {
+ if (iterBegin.value() == info.hash) {
+ break;
+ }
+ ++row;
+ ++iterBegin;
+ }
+
+ // We iterated past the end of map -> index did not exist.
+ if (iterBegin == iterEnd) {
+ qWarning() << Q_FUNC_INFO << " torrent with hash \'"
+ << info.hash << "\' not in item index table";
+ return;
+ }
+
+ // Get the model index for item from base class:
+ QModelIndex modelIndex = index(row);
+ // For QHash, insert() replaces existing item with same key.
+ d->items_.insert(info.hash, info);
+
+ // Notify view about the change.
+ emit dataChanged(modelIndex, modelIndex);
}