本文整理汇总了C++中TaskItem::takeChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TaskItem::takeChild方法的具体用法?C++ TaskItem::takeChild怎么用?C++ TaskItem::takeChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskItem
的用法示例。
在下文中一共展示了TaskItem::takeChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cut
QModelIndex TreeModel::cut(const QModelIndex &index)
{
if (!index.isValid())
return index;
delete cutItem;
cutItem = itemForIndex(index);
Q_ASSERT(cutItem);
TaskItem *parent = cutItem->parent();
Q_ASSERT(parent);
int row = parent->rowOfChild(cutItem);
Q_ASSERT(row == index.row());
beginRemoveRows(index.parent(), row, row);
TaskItem *child = parent->takeChild(row);
endRemoveRows();
Q_ASSERT(child == cutItem);
child = 0; // Silence compiler unused variable warning
if (row > 0) {
--row;
return createIndex(row, 0, parent->childAt(row));
}
if (parent != rootItem) {
TaskItem *grandParent = parent->parent();
Q_ASSERT(grandParent);
return createIndex(grandParent->rowOfChild(parent), 0, parent);
}
return QModelIndex();
}
示例2: removeRows
bool TreeModel::removeRows(int row, int count,
const QModelIndex &parent)
{
if (!rootItem)
return false;
TaskItem *item = parent.isValid() ? itemForIndex(parent)
: rootItem;
beginRemoveRows(parent, row, row + count - 1);
for (int i = 0; i < count; ++i)
delete item->takeChild(row);
endRemoveRows();
return true;
}
示例3: demote
QModelIndex TreeModel::demote(const QModelIndex &index)
{
if (!index.isValid())
return index;
TaskItem *item = itemForIndex(index);
Q_ASSERT(item);
TaskItem *parent = item->parent();
Q_ASSERT(parent);
int row = parent->rowOfChild(item);
if (row == 0)
return index; // No preceding sibling to move this under
TaskItem *child = parent->takeChild(row);
Q_ASSERT(child == item);
TaskItem *sibling = parent->childAt(row - 1);
Q_ASSERT(sibling);
sibling->addChild(child);
QModelIndex newIndex = createIndex(sibling->childCount() - 1, 0,
child);
emit dataChanged(newIndex, newIndex);
return newIndex;
}
示例4: promote
QModelIndex TreeModel::promote(const QModelIndex &index)
{
if (!index.isValid())
return index;
TaskItem *item = itemForIndex(index);
Q_ASSERT(item);
TaskItem *parent = item->parent();
Q_ASSERT(parent);
if (parent == rootItem)
return index; // Already a top-level item
int row = parent->rowOfChild(item);
TaskItem *child = parent->takeChild(row);
Q_ASSERT(child == item);
TaskItem *grandParent = parent->parent();
Q_ASSERT(grandParent);
row = grandParent->rowOfChild(parent) + 1;
grandParent->insertChild(row, child);
QModelIndex newIndex = createIndex(row, 0, child);
emit dataChanged(newIndex, newIndex);
return newIndex;
}