21#include "kspread_cell.h"
22#include "kspread_doc.h"
23#include "kspread_global.h"
24#include "kspread_locale.h"
25#include "kspread_map.h"
26#include "kspread_sheet.h"
27#include "kspread_sheetprint.h"
28#include "kspread_style.h"
29#include "kspread_style_manager.h"
30#include "kspread_util.h"
32#include "kspread_undo.h"
36bool operator < (
const TQPoint& pointA ,
const TQPoint& pointB)
38 if (pointA.y() == pointB.y())
39 return ( pointA.x() < pointB.x() );
41 return ( pointA.y() < pointB.y() );
50Undo::Undo(
Doc *_doc )
54 m_stckUndo.setAutoDelete(
false );
55 m_stckRedo.setAutoDelete(
false );
68 m_stckRedo.setAutoDelete(
true );
70 m_stckRedo.setAutoDelete(
false );
72 m_stckUndo.push( _action );
76 m_pDoc->enableUndo( hasUndoActions() );
77 m_pDoc->enableRedo( hasRedoActions() );
78 m_pDoc->setModified(
true );
87 m_stckUndo.setAutoDelete(
true );
88 m_stckRedo.setAutoDelete(
true );
93 m_stckUndo.setAutoDelete(
false );
94 m_stckRedo.setAutoDelete(
false );
99 if ( m_stckUndo.isEmpty() )
103 bool origErrorMessages =
true;
106 origErrorMessages = m_pDoc->getShowMessageError();
107 m_pDoc->setShowMessageError(
false );
112 m_stckRedo.push( a );
116 m_pDoc->setShowMessageError( origErrorMessages );
117 m_pDoc->enableUndo( hasUndoActions() );
118 m_pDoc->enableRedo( hasRedoActions() );
124 if ( m_stckRedo.isEmpty() )
128 m_stckUndo.push( a );
132 m_pDoc->enableUndo( hasUndoActions() );
133 m_pDoc->enableRedo( hasRedoActions() );
144 m_pDoc->undoUnlock();
147bool Undo::isLocked()
const
149 return m_pDoc->undoLocked();
152TQString Undo::getRedoName()
154 if ( m_stckRedo.isEmpty() )
156 return m_stckRedo.current()->getName();
160TQString Undo::getUndoName()
162 if ( m_stckUndo.isEmpty() )
164 return m_stckUndo.current()->getName();
172MacroUndoAction::MacroUndoAction(
Doc *_doc,
const TQString& _name ):
178MacroUndoAction::~MacroUndoAction()
180 m_commands.setAutoDelete(
true );
183void MacroUndoAction::addCommand(
UndoAction *command)
185 m_commands.append(command);
188void MacroUndoAction::undo()
190 TQPtrListIterator<UndoAction> it(m_commands);
191 for ( ; it.current() ; ++it )
192 it.current()->undo();
195void MacroUndoAction::redo()
197 TQPtrListIterator<UndoAction> it(m_commands);
198 for ( ; it.current() ; ++it )
199 it.current()->redo();
208UndoInsertRemoveAction::UndoInsertRemoveAction(
Doc * _doc ) :
213UndoInsertRemoveAction::~UndoInsertRemoveAction()
218void UndoInsertRemoveAction::saveFormulaReference( Sheet *_sheet,
219 int col,
int row, TQString & formula )
223 TQString sheetName = _sheet->sheetName();
225 m_lstFormulaCells.append( FormulaOfCell( sheetName, col, row, formula ) );
228void UndoInsertRemoveAction::undoFormulaReference()
230 TQValueList<FormulaOfCell>::iterator it;
231 for ( it = m_lstFormulaCells.begin(); it != m_lstFormulaCells.end(); ++it )
233 Sheet* sheet = doc()->map()->findSheet( (*it).sheetName() );
236 Cell * cell = sheet->cellAt( (*it).col(), (*it).row() );
251UndoRemoveColumn::UndoRemoveColumn(
Doc *_doc, Sheet *_sheet,
int _column,
int _nbCol ) :
252 UndoInsertRemoveAction( _doc )
254 name=i18n(
"Remove Columns");
255 m_sheetName = _sheet->sheetName();
258 m_printRange = _sheet->print()->printRange();
259 m_printRepeatColumns = _sheet->print()->printRepeatColumns();
261 selection.setCoords( _column, 1, _column+m_iNbCol, KS_rowMax );
262 TQDomDocument doc = _sheet->saveCellRegion( selection );
266 TQTextStream str( &buffer, IO_WriteOnly );
273 m_data = buffer.utf8();
274 int len = m_data.length();
275 char tmp = m_data[ len - 1 ];
276 m_data.resize( len );
277 *( m_data.data() + len - 1 ) = tmp;
280UndoRemoveColumn::~UndoRemoveColumn()
284void UndoRemoveColumn::undo()
286 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
292 sheet->insertColumn( m_iColumn,m_iNbCol);
294 TQPoint pastePoint( m_iColumn, 1 );
295 sheet->paste( m_data, TQRect( pastePoint, pastePoint ) );
296 if(sheet->getAutoCalc()) sheet->recalc();
298 sheet->print()->setPrintRange( m_printRange );
299 sheet->print()->setPrintRepeatColumns( m_printRepeatColumns );
303 undoFormulaReference();
306void UndoRemoveColumn::redo()
310 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
314 sheet->removeColumn( m_iColumn,m_iNbCol );
325UndoInsertColumn::UndoInsertColumn(
Doc *_doc, Sheet *_sheet,
int _column,
int _nbCol ) :
326 UndoInsertRemoveAction( _doc )
328 name=i18n(
"Insert Columns");
329 m_sheetName = _sheet->sheetName();
334UndoInsertColumn::~UndoInsertColumn()
338void UndoInsertColumn::undo()
340 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
345 sheet->removeColumn( m_iColumn,m_iNbCol );
348 undoFormulaReference();
351void UndoInsertColumn::redo()
353 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
358 sheet->insertColumn( m_iColumn,m_iNbCol);
368UndoRemoveRow::UndoRemoveRow(
Doc *_doc, Sheet *_sheet,
int _row,
int _nbRow) :
369 UndoInsertRemoveAction( _doc )
371 name=i18n(
"Remove Rows");
373 m_sheetName = _sheet->sheetName();
376 m_printRange=_sheet->print()->printRange();
377 m_printRepeatRows = _sheet->print()->printRepeatRows();
380 selection.setCoords( 1, _row, KS_colMax, _row+m_iNbRow );
381 TQDomDocument doc = _sheet->saveCellRegion( selection );
385 TQTextStream str( &buffer, IO_WriteOnly );
392 m_data = buffer.utf8();
393 int len = m_data.length();
394 char tmp = m_data[ len - 1 ];
395 m_data.resize( len );
396 *( m_data.data() + len - 1 ) = tmp;
405UndoRemoveRow::~UndoRemoveRow()
409void UndoRemoveRow::undo()
411 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
417 sheet->insertRow( m_iRow,m_iNbRow );
419 TQPoint pastePoint( 1, m_iRow );
420 sheet->paste( m_data, TQRect(pastePoint, pastePoint) );
422 sheet->print()->setPrintRange( m_printRange );
423 sheet->print()->setPrintRepeatRows( m_printRepeatRows );
425 if(sheet->getAutoCalc()) sheet->recalc();
429 undoFormulaReference();
432void UndoRemoveRow::redo()
436 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
440 sheet->removeRow( m_iRow,m_iNbRow );
451UndoInsertRow::UndoInsertRow(
Doc *_doc, Sheet *_sheet,
int _row,
int _nbRow ) :
452 UndoInsertRemoveAction( _doc )
454 name=i18n(
"Insert Rows");
455 m_sheetName = _sheet->sheetName();
460UndoInsertRow::~UndoInsertRow()
464void UndoInsertRow::undo()
466 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
471 sheet->removeRow( m_iRow,m_iNbRow );
474 undoFormulaReference();
477void UndoInsertRow::redo()
479 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
484 sheet->insertRow( m_iRow,m_iNbRow );
724UndoPaperLayout::UndoPaperLayout(
Doc *_doc, Sheet *_sheet )
727 name=i18n(
"Set Page Layout");
728 m_sheetName = _sheet->sheetName();
730 m_pl = _sheet->print()->paperLayout();
731 m_hf = _sheet->print()->headFootLine();
732 m_unit = doc()->unit();
733 m_printGrid = _sheet->print()->printGrid();
734 m_printCommentIndicator = _sheet->print()->printCommentIndicator();
735 m_printFormulaIndicator = _sheet->print()->printFormulaIndicator();
736 m_printRange = _sheet->print()->printRange();
737 m_printRepeatColumns = _sheet->print()->printRepeatColumns();
738 m_printRepeatRows = _sheet->print()->printRepeatRows();
739 m_dZoom = _sheet->print()->zoom();
740 m_iPageLimitX = _sheet->print()->pageLimitX();
741 m_iPageLimitY = _sheet->print()->pageLimitY();
744UndoPaperLayout::~UndoPaperLayout()
748void UndoPaperLayout::undo()
750 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
753 SheetPrint* print = sheet->print();
757 m_plRedo = print->paperLayout();
758 print->setPaperLayout( m_pl.ptLeft, m_pl.ptTop,
759 m_pl.ptRight, m_pl.ptBottom,
760 m_pl.format, m_pl.orientation );
762 m_hfRedo = print->headFootLine();
763 print->setHeadFootLine( m_hf.headLeft, m_hf.headMid, m_hf.headRight,
764 m_hf.footLeft, m_hf.footMid, m_hf.footRight );
766 m_unitRedo = doc()->unit();
767 doc()->setUnit( m_unit );
769 m_printGridRedo = print->printGrid();
770 print->setPrintGrid( m_printGrid );
772 m_printCommentIndicatorRedo = print->printCommentIndicator();
773 print->setPrintCommentIndicator( m_printCommentIndicator );
775 m_printFormulaIndicatorRedo = print->printFormulaIndicator();
776 print->setPrintFormulaIndicator( m_printFormulaIndicator );
778 m_printRangeRedo = print->printRange();
779 print->setPrintRange( m_printRange );
781 m_printRepeatColumnsRedo = print->printRepeatColumns();
782 print->setPrintRepeatColumns( m_printRepeatColumns );
784 m_printRepeatRowsRedo = print->printRepeatRows();
785 print->setPrintRepeatRows( m_printRepeatRows );
787 m_dZoomRedo = print->zoom();
788 print->setZoom( m_dZoom );
790 m_iPageLimitXRedo = print->pageLimitX();
791 print->setPageLimitX( m_iPageLimitX );
793 m_iPageLimitYRedo = print->pageLimitY();
794 print->setPageLimitY( m_iPageLimitY );
799void UndoPaperLayout::redo()
801 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
804 SheetPrint* print = sheet->print();
807 print->setPaperLayout( m_plRedo.ptLeft, m_plRedo.ptTop,
808 m_plRedo.ptRight, m_plRedo.ptBottom,
809 m_plRedo.format, m_plRedo.orientation );
811 print->setHeadFootLine( m_hfRedo.headLeft, m_hfRedo.headMid, m_hfRedo.headRight,
812 m_hfRedo.footLeft, m_hfRedo.footMid, m_hfRedo.footRight );
814 doc()->setUnit( m_unitRedo );
816 print->setPrintGrid( m_printGridRedo );
817 print->setPrintCommentIndicator( m_printCommentIndicatorRedo );
818 print->setPrintFormulaIndicator( m_printFormulaIndicatorRedo );
820 print->setPrintRange( m_printRangeRedo );
821 print->setPrintRepeatColumns( m_printRepeatColumnsRedo );
822 print->setPrintRepeatRows( m_printRepeatRowsRedo );
824 print->setZoom( m_dZoomRedo );
826 print->setPageLimitX( m_iPageLimitX );
827 print->setPageLimitY( m_iPageLimitY );
841UndoSetText::UndoSetText(
Doc *_doc, Sheet *_sheet,
const TQString& _text,
int _column,
int _row,FormatType _formatType ) :
844 name=i18n(
"Change Text");
849 m_sheetName = _sheet->sheetName();
850 m_eFormatType=_formatType;
853UndoSetText::~UndoSetText()
857void UndoSetText::undo()
859 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
864 doc()->emitBeginOperation();
865 Cell *cell = sheet->nonDefaultCell( m_iColumn, m_iRow );
866 m_strRedoText = cell->
text();
867 m_eFormatTypeRedo=cell->
format()->getFormatType( m_iColumn, m_iRow );
868 cell->
format()->setFormatType(m_eFormatType);
870 if ( m_strText.isNull() )
874 sheet->updateView( TQRect( m_iColumn, m_iRow, 1, 1 ) );
878void UndoSetText::redo()
880 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
885 doc()->emitBeginOperation();
886 Cell *cell = sheet->nonDefaultCell( m_iColumn, m_iRow );
887 m_strText = cell->
text();
888 m_eFormatType=cell->
format()->getFormatType( m_iColumn, m_iRow );
889 if ( m_strRedoText.isNull() )
893 cell->
format()->setFormatType(m_eFormatTypeRedo);
894 sheet->updateView( TQRect( m_iColumn, m_iRow, 1, 1 ) );
904UndoCellFormat::UndoCellFormat(
Doc * _doc,
906 const Region & _selection,
907 const TQString & _name ) :
910 if ( _name.isEmpty())
911 name = i18n(
"Change Format");
915 m_region = _selection;
916 m_sheetName = _sheet->sheetName();
917 copyFormat( m_lstFormats, m_lstColFormats, m_lstRowFormats, _sheet );
920void UndoCellFormat::copyFormat(TQValueList<layoutCell> & list,
921 TQValueList<layoutColumn> & listCol,
922 TQValueList<layoutRow> & listRow,
925 TQValueList<layoutCell>::Iterator it2;
926 for ( it2 = list.begin(); it2 != list.end(); ++it2 )
933 Region::ConstIterator endOfList(m_region.constEnd());
934 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
936 TQRect range = (*it)->rect().normalize();
937 int bottom = range.bottom();
938 int right = range.right();
940 if ( util_isColumnSelected( range ) )
952 for (
int c = range.left(); c <= right; ++c )
954 layoutColumn tmplayout;
956 tmplayout.l =
new ColumnFormat( sheet, c );
957 tmplayout.l->copy( *(sheet->columnFormat( c )) );
958 listCol.append(tmplayout);
960 cell = sheet->getFirstCellColumn( c );
965 cell = sheet->getNextCellDown( c, cell->
row() );
969 layoutCell tmplayout;
971 tmplayout.row = cell->
row();
972 tmplayout.l =
new Format( sheet, 0 );
973 tmplayout.l->copy( *(sheet->cellAt( tmplayout.col, tmplayout.row )->format()) );
974 list.append(tmplayout);
976 cell = sheet->getNextCellDown( c, cell->
row() );
997 else if (util_isRowSelected( range ) )
999 for (
int row = range.top(); row <= bottom; ++row )
1001 layoutRow tmplayout;
1002 tmplayout.row = row;
1003 tmplayout.l =
new RowFormat( sheet, row );
1004 tmplayout.l->copy( *(sheet->rowFormat( row )) );
1005 listRow.append(tmplayout);
1007 cell = sheet->getFirstCellRow( row );
1012 cell = sheet->getNextCellRight( cell->
column(), row );
1015 layoutCell tmplayout;
1016 tmplayout.col = cell->
column();
1017 tmplayout.row = row;
1018 tmplayout.l =
new Format( sheet, 0 );
1019 tmplayout.l->copy( *(sheet->cellAt( cell->
column(), row )->format()) );
1020 list.append(tmplayout);
1022 cell = sheet->getNextCellRight( cell->
column(), row );
1045 for (
int y = range.top(); y <= bottom; ++y )
1046 for (
int x = range.left(); x <= right; ++x )
1048 Cell * cell = sheet->nonDefaultCell( x, y );
1051 layoutCell tmplayout;
1054 tmplayout.l =
new Format( sheet, 0 );
1055 tmplayout.l->copy( *(sheet->cellAt( x, y )->format()) );
1056 list.append(tmplayout);
1063UndoCellFormat::~UndoCellFormat()
1065 TQValueList<layoutCell>::Iterator it2;
1066 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
1070 m_lstFormats.clear();
1072 for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
1076 m_lstRedoFormats.clear();
1078 TQValueList<layoutColumn>::Iterator it3;
1079 for ( it3 = m_lstColFormats.begin(); it3 != m_lstColFormats.end(); ++it3 )
1083 m_lstColFormats.clear();
1085 for ( it3 = m_lstRedoColFormats.begin(); it3 != m_lstRedoColFormats.end(); ++it3 )
1089 m_lstRedoColFormats.clear();
1091 TQValueList<layoutRow>::Iterator it4;
1092 for ( it4 = m_lstRowFormats.begin(); it4 != m_lstRowFormats.end(); ++it4 )
1096 m_lstRowFormats.clear();
1098 for ( it4 = m_lstRedoRowFormats.begin(); it4 != m_lstRedoRowFormats.end(); ++it4 )
1102 m_lstRedoRowFormats.clear();
1107void UndoCellFormat::undo()
1109 Sheet * sheet = doc()->map()->findSheet( m_sheetName );
1114 doc()->emitBeginOperation();
1115 copyFormat( m_lstRedoFormats, m_lstRedoColFormats, m_lstRedoRowFormats, sheet );
1116 Region::ConstIterator endOfList(m_region.constEnd());
1117 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
1119 TQRect range = (*it)->rect().normalize();
1120 if( util_isColumnSelected( range ) )
1122 TQValueList<layoutColumn>::Iterator it2;
1123 for ( it2 = m_lstColFormats.begin(); it2 != m_lstColFormats.end(); ++it2 )
1125 ColumnFormat * col = sheet->nonDefaultColumnFormat( (*it2).col );
1126 col->copy( *(*it2).l );
1129 else if( util_isRowSelected( range ) )
1131 TQValueList<layoutRow>::Iterator it2;
1132 for ( it2 = m_lstRowFormats.begin(); it2 != m_lstRowFormats.end(); ++it2 )
1134 RowFormat * row = sheet->nonDefaultRowFormat( (*it2).row );
1135 row->copy( *(*it2).l );
1139 TQValueList<layoutCell>::Iterator it2;
1140 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
1142 Cell *cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
1143 cell->
format()->copy( *(*it2).l );
1145 cell->setDisplayDirtyFlag();
1146 sheet->updateCell( cell, (*it2).col, (*it2).row );
1149 sheet->setRegionPaintDirty( m_region );
1150 sheet->updateView( &m_region );
1152 doc()->undoUnlock();
1155void UndoCellFormat::redo()
1157 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
1162 doc()->emitBeginOperation();
1164 Region::ConstIterator endOfList(m_region.constEnd());
1165 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
1167 TQRect range = (*it)->rect().normalize();
1168 if ( util_isColumnSelected( range ) )
1170 TQValueList<layoutColumn>::Iterator it2;
1171 for ( it2 = m_lstRedoColFormats.begin(); it2 != m_lstRedoColFormats.end(); ++it2 )
1173 ColumnFormat * col = sheet->nonDefaultColumnFormat( (*it2).col );
1174 col->copy( *(*it2).l );
1177 else if( util_isRowSelected( range ) )
1179 TQValueList<layoutRow>::Iterator it2;
1180 for ( it2 = m_lstRedoRowFormats.begin(); it2 != m_lstRedoRowFormats.end(); ++it2 )
1182 RowFormat * row = sheet->nonDefaultRowFormat( (*it2).row );
1183 row->copy( *(*it2).l );
1187 TQValueList<layoutCell>::Iterator it2;
1188 for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
1190 Cell * cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
1191 cell->
format()->copy( *(*it2).l );
1193 cell->setDisplayDirtyFlag();
1194 sheet->updateCell( cell, (*it2).col, (*it2).row );
1198 sheet->setRegionPaintDirty( m_region );
1199 sheet->updateView( &m_region );
1200 doc()->undoUnlock();
1209UndoChangeAngle::UndoChangeAngle(
Doc * _doc,
1211 const Region & _selection ) :
1214 name = i18n(
"Change Angle");
1215 m_layoutUndo =
new UndoCellFormat( _doc, _sheet, _selection, TQString() );
1216 m_resizeUndo =
new UndoResizeColRow( _doc, _sheet, _selection );
1219UndoChangeAngle::~UndoChangeAngle()
1221 delete m_resizeUndo;
1222 delete m_layoutUndo;
1225void UndoChangeAngle::undo()
1227 m_layoutUndo->undo();
1228 m_resizeUndo->undo();
1231void UndoChangeAngle::redo()
1233 m_layoutUndo->redo();
1234 m_resizeUndo->redo();
1243UndoSort::UndoSort(
Doc * _doc, Sheet * _sheet,
const TQRect & _selection ) :
1246 name = i18n(
"Sort");
1248 m_rctRect = _selection;
1249 m_sheetName = _sheet->sheetName();
1250 copyAll( m_lstFormats, m_lstColFormats, m_lstRowFormats, _sheet );
1253void UndoSort::copyAll(TQValueList<layoutTextCell> & list, TQValueList<layoutColumn> & listCol,
1254 TQValueList<layoutRow> & listRow, Sheet * sheet )
1256 TQValueList<layoutTextCell>::Iterator it2;
1257 for ( it2 = list.begin(); it2 != list.end(); ++it2 )
1263 if ( util_isColumnSelected( m_rctRect ) )
1266 for (
int col = m_rctRect.left(); col <= m_rctRect.right(); ++col)
1268 layoutColumn tmplayout;
1269 tmplayout.col = col;
1270 tmplayout.l =
new ColumnFormat( sheet, col );
1271 tmplayout.l->copy( *(sheet->columnFormat( col )) );
1272 listCol.append(tmplayout);
1274 c = sheet->getFirstCellColumn( col );
1279 layoutTextCell tmplayout;
1280 tmplayout.col = col;
1281 tmplayout.row = c->
row();
1282 tmplayout.l =
new Format( sheet, 0 );
1283 tmplayout.l->copy( *(sheet->cellAt( tmplayout.col, tmplayout.row )->format()) );
1284 tmplayout.text = c->
text();
1285 list.append(tmplayout);
1288 c = sheet->getNextCellDown( col, c->
row() );
1292 else if ( util_isRowSelected( m_rctRect ) )
1295 for (
int row = m_rctRect.top(); row <= m_rctRect.bottom(); ++row)
1297 layoutRow tmplayout;
1298 tmplayout.
row = row;
1299 tmplayout.l =
new RowFormat( sheet, row );
1300 tmplayout.l->copy( *(sheet->rowFormat( row )) );
1301 listRow.append(tmplayout);
1303 c = sheet->getFirstCellRow( row );
1308 layoutTextCell tmplayout;
1309 tmplayout.col = c->
column();
1310 tmplayout.row = row;
1311 tmplayout.l =
new Format( sheet, 0 );
1312 tmplayout.l->copy( *(sheet->cellAt( tmplayout.col, tmplayout.row )->format()) );
1313 tmplayout.text = c->
text();
1314 list.append(tmplayout);
1316 c = sheet->getNextCellRight( c->
column(), row );
1322 int bottom = m_rctRect.bottom();
1323 int right = m_rctRect.right();
1325 for (
int y = m_rctRect.top(); y <= bottom; ++y )
1326 for (
int x = m_rctRect.left(); x <= right; ++x )
1328 cell = sheet->nonDefaultCell( x, y );
1331 layoutTextCell tmplayout;
1334 tmplayout.l =
new Format( sheet, 0 );
1335 tmplayout.l->copy( *(sheet->cellAt( x, y )->format()) );
1336 tmplayout.text = cell->
text();
1337 list.append(tmplayout);
1343UndoSort::~UndoSort()
1345 TQValueList<layoutTextCell>::Iterator it2;
1346 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
1350 m_lstFormats.clear();
1352 for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
1356 m_lstRedoFormats.clear();
1358 TQValueList<layoutColumn>::Iterator it3;
1359 for ( it3 = m_lstColFormats.begin(); it3 != m_lstColFormats.end(); ++it3 )
1363 m_lstColFormats.clear();
1365 for ( it3 = m_lstRedoColFormats.begin(); it3 != m_lstRedoColFormats.end(); ++it3 )
1369 m_lstRedoColFormats.clear();
1371 TQValueList<layoutRow>::Iterator it4;
1372 for ( it4 = m_lstRowFormats.begin(); it4 != m_lstRowFormats.end(); ++it4 )
1376 m_lstRowFormats.clear();
1378 for ( it4 = m_lstRedoRowFormats.begin(); it4 != m_lstRedoRowFormats.end(); ++it4 )
1382 m_lstRedoRowFormats.clear();
1386void UndoSort::undo()
1388 Sheet * sheet = doc()->map()->findSheet( m_sheetName );
1393 doc()->emitBeginOperation();
1395 copyAll( m_lstRedoFormats, m_lstRedoColFormats,
1396 m_lstRedoRowFormats, sheet );
1398 if ( util_isColumnSelected( m_rctRect ) )
1400 TQValueList<layoutColumn>::Iterator it2;
1401 for ( it2 = m_lstColFormats.begin(); it2 != m_lstColFormats.end(); ++it2 )
1403 ColumnFormat * col = sheet->nonDefaultColumnFormat( (*it2).col );
1404 col->copy( *(*it2).l );
1407 else if( util_isRowSelected( m_rctRect ) )
1409 TQValueList<layoutRow>::Iterator it2;
1410 for ( it2 = m_lstRowFormats.begin(); it2 != m_lstRowFormats.end(); ++it2 )
1412 RowFormat *row= sheet->nonDefaultRowFormat( (*it2).row );
1413 row->copy( *(*it2).l );
1417 TQValueList<layoutTextCell>::Iterator it2;
1418 for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
1420 Cell *cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
1421 if ( (*it2).text.isEmpty() )
1423 if(!cell->
text().isEmpty())
1429 cell->
format()->copy( *(*it2).l );
1431 cell->setDisplayDirtyFlag();
1432 sheet->updateCell( cell, (*it2).col, (*it2).row );
1435 sheet->setRegionPaintDirty(m_rctRect);
1436 sheet->updateView( m_rctRect );
1438 doc()->undoUnlock();
1441void UndoSort::redo()
1443 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
1448 doc()->emitBeginOperation();
1450 if( util_isColumnSelected( m_rctRect ) )
1452 TQValueList<layoutColumn>::Iterator it2;
1453 for ( it2 = m_lstRedoColFormats.begin(); it2 != m_lstRedoColFormats.end(); ++it2 )
1455 ColumnFormat *col= sheet->nonDefaultColumnFormat( (*it2).col );
1456 col->copy( *(*it2).l );
1459 else if( util_isRowSelected( m_rctRect ) )
1461 TQValueList<layoutRow>::Iterator it2;
1462 for ( it2 = m_lstRedoRowFormats.begin(); it2 != m_lstRedoRowFormats.end(); ++it2 )
1464 RowFormat *row= sheet->nonDefaultRowFormat( (*it2).row );
1465 row->copy( *(*it2).l );
1469 TQValueList<layoutTextCell>::Iterator it2;
1470 for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
1472 Cell *cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
1474 if ( (*it2).text.isEmpty() )
1476 if(!cell->
text().isEmpty())
1482 cell->
format()->copy( *(*it2).l );
1484 cell->setDisplayDirtyFlag();
1485 sheet->updateCell( cell, (*it2).col, (*it2).row );
1487 sheet->setRegionPaintDirty(m_rctRect);
1488 sheet->updateView( m_rctRect );
1489 doc()->undoUnlock();
1498UndoDelete::UndoDelete(
Doc *_doc, Sheet* sheet,
const Region& region)
1501 name=i18n(
"Delete");
1502 m_sheetName = sheet->sheetName();
1504 createListCell(m_data, m_lstColumn, m_lstRow, sheet);
1507UndoDelete::~UndoDelete()
1511void UndoDelete::createListCell( TQCString &listCell,TQValueList<columnSize> &listCol,TQValueList<rowSize> &listRow, Sheet* sheet )
1515 Region::ConstIterator endOfList = m_region.constEnd();
1516 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
1518 TQRect range = (*it)->rect().normalize();
1520 if ((*it)->isColumn())
1522 for(
int y = range.left() ; y <= range.right() ; ++y )
1524 ColumnFormat * cl = sheet->columnFormat( y );
1525 if ( !cl->isDefault() )
1528 tmpSize.columnNumber=y;
1529 tmpSize.columnWidth=cl->dblWidth();
1530 listCol.append(tmpSize);
1535 else if ((*it)->isRow())
1538 for(
int y = range.top() ; y <= range.bottom() ; ++y )
1540 RowFormat *rw=sheet->rowFormat(y);
1541 if(!rw->isDefault())
1544 tmpSize.rowNumber=y;
1545 tmpSize.rowHeight=rw->dblHeight();
1546 listRow.append(tmpSize);
1554 TQDomDocument doc = sheet->saveCellRegion( m_region );
1557 TQTextStream str( &buffer, IO_WriteOnly );
1564 listCell = buffer.utf8();
1565 int len = listCell.length();
1566 char tmp = listCell[ len - 1 ];
1567 listCell.resize( len );
1568 *( listCell.data() + len - 1 ) = tmp;
1572void UndoDelete::undo()
1574 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
1577 createListCell( m_dataRedo, m_lstRedoColumn, m_lstRedoRow, sheet );
1580 doc()->emitBeginOperation();
1583 TQValueList<columnSize>::Iterator it2;
1584 for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
1586 ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
1587 cl->setDblWidth((*it2).columnWidth);
1592 TQValueList<rowSize>::Iterator it2;
1593 for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 )
1595 RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
1596 rw->setDblHeight((*it2).rowHeight);
1600 sheet->deleteCells(m_region);
1601 sheet->paste( m_data, m_region.boundingRect() );
1602 sheet->updateView( );
1604 if(sheet->getAutoCalc()) sheet->recalc();
1606 doc()->undoUnlock();
1609void UndoDelete::redo()
1611 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
1616 doc()->emitBeginOperation();
1619 TQValueList<columnSize>::Iterator it2;
1620 for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
1622 ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
1623 cl->setDblWidth((*it2).columnWidth);
1628 TQValueList<rowSize>::Iterator it2;
1629 for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 )
1631 RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
1632 rw->setDblHeight((*it2).rowHeight);
1640 sheet->paste( m_dataRedo, m_region.boundingRect() );
1642 sheet->updateView();
1643 sheet->refreshView( m_region );
1644 doc()->undoUnlock();
1653UndoDragDrop::UndoDragDrop(
Doc * _doc, Sheet * _sheet,
1657 m_selectionSource( _source ),
1658 m_selectionTarget( _target )
1660 name = i18n(
"Drag & Drop" );
1662 m_sheetName = _sheet->sheetName();
1664 saveCellRect( m_dataTarget, _sheet, _target );
1665 saveCellRect( m_dataSource, _sheet, _source );
1668UndoDragDrop::~UndoDragDrop()
1672void UndoDragDrop::saveCellRect( TQCString & cells, Sheet * sheet,
1675 TQDomDocument doc = sheet->saveCellRegion(region);
1678 TQTextStream str( &buffer, IO_WriteOnly );
1681 cells = buffer.utf8();
1682 int len = cells.length();
1683 char tmp = cells[ len - 1 ];
1684 cells.resize( len );
1685 *( cells.data() + len - 1 ) = tmp;
1688void UndoDragDrop::undo()
1690 Sheet * sheet = doc()->map()->findSheet( m_sheetName );
1694 saveCellRect( m_dataRedoSource, sheet, m_selectionSource );
1695 saveCellRect( m_dataRedoTarget, sheet, m_selectionTarget );
1698 doc()->emitBeginOperation();
1700 sheet->deleteCells( m_selectionTarget );
1701 sheet->paste( m_dataTarget, m_selectionTarget.boundingRect() );
1703 sheet->deleteCells( m_selectionSource );
1704 sheet->paste( m_dataSource, m_selectionSource.boundingRect() );
1706 sheet->updateView();
1708 if ( sheet->getAutoCalc() )
1711 doc()->undoUnlock();
1714void UndoDragDrop::redo()
1716 Sheet * sheet = doc()->map()->findSheet( m_sheetName );
1721 doc()->emitBeginOperation();
1727 sheet->deleteCells( m_selectionTarget );
1728 sheet->paste( m_dataRedoTarget, m_selectionTarget.boundingRect() );
1729 sheet->deleteCells( m_selectionSource );
1730 sheet->paste( m_dataRedoSource, m_selectionSource.boundingRect() );
1732 sheet->updateView();
1733 if ( sheet->getAutoCalc() )
1736 doc()->undoUnlock();
1747UndoResizeColRow::UndoResizeColRow(
Doc *_doc, Sheet *_sheet,
const Region &_selection ) :
1750 name=i18n(
"Resize");
1751 m_region = _selection;
1752 m_sheetName = _sheet->sheetName();
1754 createList( m_lstColumn,m_lstRow, _sheet );
1757void UndoResizeColRow::createList( TQValueList<columnSize> &listCol,TQValueList<rowSize> &listRow, Sheet* sheet )
1761 Region::ConstIterator endOfList(m_region.constEnd());
1762 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
1764 TQRect m_rctRect = (*it)->rect().normalize();
1766 if( util_isColumnSelected( m_rctRect ) )
1768 for(
int y = m_rctRect.left(); y <= m_rctRect.right(); y++ )
1770 ColumnFormat *cl=sheet->columnFormat(y);
1774 tmpSize.columnNumber=y;
1775 tmpSize.columnWidth=cl->dblWidth();
1776 listCol.append(tmpSize);
1780 else if( util_isRowSelected( m_rctRect ) )
1782 for(
int y = m_rctRect.top(); y <= m_rctRect.bottom(); y++ )
1784 RowFormat *rw=sheet->rowFormat(y);
1788 tmpSize.rowNumber=y;
1789 tmpSize.rowHeight=rw->dblHeight();
1790 listRow.append(tmpSize);
1796 for(
int y = m_rctRect.left(); y <= m_rctRect.right(); y++ )
1798 ColumnFormat *cl=sheet->columnFormat(y);
1802 tmpSize.columnNumber=y;
1803 tmpSize.columnWidth=cl->dblWidth();
1804 listCol.append(tmpSize);
1807 for(
int y = m_rctRect.top(); y <= m_rctRect.bottom(); y++ )
1809 RowFormat *rw=sheet->rowFormat(y);
1813 tmpSize.rowNumber=y;
1814 tmpSize.rowHeight=rw->dblHeight();
1815 listRow.append(tmpSize);
1823UndoResizeColRow::~UndoResizeColRow()
1827void UndoResizeColRow::undo()
1829 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
1835 createList( m_lstRedoColumn,m_lstRedoRow, sheet );
1837 Region::ConstIterator endOfList(m_region.constEnd());
1838 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
1840 TQRect m_rctRect = (*it)->rect().normalize();
1842 if( util_isColumnSelected( m_rctRect ) )
1844 TQValueList<columnSize>::Iterator it2;
1845 for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
1847 ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
1848 cl->setDblWidth((*it2).columnWidth);
1851 else if( util_isRowSelected( m_rctRect ) )
1853 TQValueList<rowSize>::Iterator it2;
1854 for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 )
1856 RowFormat *rw=sheet->rowFormat((*it2).rowNumber);
1857 rw->setDblHeight((*it2).rowHeight);
1862 TQValueList<columnSize>::Iterator it2;
1863 for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
1865 ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
1866 cl->setDblWidth((*it2).columnWidth);
1868 TQValueList<rowSize>::Iterator it1;
1869 for ( it1 = m_lstRow.begin(); it1 != m_lstRow.end(); ++it1 )
1871 RowFormat *rw=sheet->rowFormat((*it1).rowNumber);
1872 rw->setDblHeight((*it1).rowHeight);
1877 doc()->undoUnlock();
1880void UndoResizeColRow::redo()
1882 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
1888 Region::ConstIterator endOfList(m_region.constEnd());
1889 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
1891 TQRect m_rctRect = (*it)->rect().normalize();
1893 if( util_isColumnSelected( m_rctRect ) )
1895 TQValueList<columnSize>::Iterator it2;
1896 for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
1898 ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
1899 cl->setDblWidth((*it2).columnWidth);
1902 else if( util_isRowSelected( m_rctRect ) )
1904 TQValueList<rowSize>::Iterator it2;
1905 for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 )
1907 RowFormat *rw=sheet->rowFormat((*it2).rowNumber);
1908 rw->setDblHeight((*it2).rowHeight);
1913 TQValueList<columnSize>::Iterator it2;
1914 for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
1916 ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
1917 cl->setDblWidth((*it2).columnWidth);
1919 TQValueList<rowSize>::Iterator it1;
1920 for ( it1 = m_lstRedoRow.begin(); it1 != m_lstRedoRow.end(); ++it1 )
1922 RowFormat *rw=sheet->rowFormat((*it1).rowNumber);
1923 rw->setDblHeight((*it1).rowHeight);
1928 doc()->undoUnlock();
1938UndoChangeAreaTextCell::UndoChangeAreaTextCell(
Doc *_doc, Sheet *_sheet,
const Region &_selection ) :
1941 name=i18n(
"Change Text");
1943 m_region = _selection;
1944 m_sheetName = _sheet->sheetName();
1946 createList( m_lstTextCell, _sheet );
1949void UndoChangeAreaTextCell::createList( TQMap<TQPoint,TQString> &map, Sheet* sheet )
1953 Region::ConstIterator endOfList(m_region.constEnd());
1954 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
1956 TQRect m_rctRect = (*it)->rect().normalize();
1957 int bottom = m_rctRect.bottom();
1958 int right = m_rctRect.right();
1960 if( util_isColumnSelected( m_rctRect ) )
1963 for (
int col = m_rctRect.left(); col <= right; ++col )
1965 c = sheet->getFirstCellColumn( col );
1974 map.insert( TQPoint(col,c->
row()) , c->
text() );
1976 c = sheet->getNextCellDown( col, c->
row() );
1980 else if ( util_isRowSelected( m_rctRect ) )
1983 for (
int row = m_rctRect.top(); row <= bottom; ++row )
1985 c = sheet->getFirstCellRow( row );
1994 map.insert( TQPoint(c->
column(),row) , c->
text() );
1996 c = sheet->getNextCellRight( c->
column(), row );
2003 for (
int x = m_rctRect.left(); x <= right; ++x )
2005 cell = sheet->getFirstCellColumn( x );
2008 while ( cell && cell->
row() <= bottom )
2016 map.insert( TQPoint(x,cell->
row()) , cell->
text());
2018 cell = sheet->getNextCellDown( x, cell->
row() );
2025UndoChangeAreaTextCell::~UndoChangeAreaTextCell()
2029void UndoChangeAreaTextCell::undo()
2031 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2036 doc()->emitBeginOperation();
2037 sheet->setRegionPaintDirty(m_region);
2039 kdDebug() <<
"creating redo list..." << endl;
2040 createList( m_lstRedoTextCell, sheet );
2041 kdDebug() <<
"created redo list..." << endl;
2043 Region::ConstIterator endOfList(m_region.constEnd());
2044 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
2046 TQRect m_rctRect = (*it)->rect().normalize();
2048 if ( !util_isRowSelected( m_rctRect )
2049 && !util_isColumnSelected( m_rctRect ) )
2051 for (
int x = m_rctRect.left(); x <= m_rctRect.right(); ++x )
2052 for (
int y = m_rctRect.top(); y <= m_rctRect.bottom(); ++y )
2054 Cell* cell = sheet->nonDefaultCell( x, y );
2056 const TQPoint location(x,y);
2058 if ( m_lstTextCell.contains(location) )
2078 TQMap<TQPoint,TQString>::Iterator it2;
2079 for ( it2 = m_lstTextCell.begin(); it2 != m_lstTextCell.end(); ++it2 )
2081 Cell *cell = sheet->nonDefaultCell( it2.key().x(), it2.key().y() );
2082 if ( it2.data().isEmpty() )
2084 if ( !cell->
text().isEmpty() )
2094 doc()->emitEndOperation();
2095 doc()->undoUnlock();
2098void UndoChangeAreaTextCell::redo()
2100 Sheet * sheet = doc()->map()->findSheet( m_sheetName );
2106 doc()->emitBeginOperation();
2107 sheet->setRegionPaintDirty(m_region);
2109 Region::ConstIterator endOfList(m_region.constEnd());
2110 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
2112 TQRect m_rctRect = (*it)->rect().normalize();
2114 if ( !util_isRowSelected( m_rctRect )
2115 && !util_isColumnSelected( m_rctRect ) )
2117 for (
int x = m_rctRect.left(); x <= m_rctRect.right(); ++x )
2118 for (
int y = m_rctRect.top(); y <= m_rctRect.bottom(); ++y )
2120 Cell* cell = sheet->nonDefaultCell( x, y );
2122 const TQPoint location(x,y);
2124 if (m_lstRedoTextCell.contains(location))
2143 TQMap<TQPoint,TQString>::Iterator it2;
2144 for ( it2 = m_lstRedoTextCell.begin(); it2 != m_lstRedoTextCell.end(); ++it2 )
2146 Cell *cell = sheet->nonDefaultCell( it2.key().x(), it2.key().y() );
2147 if ( it2.data().isEmpty() )
2149 if ( !cell->
text().isEmpty() )
2159 doc()->emitEndOperation();
2160 doc()->undoUnlock();
2170UndoMergedCell::UndoMergedCell(
Doc *_doc, Sheet *_sheet,
int _column,
int _row ,
int _extraX,
int _extraY) :
2173 name=i18n(
"Merge Cells");
2175 m_sheetName = _sheet->sheetName();
2183UndoMergedCell::~UndoMergedCell()
2187void UndoMergedCell::undo()
2189 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2195 Cell *cell = sheet->nonDefaultCell( m_iCol, m_iRow );
2199 sheet->changeMergedCell( m_iCol, m_iRow, m_iExtraX,m_iExtraY);
2201 doc()->undoUnlock();
2204void UndoMergedCell::redo()
2206 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2212 sheet->changeMergedCell( m_iCol, m_iRow, m_iExtraRedoX,m_iExtraRedoY);
2214 doc()->undoUnlock();
2223UndoAutofill::UndoAutofill(
Doc *_doc, Sheet* sheet,
const TQRect & _selection)
2226 name=i18n(
"Autofill");
2228 m_sheetName = sheet->sheetName();
2229 m_selection = _selection;
2230 createListCell( m_data, sheet );
2234UndoAutofill::~UndoAutofill()
2238void UndoAutofill::createListCell( TQCString &list, Sheet* sheet )
2240 TQDomDocument doc = sheet->saveCellRegion( m_selection );
2243 TQTextStream str( &buffer, IO_WriteOnly );
2250 list = buffer.utf8();
2251 int len = list.length();
2252 char tmp = list[ len - 1 ];
2254 *( list.data() + len - 1 ) = tmp;
2257void UndoAutofill::undo()
2259 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2263 createListCell( m_dataRedo, sheet );
2266 doc()->emitBeginOperation();
2268 sheet->deleteCells( m_selection );
2269 sheet->paste( m_data, m_selection );
2272 doc()->emitEndOperation();
2275 doc()->undoUnlock();
2278void UndoAutofill::redo()
2282 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2286 doc()->emitBeginOperation();
2288 sheet->deleteCells( m_selection );
2290 sheet->paste( m_dataRedo, m_selection );
2291 if ( sheet->getAutoCalc() )
2293 sheet->updateView();
2294 doc()->undoUnlock();
2303UndoInsertCellRow::UndoInsertCellRow(
Doc *_doc, Sheet *_sheet,
const TQRect &_rect ) :
2304 UndoInsertRemoveAction( _doc )
2306 name=i18n(
"Insert Cell");
2308 m_sheetName = _sheet->sheetName();
2312UndoInsertCellRow::~UndoInsertCellRow()
2316void UndoInsertCellRow::undo()
2318 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2323 sheet->unshiftRow( m_rect);
2324 doc()->undoUnlock();
2326 undoFormulaReference();
2329void UndoInsertCellRow::redo()
2331 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2336 sheet->shiftRow( m_rect);
2337 doc()->undoUnlock();
2347UndoInsertCellCol::UndoInsertCellCol(
Doc *_doc, Sheet *_sheet,
const TQRect &_rect ) :
2348 UndoInsertRemoveAction( _doc )
2350 name=i18n(
"Insert Cell");
2352 m_sheetName = _sheet->sheetName();
2356UndoInsertCellCol::~UndoInsertCellCol()
2360void UndoInsertCellCol::undo()
2362 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2367 sheet->unshiftColumn( m_rect);
2368 doc()->undoUnlock();
2370 undoFormulaReference();
2373void UndoInsertCellCol::redo()
2375 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2380 sheet->shiftColumn( m_rect );
2381 doc()->undoUnlock();
2390UndoRemoveCellRow::UndoRemoveCellRow(
Doc *_doc, Sheet *_sheet,
const TQRect &rect ) :
2391 UndoInsertRemoveAction( _doc )
2393 name=i18n(
"Remove Cell");
2395 m_sheetName = _sheet->sheetName();
2397 TQDomDocument doc = _sheet->saveCellRegion( m_rect );
2400 TQTextStream str( &buffer, IO_WriteOnly );
2407 m_data = buffer.utf8();
2408 int len = m_data.length();
2409 char tmp = m_data[ len - 1 ];
2410 m_data.resize( len );
2411 *( m_data.data() + len - 1 ) = tmp;
2414UndoRemoveCellRow::~UndoRemoveCellRow()
2418void UndoRemoveCellRow::undo()
2420 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2425 sheet->shiftRow( m_rect );
2426 sheet->paste( m_data, m_rect );
2427 doc()->undoUnlock();
2429 undoFormulaReference();
2432void UndoRemoveCellRow::redo()
2434 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2439 sheet->unshiftRow( m_rect);
2440 doc()->undoUnlock();
2449UndoRemoveCellCol::UndoRemoveCellCol(
Doc *_doc, Sheet *_sheet,
const TQRect &_rect ) :
2450 UndoInsertRemoveAction( _doc )
2452 name=i18n(
"Remove Cell");
2454 m_sheetName = _sheet->sheetName();
2456 TQDomDocument doc = _sheet->saveCellRegion( m_rect );
2459 TQTextStream str( &buffer, IO_WriteOnly );
2466 m_data = buffer.utf8();
2467 int len = m_data.length();
2468 char tmp = m_data[ len - 1 ];
2469 m_data.resize( len );
2470 *( m_data.data() + len - 1 ) = tmp;
2473UndoRemoveCellCol::~UndoRemoveCellCol()
2477void UndoRemoveCellCol::undo()
2479 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2484 sheet->shiftColumn( m_rect );
2485 sheet->paste( m_data, m_rect );
2486 doc()->undoUnlock();
2488 undoFormulaReference();
2491void UndoRemoveCellCol::redo()
2493 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2498 sheet->unshiftColumn( m_rect );
2499 doc()->undoUnlock();
2508UndoConditional::UndoConditional(
Doc *_doc, Sheet* sheet,
const Region & _selection)
2511 name=i18n(
"Conditional Cell Attribute");
2513 m_sheetName = sheet->sheetName();
2514 m_region = _selection;
2515 createListCell( m_data, sheet );
2519UndoConditional::~UndoConditional()
2523void UndoConditional::createListCell( TQCString &list, Sheet* sheet )
2527 TQTextStream str( &buffer, IO_WriteOnly );
2529 TQDomDocument doc = sheet->saveCellRegion( m_region );
2536 list = buffer.utf8();
2537 int len = list.length();
2538 char tmp = list[ len - 1 ];
2540 *( list.data() + len - 1 ) = tmp;
2543void UndoConditional::undo()
2545 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2549 createListCell( m_dataRedo, sheet );
2552 sheet->paste(m_data, m_region.boundingRect());
2553 if (sheet->getAutoCalc())
2558 doc()->undoUnlock();
2561void UndoConditional::redo()
2565 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2570 sheet->paste(m_dataRedo, m_region.boundingRect());
2571 if (sheet->getAutoCalc())
2576 doc()->undoUnlock();
2586UndoCellPaste::UndoCellPaste(
Doc *_doc, Sheet* sheet,
2587 int _xshift,
int _yshift,
2588 const Region& region,
bool insert,
int _insertTo)
2594 name=i18n(
"Paste & Insert");
2596 m_sheetName = sheet->sheetName();
2601 m_iInsertTo=_insertTo;
2603 createListCell( m_data, m_lstColumn,m_lstRow,sheet );
2607UndoCellPaste::~UndoCellPaste()
2611void UndoCellPaste::createListCell(TQCString& listCell,
2612 TQValueList<columnSize>& listCol,
2613 TQValueList<rowSize>& listRow,
2619 Region::ConstIterator endOfList = m_region.constEnd();
2620 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
2624 TQRect range = (*it)->rect().normalize();
2625 if ((*it)->isColumn())
2627 nbCol = range.width();
2629 else if ((*it)->isRow())
2631 nbRow = range.height();
2638 for(
int y = 1; y <=nbCol ; ++y )
2640 ColumnFormat *cl=sheet->columnFormat(y);
2641 if(!cl->isDefault())
2644 tmpSize.columnNumber=y;
2645 tmpSize.columnWidth=cl->dblWidth();
2646 listCol.append(tmpSize);
2651 else if (nbRow != 0)
2654 for (
int y = 1; y <=nbRow ; ++y )
2656 RowFormat *rw=sheet->rowFormat(y);
2657 if (!rw->isDefault())
2660 tmpSize.rowNumber=y;
2661 tmpSize.rowHeight=rw->dblHeight();
2662 listRow.append(tmpSize);
2668 TQDomDocument doc = sheet->saveCellRegion(m_region);
2671 TQTextStream str( &buffer, IO_WriteOnly );
2678 listCell = buffer.utf8();
2679 int len = listCell.length();
2680 char tmp = listCell[ len - 1 ];
2681 listCell.resize( len );
2682 *( listCell.data() + len - 1 ) = tmp;
2685void UndoCellPaste::undo()
2687 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2691 createListCell( m_dataRedo, m_lstRedoColumn, m_lstRedoRow, sheet );
2694 doc()->emitBeginOperation();
2699 Region::ConstIterator endOfList = m_region.constEnd();
2700 for (Region::ConstIterator it = --m_region.constEnd(); it != endOfList; --it)
2702 TQRect range = (*it)->rect().normalize();
2704 if ((*it)->isColumn())
2708 TQValueList<columnSize>::Iterator it2;
2709 for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
2711 ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
2712 cl->setDblWidth((*it2).columnWidth);
2717 numCols += range.width();
2720 else if ((*it)->isRow())
2724 TQValueList<rowSize>::Iterator it2;
2725 for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 )
2727 RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
2728 rw->setDblHeight((*it2).rowHeight);
2733 numRows += range.height();
2739 sheet->deleteCells(range);
2745 TQRect rect = m_region.boundingRect();
2746 if (m_iInsertTo == -1 && numCols == 0 && numRows == 0)
2749 rect.setWidth(rect.width());
2750 sheet->unshiftRow(rect);
2752 else if (m_iInsertTo == 1 && numCols == 0 && numRows == 0)
2755 rect.setHeight(rect.height());
2756 sheet->unshiftColumn(rect);
2759 else if (m_iInsertTo == 0 && numCols == 0 && numRows > 0)
2761 sheet->removeRow(rect.top(), rect.height() - 1,
false);
2764 else if (m_iInsertTo == 0 && numCols > 0 && numRows == 0)
2766 sheet->removeColumn(rect.left(), rect.width() - 1,
false);
2771 sheet->paste(m_data, m_region.boundingRect());
2774 if (sheet->getAutoCalc())
2778 sheet->updateView();
2779 doc()->undoUnlock();
2782void UndoCellPaste::redo()
2784 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2789 doc()->emitBeginOperation();
2794 Region::ConstIterator endOfList(m_region.constEnd());
2795 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
2797 TQRect range = (*it)->rect().normalize();
2799 if ((*it)->isColumn())
2801 numCols += range.width();
2803 else if ((*it)->isRow())
2805 numRows += range.height();
2811 sheet->deleteCells( range );
2818 TQRect rect = m_region.boundingRect();
2819 if (m_iInsertTo == -1 && numCols == 0 && numRows == 0)
2821 rect.setWidth(rect.width());
2822 sheet->shiftRow(rect);
2824 else if (m_iInsertTo == 1 && numCols == 0 && numRows == 0)
2826 rect.setHeight(rect.height());
2827 sheet->shiftColumn(rect);
2830 else if (m_iInsertTo == 0 && numCols == 0 && numRows > 0)
2832 sheet->insertRow(rect.top(), rect.height() - 1,
false);
2835 else if (m_iInsertTo == 0 && numCols > 0 && numRows == 0)
2837 sheet->insertColumn(rect.left(), rect.width() - 1,
false);
2841 for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
2843 if ((*it)->isColumn())
2845 TQValueList<columnSize>::Iterator it2;
2846 for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
2848 ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
2849 cl->setDblWidth((*it2).columnWidth);
2852 else if ((*it)->isRow())
2854 TQValueList<rowSize>::Iterator it2;
2855 for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 )
2857 RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
2858 rw->setDblHeight((*it2).rowHeight);
2863 sheet->paste( m_dataRedo, m_region.boundingRect() );
2865 if (sheet->getAutoCalc())
2870 sheet->updateView();
2871 doc()->undoUnlock();
2881UndoStyleCell::UndoStyleCell(
Doc *_doc, Sheet* sheet,
const TQRect & _selection)
2884 name=i18n(
"Style of Cell");
2886 m_sheetName = sheet->sheetName();
2887 m_selection = _selection;
2888 createListCell( m_lstStyleCell, sheet );
2892UndoStyleCell::~UndoStyleCell()
2896void UndoStyleCell::createListCell( TQValueList<styleCell> &listCell, Sheet* sheet )
2898 int bottom = m_selection.bottom();
2899 int right = m_selection.right();
2900 if ( util_isColumnSelected( m_selection ) )
2903 for (
int col = m_selection.left(); col <= right; ++ col )
2905 c = sheet->getFirstCellColumn( col );
2910 styleCell tmpStyleCell;
2911 tmpStyleCell.row = c->
row();
2912 tmpStyleCell.col = col;
2913 listCell.append(tmpStyleCell);
2915 c = sheet->getNextCellDown( col, c->
row() );
2919 else if ( util_isRowSelected( m_selection ) )
2922 for (
int row = m_selection.top(); row <= bottom; ++row )
2924 c = sheet->getFirstCellRow( row );
2929 styleCell tmpStyleCell;
2930 tmpStyleCell.row = row;
2931 tmpStyleCell.col = c->
column();
2932 listCell.append(tmpStyleCell);
2934 c = sheet->getNextCellRight( c->
column(), row );
2941 for (
int i = m_selection.top(); i <= bottom; ++i)
2942 for (
int j = m_selection.left(); j <= right; ++j )
2944 cell = sheet->nonDefaultCell( j, i);
2945 styleCell tmpStyleCell;
2946 tmpStyleCell.row = i;
2947 tmpStyleCell.col = j;
2948 listCell.append(tmpStyleCell);
2953void UndoStyleCell::undo()
2955 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2959 createListCell( m_lstRedoStyleCell, sheet );
2962 doc()->emitBeginOperation();
2965 TQValueList<styleCell>::Iterator it2;
2966 for ( it2 = m_lstStyleCell.begin(); it2 != m_lstStyleCell.end(); ++it2 )
2968 sheet->nonDefaultCell( (*it2).col, (*it2).row);
2970 sheet->setRegionPaintDirty(m_selection);
2971 sheet->updateView( m_selection );
2972 doc()->undoUnlock();
2975void UndoStyleCell::redo()
2979 Sheet* sheet = doc()->map()->findSheet( m_sheetName );
2984 doc()->emitBeginOperation();
2986 TQValueList<styleCell>::Iterator it2;
2987 for ( it2 = m_lstRedoStyleCell.begin(); it2 != m_lstRedoStyleCell.end(); ++it2 )
2989 sheet->nonDefaultCell( (*it2).col, (*it2).row);
2991 sheet->setRegionPaintDirty(m_selection);
2992 sheet->updateView();
2994 doc()->undoUnlock();
2997UndoInsertData::UndoInsertData(
Doc * _doc, Sheet * _sheet, TQRect & _selection )
2998 : UndoChangeAreaTextCell( _doc, _sheet, _selection )
3000 name = i18n(
"Insert Data From Database");
For every cell in the spread sheet there is a Cell object.
void setLayoutDirtyFlag(bool format=false)
Causes the format to be recalculated when the cell is drawn next time.
TQString text() const
Return the text the user entered.
int row() const
Returns the cell's row.
int column() const
Returns the cell's column.
void setCellText(const TQString &_text, bool asString=false)
The high-level method for setting text, when the user inputs it.
Format * format() const
Returns the format object of this cell.
bool isDefault() const
Returns true if this is a default cell (with row and column equal to zero).
bool isPartOfMerged() const
If this cell is part of a merged cell, then the marker may never reside on this cell.
This class holds the data that makes up a spreadsheet.
The one for all class for points and ranges.