Author: craig
Date: Wed Jan 19 16:18:08 2022
New Revision: 24810

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24810
Log:
#16716: Add undo/redo for table row/column resizing

Modified:
    trunk/Scribus/scribus/canvasgesture_columnresize.cpp
    trunk/Scribus/scribus/canvasgesture_rowresize.cpp
    trunk/Scribus/scribus/pageitem_table.cpp
    trunk/Scribus/scribus/pageitem_table.h
    trunk/Scribus/scribus/scribusdoc.cpp

Modified: trunk/Scribus/scribus/canvasgesture_columnresize.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24810&path=/trunk/Scribus/scribus/canvasgesture_columnresize.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasgesture_columnresize.cpp        (original)
+++ trunk/Scribus/scribus/canvasgesture_columnresize.cpp        Wed Jan 19 
16:18:08 2022
@@ -18,6 +18,7 @@
 #include "pageitem_table.h"
 #include "scribusdoc.h"
 #include "scribusview.h"
+#include "undomanager.h"
 
 #include "canvasgesture_columnresize.h"
 
@@ -60,6 +61,10 @@
        else
                strategy = PageItem_Table::ResizeFollowing;
 
+       UndoTransaction activeTransaction;
+       if (UndoManager::undoEnabled())
+               activeTransaction = 
UndoManager::instance()->beginTransaction(table()->getUName(), 
table()->getUPixmap(), Um::TableColumnWidth, QString(), Um::ITable);
+
        table()->doc()->dontResize = true;
        table()->resizeColumn(m_column, gridPoint.x() - 
table()->columnPosition(m_column), strategy);
        if (strategy == PageItem_Table::MoveFollowing)
@@ -71,6 +76,9 @@
        table()->adjustFrameToTable();
        table()->doc()->setRedrawBounding(table());
        table()->update();
+
+       if (activeTransaction)
+               activeTransaction.commit();
 
        m_view->stopGesture();
 }

Modified: trunk/Scribus/scribus/canvasgesture_rowresize.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24810&path=/trunk/Scribus/scribus/canvasgesture_rowresize.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasgesture_rowresize.cpp   (original)
+++ trunk/Scribus/scribus/canvasgesture_rowresize.cpp   Wed Jan 19 16:18:08 2022
@@ -18,6 +18,7 @@
 #include "pageitem_table.h"
 #include "scribusdoc.h"
 #include "scribusview.h"
+#include "undomanager.h"
 
 #include "canvasgesture_rowresize.h"
 
@@ -60,6 +61,10 @@
        else
                strategy = PageItem_Table::ResizeFollowing;
 
+       UndoTransaction activeTransaction;
+       if (UndoManager::undoEnabled())
+               activeTransaction = 
UndoManager::instance()->beginTransaction(table()->getUName(), 
table()->getUPixmap(), Um::TableRowHeight, QString(), Um::ITable);
+
        table()->doc()->dontResize = true;
        table()->resizeRow(m_row, gridPoint.y() - table()->rowPosition(m_row), 
strategy);
        if (strategy == PageItem_Table::MoveFollowing)
@@ -71,6 +76,9 @@
        table()->adjustFrameToTable();
        table()->doc()->setRedrawBounding(table());
        table()->update();
+
+       if (activeTransaction)
+               activeTransaction.commit();
 
        m_view->stopGesture();
 }

Modified: trunk/Scribus/scribus/pageitem_table.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24810&path=/trunk/Scribus/scribus/pageitem_table.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.cpp    (original)
+++ trunk/Scribus/scribus/pageitem_table.cpp    Wed Jan 19 16:18:08 2022
@@ -758,7 +758,16 @@
 
        if (!validRow(row))
                return;
-
+       if (UndoManager::undoEnabled())
+       {
+               SimpleState *ss = new SimpleState(Um::TableRowHeight, 
QString(), Um::IResize);
+               ss->set("TABLE_ROW_HEIGHT");
+               ss->set("ROW", row);
+               ss->set("OLD_ROW_HEIGHT", rowHeight(row));
+               ss->set("NEW_ROW_HEIGHT", height);
+               ss->set("ROW_RESIZE_STRATEGY", strategy == MoveFollowing ? 0 : 
1);
+               undoManager->action(this, ss);
+       }
        if (strategy == MoveFollowing)
                resizeRowMoveFollowing(row, height);
        else if (strategy == ResizeFollowing)
@@ -820,7 +829,16 @@
 
        if (!validColumn(column))
                return;
-
+       if (UndoManager::undoEnabled())
+       {
+               SimpleState *ss = new SimpleState(Um::TableColumnWidth, 
QString(), Um::IResize);
+               ss->set("TABLE_COLUMN_WIDTH");
+               ss->set("COLUMN", column);
+               ss->set("OLD_COLUMN_WIDTH", columnWidth(column));
+               ss->set("NEW_COLUMN_WIDTH", width);
+               ss->set("COLUMN_RESIZE_STRATEGY", strategy == MoveFollowing ? 0 
: 1);
+               undoManager->action(this, ss);
+       }
        if (strategy == MoveFollowing)
                resizeColumnMoveFollowing(column, width);
        else if (strategy == ResizeFollowing)
@@ -2181,6 +2199,16 @@
                restoreTableStyleReset(simpleState, isUndo);
                doUpdate = true;
        }
+       else if (simpleState->contains("TABLE_ROW_HEIGHT"))
+       {
+               restoreTableRowHeight(simpleState, isUndo);
+               doUpdate = true;
+       }
+       else if (simpleState->contains("TABLE_COLUMN_WIDTH"))
+       {
+               restoreTableColumnWidth(simpleState, isUndo);
+               doUpdate = true;
+       }
        else
        {
                PageItem::restore(state, isUndo);
@@ -2490,4 +2518,36 @@
 {
        QString restoredStyle = state->get(isUndo ? "OLD_STYLE" : "NEW_STYLE");
        setStyle(restoredStyle);
-}
+}
+
+void PageItem_Table::restoreTableRowHeight(SimpleState *state, bool isUndo)
+{
+       int row = state->getInt("ROW");
+       ResizeStrategy strategy = state->getInt("ROW_RESIZE_STRATEGY") == 0 ? 
MoveFollowing : ResizeFollowing;
+       if (isUndo)
+       {
+               double oldHeight = state->getDouble("OLD_ROW_HEIGHT");
+               resizeRow(row, oldHeight, strategy);
+       }
+       else
+       {
+               double newHeight = state->getDouble("NEW_ROW_HEIGHT");
+               resizeRow(row, newHeight, strategy);
+       }
+}
+
+void PageItem_Table::restoreTableColumnWidth(SimpleState *state, bool isUndo)
+{
+       int column = state->getInt("COLUMN");
+       ResizeStrategy strategy = state->getInt("COLUMN_RESIZE_STRATEGY") == 0 
? MoveFollowing : ResizeFollowing;
+       if (isUndo)
+       {
+               double oldWidth = state->getDouble("OLD_COLUMN_WIDTH");
+               resizeColumn(column, oldWidth, strategy);
+       }
+       else
+       {
+               double newWidth = state->getDouble("NEW_COLUMN_WIDTH");
+               resizeColumn(column, newWidth, strategy);
+       }
+}

Modified: trunk/Scribus/scribus/pageitem_table.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24810&path=/trunk/Scribus/scribus/pageitem_table.h
==============================================================================
--- trunk/Scribus/scribus/pageitem_table.h      (original)
+++ trunk/Scribus/scribus/pageitem_table.h      Wed Jan 19 16:18:08 2022
@@ -699,6 +699,12 @@
        // Undo/redo unsetStyle action
        void restoreTableStyleReset(SimpleState *state, bool isUndo);
 
+       // Undo/redo row height action
+       void restoreTableRowHeight(SimpleState *state, bool isUndo);
+
+       // Undo/redo column widht action
+       void restoreTableColumnWidth(SimpleState *state, bool isUndo);
+
 private:
        //<<Data we need to save
        /// List of rows of cells in the table.

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24810&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp        (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp        Wed Jan 19 16:18:08 2022
@@ -8687,6 +8687,10 @@
        const qreal rowHeight = dialog->rowHeight();
        QScopedValueRollback<bool> dontResizeRb(dontResize, true);
 
+       UndoTransaction activeTransaction;
+       m_updateManager.setUpdatesDisabled();
+       if (UndoManager::undoEnabled())
+               activeTransaction = 
m_undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, 
Um::TableRowHeight, item->itemName(), Um::ITable);
        if (appMode == modeEditTable)
        {
                if (table->selectedCells().isEmpty())
@@ -8711,12 +8715,12 @@
                for (int row = 0; row < table->rows(); ++row)
                        table->resizeRow(row, rowHeight / unitRatio());
        }
-
        delete dialog;
-
        table->adjustTable();
        table->update();
-
+       if (activeTransaction)
+               activeTransaction.commit();
+       m_updateManager.setUpdatesEnabled();
        changed();
 }
 
@@ -8736,6 +8740,11 @@
 
        const qreal columnWidth = dialog->columnWidth();
        QScopedValueRollback<bool> dontResizeRb(dontResize, true);
+
+       UndoTransaction activeTransaction;
+       m_updateManager.setUpdatesDisabled();
+       if (UndoManager::undoEnabled())
+               activeTransaction = 
m_undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, 
Um::TableColumnWidth, item->itemName(), Um::ITable);
 
        if (appMode == modeEditTable)
        {
@@ -8766,6 +8775,9 @@
 
        table->adjustTable();
        table->update();
+       if (activeTransaction)
+               activeTransaction.commit();
+       m_updateManager.setUpdatesEnabled();
        changed();
 }
 


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to