[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: [PATCH] fix for kspread bug #58094
From: Stefan Hetzl <shetzl () chello ! at>
Date: 2003-10-08 22:35:54
[Download RAW message or body]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
This patch fixes bug #58094. It adds a new representation for a cell reference
to the XML-code for a cell. A cell reference of %1%1 means A1 in a formula
(no matter where this formula is created). This is only used when copying a
cell to the clipboard.
Is it ok to commit ?
Greetings,
Stefan Hetzl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
iD8DBQE/hJFZKN/5Ocgn19gRAlFMAJ9cV2Rqoj1iLa5W5h3LHk9v38Gs/wCdHMwf
OA1eqF2uYSY6YrUsDZr/bac=
=apgD
-----END PGP SIGNATURE-----
["kspread_58094.patch" (text/x-diff)]
Index: kspread_cell.cc
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_cell.cc,v
retrieving revision 1.521
diff -u -3 -p -r1.521 kspread_cell.cc
--- kspread_cell.cc 23 Aug 2003 21:08:03 -0000 1.521
+++ kspread_cell.cc 8 Oct 2003 22:27:48 -0000
@@ -510,7 +510,7 @@ void KSpreadCell::clicked( KSpreadCanvas
}
}
-QString KSpreadCell::encodeFormula( int _col, int _row )
+QString KSpreadCell::encodeFormula( bool _era, int _col, int _row )
{
if ( _col == -1 )
_col = m_iColumn;
@@ -612,12 +612,18 @@ QString KSpreadCell::encodeFormula( int
if ( fix1 )
erg += QString( "$%1" ).arg( col );
else
- erg += QString( "#%1" ).arg( col - _col );
+ if (_era)
+ erg += QString( "\%%1" ).arg( col );
+ else
+ erg += QString( "#%1" ).arg( col - _col );
if ( fix2 )
erg += QString( "$%1#").arg( row );
else
- erg += QString( "#%1#" ).arg( row - _row );
+ if (_era)
+ erg += QString( "\%%1#" ).arg( row );
+ else
+ erg += QString( "#%1#" ).arg( row - _row );
}
}
else
@@ -670,28 +676,34 @@ QString KSpreadCell::decodeFormula( cons
if ( pos < length )
erg += _text[pos++];
}
- else if ( _text[pos] == '#' || _text[pos] == '$' )
+ else if ( _text[pos] == '#' || _text[pos] == '$' || _text[pos] == '%')
{
- bool fix1 = FALSE;
- bool fix2 = FALSE;
- if ( _text[pos++] == '$' )
- fix1 = TRUE;
+ bool abs1 = FALSE;
+ bool abs2 = FALSE;
+ bool era1 = FALSE; // if 1st is relative but encoded absolutely
+ bool era2 = FALSE;
+ switch ( _text[pos++] ) {
+ case '$': abs1 = TRUE; break ;
+ case '%': era1 = TRUE; break ;
+ }
int col = 0;
unsigned int oldPos = pos;
while ( pos < length && ( _text[pos].isDigit() || _text[pos] == '-' ) ) ++pos;
if ( pos != oldPos )
col = _text.mid(oldPos, pos-oldPos).toInt();
- if ( !fix1 )
+ if ( !abs1 && !era1 )
col += _col;
// Skip '#' or '$'
- if ( _text[pos++] == '$' )
- fix2 = TRUE;
+ switch ( _text[pos++] ) {
+ case '$': abs2 = TRUE; break ;
+ case '%': era2 = TRUE; break ;
+ }
int row = 0;
oldPos = pos;
while ( pos < length && ( _text[pos].isDigit() || _text[pos] == '-' ) ) ++pos;
if ( pos != oldPos )
row = _text.mid(oldPos, pos-oldPos).toInt();
- if ( !fix2 )
+ if ( !abs2 && !era2)
row += _row;
// Skip '#' or '$'
++pos;
@@ -701,11 +713,11 @@ QString KSpreadCell::decodeFormula( cons
erg = "=\"#### " + i18n("REFERENCE TO COLUMN OR ROW IS OUT OF RANGE") + "\"";
return erg;
}
- if ( fix1 )
+ if ( abs1 )
erg += "$";
erg += util_encodeColumnLabelText(col); //Get column text
- if ( fix2 )
+ if ( abs2 )
erg += "$";
erg += QString::number( row );
}
@@ -4796,7 +4808,8 @@ QDomElement KSpreadCell::save( QDomDocum
if ( isFormula() )
{
QDomElement text = doc.createElement( "text" );
- text.appendChild( doc.createTextNode( encodeFormula() ) );
+ // if we are copying to the clipboard, relative references need to be encoded absolutely
+ text.appendChild( doc.createTextNode( encodeFormula( copy ) ) );
cell.appendChild( text );
/* we still want to save the results of the formula */
Index: kspread_cell.h
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_cell.h,v
retrieving revision 1.159
diff -u -3 -p -r1.159 kspread_cell.h
--- kspread_cell.h 30 Jun 2003 22:13:12 -0000 1.159
+++ kspread_cell.h 8 Oct 2003 22:27:48 -0000
@@ -604,7 +604,14 @@ public:
bool isFormula() const { return m_content == Formula; }
- QString encodeFormula( int _col = -1, int _row = -1 );
+ /**
+ * encode a formula into a text representation
+ *
+ * @param _era encode relative references absolutely (this is used for copying
+ * a cell to make the paste operation create a formula that points
+ * to the original cells, not the cells at the same relative position)
+ */
+ QString encodeFormula( bool _era = false, int _col = -1, int _row = -1 );
QString decodeFormula( const QString &_text, int _col = -1, int _row = -1 );
/**
Index: kspread_sheet.cc
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_sheet.cc,v
retrieving revision 1.517
diff -u -3 -p -r1.517 kspread_sheet.cc
--- kspread_sheet.cc 20 Sep 2003 10:51:53 -0000 1.517
+++ kspread_sheet.cc 8 Oct 2003 22:27:51 -0000
@@ -6031,7 +6031,7 @@ QDomDocument KSpreadSheet::saveCellRect(
{
QPoint p( c->column(), c->row() );
if ( _rect.contains( p ) )
- spread.appendChild( c->save( doc, 0, _rect.top() - 1, copy ) );
+ spread.appendChild( c->save( doc, 0, _rect.top() - 1, copy, copy ) );
}
}
@@ -6069,7 +6069,7 @@ QDomDocument KSpreadSheet::saveCellRect(
{
QPoint p( c->column(), c->row() );
if ( _rect.contains( p ) )
- spread.appendChild( c->save( doc, _rect.left() - 1, 0, copy ) );
+ spread.appendChild( c->save( doc, _rect.left() - 1, 0, copy, copy ) );
}
}
_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic