diff --git a/kspread/CHANGES b/kspread/CHANGES new file mode 100644 index 00000000000..c404e1343fd --- /dev/null +++ b/kspread/CHANGES @@ -0,0 +1,288 @@ +after 1.3 +========= +- undo not working after deleting multiple cells (#77844) + +since 1.3 RC1 +============= +- fix display of text starting with a single quote +- fix problem formatting the whole row (#65504) +- make the top/middle/bottom alignment buttons work +- fix problem with reference from another sheet (bug #60455) +- show indicator of chosen/selected cells (bug #58098) +- hide in-place cell editing when choosing other sheet +- proper zoom and display of formatted hyperlink (#66214) +- fix flickering problem with many hyperlinks (#65501) +- don't crash when leaving the preview in Konq (#65928) +- fix redraw problem with Print Preview (#60147) +- support only one zoom for two or more views +- fix painting problem with multiple views +- prevent possible crash with conditional formatting (#58713) +- fix dependency problem with automatic recalculation (#58097) +- better adjustment of cell references on cut&paste +- fix crash on csv import (#66047) +- fix problem for cells copy/cut to clipboard (#58712) +- show frame when embedded object is selected (#37152) +- better handling of "nothing to print" warning (#60147) +- when embedded, use real zoom instead of scaling (#45503) +- fix data sorting (#63317) + +since 1.3 beta4 +=============== +- #64794: kspread problem with calculating dates +- #61570: cell border does not work with merged cells +- fix unsorted zoom values (#64154) + +since 1.3 beta3 +=============== +- KSpread is slow during text to column conversion (#59999) +- fix problem cycling absolute cell reference with F4 key (#46959) +- the calculator plugin saves its configuration now (#49954) +- fix detection of sheet direction (for rtl support) + +since 1.3 beta2 +=============== +- KSpread crash when changing paper orientation (#60279) + + +since 1.3 beta1 +=============== +- adjust print zoom to limit printout to m x n pages +- new functions: GETPIVOTDATA, BESSELI, BESSELJ, BESSELK, BESSELY, + ERF, ERFC, CONVERT +- new templates: Balance Sheet, Price Quotation, Packing Slip + + +since 1.2 relase ( 'til 1.3 beta 1 :-) +====================================== + +- real more than one currency support +- new date and time formats +- enhanced the "Text to Columns", "Insert from file" + and "Insert from clipboard" dialog to support "ignore double delimiters" +- "Insert from file" now also adjusts the column width depending on imported + cell content +- enhanced the CSV import dlg + - to support "ignore double delimiters" + - to adjust cell width to imported cell content + - you can specify the column and row range for import +- enhanced the CSV export dialog so that you can choose + - table to export + - delimiters between tables + - delimiter between cells + - character for quotes + - export selection only +- Goal Seek message fixes + you can select the cells with the mouse now +- enhanced Gnumeric import filter to support + - background (color + patterns), borders (colors + style) + - font formating, text alignment + - format parsing (date, time, numbers,...), cell height, width + - print range, page setup, hidden columns/row, comments +- new OpenCalc export and import filter +- Added subtotal dialog and formula +- Paper layout can now be applied to all sheets +- now you can define the default cell style +- Autoscroll while selecting now also available for columns and row headers +- When cell is too short, then the content is now available in the tooltip +- Drag 'n' Drop of selections +- Protection of sheets or of the document structure (with or without password) +- Protection tab in layout dialog: you unprotect certain cells, hide their + contents, hide the formulas, or select them for not being printed +- FindNext, FindPrevious cell enhancement for find +- Fill: Fill area from right to left, left to right, bottom to top, top to bottom +- Full zoom support +- Printing: + + High resolution printing (600dpi) + + Improved WYSIWYG + + Zoom support on printout +- New direction mode when pressing Enter: you can jump now to the first cell of the next row +- hierachical style support + - builtin styles + - creation of custom styles + - creation of custom styles using a cell as template +- insert special characters +- smaller, more efficent file format +- many performance enhancements +- more powerful conditional cell attributes (you can assign a whole style if condition matches) +- conditions can be used for text and numbers now (was numbers only before) +- new templates: Body-Mass Index Calculator, Calendar 2003, Student ID Card, + Invoice, Expense Report + + +New functions: + +Date/Time (16): +- EDATE, EOMONTH, DAYS360, WEEKDAY, TIMEVALUE, DATEVALUE, YEAR, + MONTH, DAY, HOUR, MINUTE, SECOND, DAYNAME, MONTHNAME, EASTERSUNDAY, + ISOWEEKNUM + +Math (16): +- SUBTOTAL, POWER, TRUNC, CEILING, PRODUCT (now Excel compatible), + KPRODUCT, RANDEXP, RANDBINOM, RANDNEGBINOM, RANDBERNOULLI, + RANDPOISSON, MROUND, COUNTA, MINA, MAXA, SUMA + +Statistical (24): +- VARP, STDEV, VAR, STDEVP, GEOMEAN, HARMEAN, + KURT, LOGINV, DEVSQ, STANDARDIZE, HYPGEOMDIST, + NEGBINOMDIST, KURTP, CORREL, COVAR, SMALL, LARGE + STDEVA, STDEVPA, VARA, VARPA, SKEW, SKEWP, MODE + +Financial (19): +- PPMT, DDB, DURATION, PMT, NPER, + ISPMT, IPMT, TBILLEQ, TBILLPRICE, TBILLYIELD, + ACCRINT, ACCRINTM, COUPNUM, DOLLARDE, DOLLARFR, + DISC, EFFECT, INTRATE, RECEIVED + +Database (12): +- DAVERAGE, DCOUNT, DCOUNTA, DGET, DMAX, DMIN, + DPRODUCT, DSTDEV, DSTDEVP, DSUM, DVAR, DVARP + +Reference & Lookup (8): +- ADDRESS, AREAS, CHOOSE, COLUMN, COLUMNS, + INDIRECT, ROW, ROWS + +Engineering (2): +- DELTA, GESTEP + +Logical (2): +- FALSE, TRUE + +Information (2): +- ISNONTEXT, ISNUMBER + +Obsolete formulas +- stddev (was stddevp in fact) +- day (is dayname now) +- month (is monthname now) + +Obsolete but still usable formulas (do not show up in dialog ) +- variance, pow, isnottext, isnum, effective + + +===================================================== +After 1.2 above +===================================================== + + +Changes from 1.1 to 1.2 +======================= + +Since RC1: +---------- +Bugfixes: +- Fix display and printout with special files (offset by 1 pixel). +- Fix printout of thick cell borders on page borders +- Fix printout of children, when they overlap one page +- Fix #45967, #31130 +- Fix #45944 (Normal): Paste special->text overwrite borders +- Fix #42456 (Normal): merged cells with centered text do not survive insert/delete rows +- Fix #45943 (Crash): crash after "money format" +- Fix function documentation (YEAR(), FACTDOUBLE() ) +- Fix parsing and error checking for spreadsheet names. +- Fix #46045 (Normal): serious errors in forumulas +- Fix Embedded chart changes titles when opening again +- Fix #44628 (Grave): 1.1 document not read with 1.2 - circular references +- Fix #40150 (Normal): Precision problem in calculations +- Fix #29524: KSpread Formula editors tooltip should be changed +- Fix #18083: KSpread rounding error +- Fix #46530: crash on selecting validity +- Fix #45395: Save as HTML is called "mime type" +- Fix #34088: Precision of currency is too low or overflow is handled in a strange way +- Fix #45324: consolidate function result reference area selecting unintuitive + +Until RC1: +---------- +New: +- Like all of KOffice: a readonly GUI for embedding into Konqueror +- More DCOP calls + +Bugfixes: +- bug fixes +- Fix cancel add embedded document. +- Fix mem leak +- Fix copy/paste attribute. +- Fix offset of rotated text in one case (top/middle) + +Until beta2: +------------ + +- bug fixes +- perfomance enhancements +- print functions: + - added option for print grid, comment indicator and formula indicator + - added print range definiton + - added repeat columns & rows on printout + - added "" macro in header/footer +- paper layout now a property of sheet (not the whole workbook) +- header/footer now a property of sheet (not the whole workbook) +- Settings in paper layout are now undoable +- Sort enhanced for + - sorting by up to three rows or columns + - possibility of putting the result of sorting some place else + - you can use a custom lists (like days of week) as a primary key + - option if you want to copy the layout or not + - you can define a row header which gets copied but not sorted +- auto continuation support for every direction and all types supported in + KSpread and for more complex series like 1,3,4,6,... +- just one "copy" instead of "copy" and "copy as text" +- insertion of series supports now doubles and decreasing series +- support for inserting data from SQL databases +- implemented "Goal Seek" +- implemented new shortcuts for cell formating +- implemented "Insert from text file" and "Insert formated clipboard data" +- Added "Text to Column" +- improved Data Consolidate, with more choices: Sum, Average, Count, + Min, Max, Product, Standard Deviation, Variance. +- fixed some functions to be Excel-compatibel (FIND, REPLACE,LEFT, + RIGHT,MID,REPT) +- now it's "Sheet" everywhere, not more "Table" +- added formula indicator (small blue rectangle on the corner, + when the cell holds a formula). idea from Quattro Pro +- added Greek to EURO() function +- new function category: Engineering +- added support with templates +- added support for changing row/col and table of named areas +- Multiple views work for spreadsheets (can change tables, select different + parts of the sheet independantly in each open view or embedded object) +- DCOP interface for a table has changed. Many of the operations have been + moved to the 'view' class. Current DCOP scripts will need to be updated +- Zoom + +new functions added: + ISBLANK, CHAR, CODE, VALUE, DOLLAR, CONCATENATE, FIXED, T, TEXT, SUBSTITUTE, + SEARCH, INFO, FILENAME, TYPE, COUNTBLANK, N, AVEDEV, ARABIC, AVERAGEA, ROT, + FIB, BASE, FACTDOUBLE, SQRTPI, QUOTIENT, MULTINOMIAL, COUNTIF + +Until beta1: +------------ + +- bug fixes +- performance enhancements +- support up to 2^15 columns and rows, formerly it was 676 columns and 10000 + rows + +- add support for spell-check +- many new built-in functions (see detailed list below) +- function name is now case-insensitive +- "Related Function" in formula editor +- move functions in kspread_interpreter into several kspread_functions_*.cc + +New functions added: + conversion: + INT2BOOL, CharToAscii, AsciiToChar, BOOL2STRING, NUM2STRING, + BOOL2INT + math: + DIV, LCD, PRODUCT, LCM, TOGGLE, TRIM, ABS + text: + COMPARE, CLEAN, SLEEK, PROPER, REPLACE + date/time: + DAYS, WEEKS, MONTHS, YEARS + financial: + DB, SLN, SYD, EURO + logical: + XOR + statistical: + CHIDIST, FDIST, TDIST, CONFIDENCE, BETADIST, GAMMADIST, + PHI, GAUSS, MEDIAN, POISSON, GAMMALN, NORMINV, NORMSINV, + WEIBULL, EXPONDIST, NORMDIST, NORMSDIST, FISHER, + FISHERINV, LOGNORMDIST + diff --git a/kspread/kspread_undo.cc b/kspread/kspread_undo.cc new file mode 100644 index 00000000000..ca89b9b0622 --- /dev/null +++ b/kspread/kspread_undo.cc @@ -0,0 +1,3108 @@ +/* This file is part of the KDE project + Copyright (C) 1998, 1999 Torben Weis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + + +#include "kspread_global.h" +#include "kspread_undo.h" +#include "kspread_doc.h" +#include "kspread_map.h" +#include "kspread_util.h" +#include "kspread_sheetprint.h" +#include "kspread_style.h" +#include "kspread_style_manager.h" + +/**************************************************************************** + * + * KSpreadUndo + * + ***************************************************************************/ + +KSpreadUndo::KSpreadUndo( KSpreadDoc *_doc ) +{ + m_pDoc = _doc; + + m_stckUndo.setAutoDelete( FALSE ); + m_stckRedo.setAutoDelete( FALSE ); + + m_bLocked = FALSE; +} + +KSpreadUndo::~KSpreadUndo() +{ + clear(); +} + +void KSpreadUndo::appendUndo( KSpreadUndoAction *_action ) +{ + if ( m_bLocked ) + return; + + m_stckRedo.setAutoDelete( TRUE ); + m_stckRedo.clear(); + m_stckRedo.setAutoDelete( FALSE ); + + m_stckUndo.push( _action ); + + if ( m_pDoc ) + { + m_pDoc->enableUndo( hasUndoActions() ); + m_pDoc->enableRedo( hasRedoActions() ); + m_pDoc->setModified( true ); + } +} + +void KSpreadUndo::clear() +{ + if ( m_bLocked ) + return; + + m_stckUndo.setAutoDelete( TRUE ); + m_stckRedo.setAutoDelete( TRUE ); + + m_stckUndo.clear(); + m_stckRedo.clear(); + + m_stckUndo.setAutoDelete( FALSE ); + m_stckRedo.setAutoDelete( FALSE ); +} + +void KSpreadUndo::undo() +{ + if ( m_stckUndo.isEmpty() ) + return; + + //Don't show error dialogs on undo + bool origErrorMessages = true; + if ( m_pDoc ) + { + origErrorMessages = m_pDoc->getShowMessageError(); + m_pDoc->setShowMessageError( false ); + } + + KSpreadUndoAction *a = m_stckUndo.pop(); + a->undo(); + m_stckRedo.push( a ); + + if ( m_pDoc ) + { + m_pDoc->setShowMessageError( origErrorMessages ); + m_pDoc->enableUndo( hasUndoActions() ); + m_pDoc->enableRedo( hasRedoActions() ); + } +} + +void KSpreadUndo::redo() +{ + if ( m_stckRedo.isEmpty() ) + return; + KSpreadUndoAction *a = m_stckRedo.pop(); + a->redo(); + m_stckUndo.push( a ); + + if ( m_pDoc ) + { + m_pDoc->enableUndo( hasUndoActions() ); + m_pDoc->enableRedo( hasRedoActions() ); + } +} + +QString KSpreadUndo::getRedoName() +{ + if ( m_stckRedo.isEmpty() ) + return QString(""); + return m_stckRedo.current()->getName(); + +} + +QString KSpreadUndo::getUndoName() +{ + if ( m_stckUndo.isEmpty() ) + return QString(""); + return m_stckUndo.current()->getName(); +} + +/**************************************************************************** + * + * KSpreadMacroUndoAction + * + ***************************************************************************/ +KSpreadMacroUndoAction::KSpreadMacroUndoAction( KSpreadDoc *_doc, const QString& _name ): + KSpreadUndoAction( _doc ) +{ + name=_name; +} + +KSpreadMacroUndoAction::~KSpreadMacroUndoAction() +{ + m_commands.setAutoDelete( true ); +} + +void KSpreadMacroUndoAction::addCommand(KSpreadUndoAction *command) +{ + m_commands.append(command); +} + +void KSpreadMacroUndoAction::undo() +{ + QPtrListIterator it(m_commands); + for ( ; it.current() ; ++it ) + it.current()->undo(); +} + +void KSpreadMacroUndoAction::redo() +{ + QPtrListIterator it(m_commands); + for ( ; it.current() ; ++it ) + it.current()->redo(); +} + +/**************************************************************************** + * + * KSpreadUndoInsertRemoveAction + * + ***************************************************************************/ + +KSpreadUndoInsertRemoveAction::KSpreadUndoInsertRemoveAction( KSpreadDoc * _doc ) : + KSpreadUndoAction( _doc ) +{ +} + +KSpreadUndoInsertRemoveAction::~KSpreadUndoInsertRemoveAction() +{ + +} + +void KSpreadUndoInsertRemoveAction::saveFormulaReference( KSpreadSheet *_table, + int col, int row, QString & formula ) +{ + if ( _table == 0 ) + return; + QString tableName = _table->tableName(); + + m_lstFormulaCells.append( FormulaOfCell( tableName, col, row, formula ) ); +} + +void KSpreadUndoInsertRemoveAction::undoFormulaReference() +{ + QValueList::iterator it; + for ( it = m_lstFormulaCells.begin(); it != m_lstFormulaCells.end(); ++it ) + { + KSpreadSheet* table = doc()->map()->findTable( (*it).tableName() ); + if ( table ) + { + KSpreadCell * cell = table->cellAt( (*it).col(), (*it).row() ); + if ( cell && !cell->isDefault() ) + { + cell->setCellText( (*it).formula(), true ); + } + } + } +} + +/**************************************************************************** + * + * KSpreadUndoRemoveColumn + * + ***************************************************************************/ + +KSpreadUndoRemoveColumn::KSpreadUndoRemoveColumn( KSpreadDoc *_doc, KSpreadSheet *_table, int _column,int _nbCol ) : + KSpreadUndoInsertRemoveAction( _doc ) +{ + name=i18n("Remove Columns"); + m_tableName = _table->tableName(); + m_iColumn= _column; + m_iNbCol = _nbCol; + m_printRange = _table->print()->printRange(); + m_printRepeatColumns = _table->print()->printRepeatColumns(); + QRect selection; + selection.setCoords( _column, 1, _column+m_iNbCol, KS_rowMax ); + QDomDocument doc = _table->saveCellRect( selection ); + + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + m_data = buffer.utf8(); + int len = m_data.length(); + char tmp = m_data[ len - 1 ]; + m_data.resize( len ); + *( m_data.data() + len - 1 ) = tmp; +} + +KSpreadUndoRemoveColumn::~KSpreadUndoRemoveColumn() +{ +} + +void KSpreadUndoRemoveColumn::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + + table->insertColumn( m_iColumn,m_iNbCol); + + QPoint pastePoint( m_iColumn, 1 ); + table->paste( m_data, QRect( pastePoint, pastePoint ) ); + if(table->getAutoCalc()) table->recalc(); + + table->print()->setPrintRange( m_printRange ); + table->print()->setPrintRepeatColumns( m_printRepeatColumns ); + + doc()->undoBuffer()->unlock(); + + undoFormulaReference(); +} + +void KSpreadUndoRemoveColumn::redo() +{ + doc()->undoBuffer()->lock(); + + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + table->removeColumn( m_iColumn,m_iNbCol ); + + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoInsertColumn + * + ***************************************************************************/ + +KSpreadUndoInsertColumn::KSpreadUndoInsertColumn( KSpreadDoc *_doc, KSpreadSheet *_table, int _column, int _nbCol ) : + KSpreadUndoInsertRemoveAction( _doc ) +{ + name=i18n("Insert Columns"); + m_tableName = _table->tableName(); + m_iColumn= _column; + m_iNbCol=_nbCol; +} + +KSpreadUndoInsertColumn::~KSpreadUndoInsertColumn() +{ +} + +void KSpreadUndoInsertColumn::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->removeColumn( m_iColumn,m_iNbCol ); + doc()->undoBuffer()->unlock(); + + undoFormulaReference(); +} + +void KSpreadUndoInsertColumn::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->insertColumn( m_iColumn,m_iNbCol); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoRemoveRow + * + ***************************************************************************/ + +KSpreadUndoRemoveRow::KSpreadUndoRemoveRow( KSpreadDoc *_doc, KSpreadSheet *_table, int _row,int _nbRow) : + KSpreadUndoInsertRemoveAction( _doc ) +{ + name=i18n("Remove Rows"); + + m_tableName = _table->tableName(); + m_iRow = _row; + m_iNbRow= _nbRow; + m_printRange=_table->print()->printRange(); + m_printRepeatRows = _table->print()->printRepeatRows(); + + QRect selection; + selection.setCoords( 1, _row, KS_colMax, _row+m_iNbRow ); + QDomDocument doc = _table->saveCellRect( selection ); + + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + m_data = buffer.utf8(); + int len = m_data.length(); + char tmp = m_data[ len - 1 ]; + m_data.resize( len ); + *( m_data.data() + len - 1 ) = tmp; + + // printf("UNDO {{{%s}}}\n", buffer.latin1() ); + // printf("UNDO2 %i bytes, length %i {{{%s}}}\n", m_data.length(), m_data.size(), (const char*)m_data ); + // printf("length=%i, size=%i", m_data.length(), m_data.size() ); + // printf("Last characters are %i %i %i\n", (int)m_data[ m_data.size() - 3 ], + // (int)m_data[ m_data.size() - 2 ], (int)m_data[ m_data.size() - 1 ] ); +} + +KSpreadUndoRemoveRow::~KSpreadUndoRemoveRow() +{ +} + +void KSpreadUndoRemoveRow::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + + table->insertRow( m_iRow,m_iNbRow ); + + QPoint pastePoint( 1, m_iRow ); + table->paste( m_data, QRect(pastePoint, pastePoint) ); + + table->print()->setPrintRange( m_printRange ); + table->print()->setPrintRepeatRows( m_printRepeatRows ); + + if(table->getAutoCalc()) table->recalc(); + + doc()->undoBuffer()->unlock(); + + undoFormulaReference(); +} + +void KSpreadUndoRemoveRow::redo() +{ + doc()->undoBuffer()->lock(); + + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + table->removeRow( m_iRow,m_iNbRow ); + + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoInsertRow + * + ***************************************************************************/ + +KSpreadUndoInsertRow::KSpreadUndoInsertRow( KSpreadDoc *_doc, KSpreadSheet *_table, int _row,int _nbRow ) : + KSpreadUndoInsertRemoveAction( _doc ) +{ + name=i18n("Insert Rows"); + m_tableName = _table->tableName(); + m_iRow = _row; + m_iNbRow=_nbRow; +} + +KSpreadUndoInsertRow::~KSpreadUndoInsertRow() +{ +} + +void KSpreadUndoInsertRow::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->removeRow( m_iRow,m_iNbRow ); + doc()->undoBuffer()->unlock(); + + undoFormulaReference(); +} + +void KSpreadUndoInsertRow::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->insertRow( m_iRow,m_iNbRow ); + doc()->undoBuffer()->unlock(); +} + + +/**************************************************************************** + * + * KSpreadUndoHideRow + * + ***************************************************************************/ + +KSpreadUndoHideRow::KSpreadUndoHideRow( KSpreadDoc *_doc, KSpreadSheet *_table, int _row, int _nbRow , QValueList_listRow) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Hide Rows"); + m_tableName = _table->tableName(); + m_iRow= _row; + m_iNbRow=_nbRow; + if(m_iNbRow!=-1) + createList( listRow ,_table ); + else + listRow=QValueList(_listRow); +} + +KSpreadUndoHideRow::~KSpreadUndoHideRow() +{ +} + +void KSpreadUndoHideRow::createList( QValueList&list,KSpreadSheet *tab ) +{ +RowFormat *rl; +for(int i=m_iRow;i<=(m_iRow+m_iNbRow);i++) + { + rl= tab->nonDefaultRowFormat( i ); + if(!rl->isHide()) + list.append(rl->row()); + } +} + +void KSpreadUndoHideRow::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->showRow( 0,-1,listRow ); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoHideRow::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->hideRow(0,-1, listRow ); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoHideColumn + * + ***************************************************************************/ + +KSpreadUndoHideColumn::KSpreadUndoHideColumn( KSpreadDoc *_doc, KSpreadSheet *_table, int _column, int _nbCol, QValueList_listCol ) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Hide Columns"); + + m_tableName = _table->tableName(); + m_iColumn= _column; + m_iNbCol=_nbCol; + if(m_iNbCol!=-1) + createList( listCol ,_table ); + else + listCol=QValueList(_listCol); +} + +KSpreadUndoHideColumn::~KSpreadUndoHideColumn() +{ +} + +void KSpreadUndoHideColumn::createList( QValueList&list,KSpreadSheet *tab ) +{ +ColumnFormat *cl; +for(int i=m_iColumn;i<=(m_iColumn+m_iNbCol);i++) + { + cl= tab->nonDefaultColumnFormat( i ); + if(!cl->isHide()) + list.append(cl->column()); + } +} + +void KSpreadUndoHideColumn::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->showColumn(0,-1,listCol); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoHideColumn::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->hideColumn(0,-1,listCol); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoShowRow + * + ***************************************************************************/ + +KSpreadUndoShowRow::KSpreadUndoShowRow( KSpreadDoc *_doc, KSpreadSheet *_table, int _row, int _nbRow, QValueList_listRow ) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Show Rows"); + + m_tableName = _table->tableName(); + m_iRow= _row; + m_iNbRow=_nbRow; + if(m_iNbRow!=-1) + createList( listRow ,_table ); + else + listRow=QValueList(_listRow); +} + +KSpreadUndoShowRow::~KSpreadUndoShowRow() +{ +} + +void KSpreadUndoShowRow::createList( QValueList&list,KSpreadSheet *tab ) +{ +RowFormat *rl; +for(int i=m_iRow;i<=(m_iRow+m_iNbRow);i++) + { + rl= tab->nonDefaultRowFormat( i ); + if(rl->isHide()) + list.append(rl->row()); + } +} + +void KSpreadUndoShowRow::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->hideRow(0,-1,listRow); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoShowRow::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->showRow(0,-1,listRow); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoShowColumn + * + ***************************************************************************/ + +KSpreadUndoShowColumn::KSpreadUndoShowColumn( KSpreadDoc *_doc, KSpreadSheet *_table, int _column, int _nbCol,QValueList_listCol ) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Show Columns"); + + m_tableName = _table->tableName(); + m_iColumn= _column; + m_iNbCol=_nbCol; + if(m_iNbCol!=-1) + createList( listCol ,_table ); + else + listCol=QValueList(_listCol); +} + +KSpreadUndoShowColumn::~KSpreadUndoShowColumn() +{ +} + +void KSpreadUndoShowColumn::createList( QValueList&list,KSpreadSheet *tab ) +{ +ColumnFormat *cl; +for(int i=m_iColumn;i<=(m_iColumn+m_iNbCol);i++) + { + cl= tab->nonDefaultColumnFormat( i ); + if(cl->isHide()) + list.append(cl->column()); + } + +} + +void KSpreadUndoShowColumn::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->hideColumn( 0,-1,listCol ); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoShowColumn::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->showColumn(0,-1,listCol); + doc()->undoBuffer()->unlock(); +} + + +/**************************************************************************** + * + * KSpreadUndoPaperLayout + * + ***************************************************************************/ + +KSpreadUndoPaperLayout::KSpreadUndoPaperLayout( KSpreadDoc *_doc, KSpreadSheet *_table ) + : KSpreadUndoAction( _doc ) +{ + name=i18n("Set Page Layout"); + m_tableName = _table->tableName(); + + m_pl = _table->print()->paperLayout(); + m_hf = _table->print()->headFootLine(); + m_unit = doc()->getUnit(); + m_printGrid = _table->print()->printGrid(); + m_printCommentIndicator = _table->print()->printCommentIndicator(); + m_printFormulaIndicator = _table->print()->printFormulaIndicator(); + m_printRange = _table->print()->printRange(); + m_printRepeatColumns = _table->print()->printRepeatColumns(); + m_printRepeatRows = _table->print()->printRepeatRows(); + m_dZoom = _table->print()->zoom(); + m_iPageLimitX = _table->print()->pageLimitX(); + m_iPageLimitY = _table->print()->pageLimitY(); +} + +KSpreadUndoPaperLayout::~KSpreadUndoPaperLayout() +{ +} + +void KSpreadUndoPaperLayout::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + KSpreadSheetPrint* print = table->print(); + + doc()->undoBuffer()->lock(); + + m_plRedo = print->paperLayout(); + print->setPaperLayout( m_pl.ptLeft, m_pl.ptTop, + m_pl.ptRight, m_pl.ptBottom, + m_pl.format, m_pl.orientation ); + + m_hfRedo = print->headFootLine(); + print->setHeadFootLine( m_hf.headLeft, m_hf.headMid, m_hf.headRight, + m_hf.footLeft, m_hf.footMid, m_hf.footRight ); + + m_unitRedo = doc()->getUnit(); + doc()->setUnit( m_unit ); + + m_printGridRedo = print->printGrid(); + print->setPrintGrid( m_printGrid ); + + m_printCommentIndicatorRedo = print->printCommentIndicator(); + print->setPrintCommentIndicator( m_printCommentIndicator ); + + m_printFormulaIndicatorRedo = print->printFormulaIndicator(); + print->setPrintFormulaIndicator( m_printFormulaIndicator ); + + m_printRangeRedo = print->printRange(); + print->setPrintRange( m_printRange ); + + m_printRepeatColumnsRedo = print->printRepeatColumns(); + print->setPrintRepeatColumns( m_printRepeatColumns ); + + m_printRepeatRowsRedo = print->printRepeatRows(); + print->setPrintRepeatRows( m_printRepeatRows ); + + m_dZoomRedo = print->zoom(); + print->setZoom( m_dZoom ); + + m_iPageLimitXRedo = print->pageLimitX(); + print->setPageLimitX( m_iPageLimitX ); + + m_iPageLimitYRedo = print->pageLimitY(); + print->setPageLimitY( m_iPageLimitY ); + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoPaperLayout::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + KSpreadSheetPrint* print = table->print(); + + doc()->undoBuffer()->lock(); + print->setPaperLayout( m_plRedo.ptLeft, m_plRedo.ptTop, + m_plRedo.ptRight, m_plRedo.ptBottom, + m_plRedo.format, m_plRedo.orientation ); + + print->setHeadFootLine( m_hfRedo.headLeft, m_hfRedo.headMid, m_hfRedo.headRight, + m_hfRedo.footLeft, m_hfRedo.footMid, m_hfRedo.footRight ); + + doc()->setUnit( m_unitRedo ); + + print->setPrintGrid( m_printGridRedo ); + print->setPrintCommentIndicator( m_printCommentIndicatorRedo ); + print->setPrintFormulaIndicator( m_printFormulaIndicatorRedo ); + + print->setPrintRange( m_printRangeRedo ); + print->setPrintRepeatColumns( m_printRepeatColumnsRedo ); + print->setPrintRepeatRows( m_printRepeatRowsRedo ); + + print->setZoom( m_dZoomRedo ); + + print->setPageLimitX( m_iPageLimitX ); + print->setPageLimitY( m_iPageLimitY ); + + doc()->undoBuffer()->unlock(); +} + + +/**************************************************************************** + * + * KSpreadUndoDefinePrintRange + * + ***************************************************************************/ + +KSpreadUndoDefinePrintRange::KSpreadUndoDefinePrintRange( KSpreadDoc *_doc, KSpreadSheet *_table ) + : KSpreadUndoAction( _doc ) +{ + name=i18n("Set Page Layout"); + m_tableName = _table->tableName(); + + m_printRange = _table->print()->printRange(); +} + +KSpreadUndoDefinePrintRange::~KSpreadUndoDefinePrintRange() +{ +} + +void KSpreadUndoDefinePrintRange::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + m_printRangeRedo = table->print()->printRange(); + table->print()->setPrintRange( m_printRange ); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoDefinePrintRange::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->print()->setPrintRange( m_printRangeRedo ); + doc()->undoBuffer()->unlock(); +} + + +/**************************************************************************** + * + * KSpreadUndoSetText + * + ***************************************************************************/ + +KSpreadUndoSetText::KSpreadUndoSetText( KSpreadDoc *_doc, KSpreadSheet *_table, const QString& _text, int _column, int _row,KSpreadCell::FormatType _formatType ) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Change Text"); + + m_strText = _text; + m_iColumn= _column; + m_iRow = _row; + m_tableName = _table->tableName(); + m_eFormatType=_formatType; +} + +KSpreadUndoSetText::~KSpreadUndoSetText() +{ +} + +void KSpreadUndoSetText::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + KSpreadCell *cell = table->nonDefaultCell( m_iColumn, m_iRow ); + m_strRedoText = cell->text(); + m_eFormatTypeRedo=cell->getFormatType( m_iColumn, m_iRow ); + cell->setFormatType(m_eFormatType); + + if ( m_strText.isNull() ) + cell->setCellText( "" ); + else + cell->setCellText( m_strText ); + table->updateView( QRect( m_iColumn, m_iRow, 1, 1 ) ); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoSetText::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + KSpreadCell *cell = table->nonDefaultCell( m_iColumn, m_iRow ); + m_strText = cell->text(); + m_eFormatType=cell->getFormatType( m_iColumn, m_iRow ); + if ( m_strRedoText.isNull() ) + cell->setCellText( "" ); + else + cell->setCellText( m_strRedoText ); + cell->setFormatType(m_eFormatTypeRedo); + table->updateView( QRect( m_iColumn, m_iRow, 1, 1 ) ); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoSetTableName + * + ***************************************************************************/ + +KSpreadUndoSetTableName::KSpreadUndoSetTableName( KSpreadDoc *doc, KSpreadSheet *table, const QString& _name ) : + KSpreadUndoAction( doc ) +{ + name=i18n("Change Table Name"); + + m_name = _name; + m_tableName = table->tableName(); +} + +KSpreadUndoSetTableName::~KSpreadUndoSetTableName() +{ +} + +void KSpreadUndoSetTableName::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + + m_redoName = table->tableName(); + + table->setTableName( m_name,false,false ); + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoSetTableName::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_name ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + + table->setTableName( m_redoName,false,false ); + + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoCellFormat + * + ***************************************************************************/ + +KSpreadUndoCellFormat::KSpreadUndoCellFormat( KSpreadDoc * _doc, + KSpreadSheet * _table, + const QRect & _selection, + const QString & _name ) : + KSpreadUndoAction( _doc ) +{ + if ( _name.isEmpty()) + name = i18n("Change Format"); + else + name = _name; + + m_rctRect = _selection; + m_tableName = _table->tableName(); + copyFormat( m_lstFormats, m_lstColFormats, m_lstRowFormats, _table ); +} + +void KSpreadUndoCellFormat::copyFormat(QValueList & list, + QValueList & listCol, + QValueList & listRow, + KSpreadSheet * table ) +{ + QValueList::Iterator it2; + for ( it2 = list.begin(); it2 != list.end(); ++it2 ) + { + delete (*it2).l; + } + list.clear(); + + KSpreadCell * cell; + int bottom = m_rctRect.bottom(); + int right = m_rctRect.right(); + + if ( util_isColumnSelected( m_rctRect ) ) + { + /* Don't need to go through the loop twice... + for (int i = m_rctRect.left(); i <= right; ++i) + { + layoutColumn tmplayout; + tmplayout.col = i; + tmplayout.l = new ColumnFormat( table, i ); + tmplayout.l->copy( *(table->columnFormat( i )) ); + listCol.append(tmplayout); + } + */ + for ( int c = m_rctRect.left(); c <= right; ++c ) + { + layoutColumn tmplayout; + tmplayout.col = c; + tmplayout.l = new ColumnFormat( table, c ); + tmplayout.l->copy( *(table->columnFormat( c )) ); + listCol.append(tmplayout); + + cell = table->getFirstCellColumn( c ); + while ( cell ) + { + if ( cell->isObscuringForced() ) + { + cell = table->getNextCellDown( c, cell->row() ); + continue; + } + + layoutCell tmplayout; + tmplayout.col = c; + tmplayout.row = cell->row(); + tmplayout.l = new KSpreadFormat( table, 0 ); + tmplayout.l->copy( *(table->cellAt( tmplayout.col, tmplayout.row )) ); + list.append(tmplayout); + + cell = table->getNextCellDown( c, cell->row() ); + } + } + /* + KSpreadCell * c = table->firstCell(); + for( ; c; c = c->nextCell() ) + { + int col = c->column(); + if ( m_rctRect.left() <= col && right >= col + && !c->isObscuringForced()) + { + layoutCell tmplayout; + tmplayout.col = c->column(); + tmplayout.row = c->row(); + tmplayout.l = new KSpreadFormat( table, 0 ); + tmplayout.l->copy( *(table->cellAt( tmplayout.col, tmplayout.row )) ); + list.append(tmplayout); + } + } + */ + } + else if (util_isRowSelected( m_rctRect ) ) + { + for ( int row = m_rctRect.top(); row <= bottom; ++row ) + { + layoutRow tmplayout; + tmplayout.row = row; + tmplayout.l = new RowFormat( table, row ); + tmplayout.l->copy( *(table->rowFormat( row )) ); + listRow.append(tmplayout); + + cell = table->getFirstCellRow( row ); + while ( cell ) + { + if ( cell->isObscuringForced() ) + { + cell = table->getNextCellRight( cell->column(), row ); + continue; + } + layoutCell tmplayout; + tmplayout.col = cell->column(); + tmplayout.row = row; + tmplayout.l = new KSpreadFormat( table, 0 ); + tmplayout.l->copy( *(table->cellAt( cell->column(), row )) ); + list.append(tmplayout); + + cell = table->getNextCellRight( cell->column(), row ); + } + } + /* + KSpreadCell * c = table->firstCell(); + for( ; c; c = c->nextCell() ) + { + int row = c->row(); + if ( m_rctRect.top() <= row && bottom >= row + && !c->isObscuringForced()) + { + layoutCell tmplayout; + tmplayout.col = c->column(); + tmplayout.row = c->row(); + tmplayout.l = new KSpreadFormat( table, 0 ); + tmplayout.l->copy( *(table->cellAt( tmplayout.col, tmplayout.row )) ); + list.append(tmplayout); + } + } + */ + } + else + { + for ( int y = m_rctRect.top(); y <= bottom; ++y ) + for ( int x = m_rctRect.left(); x <= right; ++x ) + { + KSpreadCell * cell = table->nonDefaultCell( x, y ); + if ( !cell->isObscuringForced() ) + { + layoutCell tmplayout; + tmplayout.col = x; + tmplayout.row = y; + tmplayout.l = new KSpreadFormat( table, 0 ); + tmplayout.l->copy( *(table->cellAt( x, y )) ); + list.append(tmplayout); + } + } + } +} + +KSpreadUndoCellFormat::~KSpreadUndoCellFormat() +{ + QValueList::Iterator it2; + for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 ) + { + delete (*it2).l; + } + m_lstFormats.clear(); + + for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 ) + { + delete (*it2).l; + } + m_lstRedoFormats.clear(); + + QValueList::Iterator it3; + for ( it3 = m_lstColFormats.begin(); it3 != m_lstColFormats.end(); ++it3 ) + { + delete (*it3).l; + } + m_lstColFormats.clear(); + + for ( it3 = m_lstRedoColFormats.begin(); it3 != m_lstRedoColFormats.end(); ++it3 ) + { + delete (*it3).l; + } + m_lstRedoColFormats.clear(); + + QValueList::Iterator it4; + for ( it4 = m_lstRowFormats.begin(); it4 != m_lstRowFormats.end(); ++it4 ) + { + delete (*it4).l; + } + m_lstRowFormats.clear(); + + for ( it4 = m_lstRedoRowFormats.begin(); it4 != m_lstRedoRowFormats.end(); ++it4 ) + { + delete (*it4).l; + } + m_lstRedoRowFormats.clear(); + + +} + +void KSpreadUndoCellFormat::undo() +{ + KSpreadSheet * table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + copyFormat( m_lstRedoFormats, m_lstRedoColFormats, m_lstRedoRowFormats, table ); + if( util_isColumnSelected( m_rctRect ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstColFormats.begin(); it2 != m_lstColFormats.end(); ++it2 ) + { + ColumnFormat * col = table->nonDefaultColumnFormat( (*it2).col ); + col->copy( *(*it2).l ); + } + } + else if( util_isRowSelected( m_rctRect ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstRowFormats.begin(); it2 != m_lstRowFormats.end(); ++it2 ) + { + RowFormat * row = table->nonDefaultRowFormat( (*it2).row ); + row->copy( *(*it2).l ); + } + } + + QValueList::Iterator it2; + for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 ) + { + KSpreadCell *cell = table->nonDefaultCell( (*it2).col,(*it2).row ); + cell->copy( *(*it2).l ); + cell->setLayoutDirtyFlag(); + cell->setDisplayDirtyFlag(); + table->updateCell( cell, (*it2).col, (*it2).row ); + } + + table->setRegionPaintDirty( m_rctRect ); + table->updateView( m_rctRect ); + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoCellFormat::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + if ( util_isColumnSelected( m_rctRect ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoColFormats.begin(); it2 != m_lstRedoColFormats.end(); ++it2 ) + { + ColumnFormat * col = table->nonDefaultColumnFormat( (*it2).col ); + col->copy( *(*it2).l ); + } + } + else if( util_isRowSelected( m_rctRect ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoRowFormats.begin(); it2 != m_lstRedoRowFormats.end(); ++it2 ) + { + RowFormat * row = table->nonDefaultRowFormat( (*it2).row ); + row->copy( *(*it2).l ); + } + } + + QValueList::Iterator it2; + for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 ) + { + KSpreadCell * cell = table->nonDefaultCell( (*it2).col,(*it2).row ); + cell->copy( *(*it2).l ); + cell->setLayoutDirtyFlag(); + cell->setDisplayDirtyFlag(); + table->updateCell( cell, (*it2).col, (*it2).row ); + } + + table->setRegionPaintDirty( m_rctRect ); + table->updateView( m_rctRect ); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoChangeAngle + * + ***************************************************************************/ + +KSpreadUndoChangeAngle::KSpreadUndoChangeAngle( KSpreadDoc * _doc, + KSpreadSheet * _table, + const QRect & _selection ) : + KSpreadUndoAction( _doc ) +{ + name = i18n("Change Angle"); + m_layoutUndo = new KSpreadUndoCellFormat( _doc, _table, _selection, QString::null ); + m_resizeUndo = new KSpreadUndoResizeColRow( _doc, _table, _selection ); +} + +KSpreadUndoChangeAngle::~KSpreadUndoChangeAngle() +{ + delete m_resizeUndo; + delete m_layoutUndo; +} + +void KSpreadUndoChangeAngle::undo() +{ + m_layoutUndo->undo(); + m_resizeUndo->undo(); +} + +void KSpreadUndoChangeAngle::redo() +{ + m_layoutUndo->redo(); + m_resizeUndo->redo(); +} + +/**************************************************************************** + * + * KSpreadUndoSort + * + ***************************************************************************/ + +KSpreadUndoSort::KSpreadUndoSort( KSpreadDoc * _doc, KSpreadSheet * _table, const QRect & _selection ) : + KSpreadUndoAction( _doc ) +{ + name = i18n("Sort"); + + m_rctRect = _selection; + m_tableName = _table->tableName(); + copyAll( m_lstFormats, m_lstColFormats, m_lstRowFormats, _table ); +} + +void KSpreadUndoSort::copyAll(QValueList & list, QValueList & listCol, + QValueList & listRow, KSpreadSheet * table ) +{ + QValueList::Iterator it2; + for ( it2 = list.begin(); it2 != list.end(); ++it2 ) + { + delete (*it2).l; + } + list.clear(); + + if ( util_isColumnSelected( m_rctRect ) ) + { + KSpreadCell * c; + for (int col = m_rctRect.left(); col <= m_rctRect.right(); ++col) + { + layoutColumn tmplayout; + tmplayout.col = col; + tmplayout.l = new ColumnFormat( table, col ); + tmplayout.l->copy( *(table->columnFormat( col )) ); + listCol.append(tmplayout); + + c = table->getFirstCellColumn( col ); + while ( c ) + { + if ( !c->isObscuringForced() ) + { + layoutTextCell tmplayout; + tmplayout.col = col; + tmplayout.row = c->row(); + tmplayout.l = new KSpreadFormat( table, 0 ); + tmplayout.l->copy( *(table->cellAt( tmplayout.col, tmplayout.row )) ); + tmplayout.text = c->text(); + list.append(tmplayout); + } + + c = table->getNextCellDown( col, c->row() ); + } + } + } + else if ( util_isRowSelected( m_rctRect ) ) + { + KSpreadCell * c; + for ( int row = m_rctRect.top(); row <= m_rctRect.bottom(); ++row) + { + layoutRow tmplayout; + tmplayout.row = row; + tmplayout.l = new RowFormat( table, row ); + tmplayout.l->copy( *(table->rowFormat( row )) ); + listRow.append(tmplayout); + + c = table->getFirstCellRow( row ); + while ( c ) + { + if ( !c->isObscuringForced() ) + { + layoutTextCell tmplayout; + tmplayout.col = c->column(); + tmplayout.row = row; + tmplayout.l = new KSpreadFormat( table, 0 ); + tmplayout.l->copy( *(table->cellAt( tmplayout.col, tmplayout.row )) ); + tmplayout.text = c->text(); + list.append(tmplayout); + } + c = table->getNextCellRight( c->column(), row ); + } + } + } + else + { + int bottom = m_rctRect.bottom(); + int right = m_rctRect.right(); + KSpreadCell * cell; + for ( int y = m_rctRect.top(); y <= bottom; ++y ) + for ( int x = m_rctRect.left(); x <= right; ++x ) + { + cell = table->nonDefaultCell( x, y ); + if (!cell->isObscuringForced()) + { + layoutTextCell tmplayout; + tmplayout.col = x; + tmplayout.row = y; + tmplayout.l = new KSpreadFormat( table, 0 ); + tmplayout.l->copy( *(table->cellAt( x, y )) ); + tmplayout.text = cell->text(); + list.append(tmplayout); + } + } + } +} + +KSpreadUndoSort::~KSpreadUndoSort() +{ + QValueList::Iterator it2; + for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 ) + { + delete (*it2).l; + } + m_lstFormats.clear(); + + for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 ) + { + delete (*it2).l; + } + m_lstRedoFormats.clear(); + + QValueList::Iterator it3; + for ( it3 = m_lstColFormats.begin(); it3 != m_lstColFormats.end(); ++it3 ) + { + delete (*it3).l; + } + m_lstColFormats.clear(); + + for ( it3 = m_lstRedoColFormats.begin(); it3 != m_lstRedoColFormats.end(); ++it3 ) + { + delete (*it3).l; + } + m_lstRedoColFormats.clear(); + + QValueList::Iterator it4; + for ( it4 = m_lstRowFormats.begin(); it4 != m_lstRowFormats.end(); ++it4 ) + { + delete (*it4).l; + } + m_lstRowFormats.clear(); + + for ( it4 = m_lstRedoRowFormats.begin(); it4 != m_lstRedoRowFormats.end(); ++it4 ) + { + delete (*it4).l; + } + m_lstRedoRowFormats.clear(); + +} + +void KSpreadUndoSort::undo() +{ + KSpreadSheet * table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + copyAll( m_lstRedoFormats, m_lstRedoColFormats, + m_lstRedoRowFormats, table ); + + if ( util_isColumnSelected( m_rctRect ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstColFormats.begin(); it2 != m_lstColFormats.end(); ++it2 ) + { + ColumnFormat * col = table->nonDefaultColumnFormat( (*it2).col ); + col->copy( *(*it2).l ); + } + } + else if( util_isRowSelected( m_rctRect ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstRowFormats.begin(); it2 != m_lstRowFormats.end(); ++it2 ) + { + RowFormat *row= table->nonDefaultRowFormat( (*it2).row ); + row->copy( *(*it2).l ); + } + } + + QValueList::Iterator it2; + for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 ) + { + KSpreadCell *cell = table->nonDefaultCell( (*it2).col,(*it2).row ); + if ( (*it2).text.isEmpty() ) + { + if(!cell->text().isEmpty()) + cell->setCellText( "" ); + } + else + cell->setCellText( (*it2).text ); + + cell->copy( *(*it2).l ); + cell->setLayoutDirtyFlag(); + cell->setDisplayDirtyFlag(); + table->updateCell( cell, (*it2).col, (*it2).row ); + } + + table->setRegionPaintDirty(m_rctRect); + table->updateView( m_rctRect ); + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoSort::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + if( util_isColumnSelected( m_rctRect ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoColFormats.begin(); it2 != m_lstRedoColFormats.end(); ++it2 ) + { + ColumnFormat *col= table->nonDefaultColumnFormat( (*it2).col ); + col->copy( *(*it2).l ); + } + } + else if( util_isRowSelected( m_rctRect ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoRowFormats.begin(); it2 != m_lstRedoRowFormats.end(); ++it2 ) + { + RowFormat *row= table->nonDefaultRowFormat( (*it2).row ); + row->copy( *(*it2).l ); + } + } + + QValueList::Iterator it2; + for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 ) + { + KSpreadCell *cell = table->nonDefaultCell( (*it2).col,(*it2).row ); + + if ( (*it2).text.isEmpty() ) + { + if(!cell->text().isEmpty()) + cell->setCellText( "" ); + } + else + cell->setCellText( (*it2).text ); + + cell->copy( *(*it2).l ); + cell->setLayoutDirtyFlag(); + cell->setDisplayDirtyFlag(); + table->updateCell( cell, (*it2).col, (*it2).row ); + } + table->setRegionPaintDirty(m_rctRect); + table->updateView( m_rctRect ); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoDelete + * + ***************************************************************************/ + +KSpreadUndoDelete::KSpreadUndoDelete( KSpreadDoc *_doc, KSpreadSheet* table, const QRect & _selection) + : KSpreadUndoAction( _doc ) +{ + name=i18n("Delete"); + m_tableName = table->tableName(); + m_selection = _selection; + createListCell( m_data, m_lstColumn,m_lstRow,table ); + +} + +KSpreadUndoDelete::~KSpreadUndoDelete() +{ +} + +void KSpreadUndoDelete::createListCell( QCString &listCell,QValueList &listCol,QValueList &listRow, KSpreadSheet* table ) +{ + listRow.clear(); + listCol.clear(); + //copy a column(s) + if( util_isColumnSelected( m_selection ) ) + { + for( int y = m_selection.left() ; y <= m_selection.right() ; ++y ) + { + ColumnFormat * cl = table->columnFormat( y ); + if ( !cl->isDefault() ) + { + columnSize tmpSize; + tmpSize.columnNumber=y; + tmpSize.columnWidth=cl->dblWidth(); + listCol.append(tmpSize); + } + } + } + //copy a row(s) + else if( util_isRowSelected( m_selection ) ) + { + //save size of row(s) + for( int y =m_selection.top() ; y <=m_selection.bottom() ; ++y ) + { + RowFormat *rw=table->rowFormat(y); + if(!rw->isDefault()) + { + rowSize tmpSize; + tmpSize.rowNumber=y; + tmpSize.rowHeight=rw->dblHeight(); + listRow.append(tmpSize); + } + } + + } + + //save all cells in area + QDomDocument doc = table->saveCellRect( m_selection ); + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + listCell = buffer.utf8(); + int len = listCell.length(); + char tmp = listCell[ len - 1 ]; + listCell.resize( len ); + *( listCell.data() + len - 1 ) = tmp; + +} + + +void KSpreadUndoDelete::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + createListCell( m_dataRedo, m_lstRedoColumn,m_lstRedoRow,table ); + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + if( util_isColumnSelected( m_selection ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 ) + { + ColumnFormat *cl=table->nonDefaultColumnFormat((*it2).columnNumber); + cl->setDblWidth((*it2).columnWidth); + } + } + else if( util_isRowSelected( m_selection ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 ) + { + RowFormat *rw=table->nonDefaultRowFormat((*it2).rowNumber); + rw->setDblHeight((*it2).rowHeight); + } + } + + table->deleteCells( m_selection ); + table->paste( m_data, m_selection ); + table->updateView( ); + + if(table->getAutoCalc()) table->recalc(); + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoDelete::redo() +{ + + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + if( util_isColumnSelected( m_selection ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 ) + { + ColumnFormat *cl=table->nonDefaultColumnFormat((*it2).columnNumber); + cl->setDblWidth((*it2).columnWidth); + } + } + else if( util_isRowSelected( m_selection ) ) + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 ) + { + RowFormat *rw=table->nonDefaultRowFormat((*it2).rowNumber); + rw->setDblHeight((*it2).rowHeight); + } + } + + //move next line to refreshView + //because I must know what is the real rect + //that I must refresh, when there is cell Merged + + table->paste( m_dataRedo, m_selection ); + //table->deleteCells( m_selection ); + table->updateView(); + table->refreshView( m_selection ); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoDragDrop + * + ***************************************************************************/ + +KSpreadUndoDragDrop::KSpreadUndoDragDrop( KSpreadDoc * _doc, KSpreadSheet * _table, const QRect & _source, + const QRect & _target ) + : KSpreadUndoAction( _doc ), + m_selectionSource( _source ), + m_selectionTarget( _target ) +{ + name = i18n( "Drag & Drop" ); + + m_tableName = _table->tableName(); + + saveCellRect( m_dataTarget, _table, _target ); + if ( _source.left() > 0 ) + saveCellRect( m_dataSource, _table, _source ); +} + +KSpreadUndoDragDrop::~KSpreadUndoDragDrop() +{ +} + +void KSpreadUndoDragDrop::saveCellRect( QCString & cells, KSpreadSheet * table, + QRect const & rect ) +{ + QDomDocument doc = table->saveCellRect( rect ); + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + cells = buffer.utf8(); + int len = cells.length(); + char tmp = cells[ len - 1 ]; + cells.resize( len ); + *( cells.data() + len - 1 ) = tmp; +} + +void KSpreadUndoDragDrop::undo() +{ + KSpreadSheet * table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + if ( m_selectionSource.left() > 0 ) + saveCellRect( m_dataRedoSource, table, m_selectionSource ); + saveCellRect( m_dataRedoTarget, table, m_selectionTarget ); + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + table->deleteCells( m_selectionTarget ); + table->paste( m_dataTarget, m_selectionTarget ); + + if ( m_selectionSource.left() > 0 ) + { + table->deleteCells( m_selectionSource ); + table->paste( m_dataSource, m_selectionSource ); + } + + table->updateView(); + + if ( table->getAutoCalc() ) + table->recalc(); + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoDragDrop::redo() +{ + KSpreadSheet * table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + //move next line to refreshView + //because I must know what is the real rect + //that I must refresh, when there is cell Merged + + table->paste( m_dataRedoTarget, m_selectionTarget ); + if ( m_selectionSource.left() > 0 ) + table->paste( m_dataRedoSource, m_selectionSource ); + + table->updateView(); + table->refreshView( m_selectionSource ); + table->refreshView( m_selectionTarget ); + doc()->undoBuffer()->unlock(); +} + + +/**************************************************************************** + * + * KSpreadUndoResizeColRow + * + ***************************************************************************/ + + +KSpreadUndoResizeColRow::KSpreadUndoResizeColRow( KSpreadDoc *_doc, KSpreadSheet *_table, const QRect &_selection ) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Resize"); + m_rctRect = _selection; + m_tableName = _table->tableName(); + + createList( m_lstColumn,m_lstRow, _table ); +} + +void KSpreadUndoResizeColRow::createList( QValueList &listCol,QValueList &listRow, KSpreadSheet* table ) +{ + listCol.clear(); + listRow.clear(); + + if( util_isColumnSelected( m_rctRect ) ) // entire column(s) + { + for( int y = m_rctRect.left(); y <= m_rctRect.right(); y++ ) + { + ColumnFormat *cl=table->columnFormat(y); + if(!cl->isHide()) + { + columnSize tmpSize; + tmpSize.columnNumber=y; + tmpSize.columnWidth=cl->dblWidth(); + listCol.append(tmpSize); + } + } + } + else if( util_isRowSelected( m_rctRect ) ) // entire row(s) + { + for( int y = m_rctRect.top(); y <= m_rctRect.bottom(); y++ ) + { + RowFormat *rw=table->rowFormat(y); + if(!rw->isHide()) + { + rowSize tmpSize; + tmpSize.rowNumber=y; + tmpSize.rowHeight=rw->dblHeight(); + listRow.append(tmpSize); + } + } + } + else //row and column + { + for( int y = m_rctRect.left(); y <= m_rctRect.right(); y++ ) + { + ColumnFormat *cl=table->columnFormat(y); + if(!cl->isHide()) + { + columnSize tmpSize; + tmpSize.columnNumber=y; + tmpSize.columnWidth=cl->dblWidth(); + listCol.append(tmpSize); + } + } + for( int y = m_rctRect.top(); y <= m_rctRect.bottom(); y++ ) + { + RowFormat *rw=table->rowFormat(y); + if(!rw->isHide()) + { + rowSize tmpSize; + tmpSize.rowNumber=y; + tmpSize.rowHeight=rw->dblHeight(); + listRow.append(tmpSize); + } + } + + } +} + +KSpreadUndoResizeColRow::~KSpreadUndoResizeColRow() +{ +} + +void KSpreadUndoResizeColRow::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + + createList( m_lstRedoColumn,m_lstRedoRow, table ); + + if( util_isColumnSelected( m_rctRect ) ) // complete column(s) + { + QValueList::Iterator it2; + for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 ) + { + ColumnFormat *cl=table->columnFormat((*it2).columnNumber); + cl->setDblWidth((*it2).columnWidth); + } + } + else if( util_isRowSelected( m_rctRect ) ) // complete row(s) + { + QValueList::Iterator it2; + for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 ) + { + RowFormat *rw=table->rowFormat((*it2).rowNumber); + rw->setDblHeight((*it2).rowHeight); + } + } + else // row and column + { + QValueList::Iterator it2; + for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 ) + { + ColumnFormat *cl=table->columnFormat((*it2).columnNumber); + cl->setDblWidth((*it2).columnWidth); + } + QValueList::Iterator it1; + for ( it1 = m_lstRow.begin(); it1 != m_lstRow.end(); ++it1 ) + { + RowFormat *rw=table->rowFormat((*it1).rowNumber); + rw->setDblHeight((*it1).rowHeight); + } + } + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoResizeColRow::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + if( util_isColumnSelected( m_rctRect ) ) // complete column(s) + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 ) + { + ColumnFormat *cl=table->columnFormat((*it2).columnNumber); + cl->setDblWidth((*it2).columnWidth); + } + } + else if( util_isRowSelected( m_rctRect ) ) // complete row(s) + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 ) + { + RowFormat *rw=table->rowFormat((*it2).rowNumber); + rw->setDblHeight((*it2).rowHeight); + } + } + else // row and column + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 ) + { + ColumnFormat *cl=table->columnFormat((*it2).columnNumber); + cl->setDblWidth((*it2).columnWidth); + } + QValueList::Iterator it1; + for ( it1 = m_lstRedoRow.begin(); it1 != m_lstRedoRow.end(); ++it1 ) + { + RowFormat *rw=table->rowFormat((*it1).rowNumber); + rw->setDblHeight((*it1).rowHeight); + } + } + + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoChangeAreaTextCell + * + ***************************************************************************/ + + +KSpreadUndoChangeAreaTextCell::KSpreadUndoChangeAreaTextCell( KSpreadDoc *_doc, KSpreadSheet *_table, const QRect &_selection ) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Change Text"); + + m_rctRect = _selection; + m_tableName = _table->tableName(); + + createList( m_lstTextCell, _table ); +} + +void KSpreadUndoChangeAreaTextCell::createList( QValueList &list, KSpreadSheet* table ) +{ + int bottom = m_rctRect.bottom(); + int right = m_rctRect.right(); + list.clear(); + + if( util_isColumnSelected( m_rctRect ) ) + { + KSpreadCell * c; + for ( int col = m_rctRect.left(); col <= right; ++col ) + { + c = table->getFirstCellColumn( col ); + while ( c ) + { + if ( !c->isObscuringForced() ) + { + textOfCell tmpText; + tmpText.col = col; + tmpText.row = c->row(); + tmpText.text = c->text(); + list.append(tmpText); + } + c = table->getNextCellDown( col, c->row() ); + } + } + } + else if ( util_isRowSelected( m_rctRect ) ) + { + KSpreadCell * c; + for ( int row = m_rctRect.top(); row <= bottom; ++row ) + { + c = table->getFirstCellRow( row ); + while ( c ) + { + if ( !c->isObscuringForced() ) + { + textOfCell tmpText; + tmpText.col = c->column(); + tmpText.row = row; + tmpText.text = c->text(); + list.append(tmpText); + } + c = table->getNextCellRight( c->column(), row ); + } + } + } + else + { + KSpreadCell * cell; + for ( int x = m_rctRect.left(); x <= right; ++x ) + { + cell = table->getFirstCellColumn( x ); + if ( !cell ) + continue; + while ( cell && cell->row() <= bottom ) + { + if ( !cell->isObscured() ) + { + textOfCell tmpText; + tmpText.col = x; + tmpText.row = cell->row(); + tmpText.text = cell->text(); + list.append( tmpText ); + } + cell = table->getNextCellDown( x, cell->row() ); + } + } + } +} + +KSpreadUndoChangeAreaTextCell::~KSpreadUndoChangeAreaTextCell() +{ +} + +void KSpreadUndoChangeAreaTextCell::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + createList( m_lstRedoTextCell, table ); + + + if ( !util_isRowSelected( m_rctRect ) + && !util_isColumnSelected( m_rctRect ) ) + { + for ( int x = m_rctRect.left(); x <= m_rctRect.right(); ++x ) + for ( int y = m_rctRect.top(); y <= m_rctRect.bottom(); ++y ) + { + KSpreadCell* cell = table->nonDefaultCell( x, y ); + bool found = false; + QValueList::Iterator it; + for( it = m_lstTextCell.begin(); it != m_lstTextCell.end(); ++it ) + if ( (*it).col == x && (*it).row == y && !found ) + { + cell->setCellText( (*it).text ); + found = true; + } + if( !found ) + cell->setCellText( "", true, true ); + } + + } + else + { + QValueList::Iterator it2; + for ( it2 = m_lstTextCell.begin(); it2 != m_lstTextCell.end(); ++it2 ) + { + KSpreadCell *cell = table->nonDefaultCell( (*it2).col, (*it2).row ); + if ( (*it2).text.isEmpty() ) + { + if ( !cell->text().isEmpty() ) + cell->setCellText( "" ); + } + else + cell->setCellText( (*it2).text ); + } + } + + table->updateView(); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoChangeAreaTextCell::redo() +{ + KSpreadSheet * table = doc()->map()->findTable( m_tableName ); + + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + if ( !util_isRowSelected( m_rctRect ) + && !util_isColumnSelected( m_rctRect ) ) + { + for ( int x = m_rctRect.left(); x <= m_rctRect.right(); ++x ) + for ( int y = m_rctRect.top(); y <= m_rctRect.bottom(); ++y ) + { + KSpreadCell* cell = table->nonDefaultCell( x, y ); + bool found = false; + QValueList::Iterator it; + for( it = m_lstRedoTextCell.begin(); it != m_lstRedoTextCell.end(); ++it ) + if ( (*it).col == x && (*it).row == y && !found ) + { + cell->setCellText( (*it).text ); + found = true; + } + if( !found ) + cell->setCellText( "", true, true ); + } + + } + else + { + QValueList::Iterator it2; + for ( it2 = m_lstRedoTextCell.begin(); it2 != m_lstRedoTextCell.end(); ++it2 ) + { + KSpreadCell *cell = table->nonDefaultCell( (*it2).col, (*it2).row ); + if ( (*it2).text.isEmpty() ) + { + if ( !cell->text().isEmpty() ) + cell->setCellText( "" ); + } + else + cell->setCellText( (*it2).text ); + } + } + + table->updateView(); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoMergedCell + * + ***************************************************************************/ + + +KSpreadUndoMergedCell::KSpreadUndoMergedCell( KSpreadDoc *_doc, KSpreadSheet *_table, int _column, int _row , int _extraX,int _extraY) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Merge Cells"); + + m_tableName = _table->tableName(); + m_iRow=_row; + m_iCol=_column; + m_iExtraX=_extraX; + m_iExtraY=_extraY; + +} + +KSpreadUndoMergedCell::~KSpreadUndoMergedCell() +{ +} + +void KSpreadUndoMergedCell::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + + KSpreadCell *cell = table->nonDefaultCell( m_iCol, m_iRow ); + m_iExtraRedoX=cell->extraXCells(); + m_iExtraRedoY=cell->extraYCells(); + + table->changeMergedCell( m_iCol, m_iRow, m_iExtraX,m_iExtraY); + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoMergedCell::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + + table->changeMergedCell( m_iCol, m_iRow, m_iExtraRedoX,m_iExtraRedoY); + + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoAutofill + * + ***************************************************************************/ + +KSpreadUndoAutofill::KSpreadUndoAutofill( KSpreadDoc *_doc, KSpreadSheet* table, const QRect & _selection) + : KSpreadUndoAction( _doc ) +{ + name=i18n("Autofill"); + + m_tableName = table->tableName(); + m_selection = _selection; + createListCell( m_data, table ); + +} + +KSpreadUndoAutofill::~KSpreadUndoAutofill() +{ +} + +void KSpreadUndoAutofill::createListCell( QCString &list, KSpreadSheet* table ) +{ + QDomDocument doc = table->saveCellRect( m_selection ); + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + list = buffer.utf8(); + int len = list.length(); + char tmp = list[ len - 1 ]; + list.resize( len ); + *( list.data() + len - 1 ) = tmp; +} + +void KSpreadUndoAutofill::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + createListCell( m_dataRedo, table ); + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + table->deleteCells( m_selection ); + table->paste( m_data, m_selection ); + if(table->getAutoCalc()) table->recalc(); + + table->updateView(); + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoAutofill::redo() +{ + doc()->undoBuffer()->lock(); + + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->emitBeginOperation(); + + table->deleteCells( m_selection ); + doc()->undoBuffer()->lock(); + table->paste( m_dataRedo, m_selection ); + if ( table->getAutoCalc() ) + table->recalc(); + table->updateView(); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoInsertCellRow + * + ***************************************************************************/ + +KSpreadUndoInsertCellRow::KSpreadUndoInsertCellRow( KSpreadDoc *_doc, KSpreadSheet *_table, const QRect &_rect ) : + KSpreadUndoInsertRemoveAction( _doc ) +{ + name=i18n("Insert Cell"); + + m_tableName = _table->tableName(); + m_rect=_rect; +} + +KSpreadUndoInsertCellRow::~KSpreadUndoInsertCellRow() +{ +} + +void KSpreadUndoInsertCellRow::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->unshiftRow( m_rect); + doc()->undoBuffer()->unlock(); + + undoFormulaReference(); +} + +void KSpreadUndoInsertCellRow::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->shiftRow( m_rect); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoInsertCellCol + * + ***************************************************************************/ + + +KSpreadUndoInsertCellCol::KSpreadUndoInsertCellCol( KSpreadDoc *_doc, KSpreadSheet *_table, const QRect &_rect ) : + KSpreadUndoInsertRemoveAction( _doc ) +{ + name=i18n("Insert Cell"); + + m_tableName = _table->tableName(); + m_rect=_rect; +} + +KSpreadUndoInsertCellCol::~KSpreadUndoInsertCellCol() +{ +} + +void KSpreadUndoInsertCellCol::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->unshiftColumn( m_rect); + doc()->undoBuffer()->unlock(); + + undoFormulaReference(); +} + +void KSpreadUndoInsertCellCol::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->shiftColumn( m_rect ); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoRemoveCellRow + * + ***************************************************************************/ + +KSpreadUndoRemoveCellRow::KSpreadUndoRemoveCellRow( KSpreadDoc *_doc, KSpreadSheet *_table, const QRect &rect ) : + KSpreadUndoInsertRemoveAction( _doc ) +{ + name=i18n("Remove Cell"); + + m_tableName = _table->tableName(); + m_rect=rect; + QDomDocument doc = _table->saveCellRect( m_rect ); + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + m_data = buffer.utf8(); + int len = m_data.length(); + char tmp = m_data[ len - 1 ]; + m_data.resize( len ); + *( m_data.data() + len - 1 ) = tmp; +} + +KSpreadUndoRemoveCellRow::~KSpreadUndoRemoveCellRow() +{ +} + +void KSpreadUndoRemoveCellRow::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->shiftRow( m_rect ); + table->paste( m_data, m_rect ); + doc()->undoBuffer()->unlock(); + + undoFormulaReference(); +} + +void KSpreadUndoRemoveCellRow::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->unshiftRow( m_rect); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoRemoveCellCol + * + ***************************************************************************/ + +KSpreadUndoRemoveCellCol::KSpreadUndoRemoveCellCol( KSpreadDoc *_doc, KSpreadSheet *_table, const QRect &_rect ) : + KSpreadUndoInsertRemoveAction( _doc ) +{ + name=i18n("Remove Cell"); + + m_tableName = _table->tableName(); + m_rect=_rect; + QDomDocument doc = _table->saveCellRect( m_rect ); + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + m_data = buffer.utf8(); + int len = m_data.length(); + char tmp = m_data[ len - 1 ]; + m_data.resize( len ); + *( m_data.data() + len - 1 ) = tmp; +} + +KSpreadUndoRemoveCellCol::~KSpreadUndoRemoveCellCol() +{ +} + +void KSpreadUndoRemoveCellCol::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->shiftColumn( m_rect ); + table->paste( m_data, m_rect ); + doc()->undoBuffer()->unlock(); + + undoFormulaReference(); +} + +void KSpreadUndoRemoveCellCol::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->unshiftColumn( m_rect ); + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoConditional + * + ***************************************************************************/ + +KSpreadUndoConditional::KSpreadUndoConditional( KSpreadDoc *_doc, KSpreadSheet* table, QRect const & _selection) + : KSpreadUndoAction( _doc ) +{ + name=i18n("Conditional Cell Attribute"); + + m_tableName = table->tableName(); + m_selection = _selection; + createListCell( m_data, table ); + +} + +KSpreadUndoConditional::~KSpreadUndoConditional() +{ +} + +void KSpreadUndoConditional::createListCell( QCString &list, KSpreadSheet* table ) +{ + QDomDocument doc = table->saveCellRect( m_selection ); + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + list = buffer.utf8(); + int len = list.length(); + char tmp = list[ len - 1 ]; + list.resize( len ); + *( list.data() + len - 1 ) = tmp; +} + +void KSpreadUndoConditional::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + createListCell( m_dataRedo, table ); + + doc()->undoBuffer()->lock(); + table->paste( m_data, m_selection ); + if(table->getAutoCalc()) table->recalc(); + + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoConditional::redo() +{ + doc()->undoBuffer()->lock(); + + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->paste( m_dataRedo, m_selection ); + if(table->getAutoCalc()) table->recalc(); + + doc()->undoBuffer()->unlock(); +} + +/**************************************************************************** + * + * KSpreadUndoHideTable + * + ***************************************************************************/ + +KSpreadUndoHideTable::KSpreadUndoHideTable( KSpreadDoc *_doc, KSpreadSheet *_table) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Hide Table"); + + m_tableName = _table->tableName(); +} + +KSpreadUndoHideTable::~KSpreadUndoHideTable() +{ +} + +void KSpreadUndoHideTable::execute( bool b ) +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->hideTable(b); + doc()->undoBuffer()->unlock(); + +} +void KSpreadUndoHideTable::undo() +{ + execute( false ); +} + +void KSpreadUndoHideTable::redo() +{ + execute( true ); +} + +/**************************************************************************** + * + * KSpreadUndoShowTable + * + ***************************************************************************/ + + +KSpreadUndoShowTable::KSpreadUndoShowTable( KSpreadDoc *_doc, KSpreadSheet *_table) : + KSpreadUndoAction( _doc ) +{ + name=i18n("Show Table"); + + m_tableName = _table->tableName(); +} + +KSpreadUndoShowTable::~KSpreadUndoShowTable() +{ +} + +void KSpreadUndoShowTable::execute( bool b ) +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + table->hideTable(b); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoShowTable::undo() +{ + execute( true ); +} + +void KSpreadUndoShowTable::redo() +{ + execute( false ); +} + +/**************************************************************************** + * + * KSpreadUndoCellPaste + * + ***************************************************************************/ + +KSpreadUndoCellPaste::KSpreadUndoCellPaste( KSpreadDoc *_doc, KSpreadSheet* table, int _nbCol,int _nbRow, int _xshift,int _yshift, QRect &_selection,bool insert,int _insertTo ) + : KSpreadUndoAction( _doc ) +{ + if(!insert) + name=i18n("Paste"); + else + name=i18n("Paste & Insert"); + + m_tableName = table->tableName(); + m_selection = _selection; + nbCol=_nbCol; + nbRow=_nbRow; + xshift=_xshift; + yshift=_yshift; + b_insert=insert; + m_iInsertTo=_insertTo; + if( !b_insert) + createListCell( m_data, m_lstColumn,m_lstRow,table ); + +} + +KSpreadUndoCellPaste::~KSpreadUndoCellPaste() +{ +} + +void KSpreadUndoCellPaste::createListCell( QCString &listCell,QValueList &listCol,QValueList &listRow, KSpreadSheet* table ) +{ + listCol.clear(); + listRow.clear(); + //copy a column(s) + if(nbCol!=0) + { + //save all cells + QRect rect; + rect.setCoords( xshift, 1, xshift+nbCol, KS_rowMax ); + QDomDocument doc = table->saveCellRect( rect); + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + listCell = buffer.utf8(); + int len = listCell.length(); + char tmp = listCell[ len - 1 ]; + listCell.resize( len ); + *( listCell.data() + len - 1 ) = tmp; + + //save size of columns + for( int y = 1; y <=nbCol ; ++y ) + { + ColumnFormat *cl=table->columnFormat(y); + if(!cl->isDefault()) + { + columnSize tmpSize; + tmpSize.columnNumber=y; + tmpSize.columnWidth=cl->dblWidth(); + listCol.append(tmpSize); + } + } + } + //copy a row(s) + else if(nbRow!=0) + { + //save all cells + QRect rect; + rect.setCoords( 1, yshift, KS_colMax, yshift+nbRow ); + QDomDocument doc = table->saveCellRect( rect); + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + listCell = buffer.utf8(); + int len = listCell.length(); + char tmp = listCell[ len - 1 ]; + listCell.resize( len ); + *( listCell.data() + len - 1 ) = tmp; + + //save size of columns + for( int y = 1; y <=nbRow ; ++y ) + { + RowFormat *rw=table->rowFormat(y); + if(!rw->isDefault()) + { + rowSize tmpSize; + tmpSize.rowNumber=y; + tmpSize.rowHeight=rw->dblHeight(); + listRow.append(tmpSize); + } + } + + } + //copy just an area + else + { + //save all cells in area + QDomDocument doc = table->saveCellRect( m_selection ); + // Save to buffer + QString buffer; + QTextStream str( &buffer, IO_WriteOnly ); + str << doc; + + // This is a terrible hack to store unicode + // data in a QCString in a way that + // QCString::length() == QCString().size(). + // This allows us to treat the QCString like a QByteArray later on. + listCell = buffer.utf8(); + int len = listCell.length(); + char tmp = listCell[ len - 1 ]; + listCell.resize( len ); + *( listCell.data() + len - 1 ) = tmp; + } +} + +void KSpreadUndoCellPaste::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + createListCell( m_dataRedo, m_lstRedoColumn,m_lstRedoRow,table ); + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + if(nbCol!=0) + { + if(!b_insert) + { + QRect rect; + rect.setCoords( xshift, 1, xshift+nbCol, KS_rowMax ); + table->deleteCells( rect ); + QPoint pastePoint(xshift, 1); + table->paste( m_data, QRect(pastePoint, pastePoint) ); + QValueList::Iterator it2; + for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 ) + { + ColumnFormat *cl=table->nonDefaultColumnFormat((*it2).columnNumber); + cl->setDblWidth((*it2).columnWidth); + } + } + else + { + table->removeColumn( xshift+1,nbCol-1,false); + } + } + else if(nbRow!=0) + { + if(!b_insert) + { + QRect rect; + rect.setCoords( 1, yshift, KS_colMax, yshift+nbRow ); + table->deleteCells( rect ); + + QPoint pastePoint(1, yshift); + table->paste( m_data, QRect(pastePoint, pastePoint) ); + QValueList::Iterator it2; + for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 ) + { + RowFormat *rw=table->nonDefaultRowFormat((*it2).rowNumber); + rw->setDblHeight((*it2).rowHeight); + } + } + else + { + table->removeRow( yshift+1,nbRow-1); + } + } + else + { + if(!b_insert) + { + table->deleteCells( m_selection ); + table->paste( m_data, m_selection ); + } + else + { + if(m_iInsertTo==-1) + table->unshiftRow(m_selection); + else if(m_iInsertTo==1) + table->unshiftColumn(m_selection); + } + } + + if(table->getAutoCalc()) + table->recalc(); + table->updateView(); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoCellPaste::redo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + if(nbCol!=0) + { + if( b_insert) + { + table->insertColumn( xshift+1,nbCol-1,false); + } + QRect rect; + rect.setCoords( xshift, 1, xshift+nbCol, KS_rowMax ); + table->deleteCells( rect ); + QPoint pastePoint(xshift, 1); + table->paste( m_dataRedo, QRect(pastePoint, pastePoint) ); + QValueList::Iterator it2; + for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 ) + { + ColumnFormat *cl=table->nonDefaultColumnFormat((*it2).columnNumber); + cl->setDblWidth((*it2).columnWidth); + } + + } + else if(nbRow!=0) + { + if( b_insert) + { + table->insertRow( yshift+1,nbRow-1); + } + + QRect rect; + rect.setCoords( 1, yshift, KS_colMax, yshift+nbRow ); + table->deleteCells( rect ); + + QPoint pastePoint(1, yshift); + table->paste( m_dataRedo, QRect(pastePoint, pastePoint) ); + QValueList::Iterator it2; + for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 ) + { + RowFormat *rw=table->nonDefaultRowFormat((*it2).rowNumber); + rw->setDblHeight((*it2).rowHeight); + } + } + else + { + if (b_insert) + { + if (m_iInsertTo==-1) + table->shiftRow(m_selection); + else if(m_iInsertTo==1) + table->shiftColumn(m_selection); + + } + table->deleteCells( m_selection ); + table->paste( m_dataRedo, m_selection ); + } + if (table->getAutoCalc()) + table->recalc(); + + table->updateView(); + + doc()->undoBuffer()->unlock(); +} + + +/**************************************************************************** + * + * KSpreadUndoStyleCell + * + ***************************************************************************/ + +KSpreadUndoStyleCell::KSpreadUndoStyleCell( KSpreadDoc *_doc, KSpreadSheet* table, const QRect & _selection) + : KSpreadUndoAction( _doc ) +{ + name=i18n("Style of Cell"); + + m_tableName = table->tableName(); + m_selection = _selection; + createListCell( m_lstStyleCell, table ); + +} + +KSpreadUndoStyleCell::~KSpreadUndoStyleCell() +{ +} + +void KSpreadUndoStyleCell::createListCell( QValueList &listCell, KSpreadSheet* table ) +{ + int bottom = m_selection.bottom(); + int right = m_selection.right(); + if ( util_isColumnSelected( m_selection ) ) + { + KSpreadCell * c; + for ( int col = m_selection.left(); col <= right; ++ col ) + { + c = table->getFirstCellColumn( col ); + while ( c ) + { + if ( !c->isObscuringForced() ) + { + styleCell tmpStyleCell; + tmpStyleCell.row = c->row(); + tmpStyleCell.col = col; + tmpStyleCell.style = c->style(); + tmpStyleCell.action = c->action(); + listCell.append(tmpStyleCell); + } + c = table->getNextCellDown( col, c->row() ); + } + } + } + else if ( util_isRowSelected( m_selection ) ) + { + KSpreadCell * c; + for ( int row = m_selection.top(); row <= bottom; ++row ) + { + c = table->getFirstCellRow( row ); + while ( c ) + { + if ( !c->isObscuringForced() ) + { + styleCell tmpStyleCell; + tmpStyleCell.row = row; + tmpStyleCell.col = c->column(); + tmpStyleCell.style = c->style(); + tmpStyleCell.action = c->action(); + listCell.append(tmpStyleCell); + } + c = table->getNextCellRight( c->column(), row ); + } + } + } + else + { + KSpreadCell * cell; + for ( int i = m_selection.top(); i <= bottom; ++i) + for ( int j = m_selection.left(); j <= right; ++j ) + { + cell = table->nonDefaultCell( j, i); + styleCell tmpStyleCell; + tmpStyleCell.row = i; + tmpStyleCell.col = j; + tmpStyleCell.style = cell->style(); + tmpStyleCell.action = cell->action(); + listCell.append(tmpStyleCell); + } + } +} + +void KSpreadUndoStyleCell::undo() +{ + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + createListCell( m_lstRedoStyleCell, table ); + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + + QValueList::Iterator it2; + for ( it2 = m_lstStyleCell.begin(); it2 != m_lstStyleCell.end(); ++it2 ) + { + KSpreadCell *cell = table->nonDefaultCell( (*it2).col, (*it2).row); + cell->setStyle((*it2).style); + cell->setAction((*it2).action); + } + table->setRegionPaintDirty(m_selection); + table->updateView( m_selection ); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoStyleCell::redo() +{ + doc()->undoBuffer()->lock(); + + KSpreadSheet* table = doc()->map()->findTable( m_tableName ); + if ( !table ) + return; + + doc()->undoBuffer()->lock(); + doc()->emitBeginOperation(); + + QValueList::Iterator it2; + for ( it2 = m_lstRedoStyleCell.begin(); it2 != m_lstRedoStyleCell.end(); ++it2 ) + { + KSpreadCell *cell = table->nonDefaultCell( (*it2).col, (*it2).row); + cell->setStyle((*it2).style); + cell->setAction((*it2).action); + } + table->setRegionPaintDirty(m_selection); + table->updateView(); + + doc()->undoBuffer()->unlock(); +} + + + +KSpreadUndoAddTable::KSpreadUndoAddTable(KSpreadDoc *_doc, KSpreadSheet* _table) + : KSpreadUndoAction( _doc ), + m_table( _table ) +{ + name=i18n("Add Table"); +} + +KSpreadUndoAddTable::~KSpreadUndoAddTable() +{ +} + +void KSpreadUndoAddTable::undo() +{ + doc()->undoBuffer()->lock(); + m_table->map()->takeTable( m_table ); + doc()->takeTable( m_table ); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoAddTable::redo() +{ + doc()->undoBuffer()->lock(); + m_table->map()->insertTable( m_table ); + doc()->insertTable( m_table ); + doc()->undoBuffer()->unlock(); +} + +KSpreadUndoRemoveTable::KSpreadUndoRemoveTable(KSpreadDoc *_doc, KSpreadSheet* _table) + : KSpreadUndoAction( _doc ), + m_table( _table ) +{ + name=i18n("Remove Table"); +} + +KSpreadUndoRemoveTable::~KSpreadUndoRemoveTable() +{ +} + +void KSpreadUndoRemoveTable::undo() +{ + doc()->undoBuffer()->lock(); + m_table->map()->insertTable( m_table ); + doc()->insertTable( m_table ); + doc()->undoBuffer()->unlock(); +} + +void KSpreadUndoRemoveTable::redo() +{ + doc()->undoBuffer()->lock(); + m_table->map()->takeTable( m_table ); + doc()->takeTable( m_table ); + doc()->undoBuffer()->unlock(); +} + +KSpreadUndoInsertData::KSpreadUndoInsertData( KSpreadDoc * _doc, KSpreadSheet * _table, QRect & _selection ) + : KSpreadUndoChangeAreaTextCell( _doc, _table, _selection ) +{ + name = i18n("Insert Data From Database"); +}