本文整理汇总了C++中QStandardItem::takeRow方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItem::takeRow方法的具体用法?C++ QStandardItem::takeRow怎么用?C++ QStandardItem::takeRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItem
的用法示例。
在下文中一共展示了QStandardItem::takeRow方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_mMoveUpToolButton_clicked
void QgsComposerLegendWidget::on_mMoveUpToolButton_clicked()
{
if ( !mLegend )
{
return;
}
QStandardItemModel* itemModel = qobject_cast<QStandardItemModel *>( mItemTreeView->model() );
if ( !itemModel )
{
return;
}
QModelIndex currentIndex = mItemTreeView->currentIndex();
if ( !currentIndex.isValid() )
{
return;
}
mLegend->beginCommand( "Moved legend item up" );
//is there an older sibling?
int row = currentIndex.row();
QModelIndex olderSibling = currentIndex.sibling( row - 1, 0 );
if ( !olderSibling.isValid() )
{
return;
}
QModelIndex parentIndex = currentIndex.parent();
QList<QStandardItem*> itemToMove;
QList<QStandardItem*> olderSiblingItem;
if ( !parentIndex.isValid() ) //move toplevel item
{
itemToMove = itemModel->takeRow( row );
olderSiblingItem = itemModel->takeRow( row - 1 );
itemModel->insertRow( row - 1, itemToMove );
itemModel->insertRow( row, olderSiblingItem );
}
else //move classification items
{
QStandardItem* parentItem = itemModel->itemFromIndex( parentIndex );
itemToMove = parentItem->takeRow( row );
olderSiblingItem = parentItem->takeRow( row - 1 );
parentItem->insertRow( row - 1, itemToMove );
parentItem->insertRow( row, olderSiblingItem );
}
mItemTreeView->setCurrentIndex( itemModel->indexFromItem( itemToMove.at( 0 ) ) );
mLegend->update();
mLegend->endCommand();
}
示例2: on_mMoveDownPushButton_clicked
void QgsComposerLegendWidget::on_mMoveDownPushButton_clicked()
{
QStandardItemModel* itemModel = dynamic_cast<QStandardItemModel*>( mItemTreeView->model() );
if ( !itemModel )
{
return;
}
QModelIndex currentIndex = mItemTreeView->currentIndex();
if ( !currentIndex.isValid() )
{
return;
}
//is there an older sibling?
int row = currentIndex.row();
QModelIndex youngerSibling = currentIndex.sibling( row + 1, 0 );
if ( !youngerSibling.isValid() )
{
return;
}
QModelIndex parentIndex = currentIndex.parent();
QList<QStandardItem*> itemToMove;
QList<QStandardItem*> youngerSiblingItem;
if ( !parentIndex.isValid() ) //move toplevel (layer) item
{
youngerSiblingItem = itemModel->takeRow( row + 1 );
itemToMove = itemModel->takeRow( row );
itemModel->insertRow( row, youngerSiblingItem );
itemModel->insertRow( row + 1, itemToMove );
}
else //move child (classification) item
{
QStandardItem* parentItem = itemModel->itemFromIndex( parentIndex );
youngerSiblingItem = parentItem->takeRow( row + 1 );
itemToMove = parentItem->takeRow( row );
parentItem->insertRow( row, youngerSiblingItem );
parentItem->insertRow( row + 1, itemToMove );
}
mItemTreeView->setCurrentIndex( itemModel->indexFromItem( itemToMove.at( 0 ) ) );
if ( mLegend )
{
mLegend->update();
}
}
示例3: compare_downloads
void list_handling::compare_downloads(QModelIndex &index, std::vector<package>::iterator &new_it, std::vector<package>::iterator &old_it, vector<view_info> &info){
int dl_line = 0;
vector<download>::iterator old_dit = old_it->dls.begin();
vector<download>::iterator new_dit = new_it->dls.begin();
vector<view_info>::iterator vit;
QStandardItem *pkg;
QStandardItem *dl;
pkg = list_model->itemFromIndex(index);
if(pkg == NULL)
return;
// compare every single download of the package
while((old_dit != old_it->dls.end()) && (new_dit != new_it->dls.end())){
compare_one_download(*new_dit, *old_dit, pkg, dl_line);
// recreate selection if existed
for(vit = info.begin(); vit != info.end(); ++vit){
if((vit->id == new_dit->id) && !(vit->package)){
if(vit->selected){ // download is selected
for(int i=0; i<5; ++i)
selection_model->select(index.child(dl_line, i), QItemSelectionModel::Select);
selected_downloads_size += (double)new_dit->size / 1048576;
++selected_downloads_count;
break;
}
}
}
++old_dit;
++new_dit;
++dl_line;
}
if(old_dit != old_it->dls.end()){ // there are more old lines than new ones
while(old_dit != old_it->dls.end()){
// delete packages out of model
for(int i=0; i<5; ++i){
dl = pkg->takeChild(dl_line, i);
delete dl;
}
pkg->takeRow(dl_line);
++old_dit;
}
}else if(new_dit != new_it->dls.end()){ // there are more new lines than old ones
while(new_dit != new_it->dls.end()){
// insert new download linkes
create_new_download(*new_dit, pkg, dl_line);
++dl_line;
++new_dit;
}
list->collapse(index);
list->expand(index);
}
}
示例4: removeGroup
void AbstractCameraManager::removeGroup(QModelIndex index) {
QStandardItem * item = getModel()->itemFromIndex( index );
if( !item->isEditable() ) return;
QStandardItem * parent = item->parent();
if( parent == NULL ) parent = item->model()->invisibleRootItem();
for(int i=item->rowCount(); i>0; i--) {
newCameraList.insertRow(0, item->takeRow(0));
}
parent->removeRow( item->row() );
detectNewCamerasAndExpand();
}
示例5: updateItemRowOrder
/**
Updates the sibling position of the item, depending on the position in the model.
*/
void NavigatorTreeModel::updateItemRowOrder(const ModelNode &node)
{
if (!containsNode(node))
return;
ItemRow itemRow = itemRowForNode(node);
int currentRow = itemRow.idItem->row();
int newRow = currentRow;
if (node.parentProperty().parentModelNode().isValid())
newRow = modelNodeChildren(node.parentProperty().parentModelNode()).indexOf(node);
Q_ASSERT(newRow >= 0);
if (currentRow != newRow) {
QStandardItem *parentIdItem = itemRow.idItem->parent();
QList<QStandardItem*> items = parentIdItem->takeRow(currentRow);
parentIdItem->insertRow(newRow, items);
}
}
示例6: deleteAllChildren
void EventViewer::deleteAllChildren(QStandardItem * parent)
{
//delete all children of eventsItem;
QStandardItem * loopItem = parent; //main loop item
QList<QStandardItem *> carryItems; //Last In First Out stack of items
QList<QStandardItem *> itemsToBeDeleted; //List of items to be deleted
while (loopItem->rowCount())
{
itemsToBeDeleted << loopItem->takeRow(0);
//if the row removed has children:
if (itemsToBeDeleted.at(0)->hasChildren())
{
carryItems << loopItem; //put on the stack the current loopItem
loopItem = itemsToBeDeleted.at(0); //set the row with children as the loopItem
}
//if current loopItem has no more rows but carryItems list is not empty:
if (!loopItem->rowCount() && !carryItems.isEmpty()) loopItem = carryItems.takeFirst();
}
qDeleteAll(itemsToBeDeleted);
}
示例7: moveEffectByOffset
void QgsEffectStackPropertiesWidget::moveEffectByOffset( int offset )
{
EffectItem *item = currentEffectItem();
if ( !item )
return;
int row = item->row();
QStandardItem* root = mModel->invisibleRootItem();
int layerIdx = root->rowCount() - row - 1;
// switch effects
QgsPaintEffect* tmpEffect = mStack->takeEffect( layerIdx );
mStack->insertEffect( layerIdx - offset, tmpEffect );
QList<QStandardItem *> toMove = root->takeRow( row );
root->insertRows( row + offset, toMove );
QModelIndex newIdx = toMove[ 0 ]->index();
mEffectsList->setCurrentIndex( newIdx );
updatePreview();
updateUi();
}
示例8: moveItem
void FileOrganiserWidget::moveItem(QStandardItem *pItem,
QStandardItem *pDropItem,
const QAbstractItemView::DropIndicatorPosition &pDropPosition)
{
if (!pDropItem)
// pDropItem is not valid, so...
return;
// Move pItem above/on/below pDropItem, depending on the drop position, but
// first, determine the item that will own pItem
QStandardItem *crtParentItem = pItem->parent()?
pItem->parent():
mModel->invisibleRootItem();
QStandardItem *newParentItem = parentItem(pDropItem, pDropPosition);
// Second, check whether the (file) item points to a file which is already
// owned by newParentItem
bool fileAlreadyOwned = false;
if (!pItem->data(Item::Folder).toBool())
// The current item is a file item, so retrieve its file name and check
// whether it's already owned by newParentItem
fileAlreadyOwned = ownedBy(pItem->data(Item::Path).toString(), newParentItem);
// Third, move pItem to newParentItem and this to the right place, depending
// on the value of pDropPosition and only if the destination doesn't already
// have that item (should it be a file item, since folder items are always
// moved)
if (!fileAlreadyOwned || (crtParentItem == newParentItem)) {
// Either newParentItem doesn't already own an item which points to the
// same file as pItem or pItem's current parent is the same as
// newParentItem in which case it means that we want to move the item
// within its current location
// First, check whether the item is a folder and, if so, whether it's
// expanded (and the same with any (in)direct child folder it may
// contain)
backupExpandedInformation(pItem);
// Second, move the item (and any of its children)
dropItems(pDropItem, pDropPosition, newParentItem,
crtParentItem->takeRow(pItem->row()));
// Third, re-expand folders, if necessary
restoreExpandedInformation(pItem);
// Fourth, resize the widget, just in case the new location of the
// item(s) requires more space than is visible
resizeToContents();
} else {
// A (file) item pointing to the same file is already owned by
// newParentItem, so just remove the item rather than move it
crtParentItem->removeRow(pItem->row());
}
}
示例9: apply
//.........这里部分代码省略.........
if (rowType == RowType::Node && ModelItem::prop(child)) break;
size_t index;
// Encountered a property that has a higher index than this item, so stop
auto prop = ModelItem::prop(child);
if (prop)
{
auto propNode = mutation->cur.parent(*prop);
// add node childCount because the properties start BELOW the child nodes
index = mutation->cur.childIndex(*prop) + mutation->cur.childCount(*propNode);
if (index > maxRow) break;
}
// Encountered a node that has a higher index than this item, so stop
auto node = ModelItem::node(child);
if (node)
{
index = mutation->cur.childIndex(*node);
if (index > maxRow) break;
}
}
//LOG->debug("row: {}, rowCount: {}", row, parent->rowCount());
if (row <= static_cast<size_t>(parent->rowCount())) parent->insertRow(row, items);
else parent->appendRow(items);
};
auto applyMutations = [&](auto& changes, RowType rowType, auto createItems, bool onlyRemove)
{
for (auto&& mut : changes)
{
QStandardItem* prevParentNode = findItem(resolve(mut.prevParent));
if (!prevParentNode && rowType == RowType::Node) prevParentNode = invisibleRootItem();
QStandardItem* curParentNode = findItem(resolve(mut.curParent));
if (!curParentNode && rowType == RowType::Node) curParentNode = invisibleRootItem();
switch (mut.type)
{
case ChangeType::Added:
{
if (onlyRemove) continue;
LOG->debug("Adding at position {}: {}", mut.curIndex, *mut.cur);
setRow(curParentNode, mut.curIndex, createItems(mut.cur), rowType);
break;
}
case ChangeType::Removed:
{
if (!onlyRemove) continue;
auto item = findItem(mut.prev);
if (!item) continue; // maybe was already deleted when parent was removed
auto childIndex = findChildIndex(prevParentNode, item);
if (childIndex != -1) prevParentNode->removeRow(childIndex);
LOG->debug("Removed at position {}: {}", childIndex, *mut.prev);
break;
}
case ChangeType::Mutated:
{
if (onlyRemove) continue;
assert(prevParentNode && curParentNode);
LOG->debug("Mutating from position {} to position {}: {}", mut.prevIndex, mut.curIndex, *mut.cur);
auto nodeOrProperty = resolve(mut.prev);
auto item = findItem(nodeOrProperty);
assert(item);
auto prevIndex = findChildIndex(prevParentNode, item);
assert(prevIndex != -1);
if (prevIndex != mut.curIndex || prevParentNode != curParentNode)
{
// Move the row
auto itemRowItems = prevParentNode->takeRow(prevIndex);
setRow(curParentNode, mut.curIndex, itemRowItems, rowType);
}
break;
}
}
}
};
auto createNodeItems = [&](NodePtr node)
{
QList<QStandardItem*> items;
items << new ModelItem(this, node) << nullptr;
return items;
};
auto createPropertyItems = [&](PropertyPtr prop)
{
QList<QStandardItem*> items;
auto modelItem = new ModelItem(this, prop);
items << modelItem << modelItem->propertyValueItem();
return items;
};
applyMutations(mutation->nodes, RowType::Node, createNodeItems, false);
applyMutations(mutation->properties, RowType::Property, createPropertyItems, false);
applyMutations(mutation->nodes, RowType::Node, createNodeItems, true);
applyMutations(mutation->properties, RowType::Property, createPropertyItems, true);
}