void GraphTableWidget::highlightElements(const std::set<unsigned int>& elementsToHighligh) { QItemSelectionModel *itemSelectionModel = new QItemSelectionModel(_tulipTableModel); for(int i = 0 ; i < _tulipTableModel->rowCount() ; ++i) { if(elementsToHighligh.find(_tulipTableModel->idForIndex(i))!=elementsToHighligh.end()) { itemSelectionModel->select(_tulipTableModel->index(i,0),QItemSelectionModel::Select| QItemSelectionModel::Rows); } } QItemSelectionModel *oldSelectionModel = selectionModel(); setSelectionModel(itemSelectionModel); oldSelectionModel->deleteLater(); }
void PartitionPage::updateFromCurrentDevice() { QModelIndex index = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 ); if ( !index.isValid() ) return; Device* device = m_core->deviceModel()->deviceForIndex( index ); QAbstractItemModel* oldModel = m_ui->partitionTreeView->model(); if ( oldModel ) disconnect( oldModel, 0, this, 0 ); PartitionModel* model = m_core->partitionModelForDevice( device ); m_ui->partitionBarsView->setModel( model ); m_ui->partitionLabelsView->setModel( model ); m_ui->partitionTreeView->setModel( model ); m_ui->partitionTreeView->expandAll(); // Make all views use the same selection model. if ( m_ui->partitionBarsView->selectionModel() != m_ui->partitionTreeView->selectionModel() || m_ui->partitionBarsView->selectionModel() != m_ui->partitionLabelsView->selectionModel() ) { // Tree view QItemSelectionModel* selectionModel = m_ui->partitionTreeView->selectionModel(); m_ui->partitionTreeView->setSelectionModel( m_ui->partitionBarsView->selectionModel() ); selectionModel->deleteLater(); // Labels view selectionModel = m_ui->partitionLabelsView->selectionModel(); m_ui->partitionLabelsView->setSelectionModel( m_ui->partitionBarsView->selectionModel() ); selectionModel->deleteLater(); } // This is necessary because even with the same selection model it might happen that // a !=0 column is selected in the tree view, which for some reason doesn't trigger a // timely repaint in the bars view. connect( m_ui->partitionBarsView->selectionModel(), &QItemSelectionModel::currentChanged, this, [=] { QModelIndex selectedIndex = m_ui->partitionBarsView->selectionModel()->currentIndex(); selectedIndex = selectedIndex.sibling( selectedIndex.row(), 0 ); m_ui->partitionBarsView->setCurrentIndex( selectedIndex ); m_ui->partitionLabelsView->setCurrentIndex( selectedIndex ); }, Qt::UniqueConnection ); // Must be done here because we need to have a model set to define // individual column resize mode QHeaderView* header = m_ui->partitionTreeView->header(); header->setSectionResizeMode( QHeaderView::ResizeToContents ); header->setSectionResizeMode( 0, QHeaderView::Stretch ); updateButtons(); // Establish connection here because selection model is destroyed when // model changes connect( m_ui->partitionTreeView->selectionModel(), &QItemSelectionModel::currentChanged, [ this ]( const QModelIndex& index, const QModelIndex& oldIndex ) { updateButtons(); } ); connect( model, &QAbstractItemModel::modelReset, this, &PartitionPage::onPartitionModelReset ); }