From 81fabae3a46daa1c3c2ed317e5542b88f594ce5c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 29 Nov 2024 11:06:22 +1000 Subject: [PATCH] When merging cells in layout tables, concatenate original cell text Fixes #59611 --- src/gui/tableeditor/qgstableeditorwidget.cpp | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/gui/tableeditor/qgstableeditorwidget.cpp b/src/gui/tableeditor/qgstableeditorwidget.cpp index 2cf29c3a0249..b95defa5714b 100644 --- a/src/gui/tableeditor/qgstableeditorwidget.cpp +++ b/src/gui/tableeditor/qgstableeditorwidget.cpp @@ -1377,9 +1377,34 @@ void QgsTableEditorWidget::mergeSelectedCells() if ( maxCol == -1 || index.column() > maxCol ) maxCol = index.column(); } + QStringList mergedCellText; + for ( int row = minRow; row <= maxRow; ++row ) + { + for ( int col = minCol; col <= maxCol; ++col ) + { + if ( QTableWidgetItem *i = item( row, col ) ) + { + const QString content = i->data( CellContent ).toString(); + if ( !content.isEmpty() ) + { + mergedCellText.append( content ); + } + } + } + } setSpan( minRow, minCol, maxRow - minRow + 1, maxCol - minCol + 1 ); + // set merged cell text to concatenate original cell text + if ( !mergedCellText.isEmpty() ) + { + if ( QTableWidgetItem *i = item( minRow, minCol ) ) + { + i->setText( mergedCellText.join( ' ' ) ); + i->setData( CellContent, i->text() ); + } + } + if ( !mBlockSignals ) emit tableChanged(); }