author | thufir <thufir> | 2002-10-08 16:43:57 (UTC) |
---|---|---|
committer | thufir <thufir> | 2002-10-08 16:43:57 (UTC) |
commit | 9475b63d025c1ca386764784b7dad460935f45b0 (patch) (unidiff) | |
tree | f0b209ab08afb75e94f6d3f2b0ff4bc235774cbd /noncore/apps/opie-sheet/sheet.cpp | |
parent | 76fb8a57bf9fbae3a7073c8b0be1216f34adf99c (diff) | |
download | opie-9475b63d025c1ca386764784b7dad460935f45b0.zip opie-9475b63d025c1ca386764784b7dad460935f45b0.tar.gz opie-9475b63d025c1ca386764784b7dad460935f45b0.tar.bz2 |
fixed bug #250
Diffstat (limited to 'noncore/apps/opie-sheet/sheet.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index be4046b..c2563c2 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp | |||
@@ -87,9 +87,9 @@ void Sheet::slotCellChanged(int row, int col) | |||
87 | typeCellData *cellData=findCellData(row, col); | 87 | typeCellData *cellData=findCellData(row, col); |
88 | if (!cellData) cellData=createCellData(row, col); | 88 | if (!cellData) cellData=createCellData(row, col); |
89 | if (cellData) cellData->data=text(row, col); | 89 | if (cellData) cellData->data=text(row, col); |
90 | for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) | 90 | for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) |
91 | setText(cellData->row, cellData->col, dataParser(cellData->data)); | 91 | setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); |
92 | emit sheetModified(); | 92 | emit sheetModified(); |
93 | } | 93 | } |
94 | 94 | ||
95 | void Sheet::swapCells(int row1, int col1, int row2, int col2) | 95 | void Sheet::swapCells(int row1, int col1, int row2, int col2) |
@@ -101,10 +101,10 @@ void Sheet::swapCells(int row1, int col1, int row2, int col2) | |||
101 | { | 101 | { |
102 | QString tempData(cellData1->data); | 102 | QString tempData(cellData1->data); |
103 | cellData1->data=cellData2->data; | 103 | cellData1->data=cellData2->data; |
104 | cellData2->data=tempData; | 104 | cellData2->data=tempData; |
105 | setText(cellData1->row, cellData1->col, dataParser(cellData1->data)); | 105 | setText(cellData1->row, cellData1->col, dataParser(findCellName(cellData1->row, cellData1->col), cellData1->data)); |
106 | setText(cellData2->row, cellData2->col, dataParser(cellData2->data)); | 106 | setText(cellData2->row, cellData2->col, dataParser(findCellName(cellData2->row, cellData2->col), cellData2->data)); |
107 | emit sheetModified(); | 107 | emit sheetModified(); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
@@ -165,9 +165,9 @@ double Sheet::calculateVariable(const QString &variable) | |||
165 | double tempResult=variable.toDouble(&ok); | 165 | double tempResult=variable.toDouble(&ok); |
166 | if (ok) return tempResult; | 166 | if (ok) return tempResult; |
167 | 167 | ||
168 | int row, col; | 168 | int row, col; |
169 | return (findRowColumn(variable, &row, &col, TRUE) ? text(row, col).toDouble() : 0); | 169 | return (findRowColumn(variable, &row, &col, TRUE) ? dataParser(variable, text(row, col)).toDouble() : 0); |
170 | } | 170 | } |
171 | 171 | ||
172 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) | 172 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) |
173 | { | 173 | { |
@@ -419,13 +419,15 @@ QString Sheet::dataParserHelper(const QString &data) | |||
419 | tempElement.prepend(popStringStack(&stackElements)+","); | 419 | tempElement.prepend(popStringStack(&stackElements)+","); |
420 | return tempElement; | 420 | return tempElement; |
421 | } | 421 | } |
422 | 422 | ||
423 | QString Sheet::dataParser(const QString &data) | 423 | QString Sheet::dataParser(const QString &cell, const QString &data) |
424 | { | 424 | { |
425 | QString strippedData(data); | 425 | QString strippedData(data); |
426 | strippedData.replace(QRegExp("\\s"), ""); | 426 | strippedData.replace(QRegExp("\\s"), ""); |
427 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; | 427 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; |
428 | if (listDataParser.find(cell)!=listDataParser.end()) return "0"; | ||
429 | listDataParser.append(cell); | ||
428 | strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ",")); | 430 | strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ",")); |
429 | 431 | ||
430 | int i=0; | 432 | int i=0; |
431 | QString tempParameter(getParameter(strippedData, i)), result=""; | 433 | QString tempParameter(getParameter(strippedData, i)), result=""; |
@@ -434,8 +436,9 @@ QString Sheet::dataParser(const QString &data) | |||
434 | result+=","+QString::number(calculateVariable(tempParameter)); | 436 | result+=","+QString::number(calculateVariable(tempParameter)); |
435 | tempParameter=getParameter(strippedData, ++i); | 437 | tempParameter=getParameter(strippedData, ++i); |
436 | } | 438 | } |
437 | while (!tempParameter.isNull()); | 439 | while (!tempParameter.isNull()); |
440 | listDataParser.remove(cell); | ||
438 | return result.mid(1); | 441 | return result.mid(1); |
439 | } | 442 | } |
440 | 443 | ||
441 | void Sheet::setData(const QString &data) | 444 | void Sheet::setData(const QString &data) |
@@ -538,16 +541,21 @@ void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) | |||
538 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 541 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
539 | removeSelection(selectionNo); | 542 | removeSelection(selectionNo); |
540 | selectionNo=-1; | 543 | selectionNo=-1; |
541 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) | 544 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) |
542 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)); | 545 | emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())); |
543 | else | 546 | else |
544 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)+','+getHeaderString(oldSelection.rightCol()+1)+QString::number(oldSelection.bottomRow()+1)); | 547 | emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol())); |
545 | } | 548 | } |
546 | else | 549 | else |
547 | QTable::contentsMouseReleaseEvent(&ce); | 550 | QTable::contentsMouseReleaseEvent(&ce); |
548 | } | 551 | } |
549 | 552 | ||
553 | QString Sheet::findCellName(int row, int col) | ||
554 | { | ||
555 | return (getHeaderString(col+1)+QString::number(row+1)); | ||
556 | } | ||
557 | |||
550 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) | 558 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) |
551 | { | 559 | { |
552 | typeCellData *tempCellData, *newCellData; | 560 | typeCellData *tempCellData, *newCellData; |
553 | destSheetData->clear(); | 561 | destSheetData->clear(); |
@@ -575,9 +583,9 @@ void Sheet::setSheetData(QList<typeCellData> *srcSheetData) | |||
575 | { | 583 | { |
576 | newCellData=new typeCellData; | 584 | newCellData=new typeCellData; |
577 | *newCellData=*tempCellData; | 585 | *newCellData=*tempCellData; |
578 | sheetData.append(newCellData); | 586 | sheetData.append(newCellData); |
579 | setText(newCellData->row, newCellData->col, dataParser(newCellData->data)); | 587 | setText(newCellData->row, newCellData->col, dataParser(findCellName(newCellData->row, newCellData->col), newCellData->data)); |
580 | } | 588 | } |
581 | emit sheetModified(); | 589 | emit sheetModified(); |
582 | } | 590 | } |
583 | 591 | ||
@@ -755,9 +763,9 @@ void Sheet::editPaste(bool onlyContents) | |||
755 | *cellData=*tempCellData; | 763 | *cellData=*tempCellData; |
756 | cellData->row+=row1; | 764 | cellData->row+=row1; |
757 | cellData->col+=col1; | 765 | cellData->col+=col1; |
758 | } | 766 | } |
759 | setText(cellData->row, cellData->col, dataParser(cellData->data)); | 767 | setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); |
760 | emit sheetModified(); | 768 | emit sheetModified(); |
761 | } | 769 | } |
762 | } | 770 | } |
763 | } | 771 | } |
@@ -778,9 +786,9 @@ void Sheet::insertRows(int no, bool allColumns) | |||
778 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 786 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
779 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) | 787 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) |
780 | { | 788 | { |
781 | updateCell(tempCellData->row-no, tempCellData->col); | 789 | updateCell(tempCellData->row-no, tempCellData->col); |
782 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 790 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); |
783 | } | 791 | } |
784 | emit sheetModified(); | 792 | emit sheetModified(); |
785 | } | 793 | } |
786 | 794 | ||
@@ -804,9 +812,9 @@ void Sheet::insertColumns(int no, bool allRows) | |||
804 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 812 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
805 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) | 813 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) |
806 | { | 814 | { |
807 | updateCell(tempCellData->row, tempCellData->col-no); | 815 | updateCell(tempCellData->row, tempCellData->col-no); |
808 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 816 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); |
809 | } | 817 | } |
810 | emit sheetModified(); | 818 | emit sheetModified(); |
811 | } | 819 | } |
812 | 820 | ||
@@ -831,9 +839,9 @@ void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, b | |||
831 | setCurrentCell(tempCellData->row, tempCellData->col); | 839 | setCurrentCell(tempCellData->row, tempCellData->col); |
832 | if (replace) | 840 | if (replace) |
833 | { | 841 | { |
834 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); | 842 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); |
835 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 843 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); |
836 | } | 844 | } |
837 | if (!replace || !replaceAll) break; | 845 | if (!replace || !replaceAll) break; |
838 | } | 846 | } |
839 | } | 847 | } |