Commit db06b08a authored by Tomas Mecir's avatar Tomas Mecir
Browse files

Fix undo/redo of multiple style-affecting commands, such as the cell format dialog.

parent d0a345cd
Pipeline #185472 passed with stage
in 20 minutes and 53 seconds
......@@ -271,6 +271,7 @@ QVector< QPair<QRectF, SharedSubStyle> > StyleStorage::currentData(const Region&
pairs[i].first = pairs[i].first.intersected(rect);
// Always a default subStyle first, even if there are no pairs.
// This is necessary for undo to properly clear new substyles.
result.push_back (qMakePair(QRectF(rect), SharedSubStyle()));
result.append (QVector< QPair<QRectF, SharedSubStyle> >::fromList (pairs));
......@@ -369,7 +370,16 @@ void StyleStorage::insert(const QRect& rect, const SharedSubStyle& subStyle, boo
if (m_storingUndo) d->m_undoData << currentData(Region(rect));
if (m_storingUndo) {
auto data = currentData(Region(rect));
// We need to store this data at the BEGINNING of the undo data. This is so that multiple operations do not conceal the correct values.
// Otherwise if we e.g. set bold and italics consequently, the first call would set the correct undo data, then the second one
// would overwrite it with a bolded version.
// When the data is in reverse, this is not an issue - we do have a lot of extra values, but garbage collection will take care of that.
// We cannot simply ignore subsequent data, as the rects may be different.
for (int i = data.size() - 1; i >= 0; --i)
// debugSheetsStyle <<"StyleStorage: inserting" << SubStyle::name(subStyle->type()) <<" into" << rect;
// keep track of the used area
......@@ -57,7 +57,8 @@ StyleStorageUndoCommand::StyleStorageUndoCommand(StyleStorage *storage, KUndo2Co
void StyleStorageUndoCommand::undo()
for (int i = 0; i < m_undoData.count(); ++i) {
m_storage->insert(m_undoData[i].first.toRect(), m_undoData[i].second);
QRect rect = m_undoData[i].first.toRect();
m_storage->insert(rect, m_undoData[i].second);
KUndo2Command::undo(); // undo possible child commands
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment