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