本文整理汇总了C++中TaskItem::insertChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TaskItem::insertChild方法的具体用法?C++ TaskItem::insertChild怎么用?C++ TaskItem::insertChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskItem
的用法示例。
在下文中一共展示了TaskItem::insertChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertRows
bool TreeModel::insertRows(int row, int count,
const QModelIndex &parent)
{
if (!rootItem)
rootItem = new TaskItem;
TaskItem *parentItem = parent.isValid() ? itemForIndex(parent)
: rootItem;
beginInsertRows(parent, row, row + count - 1);
for (int i = 0; i < count; ++i) {
TaskItem *item = new TaskItem(tr("New Task"), false);
parentItem->insertChild(row, item);
}
endInsertRows();
return true;
}
示例2: paste
QModelIndex TreeModel::paste(const QModelIndex &index)
{
if (!index.isValid() || !cutItem)
return index;
TaskItem *sibling = itemForIndex(index);
Q_ASSERT(sibling);
TaskItem *parent = sibling->parent();
Q_ASSERT(parent);
int row = parent->rowOfChild(sibling) + 1;
beginInsertRows(index.parent(), row, row);
parent->insertChild(row, cutItem);
TaskItem *child = cutItem;
cutItem = 0;
endInsertRows();
return createIndex(row, 0, child);
}
示例3: 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;
}