! * custom sort of all or selected columns in the spreadsheet together by allowing * to specify the "sort by"-column(s) in the SortDialog. */
| 3565 | * to specify the "sort by"-column(s) in the SortDialog. |
| 3566 | */ |
| 3567 | void SpreadsheetView::sortCustom() { |
| 3568 | const auto& cols = selectedColumns(); |
| 3569 | QVector<Column*> columnsToSort; |
| 3570 | Column* leadingColumn{nullptr}; |
| 3571 | |
| 3572 | bool sortAll{true}; |
| 3573 | if (cols.size() == 0) |
| 3574 | // no columns selected, the function is being called from the spreadsheet context menu, |
| 3575 | // sort all columns |
| 3576 | columnsToSort = m_spreadsheet->children<Column>(); |
| 3577 | else if (cols.size() == 1) { |
| 3578 | // one single column selected, sort the whole spreadsheet (all columns) |
| 3579 | // with the current selected column being the leading column |
| 3580 | columnsToSort = m_spreadsheet->children<Column>(); |
| 3581 | leadingColumn = cols.constFirst(); |
| 3582 | } else { |
| 3583 | columnsToSort = cols; |
| 3584 | sortAll = (cols.size() == m_spreadsheet->columnCount()); |
| 3585 | } |
| 3586 | |
| 3587 | // don't do any sort if there are no values yet in the columns |
| 3588 | if (!hasValues(columnsToSort)) |
| 3589 | return; |
| 3590 | |
| 3591 | for (auto* col : columnsToSort) |
| 3592 | col->setSuppressDataChangedSignal(true); |
| 3593 | |
| 3594 | auto* dlg = new SortDialog(this, sortAll); |
| 3595 | connect(dlg, &SortDialog::sort, m_spreadsheet, &Spreadsheet::sortColumns); |
| 3596 | dlg->setColumns(columnsToSort, leadingColumn); |
| 3597 | |
| 3598 | int rc = dlg->exec(); |
| 3599 | |
| 3600 | for (auto* col : columnsToSort) { |
| 3601 | col->setSuppressDataChangedSignal(false); |
| 3602 | if (rc == QDialog::Accepted) |
| 3603 | col->setChanged(); |
| 3604 | } |
| 3605 | } |
| 3606 | |
| 3607 | bool SpreadsheetView::hasValues(const QVector<Column*> cols) { |
| 3608 | bool hasValues = false; |
nothing calls this directly
no test coverage detected