00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kspread_global.h"
00022 #include "kspread_undo.h"
00023 #include "kspread_cell.h"
00024 #include "kspread_doc.h"
00025 #include "kspread_locale.h"
00026 #include "kspread_map.h"
00027 #include "kspread_util.h"
00028 #include "kspread_sheetprint.h"
00029 #include "kspread_style.h"
00030 #include "kspread_style_manager.h"
00031
00032
00033
00034
00035
00036
00037
00038 KSpreadUndo::KSpreadUndo( KSpreadDoc *_doc )
00039 {
00040 m_pDoc = _doc;
00041
00042 m_stckUndo.setAutoDelete( FALSE );
00043 m_stckRedo.setAutoDelete( FALSE );
00044 }
00045
00046 KSpreadUndo::~KSpreadUndo()
00047 {
00048 clear();
00049 }
00050
00051 void KSpreadUndo::appendUndo( KSpreadUndoAction *_action )
00052 {
00053 if ( isLocked() )
00054 return;
00055
00056 m_stckRedo.setAutoDelete( TRUE );
00057 m_stckRedo.clear();
00058 m_stckRedo.setAutoDelete( FALSE );
00059
00060 m_stckUndo.push( _action );
00061
00062 if ( m_pDoc )
00063 {
00064 m_pDoc->enableUndo( hasUndoActions() );
00065 m_pDoc->enableRedo( hasRedoActions() );
00066 m_pDoc->setModified( true );
00067 }
00068 }
00069
00070 void KSpreadUndo::clear()
00071 {
00072 if ( isLocked() )
00073 return;
00074
00075 m_stckUndo.setAutoDelete( TRUE );
00076 m_stckRedo.setAutoDelete( TRUE );
00077
00078 m_stckUndo.clear();
00079 m_stckRedo.clear();
00080
00081 m_stckUndo.setAutoDelete( FALSE );
00082 m_stckRedo.setAutoDelete( FALSE );
00083 }
00084
00085 void KSpreadUndo::undo()
00086 {
00087 if ( m_stckUndo.isEmpty() )
00088 return;
00089
00090
00091 bool origErrorMessages = true;
00092 if ( m_pDoc )
00093 {
00094 origErrorMessages = m_pDoc->getShowMessageError();
00095 m_pDoc->setShowMessageError( false );
00096 }
00097
00098 KSpreadUndoAction *a = m_stckUndo.pop();
00099 a->undo();
00100 m_stckRedo.push( a );
00101
00102 if ( m_pDoc )
00103 {
00104 m_pDoc->setShowMessageError( origErrorMessages );
00105 m_pDoc->enableUndo( hasUndoActions() );
00106 m_pDoc->enableRedo( hasRedoActions() );
00107 }
00108 }
00109
00110 void KSpreadUndo::redo()
00111 {
00112 if ( m_stckRedo.isEmpty() )
00113 return;
00114 KSpreadUndoAction *a = m_stckRedo.pop();
00115 a->redo();
00116 m_stckUndo.push( a );
00117
00118 if ( m_pDoc )
00119 {
00120 m_pDoc->enableUndo( hasUndoActions() );
00121 m_pDoc->enableRedo( hasRedoActions() );
00122 }
00123 }
00124
00125 void KSpreadUndo::lock()
00126 {
00127 m_pDoc->undoLock();
00128 }
00129
00130 void KSpreadUndo::unlock()
00131 {
00132 m_pDoc->undoUnlock();
00133 }
00134
00135 bool KSpreadUndo::isLocked() const
00136 {
00137 return m_pDoc->undoLocked();
00138 }
00139
00140 QString KSpreadUndo::getRedoName()
00141 {
00142 if ( m_stckRedo.isEmpty() )
00143 return QString("");
00144 return m_stckRedo.current()->getName();
00145
00146 }
00147
00148 QString KSpreadUndo::getUndoName()
00149 {
00150 if ( m_stckUndo.isEmpty() )
00151 return QString("");
00152 return m_stckUndo.current()->getName();
00153 }
00154
00155
00156
00157
00158
00159
00160 KSpreadMacroUndoAction::KSpreadMacroUndoAction( KSpreadDoc *_doc, const QString& _name ):
00161 KSpreadUndoAction( _doc )
00162 {
00163 name=_name;
00164 }
00165
00166 KSpreadMacroUndoAction::~KSpreadMacroUndoAction()
00167 {
00168 m_commands.setAutoDelete( true );
00169 }
00170
00171 void KSpreadMacroUndoAction::addCommand(KSpreadUndoAction *command)
00172 {
00173 m_commands.append(command);
00174 }
00175
00176 void KSpreadMacroUndoAction::undo()
00177 {
00178 QPtrListIterator<KSpreadUndoAction> it(m_commands);
00179 for ( ; it.current() ; ++it )
00180 it.current()->undo();
00181 }
00182
00183 void KSpreadMacroUndoAction::redo()
00184 {
00185 QPtrListIterator<KSpreadUndoAction> it(m_commands);
00186 for ( ; it.current() ; ++it )
00187 it.current()->redo();
00188 }
00189
00190
00191
00192
00193
00194
00195
00196 KSpreadUndoInsertRemoveAction::KSpreadUndoInsertRemoveAction( KSpreadDoc * _doc ) :
00197 KSpreadUndoAction( _doc )
00198 {
00199 }
00200
00201 KSpreadUndoInsertRemoveAction::~KSpreadUndoInsertRemoveAction()
00202 {
00203
00204 }
00205
00206 void KSpreadUndoInsertRemoveAction::saveFormulaReference( KSpreadSheet *_sheet,
00207 int col, int row, QString & formula )
00208 {
00209 if ( _sheet == 0 )
00210 return;
00211 QString sheetName = _sheet->sheetName();
00212
00213 m_lstFormulaCells.append( FormulaOfCell( sheetName, col, row, formula ) );
00214 }
00215
00216 void KSpreadUndoInsertRemoveAction::undoFormulaReference()
00217 {
00218 QValueList<FormulaOfCell>::iterator it;
00219 for ( it = m_lstFormulaCells.begin(); it != m_lstFormulaCells.end(); ++it )
00220 {
00221 KSpreadSheet* sheet = doc()->map()->findSheet( (*it).sheetName() );
00222 if ( sheet )
00223 {
00224 KSpreadCell * cell = sheet->cellAt( (*it).col(), (*it).row() );
00225 if ( cell && !cell->isDefault() )
00226 {
00227 cell->setCellText( (*it).formula() );
00228 }
00229 }
00230 }
00231 }
00232
00233
00234
00235
00236
00237
00238
00239 KSpreadUndoRemoveColumn::KSpreadUndoRemoveColumn( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column,int _nbCol ) :
00240 KSpreadUndoInsertRemoveAction( _doc )
00241 {
00242 name=i18n("Remove Columns");
00243 m_sheetName = _sheet->sheetName();
00244 m_iColumn= _column;
00245 m_iNbCol = _nbCol;
00246 m_printRange = _sheet->print()->printRange();
00247 m_printRepeatColumns = _sheet->print()->printRepeatColumns();
00248 QRect selection;
00249 selection.setCoords( _column, 1, _column+m_iNbCol, KS_rowMax );
00250 QDomDocument doc = _sheet->saveCellRect( selection );
00251
00252
00253 QString buffer;
00254 QTextStream str( &buffer, IO_WriteOnly );
00255 str << doc;
00256
00257
00258
00259
00260
00261 m_data = buffer.utf8();
00262 int len = m_data.length();
00263 char tmp = m_data[ len - 1 ];
00264 m_data.resize( len );
00265 *( m_data.data() + len - 1 ) = tmp;
00266 }
00267
00268 KSpreadUndoRemoveColumn::~KSpreadUndoRemoveColumn()
00269 {
00270 }
00271
00272 void KSpreadUndoRemoveColumn::undo()
00273 {
00274 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00275 if ( !sheet )
00276 return;
00277
00278 doc()->undoLock();
00279
00280 sheet->insertColumn( m_iColumn,m_iNbCol);
00281
00282 QPoint pastePoint( m_iColumn, 1 );
00283 sheet->paste( m_data, QRect( pastePoint, pastePoint ) );
00284 if(sheet->getAutoCalc()) sheet->recalc();
00285
00286 sheet->print()->setPrintRange( m_printRange );
00287 sheet->print()->setPrintRepeatColumns( m_printRepeatColumns );
00288
00289 doc()->undoUnlock();
00290
00291 undoFormulaReference();
00292 }
00293
00294 void KSpreadUndoRemoveColumn::redo()
00295 {
00296 doc()->undoLock();
00297
00298 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00299 if ( !sheet )
00300 return;
00301
00302 sheet->removeColumn( m_iColumn,m_iNbCol );
00303
00304 doc()->undoUnlock();
00305 }
00306
00307
00308
00309
00310
00311
00312
00313 KSpreadUndoInsertColumn::KSpreadUndoInsertColumn( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column, int _nbCol ) :
00314 KSpreadUndoInsertRemoveAction( _doc )
00315 {
00316 name=i18n("Insert Columns");
00317 m_sheetName = _sheet->sheetName();
00318 m_iColumn= _column;
00319 m_iNbCol=_nbCol;
00320 }
00321
00322 KSpreadUndoInsertColumn::~KSpreadUndoInsertColumn()
00323 {
00324 }
00325
00326 void KSpreadUndoInsertColumn::undo()
00327 {
00328 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00329 if ( !sheet )
00330 return;
00331
00332 doc()->undoLock();
00333 sheet->removeColumn( m_iColumn,m_iNbCol );
00334 doc()->undoUnlock();
00335
00336 undoFormulaReference();
00337 }
00338
00339 void KSpreadUndoInsertColumn::redo()
00340 {
00341 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00342 if ( !sheet )
00343 return;
00344
00345 doc()->undoLock();
00346 sheet->insertColumn( m_iColumn,m_iNbCol);
00347 doc()->undoUnlock();
00348 }
00349
00350
00351
00352
00353
00354
00355
00356 KSpreadUndoRemoveRow::KSpreadUndoRemoveRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _row,int _nbRow) :
00357 KSpreadUndoInsertRemoveAction( _doc )
00358 {
00359 name=i18n("Remove Rows");
00360
00361 m_sheetName = _sheet->sheetName();
00362 m_iRow = _row;
00363 m_iNbRow= _nbRow;
00364 m_printRange=_sheet->print()->printRange();
00365 m_printRepeatRows = _sheet->print()->printRepeatRows();
00366
00367 QRect selection;
00368 selection.setCoords( 1, _row, KS_colMax, _row+m_iNbRow );
00369 QDomDocument doc = _sheet->saveCellRect( selection );
00370
00371
00372 QString buffer;
00373 QTextStream str( &buffer, IO_WriteOnly );
00374 str << doc;
00375
00376
00377
00378
00379
00380 m_data = buffer.utf8();
00381 int len = m_data.length();
00382 char tmp = m_data[ len - 1 ];
00383 m_data.resize( len );
00384 *( m_data.data() + len - 1 ) = tmp;
00385
00386
00387
00388
00389
00390
00391 }
00392
00393 KSpreadUndoRemoveRow::~KSpreadUndoRemoveRow()
00394 {
00395 }
00396
00397 void KSpreadUndoRemoveRow::undo()
00398 {
00399 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00400 if ( !sheet )
00401 return;
00402
00403 doc()->undoLock();
00404
00405 sheet->insertRow( m_iRow,m_iNbRow );
00406
00407 QPoint pastePoint( 1, m_iRow );
00408 sheet->paste( m_data, QRect(pastePoint, pastePoint) );
00409
00410 sheet->print()->setPrintRange( m_printRange );
00411 sheet->print()->setPrintRepeatRows( m_printRepeatRows );
00412
00413 if(sheet->getAutoCalc()) sheet->recalc();
00414
00415 doc()->undoUnlock();
00416
00417 undoFormulaReference();
00418 }
00419
00420 void KSpreadUndoRemoveRow::redo()
00421 {
00422 doc()->undoLock();
00423
00424 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00425 if ( !sheet )
00426 return;
00427
00428 sheet->removeRow( m_iRow,m_iNbRow );
00429
00430 doc()->undoUnlock();
00431 }
00432
00433
00434
00435
00436
00437
00438
00439 KSpreadUndoInsertRow::KSpreadUndoInsertRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _row,int _nbRow ) :
00440 KSpreadUndoInsertRemoveAction( _doc )
00441 {
00442 name=i18n("Insert Rows");
00443 m_sheetName = _sheet->sheetName();
00444 m_iRow = _row;
00445 m_iNbRow=_nbRow;
00446 }
00447
00448 KSpreadUndoInsertRow::~KSpreadUndoInsertRow()
00449 {
00450 }
00451
00452 void KSpreadUndoInsertRow::undo()
00453 {
00454 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00455 if ( !sheet )
00456 return;
00457
00458 doc()->undoLock();
00459 sheet->removeRow( m_iRow,m_iNbRow );
00460 doc()->undoUnlock();
00461
00462 undoFormulaReference();
00463 }
00464
00465 void KSpreadUndoInsertRow::redo()
00466 {
00467 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00468 if ( !sheet )
00469 return;
00470
00471 doc()->undoLock();
00472 sheet->insertRow( m_iRow,m_iNbRow );
00473 doc()->undoUnlock();
00474 }
00475
00476
00477
00478
00479
00480
00481
00482
00483 KSpreadUndoHideRow::KSpreadUndoHideRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _row, int _nbRow , QValueList<int>_listRow) :
00484 KSpreadUndoAction( _doc )
00485 {
00486 name=i18n("Hide Rows");
00487 m_sheetName = _sheet->sheetName();
00488 m_iRow= _row;
00489 m_iNbRow=_nbRow;
00490 if(m_iNbRow!=-1)
00491 createList( listRow ,_sheet );
00492 else
00493 listRow=QValueList<int>(_listRow);
00494 }
00495
00496 KSpreadUndoHideRow::~KSpreadUndoHideRow()
00497 {
00498 }
00499
00500 void KSpreadUndoHideRow::createList( QValueList<int>&list,KSpreadSheet *tab )
00501 {
00502 RowFormat *rl;
00503 for(int i=m_iRow;i<=(m_iRow+m_iNbRow);i++)
00504 {
00505 rl= tab->nonDefaultRowFormat( i );
00506 if(!rl->isHide())
00507 list.append(rl->row());
00508 }
00509 }
00510
00511 void KSpreadUndoHideRow::undo()
00512 {
00513 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00514 if ( !sheet )
00515 return;
00516
00517 doc()->undoLock();
00518 sheet->showRow( 0,-1,listRow );
00519 doc()->undoUnlock();
00520 }
00521
00522 void KSpreadUndoHideRow::redo()
00523 {
00524 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00525 if ( !sheet )
00526 return;
00527
00528 doc()->undoLock();
00529 sheet->hideRow(0,-1, listRow );
00530 doc()->undoUnlock();
00531 }
00532
00533
00534
00535
00536
00537
00538
00539 KSpreadUndoHideColumn::KSpreadUndoHideColumn( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column, int _nbCol, QValueList<int>_listCol ) :
00540 KSpreadUndoAction( _doc )
00541 {
00542 name=i18n("Hide Columns");
00543
00544 m_sheetName = _sheet->sheetName();
00545 m_iColumn= _column;
00546 m_iNbCol=_nbCol;
00547 if(m_iNbCol!=-1)
00548 createList( listCol ,_sheet );
00549 else
00550 listCol=QValueList<int>(_listCol);
00551 }
00552
00553 KSpreadUndoHideColumn::~KSpreadUndoHideColumn()
00554 {
00555 }
00556
00557 void KSpreadUndoHideColumn::createList( QValueList<int>&list,KSpreadSheet *tab )
00558 {
00559 ColumnFormat *cl;
00560 for(int i=m_iColumn;i<=(m_iColumn+m_iNbCol);i++)
00561 {
00562 cl= tab->nonDefaultColumnFormat( i );
00563 if(!cl->isHide())
00564 list.append(cl->column());
00565 }
00566 }
00567
00568 void KSpreadUndoHideColumn::undo()
00569 {
00570 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00571 if ( !sheet )
00572 return;
00573
00574 doc()->undoLock();
00575 sheet->showColumn(0,-1,listCol);
00576 doc()->undoUnlock();
00577 }
00578
00579 void KSpreadUndoHideColumn::redo()
00580 {
00581 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00582 if ( !sheet )
00583 return;
00584
00585 doc()->undoLock();
00586 sheet->hideColumn(0,-1,listCol);
00587 doc()->undoUnlock();
00588 }
00589
00590
00591
00592
00593
00594
00595
00596 KSpreadUndoShowRow::KSpreadUndoShowRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _row, int _nbRow, QValueList<int>_listRow ) :
00597 KSpreadUndoAction( _doc )
00598 {
00599 name=i18n("Show Rows");
00600
00601 m_sheetName = _sheet->sheetName();
00602 m_iRow= _row;
00603 m_iNbRow=_nbRow;
00604 if(m_iNbRow!=-1)
00605 createList( listRow ,_sheet );
00606 else
00607 listRow=QValueList<int>(_listRow);
00608 }
00609
00610 KSpreadUndoShowRow::~KSpreadUndoShowRow()
00611 {
00612 }
00613
00614 void KSpreadUndoShowRow::createList( QValueList<int>&list,KSpreadSheet *tab )
00615 {
00616 RowFormat *rl;
00617 for(int i=m_iRow;i<=(m_iRow+m_iNbRow);i++)
00618 {
00619 rl= tab->nonDefaultRowFormat( i );
00620 if(rl->isHide())
00621 list.append(rl->row());
00622 }
00623 }
00624
00625 void KSpreadUndoShowRow::undo()
00626 {
00627 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00628 if ( !sheet )
00629 return;
00630
00631 doc()->undoLock();
00632 sheet->hideRow(0,-1,listRow);
00633 doc()->undoUnlock();
00634 }
00635
00636 void KSpreadUndoShowRow::redo()
00637 {
00638 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00639 if ( !sheet )
00640 return;
00641
00642 doc()->undoLock();
00643 sheet->showRow(0,-1,listRow);
00644 doc()->undoUnlock();
00645 }
00646
00647
00648
00649
00650
00651
00652
00653 KSpreadUndoShowColumn::KSpreadUndoShowColumn( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column, int _nbCol,QValueList<int>_listCol ) :
00654 KSpreadUndoAction( _doc )
00655 {
00656 name=i18n("Show Columns");
00657
00658 m_sheetName = _sheet->sheetName();
00659 m_iColumn= _column;
00660 m_iNbCol=_nbCol;
00661 if(m_iNbCol!=-1)
00662 createList( listCol ,_sheet );
00663 else
00664 listCol=QValueList<int>(_listCol);
00665 }
00666
00667 KSpreadUndoShowColumn::~KSpreadUndoShowColumn()
00668 {
00669 }
00670
00671 void KSpreadUndoShowColumn::createList( QValueList<int>&list,KSpreadSheet *tab )
00672 {
00673 ColumnFormat *cl;
00674 for(int i=m_iColumn;i<=(m_iColumn+m_iNbCol);i++)
00675 {
00676 cl= tab->nonDefaultColumnFormat( i );
00677 if(cl->isHide())
00678 list.append(cl->column());
00679 }
00680
00681 }
00682
00683 void KSpreadUndoShowColumn::undo()
00684 {
00685 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00686 if ( !sheet )
00687 return;
00688
00689 doc()->undoLock();
00690 sheet->hideColumn( 0,-1,listCol );
00691 doc()->undoUnlock();
00692 }
00693
00694 void KSpreadUndoShowColumn::redo()
00695 {
00696 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00697 if ( !sheet )
00698 return;
00699
00700 doc()->undoLock();
00701 sheet->showColumn(0,-1,listCol);
00702 doc()->undoUnlock();
00703 }
00704
00705
00706
00707
00708
00709
00710
00711
00712 KSpreadUndoPaperLayout::KSpreadUndoPaperLayout( KSpreadDoc *_doc, KSpreadSheet *_sheet )
00713 : KSpreadUndoAction( _doc )
00714 {
00715 name=i18n("Set Page Layout");
00716 m_sheetName = _sheet->sheetName();
00717
00718 m_pl = _sheet->print()->paperLayout();
00719 m_hf = _sheet->print()->headFootLine();
00720 m_unit = doc()->getUnit();
00721 m_printGrid = _sheet->print()->printGrid();
00722 m_printCommentIndicator = _sheet->print()->printCommentIndicator();
00723 m_printFormulaIndicator = _sheet->print()->printFormulaIndicator();
00724 m_printRange = _sheet->print()->printRange();
00725 m_printRepeatColumns = _sheet->print()->printRepeatColumns();
00726 m_printRepeatRows = _sheet->print()->printRepeatRows();
00727 m_dZoom = _sheet->print()->zoom();
00728 m_iPageLimitX = _sheet->print()->pageLimitX();
00729 m_iPageLimitY = _sheet->print()->pageLimitY();
00730 }
00731
00732 KSpreadUndoPaperLayout::~KSpreadUndoPaperLayout()
00733 {
00734 }
00735
00736 void KSpreadUndoPaperLayout::undo()
00737 {
00738 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00739 if ( !sheet )
00740 return;
00741 KSpreadSheetPrint* print = sheet->print();
00742
00743 doc()->undoLock();
00744
00745 m_plRedo = print->paperLayout();
00746 print->setPaperLayout( m_pl.ptLeft, m_pl.ptTop,
00747 m_pl.ptRight, m_pl.ptBottom,
00748 m_pl.format, m_pl.orientation );
00749
00750 m_hfRedo = print->headFootLine();
00751 print->setHeadFootLine( m_hf.headLeft, m_hf.headMid, m_hf.headRight,
00752 m_hf.footLeft, m_hf.footMid, m_hf.footRight );
00753
00754 m_unitRedo = doc()->getUnit();
00755 doc()->setUnit( m_unit );
00756
00757 m_printGridRedo = print->printGrid();
00758 print->setPrintGrid( m_printGrid );
00759
00760 m_printCommentIndicatorRedo = print->printCommentIndicator();
00761 print->setPrintCommentIndicator( m_printCommentIndicator );
00762
00763 m_printFormulaIndicatorRedo = print->printFormulaIndicator();
00764 print->setPrintFormulaIndicator( m_printFormulaIndicator );
00765
00766 m_printRangeRedo = print->printRange();
00767 print->setPrintRange( m_printRange );
00768
00769 m_printRepeatColumnsRedo = print->printRepeatColumns();
00770 print->setPrintRepeatColumns( m_printRepeatColumns );
00771
00772 m_printRepeatRowsRedo = print->printRepeatRows();
00773 print->setPrintRepeatRows( m_printRepeatRows );
00774
00775 m_dZoomRedo = print->zoom();
00776 print->setZoom( m_dZoom );
00777
00778 m_iPageLimitXRedo = print->pageLimitX();
00779 print->setPageLimitX( m_iPageLimitX );
00780
00781 m_iPageLimitYRedo = print->pageLimitY();
00782 print->setPageLimitY( m_iPageLimitY );
00783
00784 doc()->undoUnlock();
00785 }
00786
00787 void KSpreadUndoPaperLayout::redo()
00788 {
00789 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00790 if ( !sheet )
00791 return;
00792 KSpreadSheetPrint* print = sheet->print();
00793
00794 doc()->undoLock();
00795 print->setPaperLayout( m_plRedo.ptLeft, m_plRedo.ptTop,
00796 m_plRedo.ptRight, m_plRedo.ptBottom,
00797 m_plRedo.format, m_plRedo.orientation );
00798
00799 print->setHeadFootLine( m_hfRedo.headLeft, m_hfRedo.headMid, m_hfRedo.headRight,
00800 m_hfRedo.footLeft, m_hfRedo.footMid, m_hfRedo.footRight );
00801
00802 doc()->setUnit( m_unitRedo );
00803
00804 print->setPrintGrid( m_printGridRedo );
00805 print->setPrintCommentIndicator( m_printCommentIndicatorRedo );
00806 print->setPrintFormulaIndicator( m_printFormulaIndicatorRedo );
00807
00808 print->setPrintRange( m_printRangeRedo );
00809 print->setPrintRepeatColumns( m_printRepeatColumnsRedo );
00810 print->setPrintRepeatRows( m_printRepeatRowsRedo );
00811
00812 print->setZoom( m_dZoomRedo );
00813
00814 print->setPageLimitX( m_iPageLimitX );
00815 print->setPageLimitY( m_iPageLimitY );
00816
00817 doc()->undoUnlock();
00818 }
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829 KSpreadUndoSetText::KSpreadUndoSetText( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QString& _text, int _column, int _row,FormatType _formatType ) :
00830 KSpreadUndoAction( _doc )
00831 {
00832 name=i18n("Change Text");
00833
00834 m_strText = _text;
00835 m_iColumn= _column;
00836 m_iRow = _row;
00837 m_sheetName = _sheet->sheetName();
00838 m_eFormatType=_formatType;
00839 }
00840
00841 KSpreadUndoSetText::~KSpreadUndoSetText()
00842 {
00843 }
00844
00845 void KSpreadUndoSetText::undo()
00846 {
00847 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00848 if ( !sheet )
00849 return;
00850
00851 doc()->undoLock();
00852 doc()->emitBeginOperation();
00853 KSpreadCell *cell = sheet->nonDefaultCell( m_iColumn, m_iRow );
00854 m_strRedoText = cell->text();
00855 m_eFormatTypeRedo=cell->getFormatType( m_iColumn, m_iRow );
00856 cell->setFormatType(m_eFormatType);
00857
00858 if ( m_strText.isNull() )
00859 cell->setCellText( "" );
00860 else
00861 cell->setCellText( m_strText );
00862 sheet->updateView( QRect( m_iColumn, m_iRow, 1, 1 ) );
00863 doc()->undoUnlock();
00864 }
00865
00866 void KSpreadUndoSetText::redo()
00867 {
00868 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
00869 if ( !sheet )
00870 return;
00871
00872 doc()->undoLock();
00873 doc()->emitBeginOperation();
00874 KSpreadCell *cell = sheet->nonDefaultCell( m_iColumn, m_iRow );
00875 m_strText = cell->text();
00876 m_eFormatType=cell->getFormatType( m_iColumn, m_iRow );
00877 if ( m_strRedoText.isNull() )
00878 cell->setCellText( "" );
00879 else
00880 cell->setCellText( m_strRedoText );
00881 cell->setFormatType(m_eFormatTypeRedo);
00882 sheet->updateView( QRect( m_iColumn, m_iRow, 1, 1 ) );
00883 doc()->undoUnlock();
00884 }
00885
00886
00887
00888
00889
00890
00891
00892 KSpreadUndoCellFormat::KSpreadUndoCellFormat( KSpreadDoc * _doc,
00893 KSpreadSheet * _sheet,
00894 const QRect & _selection,
00895 const QString & _name ) :
00896 KSpreadUndoAction( _doc )
00897 {
00898 if ( _name.isEmpty())
00899 name = i18n("Change Format");
00900 else
00901 name = _name;
00902
00903 m_rctRect = _selection;
00904 m_sheetName = _sheet->sheetName();
00905 copyFormat( m_lstFormats, m_lstColFormats, m_lstRowFormats, _sheet );
00906 }
00907
00908 void KSpreadUndoCellFormat::copyFormat(QValueList<layoutCell> & list,
00909 QValueList<layoutColumn> & listCol,
00910 QValueList<layoutRow> & listRow,
00911 KSpreadSheet * sheet )
00912 {
00913 QValueList<layoutCell>::Iterator it2;
00914 for ( it2 = list.begin(); it2 != list.end(); ++it2 )
00915 {
00916 delete (*it2).l;
00917 }
00918 list.clear();
00919
00920 KSpreadCell * cell;
00921 int bottom = m_rctRect.bottom();
00922 int right = m_rctRect.right();
00923
00924 if ( util_isColumnSelected( m_rctRect ) )
00925 {
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936 for ( int c = m_rctRect.left(); c <= right; ++c )
00937 {
00938 layoutColumn tmplayout;
00939 tmplayout.col = c;
00940 tmplayout.l = new ColumnFormat( sheet, c );
00941 tmplayout.l->copy( *(sheet->columnFormat( c )) );
00942 listCol.append(tmplayout);
00943
00944 cell = sheet->getFirstCellColumn( c );
00945 while ( cell )
00946 {
00947 if ( cell->isObscuringForced() )
00948 {
00949 cell = sheet->getNextCellDown( c, cell->row() );
00950 continue;
00951 }
00952
00953 layoutCell tmplayout;
00954 tmplayout.col = c;
00955 tmplayout.row = cell->row();
00956 tmplayout.l = new KSpreadFormat( sheet, 0 );
00957 tmplayout.l->copy( *(sheet->cellAt( tmplayout.col, tmplayout.row )) );
00958 list.append(tmplayout);
00959
00960 cell = sheet->getNextCellDown( c, cell->row() );
00961 }
00962 }
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980 }
00981 else if (util_isRowSelected( m_rctRect ) )
00982 {
00983 for ( int row = m_rctRect.top(); row <= bottom; ++row )
00984 {
00985 layoutRow tmplayout;
00986 tmplayout.row = row;
00987 tmplayout.l = new RowFormat( sheet, row );
00988 tmplayout.l->copy( *(sheet->rowFormat( row )) );
00989 listRow.append(tmplayout);
00990
00991 cell = sheet->getFirstCellRow( row );
00992 while ( cell )
00993 {
00994 if ( cell->isObscuringForced() )
00995 {
00996 cell = sheet->getNextCellRight( cell->column(), row );
00997 continue;
00998 }
00999 layoutCell tmplayout;
01000 tmplayout.col = cell->column();
01001 tmplayout.row = row;
01002 tmplayout.l = new KSpreadFormat( sheet, 0 );
01003 tmplayout.l->copy( *(sheet->cellAt( cell->column(), row )) );
01004 list.append(tmplayout);
01005
01006 cell = sheet->getNextCellRight( cell->column(), row );
01007 }
01008 }
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026 }
01027 else
01028 {
01029 for ( int y = m_rctRect.top(); y <= bottom; ++y )
01030 for ( int x = m_rctRect.left(); x <= right; ++x )
01031 {
01032 KSpreadCell * cell = sheet->nonDefaultCell( x, y );
01033 if ( !cell->isObscuringForced() )
01034 {
01035 layoutCell tmplayout;
01036 tmplayout.col = x;
01037 tmplayout.row = y;
01038 tmplayout.l = new KSpreadFormat( sheet, 0 );
01039 tmplayout.l->copy( *(sheet->cellAt( x, y )) );
01040 list.append(tmplayout);
01041 }
01042 }
01043 }
01044 }
01045
01046 KSpreadUndoCellFormat::~KSpreadUndoCellFormat()
01047 {
01048 QValueList<layoutCell>::Iterator it2;
01049 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
01050 {
01051 delete (*it2).l;
01052 }
01053 m_lstFormats.clear();
01054
01055 for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
01056 {
01057 delete (*it2).l;
01058 }
01059 m_lstRedoFormats.clear();
01060
01061 QValueList<layoutColumn>::Iterator it3;
01062 for ( it3 = m_lstColFormats.begin(); it3 != m_lstColFormats.end(); ++it3 )
01063 {
01064 delete (*it3).l;
01065 }
01066 m_lstColFormats.clear();
01067
01068 for ( it3 = m_lstRedoColFormats.begin(); it3 != m_lstRedoColFormats.end(); ++it3 )
01069 {
01070 delete (*it3).l;
01071 }
01072 m_lstRedoColFormats.clear();
01073
01074 QValueList<layoutRow>::Iterator it4;
01075 for ( it4 = m_lstRowFormats.begin(); it4 != m_lstRowFormats.end(); ++it4 )
01076 {
01077 delete (*it4).l;
01078 }
01079 m_lstRowFormats.clear();
01080
01081 for ( it4 = m_lstRedoRowFormats.begin(); it4 != m_lstRedoRowFormats.end(); ++it4 )
01082 {
01083 delete (*it4).l;
01084 }
01085 m_lstRedoRowFormats.clear();
01086
01087
01088 }
01089
01090 void KSpreadUndoCellFormat::undo()
01091 {
01092 KSpreadSheet * sheet = doc()->map()->findSheet( m_sheetName );
01093 if ( !sheet )
01094 return;
01095
01096 doc()->undoLock();
01097 doc()->emitBeginOperation();
01098 copyFormat( m_lstRedoFormats, m_lstRedoColFormats, m_lstRedoRowFormats, sheet );
01099 if( util_isColumnSelected( m_rctRect ) )
01100 {
01101 QValueList<layoutColumn>::Iterator it2;
01102 for ( it2 = m_lstColFormats.begin(); it2 != m_lstColFormats.end(); ++it2 )
01103 {
01104 ColumnFormat * col = sheet->nonDefaultColumnFormat( (*it2).col );
01105 col->copy( *(*it2).l );
01106 }
01107 }
01108 else if( util_isRowSelected( m_rctRect ) )
01109 {
01110 QValueList<layoutRow>::Iterator it2;
01111 for ( it2 = m_lstRowFormats.begin(); it2 != m_lstRowFormats.end(); ++it2 )
01112 {
01113 RowFormat * row = sheet->nonDefaultRowFormat( (*it2).row );
01114 row->copy( *(*it2).l );
01115 }
01116 }
01117
01118 QValueList<layoutCell>::Iterator it2;
01119 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
01120 {
01121 KSpreadCell *cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
01122 cell->copy( *(*it2).l );
01123 cell->setLayoutDirtyFlag();
01124 cell->setDisplayDirtyFlag();
01125 sheet->updateCell( cell, (*it2).col, (*it2).row );
01126 }
01127
01128 sheet->setRegionPaintDirty( m_rctRect );
01129 sheet->updateView( m_rctRect );
01130
01131 doc()->undoUnlock();
01132 }
01133
01134 void KSpreadUndoCellFormat::redo()
01135 {
01136 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
01137 if ( !sheet )
01138 return;
01139
01140 doc()->undoLock();
01141 doc()->emitBeginOperation();
01142
01143 if ( util_isColumnSelected( m_rctRect ) )
01144 {
01145 QValueList<layoutColumn>::Iterator it2;
01146 for ( it2 = m_lstRedoColFormats.begin(); it2 != m_lstRedoColFormats.end(); ++it2 )
01147 {
01148 ColumnFormat * col = sheet->nonDefaultColumnFormat( (*it2).col );
01149 col->copy( *(*it2).l );
01150 }
01151 }
01152 else if( util_isRowSelected( m_rctRect ) )
01153 {
01154 QValueList<layoutRow>::Iterator it2;
01155 for ( it2 = m_lstRedoRowFormats.begin(); it2 != m_lstRedoRowFormats.end(); ++it2 )
01156 {
01157 RowFormat * row = sheet->nonDefaultRowFormat( (*it2).row );
01158 row->copy( *(*it2).l );
01159 }
01160 }
01161
01162 QValueList<layoutCell>::Iterator it2;
01163 for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
01164 {
01165 KSpreadCell * cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
01166 cell->copy( *(*it2).l );
01167 cell->setLayoutDirtyFlag();
01168 cell->setDisplayDirtyFlag();
01169 sheet->updateCell( cell, (*it2).col, (*it2).row );
01170 }
01171
01172 sheet->setRegionPaintDirty( m_rctRect );
01173 sheet->updateView( m_rctRect );
01174 doc()->undoUnlock();
01175 }
01176
01177
01178
01179
01180
01181
01182
01183 KSpreadUndoChangeAngle::KSpreadUndoChangeAngle( KSpreadDoc * _doc,
01184 KSpreadSheet * _sheet,
01185 const QRect & _selection ) :
01186 KSpreadUndoAction( _doc )
01187 {
01188 name = i18n("Change Angle");
01189 m_layoutUndo = new KSpreadUndoCellFormat( _doc, _sheet, _selection, QString::null );
01190 m_resizeUndo = new KSpreadUndoResizeColRow( _doc, _sheet, _selection );
01191 }
01192
01193 KSpreadUndoChangeAngle::~KSpreadUndoChangeAngle()
01194 {
01195 delete m_resizeUndo;
01196 delete m_layoutUndo;
01197 }
01198
01199 void KSpreadUndoChangeAngle::undo()
01200 {
01201 m_layoutUndo->undo();
01202 m_resizeUndo->undo();
01203 }
01204
01205 void KSpreadUndoChangeAngle::redo()
01206 {
01207 m_layoutUndo->redo();
01208 m_resizeUndo->redo();
01209 }
01210
01211
01212
01213
01214
01215
01216
01217 KSpreadUndoSort::KSpreadUndoSort( KSpreadDoc * _doc, KSpreadSheet * _sheet, const QRect & _selection ) :
01218 KSpreadUndoAction( _doc )
01219 {
01220 name = i18n("Sort");
01221
01222 m_rctRect = _selection;
01223 m_sheetName = _sheet->sheetName();
01224 copyAll( m_lstFormats, m_lstColFormats, m_lstRowFormats, _sheet );
01225 }
01226
01227 void KSpreadUndoSort::copyAll(QValueList<layoutTextCell> & list, QValueList<layoutColumn> & listCol,
01228 QValueList<layoutRow> & listRow, KSpreadSheet * sheet )
01229 {
01230 QValueList<layoutTextCell>::Iterator it2;
01231 for ( it2 = list.begin(); it2 != list.end(); ++it2 )
01232 {
01233 delete (*it2).l;
01234 }
01235 list.clear();
01236
01237 if ( util_isColumnSelected( m_rctRect ) )
01238 {
01239 KSpreadCell * c;
01240 for (int col = m_rctRect.left(); col <= m_rctRect.right(); ++col)
01241 {
01242 layoutColumn tmplayout;
01243 tmplayout.col = col;
01244 tmplayout.l = new ColumnFormat( sheet, col );
01245 tmplayout.l->copy( *(sheet->columnFormat( col )) );
01246 listCol.append(tmplayout);
01247
01248 c = sheet->getFirstCellColumn( col );
01249 while ( c )
01250 {
01251 if ( !c->isObscuringForced() )
01252 {
01253 layoutTextCell tmplayout;
01254 tmplayout.col = col;
01255 tmplayout.row = c->row();
01256 tmplayout.l = new KSpreadFormat( sheet, 0 );
01257 tmplayout.l->copy( *(sheet->cellAt( tmplayout.col, tmplayout.row )) );
01258 tmplayout.text = c->text();
01259 list.append(tmplayout);
01260 }
01261
01262 c = sheet->getNextCellDown( col, c->row() );
01263 }
01264 }
01265 }
01266 else if ( util_isRowSelected( m_rctRect ) )
01267 {
01268 KSpreadCell * c;
01269 for ( int row = m_rctRect.top(); row <= m_rctRect.bottom(); ++row)
01270 {
01271 layoutRow tmplayout;
01272 tmplayout.row = row;
01273 tmplayout.l = new RowFormat( sheet, row );
01274 tmplayout.l->copy( *(sheet->rowFormat( row )) );
01275 listRow.append(tmplayout);
01276
01277 c = sheet->getFirstCellRow( row );
01278 while ( c )
01279 {
01280 if ( !c->isObscuringForced() )
01281 {
01282 layoutTextCell tmplayout;
01283 tmplayout.col = c->column();
01284 tmplayout.row = row;
01285 tmplayout.l = new KSpreadFormat( sheet, 0 );
01286 tmplayout.l->copy( *(sheet->cellAt( tmplayout.col, tmplayout.row )) );
01287 tmplayout.text = c->text();
01288 list.append(tmplayout);
01289 }
01290 c = sheet->getNextCellRight( c->column(), row );
01291 }
01292 }
01293 }
01294 else
01295 {
01296 int bottom = m_rctRect.bottom();
01297 int right = m_rctRect.right();
01298 KSpreadCell * cell;
01299 for ( int y = m_rctRect.top(); y <= bottom; ++y )
01300 for ( int x = m_rctRect.left(); x <= right; ++x )
01301 {
01302 cell = sheet->nonDefaultCell( x, y );
01303 if (!cell->isObscuringForced())
01304 {
01305 layoutTextCell tmplayout;
01306 tmplayout.col = x;
01307 tmplayout.row = y;
01308 tmplayout.l = new KSpreadFormat( sheet, 0 );
01309 tmplayout.l->copy( *(sheet->cellAt( x, y )) );
01310 tmplayout.text = cell->text();
01311 list.append(tmplayout);
01312 }
01313 }
01314 }
01315 }
01316
01317 KSpreadUndoSort::~KSpreadUndoSort()
01318 {
01319 QValueList<layoutTextCell>::Iterator it2;
01320 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
01321 {
01322 delete (*it2).l;
01323 }
01324 m_lstFormats.clear();
01325
01326 for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
01327 {
01328 delete (*it2).l;
01329 }
01330 m_lstRedoFormats.clear();
01331
01332 QValueList<layoutColumn>::Iterator it3;
01333 for ( it3 = m_lstColFormats.begin(); it3 != m_lstColFormats.end(); ++it3 )
01334 {
01335 delete (*it3).l;
01336 }
01337 m_lstColFormats.clear();
01338
01339 for ( it3 = m_lstRedoColFormats.begin(); it3 != m_lstRedoColFormats.end(); ++it3 )
01340 {
01341 delete (*it3).l;
01342 }
01343 m_lstRedoColFormats.clear();
01344
01345 QValueList<layoutRow>::Iterator it4;
01346 for ( it4 = m_lstRowFormats.begin(); it4 != m_lstRowFormats.end(); ++it4 )
01347 {
01348 delete (*it4).l;
01349 }
01350 m_lstRowFormats.clear();
01351
01352 for ( it4 = m_lstRedoRowFormats.begin(); it4 != m_lstRedoRowFormats.end(); ++it4 )
01353 {
01354 delete (*it4).l;
01355 }
01356 m_lstRedoRowFormats.clear();
01357
01358 }
01359
01360 void KSpreadUndoSort::undo()
01361 {
01362 KSpreadSheet * sheet = doc()->map()->findSheet( m_sheetName );
01363 if ( !sheet )
01364 return;
01365
01366 doc()->undoLock();
01367 doc()->emitBeginOperation();
01368
01369 copyAll( m_lstRedoFormats, m_lstRedoColFormats,
01370 m_lstRedoRowFormats, sheet );
01371
01372 if ( util_isColumnSelected( m_rctRect ) )
01373 {
01374 QValueList<layoutColumn>::Iterator it2;
01375 for ( it2 = m_lstColFormats.begin(); it2 != m_lstColFormats.end(); ++it2 )
01376 {
01377 ColumnFormat * col = sheet->nonDefaultColumnFormat( (*it2).col );
01378 col->copy( *(*it2).l );
01379 }
01380 }
01381 else if( util_isRowSelected( m_rctRect ) )
01382 {
01383 QValueList<layoutRow>::Iterator it2;
01384 for ( it2 = m_lstRowFormats.begin(); it2 != m_lstRowFormats.end(); ++it2 )
01385 {
01386 RowFormat *row= sheet->nonDefaultRowFormat( (*it2).row );
01387 row->copy( *(*it2).l );
01388 }
01389 }
01390
01391 QValueList<layoutTextCell>::Iterator it2;
01392 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
01393 {
01394 KSpreadCell *cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
01395 if ( (*it2).text.isEmpty() )
01396 {
01397 if(!cell->text().isEmpty())
01398 cell->setCellText( "" );
01399 }
01400 else
01401 cell->setCellText( (*it2).text );
01402
01403 cell->copy( *(*it2).l );
01404 cell->setLayoutDirtyFlag();
01405 cell->setDisplayDirtyFlag();
01406 sheet->updateCell( cell, (*it2).col, (*it2).row );
01407 }
01408
01409 sheet->setRegionPaintDirty(m_rctRect);
01410 sheet->updateView( m_rctRect );
01411
01412 doc()->undoUnlock();
01413 }
01414
01415 void KSpreadUndoSort::redo()
01416 {
01417 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
01418 if ( !sheet )
01419 return;
01420
01421 doc()->undoLock();
01422 doc()->emitBeginOperation();
01423
01424 if( util_isColumnSelected( m_rctRect ) )
01425 {
01426 QValueList<layoutColumn>::Iterator it2;
01427 for ( it2 = m_lstRedoColFormats.begin(); it2 != m_lstRedoColFormats.end(); ++it2 )
01428 {
01429 ColumnFormat *col= sheet->nonDefaultColumnFormat( (*it2).col );
01430 col->copy( *(*it2).l );
01431 }
01432 }
01433 else if( util_isRowSelected( m_rctRect ) )
01434 {
01435 QValueList<layoutRow>::Iterator it2;
01436 for ( it2 = m_lstRedoRowFormats.begin(); it2 != m_lstRedoRowFormats.end(); ++it2 )
01437 {
01438 RowFormat *row= sheet->nonDefaultRowFormat( (*it2).row );
01439 row->copy( *(*it2).l );
01440 }
01441 }
01442
01443 QValueList<layoutTextCell>::Iterator it2;
01444 for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
01445 {
01446 KSpreadCell *cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
01447
01448 if ( (*it2).text.isEmpty() )
01449 {
01450 if(!cell->text().isEmpty())
01451 cell->setCellText( "" );
01452 }
01453 else
01454 cell->setCellText( (*it2).text );
01455
01456 cell->copy( *(*it2).l );
01457 cell->setLayoutDirtyFlag();
01458 cell->setDisplayDirtyFlag();
01459 sheet->updateCell( cell, (*it2).col, (*it2).row );
01460 }
01461 sheet->setRegionPaintDirty(m_rctRect);
01462 sheet->updateView( m_rctRect );
01463 doc()->undoUnlock();
01464 }
01465
01466
01467
01468
01469
01470
01471
01472 KSpreadUndoDelete::KSpreadUndoDelete( KSpreadDoc *_doc, KSpreadSheet* sheet, const QRect & _selection)
01473 : KSpreadUndoAction( _doc )
01474 {
01475 name=i18n("Delete");
01476 m_sheetName = sheet->sheetName();
01477 m_selection = _selection;
01478 createListCell( m_data, m_lstColumn,m_lstRow,sheet );
01479
01480 }
01481
01482 KSpreadUndoDelete::~KSpreadUndoDelete()
01483 {
01484 }
01485
01486 void KSpreadUndoDelete::createListCell( QCString &listCell,QValueList<columnSize> &listCol,QValueList<rowSize> &listRow, KSpreadSheet* sheet )
01487 {
01488 listRow.clear();
01489 listCol.clear();
01490
01491 if( util_isColumnSelected( m_selection ) )
01492 {
01493 for( int y = m_selection.left() ; y <= m_selection.right() ; ++y )
01494 {
01495 ColumnFormat * cl = sheet->columnFormat( y );
01496 if ( !cl->isDefault() )
01497 {
01498 columnSize tmpSize;
01499 tmpSize.columnNumber=y;
01500 tmpSize.columnWidth=cl->dblWidth();
01501 listCol.append(tmpSize);
01502 }
01503 }
01504 }
01505
01506 else if( util_isRowSelected( m_selection ) )
01507 {
01508
01509 for( int y =m_selection.top() ; y <=m_selection.bottom() ; ++y )
01510 {
01511 RowFormat *rw=sheet->rowFormat(y);
01512 if(!rw->isDefault())
01513 {
01514 rowSize tmpSize;
01515 tmpSize.rowNumber=y;
01516 tmpSize.rowHeight=rw->dblHeight();
01517 listRow.append(tmpSize);
01518 }
01519 }
01520
01521 }
01522
01523
01524 QDomDocument doc = sheet->saveCellRect( m_selection );
01525
01526 QString buffer;
01527 QTextStream str( &buffer, IO_WriteOnly );
01528 str << doc;
01529
01530
01531
01532
01533
01534 listCell = buffer.utf8();
01535 int len = listCell.length();
01536 char tmp = listCell[ len - 1 ];
01537 listCell.resize( len );
01538 *( listCell.data() + len - 1 ) = tmp;
01539
01540 }
01541
01542
01543 void KSpreadUndoDelete::undo()
01544 {
01545 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
01546 if ( !sheet )
01547 return;
01548 createListCell( m_dataRedo, m_lstRedoColumn,m_lstRedoRow,sheet );
01549
01550 doc()->undoLock();
01551 doc()->emitBeginOperation();
01552
01553 if( util_isColumnSelected( m_selection ) )
01554 {
01555 QValueList<columnSize>::Iterator it2;
01556 for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
01557 {
01558 ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
01559 cl->setDblWidth((*it2).columnWidth);
01560 }
01561 }
01562 else if( util_isRowSelected( m_selection ) )
01563 {
01564 QValueList<rowSize>::Iterator it2;
01565 for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 )
01566 {
01567 RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
01568 rw->setDblHeight((*it2).rowHeight);
01569 }
01570 }
01571
01572 sheet->deleteCells( m_selection );
01573 sheet->paste( m_data, m_selection );
01574 sheet->updateView( );
01575
01576 if(sheet->getAutoCalc()) sheet->recalc();
01577
01578 doc()->undoUnlock();
01579 }
01580
01581 void KSpreadUndoDelete::redo()
01582 {
01583
01584 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
01585 if ( !sheet )
01586 return;
01587
01588 doc()->undoLock();
01589 doc()->emitBeginOperation();
01590
01591 if( util_isColumnSelected( m_selection ) )
01592 {
01593 QValueList<columnSize>::Iterator it2;
01594 for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
01595 {
01596 ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
01597 cl->setDblWidth((*it2).columnWidth);
01598 }
01599 }
01600 else if( util_isRowSelected( m_selection ) )
01601 {
01602 QValueList<rowSize>::Iterator it2;
01603 for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 )
01604 {
01605 RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
01606 rw->setDblHeight((*it2).rowHeight);
01607 }
01608 }
01609
01610
01611
01612
01613
01614 sheet->paste( m_dataRedo, m_selection );
01615
01616 sheet->updateView();
01617 sheet->refreshView( m_selection );
01618 doc()->undoUnlock();
01619 }
01620
01621
01622
01623
01624
01625
01626
01627 KSpreadUndoDragDrop::KSpreadUndoDragDrop( KSpreadDoc * _doc, KSpreadSheet * _sheet, const QRect & _source,
01628 const QRect & _target )
01629 : KSpreadUndoAction( _doc ),
01630 m_selectionSource( _source ),
01631 m_selectionTarget( _target )
01632 {
01633 name = i18n( "Drag & Drop" );
01634
01635 m_sheetName = _sheet->sheetName();
01636
01637 saveCellRect( m_dataTarget, _sheet, _target );
01638 if ( _source.left() > 0 )
01639 saveCellRect( m_dataSource, _sheet, _source );
01640 }
01641
01642 KSpreadUndoDragDrop::~KSpreadUndoDragDrop()
01643 {
01644 }
01645
01646 void KSpreadUndoDragDrop::saveCellRect( QCString & cells, KSpreadSheet * sheet,
01647 QRect const & rect )
01648 {
01649 QDomDocument doc = sheet->saveCellRect( rect );
01650
01651 QString buffer;
01652 QTextStream str( &buffer, IO_WriteOnly );
01653 str << doc;
01654
01655 cells = buffer.utf8();
01656 int len = cells.length();
01657 char tmp = cells[ len - 1 ];
01658 cells.resize( len );
01659 *( cells.data() + len - 1 ) = tmp;
01660 }
01661
01662 void KSpreadUndoDragDrop::undo()
01663 {
01664 KSpreadSheet * sheet = doc()->map()->findSheet( m_sheetName );
01665 if ( !sheet )
01666 return;
01667
01668 if ( m_selectionSource.left() > 0 )
01669 saveCellRect( m_dataRedoSource, sheet, m_selectionSource );
01670 saveCellRect( m_dataRedoTarget, sheet, m_selectionTarget );
01671
01672 doc()->undoLock();
01673 doc()->emitBeginOperation();
01674
01675 sheet->deleteCells( m_selectionTarget );
01676 sheet->paste( m_dataTarget, m_selectionTarget );
01677
01678 if ( m_selectionSource.left() > 0 )
01679 {
01680 sheet->deleteCells( m_selectionSource );
01681 sheet->paste( m_dataSource, m_selectionSource );
01682 }
01683
01684 sheet->updateView();
01685
01686 if ( sheet->getAutoCalc() )
01687 sheet->recalc();
01688
01689 doc()->undoUnlock();
01690 }
01691
01692 void KSpreadUndoDragDrop::redo()
01693 {
01694 KSpreadSheet * sheet = doc()->map()->findSheet( m_sheetName );
01695 if ( !sheet )
01696 return;
01697
01698 doc()->undoLock();
01699 doc()->emitBeginOperation();
01700
01701
01702
01703
01704
01705 sheet->paste( m_dataRedoTarget, m_selectionTarget );
01706 if ( m_selectionSource.left() > 0 )
01707 sheet->paste( m_dataRedoSource, m_selectionSource );
01708
01709 sheet->updateView();
01710 sheet->refreshView( m_selectionSource );
01711 sheet->refreshView( m_selectionTarget );
01712 doc()->undoUnlock();
01713 }
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723 KSpreadUndoResizeColRow::KSpreadUndoResizeColRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_selection ) :
01724 KSpreadUndoAction( _doc )
01725 {
01726 name=i18n("Resize");
01727 m_rctRect = _selection;
01728 m_sheetName = _sheet->sheetName();
01729
01730 createList( m_lstColumn,m_lstRow, _sheet );
01731 }
01732
01733 void KSpreadUndoResizeColRow::createList( QValueList<columnSize> &listCol,QValueList<rowSize> &listRow, KSpreadSheet* sheet )
01734 {
01735 listCol.clear();
01736 listRow.clear();
01737
01738 if( util_isColumnSelected( m_rctRect ) )
01739 {
01740 for( int y = m_rctRect.left(); y <= m_rctRect.right(); y++ )
01741 {
01742 ColumnFormat *cl=sheet->columnFormat(y);
01743 if(!cl->isHide())
01744 {
01745 columnSize tmpSize;
01746 tmpSize.columnNumber=y;
01747 tmpSize.columnWidth=cl->dblWidth();
01748 listCol.append(tmpSize);
01749 }
01750 }
01751 }
01752 else if( util_isRowSelected( m_rctRect ) )
01753 {
01754 for( int y = m_rctRect.top(); y <= m_rctRect.bottom(); y++ )
01755 {
01756 RowFormat *rw=sheet->rowFormat(y);
01757 if(!rw->isHide())
01758 {
01759 rowSize tmpSize;
01760 tmpSize.rowNumber=y;
01761 tmpSize.rowHeight=rw->dblHeight();
01762 listRow.append(tmpSize);
01763 }
01764 }
01765 }
01766 else
01767 {
01768 for( int y = m_rctRect.left(); y <= m_rctRect.right(); y++ )
01769 {
01770 ColumnFormat *cl=sheet->columnFormat(y);
01771 if(!cl->isHide())
01772 {
01773 columnSize tmpSize;
01774 tmpSize.columnNumber=y;
01775 tmpSize.columnWidth=cl->dblWidth();
01776 listCol.append(tmpSize);
01777 }
01778 }
01779 for( int y = m_rctRect.top(); y <= m_rctRect.bottom(); y++ )
01780 {
01781 RowFormat *rw=sheet->rowFormat(y);
01782 if(!rw->isHide())
01783 {
01784 rowSize tmpSize;
01785 tmpSize.rowNumber=y;
01786 tmpSize.rowHeight=rw->dblHeight();
01787 listRow.append(tmpSize);
01788 }
01789 }
01790
01791 }
01792 }
01793
01794 KSpreadUndoResizeColRow::~KSpreadUndoResizeColRow()
01795 {
01796 }
01797
01798 void KSpreadUndoResizeColRow::undo()
01799 {
01800 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
01801 if ( !sheet )
01802 return;
01803
01804 doc()->undoLock();
01805
01806 createList( m_lstRedoColumn,m_lstRedoRow, sheet );
01807
01808 if( util_isColumnSelected( m_rctRect ) )
01809 {
01810 QValueList<columnSize>::Iterator it2;
01811 for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
01812 {
01813 ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
01814 cl->setDblWidth((*it2).columnWidth);
01815 }
01816 }
01817 else if( util_isRowSelected( m_rctRect ) )
01818 {
01819 QValueList<rowSize>::Iterator it2;
01820 for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 )
01821 {
01822 RowFormat *rw=sheet->rowFormat((*it2).rowNumber);
01823 rw->setDblHeight((*it2).rowHeight);
01824 }
01825 }
01826 else
01827 {
01828 QValueList<columnSize>::Iterator it2;
01829 for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
01830 {
01831 ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
01832 cl->setDblWidth((*it2).columnWidth);
01833 }
01834 QValueList<rowSize>::Iterator it1;
01835 for ( it1 = m_lstRow.begin(); it1 != m_lstRow.end(); ++it1 )
01836 {
01837 RowFormat *rw=sheet->rowFormat((*it1).rowNumber);
01838 rw->setDblHeight((*it1).rowHeight);
01839 }
01840 }
01841
01842 doc()->undoUnlock();
01843 }
01844
01845 void KSpreadUndoResizeColRow::redo()
01846 {
01847 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
01848 if ( !sheet )
01849 return;
01850
01851 doc()->undoLock();
01852 if( util_isColumnSelected( m_rctRect ) )
01853 {
01854 QValueList<columnSize>::Iterator it2;
01855 for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
01856 {
01857 ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
01858 cl->setDblWidth((*it2).columnWidth);
01859 }
01860 }
01861 else if( util_isRowSelected( m_rctRect ) )
01862 {
01863 QValueList<rowSize>::Iterator it2;
01864 for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 )
01865 {
01866 RowFormat *rw=sheet->rowFormat((*it2).rowNumber);
01867 rw->setDblHeight((*it2).rowHeight);
01868 }
01869 }
01870 else
01871 {
01872 QValueList<columnSize>::Iterator it2;
01873 for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
01874 {
01875 ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
01876 cl->setDblWidth((*it2).columnWidth);
01877 }
01878 QValueList<rowSize>::Iterator it1;
01879 for ( it1 = m_lstRedoRow.begin(); it1 != m_lstRedoRow.end(); ++it1 )
01880 {
01881 RowFormat *rw=sheet->rowFormat((*it1).rowNumber);
01882 rw->setDblHeight((*it1).rowHeight);
01883 }
01884 }
01885
01886 doc()->undoUnlock();
01887 }
01888
01889
01890
01891
01892
01893
01894
01895
01896 KSpreadUndoChangeAreaTextCell::KSpreadUndoChangeAreaTextCell( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_selection ) :
01897 KSpreadUndoAction( _doc )
01898 {
01899 name=i18n("Change Text");
01900
01901 m_rctRect = _selection;
01902 m_sheetName = _sheet->sheetName();
01903
01904 createList( m_lstTextCell, _sheet );
01905 }
01906
01907 void KSpreadUndoChangeAreaTextCell::createList( QValueList<textOfCell> &list, KSpreadSheet* sheet )
01908 {
01909 int bottom = m_rctRect.bottom();
01910 int right = m_rctRect.right();
01911 list.clear();
01912
01913 if( util_isColumnSelected( m_rctRect ) )
01914 {
01915 KSpreadCell * c;
01916 for ( int col = m_rctRect.left(); col <= right; ++col )
01917 {
01918 c = sheet->getFirstCellColumn( col );
01919 while ( c )
01920 {
01921 if ( !c->isObscuringForced() )
01922 {
01923 textOfCell tmpText;
01924 tmpText.col = col;
01925 tmpText.row = c->row();
01926 tmpText.text = c->text();
01927 list.append(tmpText);
01928 }
01929 c = sheet->getNextCellDown( col, c->row() );
01930 }
01931 }
01932 }
01933 else if ( util_isRowSelected( m_rctRect ) )
01934 {
01935 KSpreadCell * c;
01936 for ( int row = m_rctRect.top(); row <= bottom; ++row )
01937 {
01938 c = sheet->getFirstCellRow( row );
01939 while ( c )
01940 {
01941 if ( !c->isObscuringForced() )
01942 {
01943 textOfCell tmpText;
01944 tmpText.col = c->column();
01945 tmpText.row = row;
01946 tmpText.text = c->text();
01947 list.append(tmpText);
01948 }
01949 c = sheet->getNextCellRight( c->column(), row );
01950 }
01951 }
01952 }
01953 else
01954 {
01955 KSpreadCell * cell;
01956 for ( int x = m_rctRect.left(); x <= right; ++x )
01957 {
01958 cell = sheet->getFirstCellColumn( x );
01959 if ( !cell )
01960 continue;
01961 while ( cell && cell->row() <= bottom )
01962 {
01963 if ( !cell->isObscured() )
01964 {
01965 textOfCell tmpText;
01966 tmpText.col = x;
01967 tmpText.row = cell->row();
01968 tmpText.text = cell->text();
01969 list.append( tmpText );
01970 }
01971 cell = sheet->getNextCellDown( x, cell->row() );
01972 }
01973 }
01974 }
01975 }
01976
01977 KSpreadUndoChangeAreaTextCell::~KSpreadUndoChangeAreaTextCell()
01978 {
01979 }
01980
01981 void KSpreadUndoChangeAreaTextCell::undo()
01982 {
01983 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
01984 if ( !sheet )
01985 return;
01986
01987 doc()->undoLock();
01988 doc()->emitBeginOperation();
01989 createList( m_lstRedoTextCell, sheet );
01990
01991
01992 if ( !util_isRowSelected( m_rctRect )
01993 && !util_isColumnSelected( m_rctRect ) )
01994 {
01995 for ( int x = m_rctRect.left(); x <= m_rctRect.right(); ++x )
01996 for ( int y = m_rctRect.top(); y <= m_rctRect.bottom(); ++y )
01997 {
01998 KSpreadCell* cell = sheet->nonDefaultCell( x, y );
01999 bool found = false;
02000 QValueList<textOfCell>::Iterator it;
02001 for( it = m_lstTextCell.begin(); it != m_lstTextCell.end(); ++it )
02002 if ( (*it).col == x && (*it).row == y && !found )
02003 {
02004 cell->setCellText( (*it).text );
02005 found = true;
02006 }
02007 if( !found )
02008 cell->setCellText( "", true );
02009 }
02010
02011 }
02012 else
02013 {
02014 QValueList<textOfCell>::Iterator it2;
02015 for ( it2 = m_lstTextCell.begin(); it2 != m_lstTextCell.end(); ++it2 )
02016 {
02017 KSpreadCell *cell = sheet->nonDefaultCell( (*it2).col, (*it2).row );
02018 if ( (*it2).text.isEmpty() )
02019 {
02020 if ( !cell->text().isEmpty() )
02021 cell->setCellText( "" );
02022 }
02023 else
02024 cell->setCellText( (*it2).text );
02025 }
02026 }
02027
02028 sheet->updateView();
02029 doc()->undoUnlock();
02030 }
02031
02032 void KSpreadUndoChangeAreaTextCell::redo()
02033 {
02034 KSpreadSheet * sheet = doc()->map()->findSheet( m_sheetName );
02035
02036 if ( !sheet )
02037 return;
02038
02039 doc()->undoLock();
02040 doc()->emitBeginOperation();
02041
02042 if ( !util_isRowSelected( m_rctRect )
02043 && !util_isColumnSelected( m_rctRect ) )
02044 {
02045 for ( int x = m_rctRect.left(); x <= m_rctRect.right(); ++x )
02046 for ( int y = m_rctRect.top(); y <= m_rctRect.bottom(); ++y )
02047 {
02048 KSpreadCell* cell = sheet->nonDefaultCell( x, y );
02049 bool found = false;
02050 QValueList<textOfCell>::Iterator it;
02051 for( it = m_lstRedoTextCell.begin(); it != m_lstRedoTextCell.end(); ++it )
02052 if ( (*it).col == x && (*it).row == y && !found )
02053 {
02054 cell->setCellText( (*it).text );
02055 found = true;
02056 }
02057 if( !found )
02058 cell->setCellText( "", true );
02059 }
02060
02061 }
02062 else
02063 {
02064 QValueList<textOfCell>::Iterator it2;
02065 for ( it2 = m_lstRedoTextCell.begin(); it2 != m_lstRedoTextCell.end(); ++it2 )
02066 {
02067 KSpreadCell *cell = sheet->nonDefaultCell( (*it2).col, (*it2).row );
02068 if ( (*it2).text.isEmpty() )
02069 {
02070 if ( !cell->text().isEmpty() )
02071 cell->setCellText( "" );
02072 }
02073 else
02074 cell->setCellText( (*it2).text );
02075 }
02076 }
02077
02078 sheet->updateView();
02079 doc()->undoUnlock();
02080 }
02081
02082
02083
02084
02085
02086
02087
02088
02089 KSpreadUndoMergedCell::KSpreadUndoMergedCell( KSpreadDoc *_doc, KSpreadSheet *_sheet, int _column, int _row , int _extraX,int _extraY) :
02090 KSpreadUndoAction( _doc )
02091 {
02092 name=i18n("Merge Cells");
02093
02094 m_sheetName = _sheet->sheetName();
02095 m_iRow=_row;
02096 m_iCol=_column;
02097 m_iExtraX=_extraX;
02098 m_iExtraY=_extraY;
02099
02100 }
02101
02102 KSpreadUndoMergedCell::~KSpreadUndoMergedCell()
02103 {
02104 }
02105
02106 void KSpreadUndoMergedCell::undo()
02107 {
02108 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02109 if ( !sheet )
02110 return;
02111
02112 doc()->undoLock();
02113
02114 KSpreadCell *cell = sheet->nonDefaultCell( m_iCol, m_iRow );
02115 m_iExtraRedoX=cell->extraXCells();
02116 m_iExtraRedoY=cell->extraYCells();
02117
02118 sheet->changeMergedCell( m_iCol, m_iRow, m_iExtraX,m_iExtraY);
02119
02120 doc()->undoUnlock();
02121 }
02122
02123 void KSpreadUndoMergedCell::redo()
02124 {
02125 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02126 if ( !sheet )
02127 return;
02128
02129 doc()->undoLock();
02130
02131 sheet->changeMergedCell( m_iCol, m_iRow, m_iExtraRedoX,m_iExtraRedoY);
02132
02133 doc()->undoUnlock();
02134 }
02135
02136
02137
02138
02139
02140
02141
02142 KSpreadUndoAutofill::KSpreadUndoAutofill( KSpreadDoc *_doc, KSpreadSheet* sheet, const QRect & _selection)
02143 : KSpreadUndoAction( _doc )
02144 {
02145 name=i18n("Autofill");
02146
02147 m_sheetName = sheet->sheetName();
02148 m_selection = _selection;
02149 createListCell( m_data, sheet );
02150
02151 }
02152
02153 KSpreadUndoAutofill::~KSpreadUndoAutofill()
02154 {
02155 }
02156
02157 void KSpreadUndoAutofill::createListCell( QCString &list, KSpreadSheet* sheet )
02158 {
02159 QDomDocument doc = sheet->saveCellRect( m_selection );
02160
02161 QString buffer;
02162 QTextStream str( &buffer, IO_WriteOnly );
02163 str << doc;
02164
02165
02166
02167
02168
02169 list = buffer.utf8();
02170 int len = list.length();
02171 char tmp = list[ len - 1 ];
02172 list.resize( len );
02173 *( list.data() + len - 1 ) = tmp;
02174 }
02175
02176 void KSpreadUndoAutofill::undo()
02177 {
02178 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02179 if ( !sheet )
02180 return;
02181
02182 createListCell( m_dataRedo, sheet );
02183
02184 doc()->undoLock();
02185 doc()->emitBeginOperation();
02186
02187 sheet->deleteCells( m_selection );
02188 sheet->paste( m_data, m_selection );
02189 if(sheet->getAutoCalc()) sheet->recalc();
02190
02191 sheet->updateView();
02192
02193 doc()->undoUnlock();
02194 }
02195
02196 void KSpreadUndoAutofill::redo()
02197 {
02198 doc()->undoLock();
02199
02200 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02201 if ( !sheet )
02202 return;
02203
02204 doc()->emitBeginOperation();
02205
02206 sheet->deleteCells( m_selection );
02207 doc()->undoLock();
02208 sheet->paste( m_dataRedo, m_selection );
02209 if ( sheet->getAutoCalc() )
02210 sheet->recalc();
02211 sheet->updateView();
02212 doc()->undoUnlock();
02213 }
02214
02215
02216
02217
02218
02219
02220
02221 KSpreadUndoInsertCellRow::KSpreadUndoInsertCellRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_rect ) :
02222 KSpreadUndoInsertRemoveAction( _doc )
02223 {
02224 name=i18n("Insert Cell");
02225
02226 m_sheetName = _sheet->sheetName();
02227 m_rect=_rect;
02228 }
02229
02230 KSpreadUndoInsertCellRow::~KSpreadUndoInsertCellRow()
02231 {
02232 }
02233
02234 void KSpreadUndoInsertCellRow::undo()
02235 {
02236 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02237 if ( !sheet )
02238 return;
02239
02240 doc()->undoLock();
02241 sheet->unshiftRow( m_rect);
02242 doc()->undoUnlock();
02243
02244 undoFormulaReference();
02245 }
02246
02247 void KSpreadUndoInsertCellRow::redo()
02248 {
02249 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02250 if ( !sheet )
02251 return;
02252
02253 doc()->undoLock();
02254 sheet->shiftRow( m_rect);
02255 doc()->undoUnlock();
02256 }
02257
02258
02259
02260
02261
02262
02263
02264
02265 KSpreadUndoInsertCellCol::KSpreadUndoInsertCellCol( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_rect ) :
02266 KSpreadUndoInsertRemoveAction( _doc )
02267 {
02268 name=i18n("Insert Cell");
02269
02270 m_sheetName = _sheet->sheetName();
02271 m_rect=_rect;
02272 }
02273
02274 KSpreadUndoInsertCellCol::~KSpreadUndoInsertCellCol()
02275 {
02276 }
02277
02278 void KSpreadUndoInsertCellCol::undo()
02279 {
02280 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02281 if ( !sheet )
02282 return;
02283
02284 doc()->undoLock();
02285 sheet->unshiftColumn( m_rect);
02286 doc()->undoUnlock();
02287
02288 undoFormulaReference();
02289 }
02290
02291 void KSpreadUndoInsertCellCol::redo()
02292 {
02293 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02294 if ( !sheet )
02295 return;
02296
02297 doc()->undoLock();
02298 sheet->shiftColumn( m_rect );
02299 doc()->undoUnlock();
02300 }
02301
02302
02303
02304
02305
02306
02307
02308 KSpreadUndoRemoveCellRow::KSpreadUndoRemoveCellRow( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &rect ) :
02309 KSpreadUndoInsertRemoveAction( _doc )
02310 {
02311 name=i18n("Remove Cell");
02312
02313 m_sheetName = _sheet->sheetName();
02314 m_rect=rect;
02315 QDomDocument doc = _sheet->saveCellRect( m_rect );
02316
02317 QString buffer;
02318 QTextStream str( &buffer, IO_WriteOnly );
02319 str << doc;
02320
02321
02322
02323
02324
02325 m_data = buffer.utf8();
02326 int len = m_data.length();
02327 char tmp = m_data[ len - 1 ];
02328 m_data.resize( len );
02329 *( m_data.data() + len - 1 ) = tmp;
02330 }
02331
02332 KSpreadUndoRemoveCellRow::~KSpreadUndoRemoveCellRow()
02333 {
02334 }
02335
02336 void KSpreadUndoRemoveCellRow::undo()
02337 {
02338 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02339 if ( !sheet )
02340 return;
02341
02342 doc()->undoLock();
02343 sheet->shiftRow( m_rect );
02344 sheet->paste( m_data, m_rect );
02345 doc()->undoUnlock();
02346
02347 undoFormulaReference();
02348 }
02349
02350 void KSpreadUndoRemoveCellRow::redo()
02351 {
02352 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02353 if ( !sheet )
02354 return;
02355
02356 doc()->undoLock();
02357 sheet->unshiftRow( m_rect);
02358 doc()->undoUnlock();
02359 }
02360
02361
02362
02363
02364
02365
02366
02367 KSpreadUndoRemoveCellCol::KSpreadUndoRemoveCellCol( KSpreadDoc *_doc, KSpreadSheet *_sheet, const QRect &_rect ) :
02368 KSpreadUndoInsertRemoveAction( _doc )
02369 {
02370 name=i18n("Remove Cell");
02371
02372 m_sheetName = _sheet->sheetName();
02373 m_rect=_rect;
02374 QDomDocument doc = _sheet->saveCellRect( m_rect );
02375
02376 QString buffer;
02377 QTextStream str( &buffer, IO_WriteOnly );
02378 str << doc;
02379
02380
02381
02382
02383
02384 m_data = buffer.utf8();
02385 int len = m_data.length();
02386 char tmp = m_data[ len - 1 ];
02387 m_data.resize( len );
02388 *( m_data.data() + len - 1 ) = tmp;
02389 }
02390
02391 KSpreadUndoRemoveCellCol::~KSpreadUndoRemoveCellCol()
02392 {
02393 }
02394
02395 void KSpreadUndoRemoveCellCol::undo()
02396 {
02397 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02398 if ( !sheet )
02399 return;
02400
02401 doc()->undoLock();
02402 sheet->shiftColumn( m_rect );
02403 sheet->paste( m_data, m_rect );
02404 doc()->undoUnlock();
02405
02406 undoFormulaReference();
02407 }
02408
02409 void KSpreadUndoRemoveCellCol::redo()
02410 {
02411 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02412 if ( !sheet )
02413 return;
02414
02415 doc()->undoLock();
02416 sheet->unshiftColumn( m_rect );
02417 doc()->undoUnlock();
02418 }
02419
02420
02421
02422
02423
02424
02425
02426 KSpreadUndoConditional::KSpreadUndoConditional( KSpreadDoc *_doc, KSpreadSheet* sheet, QRect const & _selection)
02427 : KSpreadUndoAction( _doc )
02428 {
02429 name=i18n("Conditional Cell Attribute");
02430
02431 m_sheetName = sheet->sheetName();
02432 m_selection = _selection;
02433 createListCell( m_data, sheet );
02434
02435 }
02436
02437 KSpreadUndoConditional::~KSpreadUndoConditional()
02438 {
02439 }
02440
02441 void KSpreadUndoConditional::createListCell( QCString &list, KSpreadSheet* sheet )
02442 {
02443 QDomDocument doc = sheet->saveCellRect( m_selection );
02444
02445 QString buffer;
02446 QTextStream str( &buffer, IO_WriteOnly );
02447 str << doc;
02448
02449
02450
02451
02452
02453 list = buffer.utf8();
02454 int len = list.length();
02455 char tmp = list[ len - 1 ];
02456 list.resize( len );
02457 *( list.data() + len - 1 ) = tmp;
02458 }
02459
02460 void KSpreadUndoConditional::undo()
02461 {
02462 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02463 if ( !sheet )
02464 return;
02465
02466 createListCell( m_dataRedo, sheet );
02467
02468 doc()->undoLock();
02469 sheet->paste( m_data, m_selection );
02470 if(sheet->getAutoCalc()) sheet->recalc();
02471
02472 doc()->undoUnlock();
02473 }
02474
02475 void KSpreadUndoConditional::redo()
02476 {
02477 doc()->undoLock();
02478
02479 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02480 if ( !sheet )
02481 return;
02482
02483 doc()->undoLock();
02484 sheet->paste( m_dataRedo, m_selection );
02485 if(sheet->getAutoCalc()) sheet->recalc();
02486
02487 doc()->undoUnlock();
02488 }
02489
02490
02491
02492
02493
02494
02495
02496
02497 KSpreadUndoCellPaste::KSpreadUndoCellPaste( KSpreadDoc *_doc, KSpreadSheet* sheet, int _nbCol,int _nbRow, int _xshift,int _yshift, QRect &_selection,bool insert,int _insertTo )
02498 : KSpreadUndoAction( _doc )
02499 {
02500 if(!insert)
02501 name=i18n("Paste");
02502 else
02503 name=i18n("Paste & Insert");
02504
02505 m_sheetName = sheet->sheetName();
02506 m_selection = _selection;
02507 nbCol=_nbCol;
02508 nbRow=_nbRow;
02509 xshift=_xshift;
02510 yshift=_yshift;
02511 b_insert=insert;
02512 m_iInsertTo=_insertTo;
02513 if( !b_insert)
02514 createListCell( m_data, m_lstColumn,m_lstRow,sheet );
02515
02516 }
02517
02518 KSpreadUndoCellPaste::~KSpreadUndoCellPaste()
02519 {
02520 }
02521
02522 void KSpreadUndoCellPaste::createListCell( QCString &listCell,QValueList<columnSize> &listCol,QValueList<rowSize> &listRow, KSpreadSheet* sheet )
02523 {
02524 listCol.clear();
02525 listRow.clear();
02526
02527 if(nbCol!=0)
02528 {
02529
02530 QRect rect;
02531 rect.setCoords( xshift, 1, xshift+nbCol, KS_rowMax );
02532 QDomDocument doc = sheet->saveCellRect( rect);
02533
02534 QString buffer;
02535 QTextStream str( &buffer, IO_WriteOnly );
02536 str << doc;
02537
02538
02539
02540
02541
02542 listCell = buffer.utf8();
02543 int len = listCell.length();
02544 char tmp = listCell[ len - 1 ];
02545 listCell.resize( len );
02546 *( listCell.data() + len - 1 ) = tmp;
02547
02548
02549 for( int y = 1; y <=nbCol ; ++y )
02550 {
02551 ColumnFormat *cl=sheet->columnFormat(y);
02552 if(!cl->isDefault())
02553 {
02554 columnSize tmpSize;
02555 tmpSize.columnNumber=y;
02556 tmpSize.columnWidth=cl->dblWidth();
02557 listCol.append(tmpSize);
02558 }
02559 }
02560 }
02561
02562 else if(nbRow!=0)
02563 {
02564
02565 QRect rect;
02566 rect.setCoords( 1, yshift, KS_colMax, yshift+nbRow );
02567 QDomDocument doc = sheet->saveCellRect( rect);
02568
02569 QString buffer;
02570 QTextStream str( &buffer, IO_WriteOnly );
02571 str << doc;
02572
02573
02574
02575
02576
02577 listCell = buffer.utf8();
02578 int len = listCell.length();
02579 char tmp = listCell[ len - 1 ];
02580 listCell.resize( len );
02581 *( listCell.data() + len - 1 ) = tmp;
02582
02583
02584 for( int y = 1; y <=nbRow ; ++y )
02585 {
02586 RowFormat *rw=sheet->rowFormat(y);
02587 if(!rw->isDefault())
02588 {
02589 rowSize tmpSize;
02590 tmpSize.rowNumber=y;
02591 tmpSize.rowHeight=rw->dblHeight();
02592 listRow.append(tmpSize);
02593 }
02594 }
02595
02596 }
02597
02598 else
02599 {
02600
02601 QDomDocument doc = sheet->saveCellRect( m_selection );
02602
02603 QString buffer;
02604 QTextStream str( &buffer, IO_WriteOnly );
02605 str << doc;
02606
02607
02608
02609
02610
02611 listCell = buffer.utf8();
02612 int len = listCell.length();
02613 char tmp = listCell[ len - 1 ];
02614 listCell.resize( len );
02615 *( listCell.data() + len - 1 ) = tmp;
02616 }
02617 }
02618
02619 void KSpreadUndoCellPaste::undo()
02620 {
02621 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02622 if ( !sheet )
02623 return;
02624
02625 createListCell( m_dataRedo, m_lstRedoColumn,m_lstRedoRow,sheet );
02626
02627 doc()->undoLock();
02628 doc()->emitBeginOperation();
02629
02630 if(nbCol!=0)
02631 {
02632 if(!b_insert)
02633 {
02634 QRect rect;
02635 rect.setCoords( xshift, 1, xshift+nbCol, KS_rowMax );
02636 sheet->deleteCells( rect );
02637 QPoint pastePoint(xshift, 1);
02638 sheet->paste( m_data, QRect(pastePoint, pastePoint) );
02639 QValueList<columnSize>::Iterator it2;
02640 for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
02641 {
02642 ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
02643 cl->setDblWidth((*it2).columnWidth);
02644 }
02645 }
02646 else
02647 {
02648 sheet->removeColumn( xshift+1,nbCol-1,false);
02649 }
02650 }
02651 else if(nbRow!=0)
02652 {
02653 if(!b_insert)
02654 {
02655 QRect rect;
02656 rect.setCoords( 1, yshift, KS_colMax, yshift+nbRow );
02657 sheet->deleteCells( rect );
02658
02659 QPoint pastePoint(1, yshift);
02660 sheet->paste( m_data, QRect(pastePoint, pastePoint) );
02661 QValueList<rowSize>::Iterator it2;
02662 for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 )
02663 {
02664 RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
02665 rw->setDblHeight((*it2).rowHeight);
02666 }
02667 }
02668 else
02669 {
02670 sheet->removeRow( yshift+1,nbRow-1);
02671 }
02672 }
02673 else
02674 {
02675 if(!b_insert)
02676 {
02677 sheet->deleteCells( m_selection );
02678 sheet->paste( m_data, m_selection );
02679 }
02680 else
02681 {
02682 if(m_iInsertTo==-1)
02683 sheet->unshiftRow(m_selection);
02684 else if(m_iInsertTo==1)
02685 sheet->unshiftColumn(m_selection);
02686 }
02687 }
02688
02689 if(sheet->getAutoCalc())
02690 sheet->recalc();
02691 sheet->updateView();
02692 doc()->undoUnlock();
02693 }
02694
02695 void KSpreadUndoCellPaste::redo()
02696 {
02697 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02698 if ( !sheet )
02699 return;
02700
02701 doc()->undoLock();
02702 doc()->emitBeginOperation();
02703
02704 if(nbCol!=0)
02705 {
02706 if( b_insert)
02707 {
02708 sheet->insertColumn( xshift+1,nbCol-1,false);
02709 }
02710 QRect rect;
02711 rect.setCoords( xshift, 1, xshift+nbCol, KS_rowMax );
02712 sheet->deleteCells( rect );
02713 QPoint pastePoint(xshift, 1);
02714 sheet->paste( m_dataRedo, QRect(pastePoint, pastePoint) );
02715 QValueList<columnSize>::Iterator it2;
02716 for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
02717 {
02718 ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
02719 cl->setDblWidth((*it2).columnWidth);
02720 }
02721
02722 }
02723 else if(nbRow!=0)
02724 {
02725 if( b_insert)
02726 {
02727 sheet->insertRow( yshift+1,nbRow-1);
02728 }
02729
02730 QRect rect;
02731 rect.setCoords( 1, yshift, KS_colMax, yshift+nbRow );
02732 sheet->deleteCells( rect );
02733
02734 QPoint pastePoint(1, yshift);
02735 sheet->paste( m_dataRedo, QRect(pastePoint, pastePoint) );
02736 QValueList<rowSize>::Iterator it2;
02737 for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 )
02738 {
02739 RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
02740 rw->setDblHeight((*it2).rowHeight);
02741 }
02742 }
02743 else
02744 {
02745 if (b_insert)
02746 {
02747 if (m_iInsertTo==-1)
02748 sheet->shiftRow(m_selection);
02749 else if(m_iInsertTo==1)
02750 sheet->shiftColumn(m_selection);
02751
02752 }
02753 sheet->deleteCells( m_selection );
02754 sheet->paste( m_dataRedo, m_selection );
02755 }
02756 if (sheet->getAutoCalc())
02757 sheet->recalc();
02758
02759 sheet->updateView();
02760
02761 doc()->undoUnlock();
02762 }
02763
02764
02765
02766
02767
02768
02769
02770
02771 KSpreadUndoStyleCell::KSpreadUndoStyleCell( KSpreadDoc *_doc, KSpreadSheet* sheet, const QRect & _selection)
02772 : KSpreadUndoAction( _doc )
02773 {
02774 name=i18n("Style of Cell");
02775
02776 m_sheetName = sheet->sheetName();
02777 m_selection = _selection;
02778 createListCell( m_lstStyleCell, sheet );
02779
02780 }
02781
02782 KSpreadUndoStyleCell::~KSpreadUndoStyleCell()
02783 {
02784 }
02785
02786 void KSpreadUndoStyleCell::createListCell( QValueList<styleCell> &listCell, KSpreadSheet* sheet )
02787 {
02788 int bottom = m_selection.bottom();
02789 int right = m_selection.right();
02790 if ( util_isColumnSelected( m_selection ) )
02791 {
02792 KSpreadCell * c;
02793 for ( int col = m_selection.left(); col <= right; ++ col )
02794 {
02795 c = sheet->getFirstCellColumn( col );
02796 while ( c )
02797 {
02798 if ( !c->isObscuringForced() )
02799 {
02800 styleCell tmpStyleCell;
02801 tmpStyleCell.row = c->row();
02802 tmpStyleCell.col = col;
02803 listCell.append(tmpStyleCell);
02804 }
02805 c = sheet->getNextCellDown( col, c->row() );
02806 }
02807 }
02808 }
02809 else if ( util_isRowSelected( m_selection ) )
02810 {
02811 KSpreadCell * c;
02812 for ( int row = m_selection.top(); row <= bottom; ++row )
02813 {
02814 c = sheet->getFirstCellRow( row );
02815 while ( c )
02816 {
02817 if ( !c->isObscuringForced() )
02818 {
02819 styleCell tmpStyleCell;
02820 tmpStyleCell.row = row;
02821 tmpStyleCell.col = c->column();
02822 listCell.append(tmpStyleCell);
02823 }
02824 c = sheet->getNextCellRight( c->column(), row );
02825 }
02826 }
02827 }
02828 else
02829 {
02830 KSpreadCell * cell;
02831 for ( int i = m_selection.top(); i <= bottom; ++i)
02832 for ( int j = m_selection.left(); j <= right; ++j )
02833 {
02834 cell = sheet->nonDefaultCell( j, i);
02835 styleCell tmpStyleCell;
02836 tmpStyleCell.row = i;
02837 tmpStyleCell.col = j;
02838 listCell.append(tmpStyleCell);
02839 }
02840 }
02841 }
02842
02843 void KSpreadUndoStyleCell::undo()
02844 {
02845 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02846 if ( !sheet )
02847 return;
02848
02849 createListCell( m_lstRedoStyleCell, sheet );
02850
02851 doc()->undoLock();
02852 doc()->emitBeginOperation();
02853
02854
02855 QValueList<styleCell>::Iterator it2;
02856 for ( it2 = m_lstStyleCell.begin(); it2 != m_lstStyleCell.end(); ++it2 )
02857 {
02858 KSpreadCell *cell = sheet->nonDefaultCell( (*it2).col, (*it2).row);
02859 }
02860 sheet->setRegionPaintDirty(m_selection);
02861 sheet->updateView( m_selection );
02862 doc()->undoUnlock();
02863 }
02864
02865 void KSpreadUndoStyleCell::redo()
02866 {
02867 doc()->undoLock();
02868
02869 KSpreadSheet* sheet = doc()->map()->findSheet( m_sheetName );
02870 if ( !sheet )
02871 return;
02872
02873 doc()->undoLock();
02874 doc()->emitBeginOperation();
02875
02876 QValueList<styleCell>::Iterator it2;
02877 for ( it2 = m_lstRedoStyleCell.begin(); it2 != m_lstRedoStyleCell.end(); ++it2 )
02878 {
02879 KSpreadCell *cell = sheet->nonDefaultCell( (*it2).col, (*it2).row);
02880 }
02881 sheet->setRegionPaintDirty(m_selection);
02882 sheet->updateView();
02883
02884 doc()->undoUnlock();
02885 }
02886
02887 KSpreadUndoInsertData::KSpreadUndoInsertData( KSpreadDoc * _doc, KSpreadSheet * _sheet, QRect & _selection )
02888 : KSpreadUndoChangeAreaTextCell( _doc, _sheet, _selection )
02889 {
02890 name = i18n("Insert Data From Database");
02891 }