void Matrix::deleteSelectedColumns() { QItemSelectionModel *selModel = d_table_view->selectionModel(); if (!selModel || !selModel->hasSelection()) return; int startCol = -1; int count = 0; int cols = numCols(); for (int i=0; i<cols; i++){ if (selModel->isColumnSelected(i, QModelIndex())){ if (startCol < 0) startCol = i; ++count; } } if (startCol < 0 || !count) return; double *buffer = d_matrix_model->dataCopy(0, numRows() - 1, startCol, startCol + count - 1); if (buffer){ d_undo_stack->push(new MatrixDeleteColsCommand(d_matrix_model, startCol, count, buffer, tr("Delete Columns") + " " + QString::number(startCol + 1) + " - " + QString::number(startCol + count))); emit modifiedWindow(this); } else if (ignoreUndo()){ d_matrix_model->removeColumns(startCol, count); d_table_view->reset(); emit modifiedWindow(this); } }
int Matrix::numSelectedColumns() { QItemSelectionModel *selModel = d_table_view->selectionModel(); if (!selModel || !selModel->hasSelection()) return 0; int cols = numCols(); int count = 0; for (int i = 0; i<cols; i++){ if (selModel->isColumnSelected (i, QModelIndex())) count++; } return count; }