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& ) ) ); }
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()); } }
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(); }
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); } }
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(); } }
void BookmarkDialog::selectBookmarkFolder(const QString &folderName) { if (folderName.isEmpty()) return; if (folderName == tr("Bookmarks")) { ui.treeView->clearSelection(); return; } QStandardItemModel *model = bookmarkManager->treeBookmarkModel(); QList<QStandardItem*> list = model->findItems(folderName, Qt::MatchCaseSensitive | Qt::MatchRecursive, 0); if (!list.isEmpty()) { QModelIndex index = model->indexFromItem(list.at(0)); ui.treeView->selectionModel()->setCurrentIndex( proxyModel->mapFromSource(index), QItemSelectionModel::ClearAndSelect); } }