void TreeExtensionOld::setCurrentIndex( const QVariant& index ) { QModelIndex idx = index.toModelIndex(); impl_->currentIndex_ = idx; emit currentIndexChanged(); }
void RemoteModel::parseDirectoryListing(const QString& json, const QVariant& userdata) { // Load new JSON root document assuming it's an array QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); if(doc.isNull() || !doc.isArray()) return; QJsonArray array = doc.array(); // Get model index to store the new data under QModelIndex parent = userdata.toModelIndex(); RemoteModelItem* parentItem = const_cast<RemoteModelItem*>(modelIndexToItem(parent)); // An invalid model index indicates that this is a new root item. This means the old one needs to be entirely deleted first. if(!parent.isValid()) { // Clear root item beginResetModel(); delete rootItem; rootItem = new RemoteModelItem(); endResetModel(); // Set parent model index and parent item to the new values parent = QModelIndex(); parentItem = rootItem; } // Insert data beginInsertRows(parent, 0, array.size()); QList<RemoteModelItem*> items = RemoteModelItem::loadArray(QJsonValue(array), parentItem); foreach(RemoteModelItem* item, items) parentItem->appendChild(item); endInsertRows(); // Emit directory listing parsed signal emit directoryListingParsed(parent); }