本文整理汇总了C++中TableItem::row方法的典型用法代码示例。如果您正苦于以下问题:C++ TableItem::row方法的具体用法?C++ TableItem::row怎么用?C++ TableItem::row使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableItem
的用法示例。
在下文中一共展示了TableItem::row方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: aboutToDrop
void
TableView::dropEvent(QDropEvent* e)
{
// QTreeView::dropEvent(e);
DropIndicatorPosition position = dropIndicatorPosition();
switch (position) {
case QAbstractItemView::OnItem:
case QAbstractItemView::OnViewport:
default:
return;
case QAbstractItemView::AboveItem:
case QAbstractItemView::BelowItem:
break;
}
TableItem* into = itemAt( e->pos() );
if ( !into || _imp->draggedItems.empty() ) {
return;
}
Q_EMIT aboutToDrop();
int targetRow = into->row();
//We only support full rows
assert(selectionBehavior() == QAbstractItemView::SelectRows);
///Remove the items
std::map<int, std::map<int, TableItem*> > rowMoved;
for (std::list<TableItem*>::iterator it = _imp->draggedItems.begin(); it != _imp->draggedItems.end(); ++it) {
rowMoved[(*it)->row()][(*it)->column()] = *it;
TableItem* taken = _imp->model->takeItem( (*it)->row(), (*it)->column() );
assert(taken == *it);
Q_UNUSED(taken);
}
/// remove the rows in reverse order so that indexes are still valid
for (std::map<int, std::map<int, TableItem*> >::reverse_iterator it = rowMoved.rbegin(); it != rowMoved.rend(); ++it) {
_imp->model->removeRows(it->first);
if (it->first <= targetRow) {
--targetRow;
}
}
_imp->draggedItems.clear();
///insert back at the correct position
int nRows = _imp->model->rowCount();
switch (position) {
case QAbstractItemView::AboveItem: {
_imp->model->insertRows( targetRow, rowMoved.size() );
break;
}
case QAbstractItemView::BelowItem: {
++targetRow;
if (targetRow > nRows) {
targetRow = nRows;
}
_imp->model->insertRows( targetRow, rowMoved.size() );
break;
}
default:
assert(false);
return;
}
;
int rowIndex = targetRow;
for (std::map<int, std::map<int, TableItem*> >::iterator it = rowMoved.begin(); it != rowMoved.end(); ++it, ++rowIndex) {
for (std::map<int, TableItem*>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
_imp->model->setItem(rowIndex, it2->first, it2->second);
}
}
Q_EMIT itemDropped();
} // TableView::dropEvent