本文整理汇总了C++中QStandardItemModel::indexFromItem方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItemModel::indexFromItem方法的具体用法?C++ QStandardItemModel::indexFromItem怎么用?C++ QStandardItemModel::indexFromItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItemModel
的用法示例。
在下文中一共展示了QStandardItemModel::indexFromItem方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QDialog
QgsStyleV2GroupSelectionDialog::QgsStyleV2GroupSelectionDialog( QgsStyleV2 *style, QWidget *parent ) :
QDialog( parent )
, mStyle( style )
{
setupUi( this );
QStandardItemModel* model = new QStandardItemModel( groupTree );
groupTree->setModel( model );
QStandardItem *allSymbols = new QStandardItem( tr( "All Symbols" ) );
allSymbols->setData( "all", Qt::UserRole + 2 );
allSymbols->setEditable( false );
setBold( allSymbols );
model->appendRow( allSymbols );
QStandardItem *group = new QStandardItem( "" ); //require empty name to get first order groups
group->setData( "groupsheader", Qt::UserRole + 2 );
group->setEditable( false );
group->setFlags( group->flags() & ~Qt::ItemIsSelectable );
buildGroupTree( group );
group->setText( tr( "Groups" ) );//set title later
QStandardItem *ungrouped = new QStandardItem( tr( "Ungrouped" ) );
ungrouped->setData( 0 );
ungrouped->setData( "group", Qt::UserRole + 2 );
setBold( ungrouped );
setBold( group );
group->appendRow( ungrouped );
model->appendRow( group );
QStandardItem *tag = new QStandardItem( tr( "Smart Groups" ) );
tag->setData( "smartgroupsheader" , Qt::UserRole + 2 );
tag->setEditable( false );
tag->setFlags( group->flags() & ~Qt::ItemIsSelectable );
setBold( tag );
QgsSymbolGroupMap sgMap = mStyle->smartgroupsListMap();
QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
while ( i != sgMap.constEnd() )
{
QStandardItem *item = new QStandardItem( i.value() );
item->setEditable( false );
item->setData( i.key() );
item->setData( "smartgroup" , Qt::UserRole + 2 );
tag->appendRow( item );
++i;
}
model->appendRow( tag );
// expand things in the group tree
int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
for ( int i = 0; i < rows; i++ )
{
groupTree->setExpanded( model->indexFromItem( model->item( i ) ), true );
}
connect( groupTree->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), this, SLOT( groupTreeSelectionChanged( const QItemSelection&, const QItemSelection& ) ) );
}
示例2: expandItems
void BookmarkWidget::expandItems()
{
QStandardItemModel *model = bookmarkManager->treeBookmarkModel();
QList<QStandardItem*>list = model->findItems(QLatin1String("*"),
Qt::MatchWildcard | Qt::MatchRecursive, 0);
foreach (const QStandardItem* item, list) {
const QModelIndex& index = model->indexFromItem(item);
treeView->setExpanded(filterBookmarkModel->mapFromSource(index),
item->data(Qt::UserRole + 11).toBool());
}
}
示例3: 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();
}
示例4: focusResults
void GenericLookupDialog::focusResults()
{
mResult->header()->resizeSections(QHeaderView::ResizeToContents);
mResult->setFocus(Qt::OtherFocusReason);
QStandardItemModel * model = qobject_cast<QStandardItemModel*>(mResult->model());
QStandardItem * firstItem = model->item(0, 0);
if (firstItem) {
QModelIndex firstIndex = model->indexFromItem(firstItem);
mResult->setCurrentIndex(firstIndex);
}
}
示例5: 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();
}
}