本文整理汇总了C++中QAbstractItemModel::fetchMore方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::fetchMore方法的具体用法?C++ QAbstractItemModel::fetchMore怎么用?C++ QAbstractItemModel::fetchMore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemModel
的用法示例。
在下文中一共展示了QAbstractItemModel::fetchMore方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nextIndex
QModelIndex ItemViewFind::nextIndex(const QModelIndex &idx, bool *wrapped) const
{
if (wrapped)
*wrapped = false;
QAbstractItemModel *model = d->m_view->model();
// pathological
if (!idx.isValid())
return model->index(0, 0);
// same parent has more columns, go to next column
if (idx.column() + 1 < model->columnCount(idx.parent()))
return model->index(idx.row(), idx.column() + 1, idx.parent());
// tree views have their children attached to first column
// make sure we are at first column
QModelIndex current = model->index(idx.row(), 0, idx.parent());
// check for children
if (d->m_option == FetchMoreWhileSearching && model->canFetchMore(current))
model->fetchMore(current);
if (model->rowCount(current) > 0)
return current.child(0, 0);
// no more children, go up and look for parent with more children
QModelIndex nextIndex;
while (!nextIndex.isValid()) {
int row = current.row();
current = current.parent();
if (d->m_option == FetchMoreWhileSearching && model->canFetchMore(current))
model->fetchMore(current);
if (row + 1 < model->rowCount(current)) {
// Same parent has another child
nextIndex = model->index(row + 1, 0, current);
} else {
// go up one parent
if (!current.isValid()) {
// we start from the beginning
if (wrapped)
*wrapped = true;
nextIndex = model->index(0, 0);
}
}
}
return nextIndex;
}
示例2: prevIndex
QModelIndex ItemViewFind::prevIndex(const QModelIndex &idx, bool *wrapped) const
{
if (wrapped)
*wrapped = false;
QAbstractItemModel *model = d->m_view->model();
// if same parent has earlier columns, just move there
if (idx.column() > 0)
return model->index(idx.row(), idx.column() - 1, idx.parent());
QModelIndex current = idx;
bool checkForChildren = true;
if (current.isValid()) {
int row = current.row();
if (row > 0) {
current = model->index(row - 1, 0, current.parent());
} else {
current = current.parent();
checkForChildren = !current.isValid();
if (checkForChildren && wrapped) {
// we start from the end
*wrapped = true;
}
}
}
if (checkForChildren) {
// traverse down the hierarchy
if (d->m_option == FetchMoreWhileSearching && model->canFetchMore(current))
model->fetchMore(current);
while (int rc = model->rowCount(current)) {
current = model->index(rc - 1, 0, current);
}
}
// set to last column
current = model->index(current.row(), model->columnCount(current.parent()) - 1, current.parent());
return current;
}