本文整理汇总了C++中QVariant::toModelIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::toModelIndex方法的具体用法?C++ QVariant::toModelIndex怎么用?C++ QVariant::toModelIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::toModelIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setCurrentIndex
void TreeExtensionOld::setCurrentIndex( const QVariant& index )
{
QModelIndex idx = index.toModelIndex();
impl_->currentIndex_ = idx;
emit currentIndexChanged();
}
示例2: parseDirectoryListing
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);
}