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 class KSpreadUndo;
00024 class KSpreadUndoAction;
00025 class KSpreadSheet;
00026 class KSpreadFormat;
00027 class KSpreadDoc;
00028 class ColumnFormat;
00029 class RowFormat;
00030
00031 #include "kspread_global.h"
00032 #include "kspread_doc.h"
00033 #include <koUnit.h>
00034 #include <koPageLayout.h>
00035
00036 #include <qptrstack.h>
00037 #include <qstring.h>
00038 #include <qrect.h>
00039 #include <qptrlist.h>
00040 #include <qvaluelist.h>
00041
00042 struct rowSize {
00043 int rowNumber;
00044 double rowHeight;
00045 };
00046
00047 struct columnSize {
00048 int columnNumber;
00049 double columnWidth;
00050 };
00051
00052 struct textOfCell {
00053 int row;
00054 int col;
00055 QString text;
00056 };
00057
00058 struct layoutTextCell {
00059 int row;
00060 int col;
00061 KSpreadFormat * l;
00062 QString text;
00063 };
00064
00065 struct layoutCell {
00066 int row;
00067 int col;
00068 KSpreadFormat *l;
00069 };
00070
00071 struct layoutColumn {
00072 int col;
00073 ColumnFormat *l;
00074 };
00075
00076 struct layoutRow {
00077 int row;
00078 RowFormat *l;
00079 };
00080
00081 struct styleCell {
00082 int row;
00083 int col;
00084 QString action;
00085 };
00086
00087 class FormulaOfCell
00088 {
00089 public:
00090 FormulaOfCell(): m_sheetName(0) {}
00091 FormulaOfCell( QString & sheetName, int col, int row, QString & formula )
00092 : m_sheetName( sheetName ), m_col( col ), m_row( row ), m_formula( formula )
00093 {}
00094
00095 QString sheetName() const { return m_sheetName; }
00096 QString formula() const { return m_formula; }
00097 int col() const { return m_col; }
00098 int row() const { return m_row; }
00099
00100 private:
00101 QString m_sheetName;
00102 int m_col;
00103 int m_row;
00104 QString m_formula;
00105 };
00106
00111 class KSpreadUndoAction
00112 {
00113 public:
00114 KSpreadUndoAction( KSpreadDoc *_doc ) { m_pDoc = _doc; m_pDoc->setModified(true);}
00115 virtual ~KSpreadUndoAction() { }
00116
00117 virtual void undo() = 0;
00118 virtual void redo() = 0;
00119
00120 KSpreadDoc* doc()const { return m_pDoc; }
00121
00122 QString getName()const {return name ;}
00123
00124
00125
00126 protected:
00127 KSpreadDoc *m_pDoc;
00128 QString name;
00129 };
00130
00131 class KSpreadMacroUndoAction : public KSpreadUndoAction
00132 {
00133 public:
00134 KSpreadMacroUndoAction( KSpreadDoc * _doc, const QString & _name );
00135 virtual ~KSpreadMacroUndoAction();
00136
00137 void addCommand(KSpreadUndoAction *command);
00138
00139 virtual void undo();
00140 virtual void redo();
00141
00142 protected:
00143 QPtrList<KSpreadUndoAction> m_commands;
00144 };
00145
00146 class KSpreadUndoInsertRemoveAction : public KSpreadUndoAction
00147 {
00148 public:
00149 KSpreadUndoInsertRemoveAction( KSpreadDoc *_doc );
00150 virtual ~KSpreadUndoInsertRemoveAction();
00151
00152 void saveFormulaReference( KSpreadSheet *_sheet, int col, int row, QString & formula );
00153
00154 protected:
00155 void undoFormulaReference();
00156 QValueList<FormulaOfCell> m_lstFormulaCells;
00157 };
00158
00159 class KSpreadUndoRemoveColumn : public KSpreadUndoInsertRemoveAction
00160 {
00161 public:
00162 KSpreadUndoRemoveColumn( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column,int _nbCol=0 );
00163 virtual ~KSpreadUndoRemoveColumn();
00164
00165 virtual void undo();
00166 virtual void redo();
00167
00168 protected:
00169 QString m_sheetName;
00170 QCString m_data;
00171 int m_iColumn;
00172 int m_iNbCol;
00173 QRect m_printRange;
00174 QPair<int, int> m_printRepeatColumns;
00175 };
00176
00177 class KSpreadUndoInsertColumn : public KSpreadUndoInsertRemoveAction
00178 {
00179 public:
00180 KSpreadUndoInsertColumn( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column,int _nbCol=0 );
00181 virtual ~KSpreadUndoInsertColumn();
00182
00183 virtual void undo();
00184 virtual void redo();
00185
00186 protected:
00187 QString m_sheetName;
00188 int m_iColumn;
00189 int m_iNbCol;
00190 };
00191
00192 class KSpreadUndoRemoveRow : public KSpreadUndoInsertRemoveAction
00193 {
00194 public:
00195 KSpreadUndoRemoveRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _row,int _nbRow=0 );
00196 virtual ~KSpreadUndoRemoveRow();
00197
00198 virtual void undo();
00199 virtual void redo();
00200
00201 protected:
00202 QString m_sheetName;
00203 QCString m_data;
00204 int m_iRow;
00205 int m_iNbRow;
00206 QRect m_printRange;
00207 QPair<int, int> m_printRepeatRows;
00208 };
00209
00210 class KSpreadUndoInsertRow : public KSpreadUndoInsertRemoveAction
00211 {
00212 public:
00213 KSpreadUndoInsertRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _row,int _nbRow=0 );
00214 virtual ~KSpreadUndoInsertRow();
00215
00216 virtual void undo();
00217 virtual void redo();
00218
00219 protected:
00220 QString m_sheetName;
00221 int m_iRow;
00222 int m_iNbRow;
00223 };
00224
00225
00226 class KSpreadUndoHideColumn : public KSpreadUndoAction
00227 {
00228 public:
00229 KSpreadUndoHideColumn( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column,int _nbCol=0, QValueList<int>listCol=QValueList<int>() );
00230 virtual ~KSpreadUndoHideColumn();
00231
00232 virtual void undo();
00233 virtual void redo();
00234 void createList( QValueList<int>&list,KSpreadSheet *_tab );
00235
00236 protected:
00237 QString m_sheetName;
00238 int m_iColumn;
00239 int m_iNbCol;
00240 QValueList<int> listCol;
00241 };
00242
00243 class KSpreadUndoHideRow : public KSpreadUndoAction
00244 {
00245 public:
00246 KSpreadUndoHideRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column,int _nbCol=0, QValueList<int>_listRow=QValueList<int>() );
00247 virtual ~KSpreadUndoHideRow();
00248
00249 virtual void undo();
00250 virtual void redo();
00251 protected:
00252 void createList( QValueList<int>&list,KSpreadSheet *_tab );
00253
00254 QString m_sheetName;
00255 int m_iRow;
00256 int m_iNbRow;
00257 QValueList<int> listRow;
00258 };
00259
00260 class KSpreadUndoShowColumn : public KSpreadUndoAction
00261 {
00262 public:
00263 KSpreadUndoShowColumn( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column,int _nbCol=0, QValueList<int>_list=QValueList<int>() );
00264 virtual ~KSpreadUndoShowColumn();
00265
00266 virtual void undo();
00267 virtual void redo();
00268 protected:
00269 void createList( QValueList<int>&list,KSpreadSheet *_tab );
00270
00271 QString m_sheetName;
00272 int m_iColumn;
00273 int m_iNbCol;
00274 QValueList<int> listCol;
00275 };
00276
00277 class KSpreadUndoShowRow : public KSpreadUndoAction
00278 {
00279 public:
00280 KSpreadUndoShowRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column,int _nbCol=0, QValueList<int>list=QValueList<int>() );
00281 virtual ~KSpreadUndoShowRow();
00282
00283 virtual void undo();
00284 virtual void redo();
00285
00286 protected:
00287 void createList( QValueList<int>&list,KSpreadSheet *_tab );
00288 QString m_sheetName;
00289 int m_iRow;
00290 int m_iNbRow;
00291 QValueList<int> listRow;
00292 };
00293
00294
00295 class KSpreadUndoPaperLayout : public KSpreadUndoAction
00296 {
00297 public:
00298 KSpreadUndoPaperLayout( KSpreadDoc *_doc, KSpreadSheet *_sheet );
00299 virtual ~KSpreadUndoPaperLayout();
00300
00301 virtual void undo();
00302 virtual void redo();
00303
00304 protected:
00305 QString m_sheetName;
00306 KoPageLayout m_pl;
00307 KoPageLayout m_plRedo;
00308 KoHeadFoot m_hf;
00309 KoHeadFoot m_hfRedo;
00310 KoUnit::Unit m_unit;
00311 KoUnit::Unit m_unitRedo;
00312 bool m_printGrid;
00313 bool m_printGridRedo;
00314 bool m_printCommentIndicator;
00315 bool m_printCommentIndicatorRedo;
00316 bool m_printFormulaIndicator;
00317 bool m_printFormulaIndicatorRedo;
00318 QRect m_printRange;
00319 QRect m_printRangeRedo;
00320 QPair<int, int> m_printRepeatColumns;
00321 QPair<int, int> m_printRepeatColumnsRedo;
00322 QPair<int, int> m_printRepeatRows;
00323 QPair<int, int> m_printRepeatRowsRedo;
00324 double m_dZoom;
00325 double m_dZoomRedo;
00326 int m_iPageLimitX;
00327 int m_iPageLimitXRedo;
00328 int m_iPageLimitY;
00329 int m_iPageLimitYRedo;
00330 };
00331
00332
00333 class KSpreadUndoSetText : public KSpreadUndoAction
00334 {
00335 public:
00336 KSpreadUndoSetText( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QString& _text, int _column, int _row, FormatType _formatType );
00337 virtual ~KSpreadUndoSetText();
00338
00339 virtual void undo();
00340 virtual void redo();
00341
00342 protected:
00343 QString m_sheetName;
00344 int m_iRow;
00345 int m_iColumn;
00346 QString m_strText;
00347 QString m_strRedoText;
00348 FormatType m_eFormatType;
00349 FormatType m_eFormatTypeRedo;
00350 };
00351
00352 class KSpreadUndoCellFormat : public KSpreadUndoAction
00353 {
00354 public:
00355 KSpreadUndoCellFormat( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_selection, const QString &_title );
00356 virtual ~KSpreadUndoCellFormat();
00357
00358 virtual void undo();
00359 virtual void redo();
00360
00361 protected:
00362 void copyFormat( QValueList<layoutCell> &list,QValueList<layoutColumn> &listCol,QValueList<layoutRow> &listRow, KSpreadSheet* sheet );
00363
00364 QRect m_rctRect;
00365 QValueList<layoutCell> m_lstFormats;
00366 QValueList<layoutCell> m_lstRedoFormats;
00367 QValueList<layoutColumn> m_lstColFormats;
00368 QValueList<layoutColumn> m_lstRedoColFormats;
00369 QValueList<layoutRow> m_lstRowFormats;
00370 QValueList<layoutRow> m_lstRedoRowFormats;
00371
00372 QString m_sheetName;
00373 };
00374
00375 class KSpreadUndoResizeColRow;
00376
00377 class KSpreadUndoChangeAngle : public KSpreadUndoAction
00378 {
00379 public:
00380 KSpreadUndoChangeAngle( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_selection );
00381 virtual ~KSpreadUndoChangeAngle();
00382
00383 virtual void undo();
00384 virtual void redo();
00385
00386 protected:
00387
00388 KSpreadUndoCellFormat* m_layoutUndo;
00389 KSpreadUndoResizeColRow* m_resizeUndo;
00390
00391 };
00392
00393 class KSpreadUndoDelete : public KSpreadUndoAction
00394 {
00395 public:
00396 KSpreadUndoDelete( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_rect );
00397 virtual ~KSpreadUndoDelete();
00398
00399 virtual void undo();
00400 virtual void redo();
00401
00402 protected:
00403 void createListCell( QCString &listCell,QValueList<columnSize> &listCol,QValueList<rowSize> &listRow, KSpreadSheet* sheet );
00404
00405 QRect m_selection;
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 KSpreadUndoDragDrop : public KSpreadUndoAction
00416 {
00417 public:
00418 KSpreadUndoDragDrop( KSpreadDoc * _doc, KSpreadSheet * _sheet, const QRect & _source, const QRect & _target );
00419 virtual ~KSpreadUndoDragDrop();
00420
00421 virtual void undo();
00422 virtual void redo();
00423
00424 protected:
00425 QRect m_selectionSource;
00426 QRect 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, KSpreadSheet * sheet,
00434 QRect const & rect );
00435 };
00436
00437 class KSpreadUndoResizeColRow : public KSpreadUndoAction
00438 {
00439 public:
00440 KSpreadUndoResizeColRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_selection );
00441 virtual ~KSpreadUndoResizeColRow();
00442
00443 virtual void undo();
00444 virtual void redo();
00445
00446 protected:
00447 void createList( QValueList<columnSize> &listCol,QValueList<rowSize> &listRow, KSpreadSheet* sheet );
00448
00449 QRect m_rctRect;
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 KSpreadUndoChangeAreaTextCell : public KSpreadUndoAction
00458 {
00459 public:
00460 KSpreadUndoChangeAreaTextCell( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_selection );
00461 virtual ~KSpreadUndoChangeAreaTextCell();
00462
00463 virtual void undo();
00464 virtual void redo();
00465
00466 protected:
00467 void createList( QValueList<textOfCell> &list, KSpreadSheet* sheet );
00468
00469 QRect m_rctRect;
00470 QValueList<textOfCell> m_lstTextCell;
00471 QValueList<textOfCell> m_lstRedoTextCell;
00472 QString m_sheetName;
00473 };
00474
00475 class KSpreadUndoSort : public KSpreadUndoAction
00476 {
00477 public:
00478 KSpreadUndoSort( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_selection);
00479 virtual ~KSpreadUndoSort();
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, KSpreadSheet * 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 KSpreadUndoMergedCell : public KSpreadUndoAction
00500 {
00501 public:
00502 KSpreadUndoMergedCell( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column, int _row, int _extraX,int _extraY);
00503 virtual ~KSpreadUndoMergedCell();
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 KSpreadUndoAutofill : public KSpreadUndoAction
00520 {
00521 public:
00522 KSpreadUndoAutofill( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_rect );
00523 virtual ~KSpreadUndoAutofill();
00524
00525 virtual void undo();
00526 virtual void redo();
00527 protected:
00528 void createListCell( QCString &list, KSpreadSheet* sheet );
00529 QRect m_selection;
00530 QCString m_data;
00531 QCString m_dataRedo;
00532 QString m_sheetName;
00533 };
00534
00535 class KSpreadUndoInsertCellCol : public KSpreadUndoInsertRemoveAction
00536 {
00537 public:
00538 KSpreadUndoInsertCellCol( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_rect );
00539 virtual ~KSpreadUndoInsertCellCol();
00540
00541 virtual void undo();
00542 virtual void redo();
00543
00544 protected:
00545 QString m_sheetName;
00546 QRect m_rect;
00547 };
00548
00549 class KSpreadUndoInsertCellRow : public KSpreadUndoInsertRemoveAction
00550 {
00551 public:
00552 KSpreadUndoInsertCellRow( KSpreadDoc *_doc, KSpreadSheet *_sheet,const QRect &_rect );
00553 virtual ~KSpreadUndoInsertCellRow();
00554
00555 virtual void undo();
00556 virtual void redo();
00557
00558 protected:
00559 QString m_sheetName;
00560 QRect m_rect;
00561 };
00562
00563 class KSpreadUndoRemoveCellCol : public KSpreadUndoInsertRemoveAction
00564 {
00565 public:
00566 KSpreadUndoRemoveCellCol( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_rect );
00567 virtual ~KSpreadUndoRemoveCellCol();
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 KSpreadUndoRemoveCellRow : public KSpreadUndoInsertRemoveAction
00579 {
00580 public:
00581 KSpreadUndoRemoveCellRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_rect );
00582 virtual ~KSpreadUndoRemoveCellRow();
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 KSpreadUndoConditional : public KSpreadUndoAction
00594 {
00595 public:
00596 KSpreadUndoConditional( KSpreadDoc *_doc, KSpreadSheet *_sheet, QRect const & _rect );
00597 virtual ~KSpreadUndoConditional();
00598
00599 virtual void undo();
00600 virtual void redo();
00601 protected:
00602 void createListCell( QCString &list, KSpreadSheet* sheet );
00603 QRect m_selection;
00604 QCString m_data;
00605 QCString m_dataRedo;
00606 QString m_sheetName;
00607 };
00608
00609 class KSpreadUndoCellPaste : public KSpreadUndoAction
00610 {
00611 public:
00612 KSpreadUndoCellPaste( KSpreadDoc *_doc, KSpreadSheet *_sheet,int _nbCol,int _nbRow, int _xshift,int _yshift, QRect &_selection,bool insert,int insertTo=0 );
00613 virtual ~KSpreadUndoCellPaste();
00614
00615 virtual void undo();
00616 virtual void redo();
00617
00618 protected:
00619 void createListCell( QCString &listCell,QValueList<columnSize> &listCol,QValueList<rowSize> &listRow, KSpreadSheet* sheet );
00620
00621 QRect m_selection;
00622 QCString m_data;
00623 QCString m_dataRedo;
00624 QValueList<columnSize> m_lstColumn;
00625 QValueList<columnSize> m_lstRedoColumn;
00626 QValueList<rowSize> m_lstRow;
00627 QValueList<rowSize> m_lstRedoRow;
00628 int nbCol;
00629 int nbRow;
00630 int xshift;
00631 int yshift;
00632 bool b_insert;
00633 int m_iInsertTo;
00634 QString m_sheetName;
00635 };
00636
00637
00638 class KSpreadUndoStyleCell : public KSpreadUndoAction
00639 {
00640 public:
00641 KSpreadUndoStyleCell( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_rect );
00642 virtual ~KSpreadUndoStyleCell();
00643
00644 virtual void undo();
00645 virtual void redo();
00646
00647 protected:
00648 void createListCell( QValueList<styleCell> &listCell, KSpreadSheet* sheet );
00649 QRect m_selection;
00650 QValueList<styleCell> m_lstStyleCell;
00651 QValueList<styleCell> m_lstRedoStyleCell;
00652 QString m_sheetName;
00653 };
00654
00655 class KSpreadUndoInsertData : public KSpreadUndoChangeAreaTextCell
00656 {
00657 public:
00658 KSpreadUndoInsertData( KSpreadDoc * _doc, KSpreadSheet * _sheet, QRect & _selection );
00659 };
00660
00661
00662 class KSpreadUndo
00663 {
00664 public:
00665 KSpreadUndo( KSpreadDoc *_doc );
00666 ~KSpreadUndo();
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( KSpreadUndoAction *_action );
00680
00681 QString getUndoName();
00682 QString getRedoName();
00683
00684 protected:
00685 QPtrStack<KSpreadUndoAction> m_stckUndo;
00686 QPtrStack<KSpreadUndoAction> m_stckRedo;
00687
00688 KSpreadDoc *m_pDoc;
00689 };
00690
00691 #endif