00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __kspread_undo_h__
00021 #define __kspread_undo_h__
00022
00023 #include <qptrstack.h>
00024 #include <qstring.h>
00025 #include <qrect.h>
00026 #include <qptrlist.h>
00027 #include <qvaluelist.h>
00028
00029 #include <KoUnit.h>
00030 #include <KoPageLayout.h>
00031
00032 #include "kspread_doc.h"
00033 #include "region.h"
00034
00035 namespace KSpread
00036 {
00037 class ColumnFormat;
00038 class Doc;
00039 class Format;
00040 class Region;
00041 class RowFormat;
00042 class Sheet;
00043 class Undo;
00044 class UndoResizeColRow;
00045
00046 struct rowSize {
00047 int rowNumber;
00048 double rowHeight;
00049 };
00050
00051 struct columnSize {
00052 int columnNumber;
00053 double columnWidth;
00054 };
00055
00056 struct textOfCell {
00057 int row;
00058 int col;
00059 QString text;
00060 };
00061
00062 struct layoutTextCell {
00063 int row;
00064 int col;
00065 Format * l;
00066 QString text;
00067 };
00068
00069 struct layoutCell {
00070 int row;
00071 int col;
00072 Format *l;
00073 };
00074
00075 struct layoutColumn {
00076 int col;
00077 ColumnFormat *l;
00078 };
00079
00080 struct layoutRow {
00081 int row;
00082 RowFormat *l;
00083 };
00084
00085 struct styleCell {
00086 int row;
00087 int col;
00088 QString action;
00089 };
00090
00091 class FormulaOfCell
00092 {
00093 public:
00094 FormulaOfCell(): m_sheetName(0) {}
00095 FormulaOfCell( QString & sheetName, int col, int row, QString & formula )
00096 : m_sheetName( sheetName ), m_col( col ), m_row( row ), m_formula( formula )
00097 {}
00098
00099 QString sheetName() const { return m_sheetName; }
00100 QString formula() const { return m_formula; }
00101 int col() const { return m_col; }
00102 int row() const { return m_row; }
00103
00104 private:
00105 QString m_sheetName;
00106 int m_col;
00107 int m_row;
00108 QString m_formula;
00109 };
00110
00115 class UndoAction
00116 {
00117 public:
00118 UndoAction( Doc *_doc ) { m_pDoc = _doc; m_pDoc->setModified(true); }
00119 virtual ~UndoAction() { }
00120
00121 virtual void undo() = 0;
00122 virtual void redo() = 0;
00123
00124 Doc* doc()const { return m_pDoc; }
00125
00126 QString getName()const {return name ;}
00127
00128 protected:
00129 Doc *m_pDoc;
00130 QString name;
00131 };
00132
00133 class MacroUndoAction : public UndoAction
00134 {
00135 public:
00136 MacroUndoAction( Doc * _doc, const QString & _name );
00137 virtual ~MacroUndoAction();
00138
00139 void addCommand(UndoAction *command);
00140
00141 virtual void undo();
00142 virtual void redo();
00143
00144 protected:
00145 QPtrList<UndoAction> m_commands;
00146 };
00147
00148 class UndoInsertRemoveAction : public UndoAction
00149 {
00150 public:
00151 UndoInsertRemoveAction( Doc *_doc );
00152 virtual ~UndoInsertRemoveAction();
00153
00154 void saveFormulaReference( Sheet *_sheet, int col, int row, QString & formula );
00155
00156 protected:
00157 void undoFormulaReference();
00158 QValueList<FormulaOfCell> m_lstFormulaCells;
00159 };
00160
00161 class UndoRemoveColumn : public UndoInsertRemoveAction
00162 {
00163 public:
00164 UndoRemoveColumn( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0 );
00165 virtual ~UndoRemoveColumn();
00166
00167 virtual void undo();
00168 virtual void redo();
00169
00170 protected:
00171 QString m_sheetName;
00172 QCString m_data;
00173 int m_iColumn;
00174 int m_iNbCol;
00175 QRect m_printRange;
00176 QPair<int, int> m_printRepeatColumns;
00177 };
00178
00179 class UndoInsertColumn : public UndoInsertRemoveAction
00180 {
00181 public:
00182 UndoInsertColumn( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0 );
00183 virtual ~UndoInsertColumn();
00184
00185 virtual void undo();
00186 virtual void redo();
00187
00188 protected:
00189 QString m_sheetName;
00190 int m_iColumn;
00191 int m_iNbCol;
00192 };
00193
00194 class UndoRemoveRow : public UndoInsertRemoveAction
00195 {
00196 public:
00197 UndoRemoveRow( Doc *_doc, Sheet *_sheet, int _row,int _nbRow=0 );
00198 virtual ~UndoRemoveRow();
00199
00200 virtual void undo();
00201 virtual void redo();
00202
00203 protected:
00204 QString m_sheetName;
00205 QCString m_data;
00206 int m_iRow;
00207 int m_iNbRow;
00208 QRect m_printRange;
00209 QPair<int, int> m_printRepeatRows;
00210 };
00211
00212 class UndoInsertRow : public UndoInsertRemoveAction
00213 {
00214 public:
00215 UndoInsertRow( Doc *_doc, Sheet *_sheet, int _row,int _nbRow=0 );
00216 virtual ~UndoInsertRow();
00217
00218 virtual void undo();
00219 virtual void redo();
00220
00221 protected:
00222 QString m_sheetName;
00223 int m_iRow;
00224 int m_iNbRow;
00225 };
00226
00227
00228 class UndoHideColumn : public UndoAction
00229 {
00230 public:
00231 UndoHideColumn( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0, QValueList<int>listCol=QValueList<int>() );
00232 virtual ~UndoHideColumn();
00233
00234 virtual void undo();
00235 virtual void redo();
00236 void createList( QValueList<int>&list,Sheet *_tab );
00237
00238 protected:
00239 QString m_sheetName;
00240 int m_iColumn;
00241 int m_iNbCol;
00242 QValueList<int> listCol;
00243 };
00244
00245 class UndoHideRow : public UndoAction
00246 {
00247 public:
00248 UndoHideRow( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0, QValueList<int>_listRow=QValueList<int>() );
00249 virtual ~UndoHideRow();
00250
00251 virtual void undo();
00252 virtual void redo();
00253 protected:
00254 void createList( QValueList<int>&list,Sheet *_tab );
00255
00256 QString m_sheetName;
00257 int m_iRow;
00258 int m_iNbRow;
00259 QValueList<int> listRow;
00260 };
00261
00262 class UndoShowColumn : public UndoAction
00263 {
00264 public:
00265 UndoShowColumn( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0, QValueList<int>_list=QValueList<int>() );
00266 virtual ~UndoShowColumn();
00267
00268 virtual void undo();
00269 virtual void redo();
00270 protected:
00271 void createList( QValueList<int>&list,Sheet *_tab );
00272
00273 QString m_sheetName;
00274 int m_iColumn;
00275 int m_iNbCol;
00276 QValueList<int> listCol;
00277 };
00278
00279 class UndoShowRow : public UndoAction
00280 {
00281 public:
00282 UndoShowRow( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0, QValueList<int>list=QValueList<int>() );
00283 virtual ~UndoShowRow();
00284
00285 virtual void undo();
00286 virtual void redo();
00287
00288 protected:
00289 void createList( QValueList<int>&list,Sheet *_tab );
00290 QString m_sheetName;
00291 int m_iRow;
00292 int m_iNbRow;
00293 QValueList<int> listRow;
00294 };
00295
00296
00297 class UndoPaperLayout : public UndoAction
00298 {
00299 public:
00300 UndoPaperLayout( Doc *_doc, Sheet *_sheet );
00301 virtual ~UndoPaperLayout();
00302
00303 virtual void undo();
00304 virtual void redo();
00305
00306 protected:
00307 QString m_sheetName;
00308 KoPageLayout m_pl;
00309 KoPageLayout m_plRedo;
00310 KoHeadFoot m_hf;
00311 KoHeadFoot m_hfRedo;
00312 KoUnit::Unit m_unit;
00313 KoUnit::Unit m_unitRedo;
00314 bool m_printGrid;
00315 bool m_printGridRedo;
00316 bool m_printCommentIndicator;
00317 bool m_printCommentIndicatorRedo;
00318 bool m_printFormulaIndicator;
00319 bool m_printFormulaIndicatorRedo;
00320 QRect m_printRange;
00321 QRect m_printRangeRedo;
00322 QPair<int, int> m_printRepeatColumns;
00323 QPair<int, int> m_printRepeatColumnsRedo;
00324 QPair<int, int> m_printRepeatRows;
00325 QPair<int, int> m_printRepeatRowsRedo;
00326 double m_dZoom;
00327 double m_dZoomRedo;
00328 int m_iPageLimitX;
00329 int m_iPageLimitXRedo;
00330 int m_iPageLimitY;
00331 int m_iPageLimitYRedo;
00332 };
00333
00334
00335 class UndoSetText : public UndoAction
00336 {
00337 public:
00338 UndoSetText( Doc *_doc, Sheet *_sheet, const QString& _text, int _column, int _row, FormatType _formatType );
00339 virtual ~UndoSetText();
00340
00341 virtual void undo();
00342 virtual void redo();
00343
00344 protected:
00345 QString m_sheetName;
00346 int m_iRow;
00347 int m_iColumn;
00348 QString m_strText;
00349 QString m_strRedoText;
00350 FormatType m_eFormatType;
00351 FormatType m_eFormatTypeRedo;
00352 };
00353
00354 class UndoCellFormat : public UndoAction
00355 {
00356 public:
00357 UndoCellFormat( Doc *_doc, Sheet *_sheet, const Region &_selection, const QString &_title );
00358 virtual ~UndoCellFormat();
00359
00360 virtual void undo();
00361 virtual void redo();
00362
00363 protected:
00364 void copyFormat( QValueList<layoutCell> &list,QValueList<layoutColumn> &listCol,QValueList<layoutRow> &listRow, Sheet* sheet );
00365
00366 Region m_region;
00367 QValueList<layoutCell> m_lstFormats;
00368 QValueList<layoutCell> m_lstRedoFormats;
00369 QValueList<layoutColumn> m_lstColFormats;
00370 QValueList<layoutColumn> m_lstRedoColFormats;
00371 QValueList<layoutRow> m_lstRowFormats;
00372 QValueList<layoutRow> m_lstRedoRowFormats;
00373
00374 QString m_sheetName;
00375 };
00376
00377 class UndoChangeAngle : public UndoAction
00378 {
00379 public:
00380 UndoChangeAngle( Doc *_doc, Sheet *_sheet, const Region &_selection );
00381 virtual ~UndoChangeAngle();
00382
00383 virtual void undo();
00384 virtual void redo();
00385
00386 protected:
00387
00388 UndoCellFormat* m_layoutUndo;
00389 UndoResizeColRow* m_resizeUndo;
00390
00391 };
00392
00393 class UndoDelete : public UndoAction
00394 {
00395 public:
00396 UndoDelete(Doc *_doc, Sheet *_sheet, const Region& region);
00397 virtual ~UndoDelete();
00398
00399 virtual void undo();
00400 virtual void redo();
00401
00402 protected:
00403 void createListCell( QCString &listCell,QValueList<columnSize> &listCol,QValueList<rowSize> &listRow, Sheet* sheet );
00404
00405 Region m_region;
00406 QCString m_data;
00407 QCString m_dataRedo;
00408 QValueList<columnSize> m_lstColumn;
00409 QValueList<columnSize> m_lstRedoColumn;
00410 QValueList<rowSize> m_lstRow;
00411 QValueList<rowSize> m_lstRedoRow;
00412 QString m_sheetName;
00413 };
00414
00415 class UndoDragDrop : public UndoAction
00416 {
00417 public:
00418 UndoDragDrop( Doc * _doc, Sheet * _sheet, const Region& _source, const Region& _target );
00419 virtual ~UndoDragDrop();
00420
00421 virtual void undo();
00422 virtual void redo();
00423
00424 protected:
00425 Region m_selectionSource;
00426 Region m_selectionTarget;
00427 QCString m_dataSource;
00428 QCString m_dataTarget;
00429 QCString m_dataRedoSource;
00430 QCString m_dataRedoTarget;
00431 QString m_sheetName;
00432
00433 void saveCellRect( QCString & cells, Sheet * sheet,
00434 const Region& region );
00435 };
00436
00437 class UndoResizeColRow : public UndoAction
00438 {
00439 public:
00440 UndoResizeColRow( Doc *_doc, Sheet *_sheet, const Region &_selection );
00441 virtual ~UndoResizeColRow();
00442
00443 virtual void undo();
00444 virtual void redo();
00445
00446 protected:
00447 void createList( QValueList<columnSize> &listCol,QValueList<rowSize> &listRow, Sheet* sheet );
00448
00449 Region m_region;
00450 QValueList<columnSize> m_lstColumn;
00451 QValueList<columnSize> m_lstRedoColumn;
00452 QValueList<rowSize> m_lstRow;
00453 QValueList<rowSize> m_lstRedoRow;
00454 QString m_sheetName;
00455 };
00456
00457 class UndoChangeAreaTextCell : public UndoAction
00458 {
00459 public:
00460 UndoChangeAreaTextCell( Doc *_doc, Sheet *_sheet, const Region &_selection );
00461 virtual ~UndoChangeAreaTextCell();
00462
00463 virtual void undo();
00464 virtual void redo();
00465
00466 protected:
00467 void createList( QValueList<textOfCell> &list, Sheet* sheet );
00468
00469 Region m_region;
00470 QValueList<textOfCell> m_lstTextCell;
00471 QValueList<textOfCell> m_lstRedoTextCell;
00472 QString m_sheetName;
00473 };
00474
00475 class UndoSort : public UndoAction
00476 {
00477 public:
00478 UndoSort( Doc *_doc, Sheet *_sheet, const QRect &_selection);
00479 virtual ~UndoSort();
00480
00481 virtual void undo();
00482 virtual void redo();
00483
00484 protected:
00485 void copyAll( QValueList<layoutTextCell> & list, QValueList<layoutColumn> & listCol,
00486 QValueList<layoutRow> & listRow, Sheet * sheet );
00487
00488 QRect m_rctRect;
00489 QValueList<layoutTextCell> m_lstFormats;
00490 QValueList<layoutTextCell> m_lstRedoFormats;
00491 QValueList<layoutColumn> m_lstColFormats;
00492 QValueList<layoutColumn> m_lstRedoColFormats;
00493 QValueList<layoutRow> m_lstRowFormats;
00494 QValueList<layoutRow> m_lstRedoRowFormats;
00495
00496 QString m_sheetName;
00497 };
00498
00499 class UndoMergedCell : public UndoAction
00500 {
00501 public:
00502 UndoMergedCell( Doc *_doc, Sheet *_sheet, int _column, int _row, int _extraX,int _extraY);
00503 virtual ~UndoMergedCell();
00504
00505 virtual void undo();
00506 virtual void redo();
00507
00508 protected:
00509 int m_iRow;
00510 int m_iCol;
00511 int m_iExtraX;
00512 int m_iExtraY;
00513 int m_iExtraRedoX;
00514 int m_iExtraRedoY;
00515 QString m_sheetName;
00516 };
00517
00518
00519 class UndoAutofill : public UndoAction
00520 {
00521 public:
00522 UndoAutofill( Doc *_doc, Sheet *_sheet, const QRect &_rect );
00523 virtual ~UndoAutofill();
00524
00525 virtual void undo();
00526 virtual void redo();
00527 protected:
00528 void createListCell( QCString &list, Sheet* sheet );
00529 QRect m_selection;
00530 QCString m_data;
00531 QCString m_dataRedo;
00532 QString m_sheetName;
00533 };
00534
00535 class UndoInsertCellCol : public UndoInsertRemoveAction
00536 {
00537 public:
00538 UndoInsertCellCol( Doc *_doc, Sheet *_sheet, const QRect &_rect );
00539 virtual ~UndoInsertCellCol();
00540
00541 virtual void undo();
00542 virtual void redo();
00543
00544 protected:
00545 QString m_sheetName;
00546 QRect m_rect;
00547 };
00548
00549 class UndoInsertCellRow : public UndoInsertRemoveAction
00550 {
00551 public:
00552 UndoInsertCellRow( Doc *_doc, Sheet *_sheet,const QRect &_rect );
00553 virtual ~UndoInsertCellRow();
00554
00555 virtual void undo();
00556 virtual void redo();
00557
00558 protected:
00559 QString m_sheetName;
00560 QRect m_rect;
00561 };
00562
00563 class UndoRemoveCellCol : public UndoInsertRemoveAction
00564 {
00565 public:
00566 UndoRemoveCellCol( Doc *_doc, Sheet *_sheet, const QRect &_rect );
00567 virtual ~UndoRemoveCellCol();
00568
00569 virtual void undo();
00570 virtual void redo();
00571
00572 protected:
00573 QString m_sheetName;
00574 QRect m_rect;
00575 QCString m_data;
00576 };
00577
00578 class UndoRemoveCellRow : public UndoInsertRemoveAction
00579 {
00580 public:
00581 UndoRemoveCellRow( Doc *_doc, Sheet *_sheet, const QRect &_rect );
00582 virtual ~UndoRemoveCellRow();
00583
00584 virtual void undo();
00585 virtual void redo();
00586
00587 protected:
00588 QString m_sheetName;
00589 QRect m_rect;
00590 QCString m_data;
00591 };
00592
00593 class UndoConditional : public UndoAction
00594 {
00595 public:
00596 UndoConditional( Doc *_doc, Sheet *_sheet, const Region & _selection );
00597 virtual ~UndoConditional();
00598
00599 virtual void undo();
00600 virtual void redo();
00601 protected:
00602 void createListCell( QCString &list, Sheet* sheet );
00603 Region m_region;
00604 QCString m_data;
00605 QCString m_dataRedo;
00606 QString m_sheetName;
00607 };
00608
00609 class UndoCellPaste : public UndoAction
00610 {
00611 public:
00612 UndoCellPaste(Doc *_doc, Sheet *_sheet,
00613 int _xshift, int _yshift,
00614 const Region& _selection, bool insert, int insertTo = 0);
00615 virtual ~UndoCellPaste();
00616
00617 virtual void undo();
00618 virtual void redo();
00619
00620 protected:
00621 void createListCell( QCString &listCell,QValueList<columnSize> &listCol,QValueList<rowSize> &listRow, Sheet* sheet );
00622
00623 Region m_region;
00624 QCString m_data;
00625 QCString m_dataRedo;
00626 QValueList<columnSize> m_lstColumn;
00627 QValueList<columnSize> m_lstRedoColumn;
00628 QValueList<rowSize> m_lstRow;
00629 QValueList<rowSize> m_lstRedoRow;
00630 int xshift;
00631 int yshift;
00632 bool b_insert;
00633 int m_iInsertTo;
00634 QString m_sheetName;
00635 };
00636
00637
00638 class UndoStyleCell : public UndoAction
00639 {
00640 public:
00641 UndoStyleCell( Doc *_doc, Sheet *_sheet, const QRect &_rect );
00642 virtual ~UndoStyleCell();
00643
00644 virtual void undo();
00645 virtual void redo();
00646
00647 protected:
00648 void createListCell( QValueList<styleCell> &listCell, Sheet* sheet );
00649 QRect m_selection;
00650 QValueList<styleCell> m_lstStyleCell;
00651 QValueList<styleCell> m_lstRedoStyleCell;
00652 QString m_sheetName;
00653 };
00654
00655 class UndoInsertData : public UndoChangeAreaTextCell
00656 {
00657 public:
00658 UndoInsertData( Doc * _doc, Sheet * _sheet, QRect & _selection );
00659 };
00660
00661
00662 class Undo
00663 {
00664 public:
00665 Undo( Doc *_doc );
00666 ~Undo();
00667
00668 void undo();
00669 void redo();
00670 void clear();
00671
00672 void lock();
00673 void unlock();
00674 bool isLocked() const ;
00675
00676 bool hasUndoActions()const { return !m_stckUndo.isEmpty(); }
00677 bool hasRedoActions()const { return !m_stckRedo.isEmpty(); }
00678
00679 void appendUndo( UndoAction *_action );
00680
00681 QString getUndoName();
00682 QString getRedoName();
00683
00684 protected:
00685 QPtrStack<UndoAction> m_stckUndo;
00686 QPtrStack<UndoAction> m_stckRedo;
00687
00688 Doc *m_pDoc;
00689 };
00690
00691 }
00692
00693 #endif