kspread

kspread_undo.h

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