kspread

kspread_undo.cc

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