bool MainWindow::removeColumn(const QModelIndex &parent) { QAbstractItemModel *model = view->model(); int column = view->selectionModel()->currentIndex().column(); // Insert columns in each child of the parent item. bool changed = model->removeColumn(column, parent); if (!parent.isValid() && changed) updateActions(); return changed; }
void Button::on_clicked() { QTableView* table = qobject_cast<QTableView*>(this->parent()); if (!table) return; QAbstractItemModel* model = table->model(); if (!model) return; if (_type == InsertRemove::Insert) { if (_orientation == Qt::Horizontal) model->insertColumn(_modelIndex); else model->insertRow(_modelIndex); } else // _type == InsertRemove::Remove { if (_orientation == Qt::Horizontal) model->removeColumn(_modelIndex); else model->removeRow(_modelIndex); } }