summaryrefslogtreecommitdiff
authorthufir <thufir>2002-10-08 16:43:57 (UTC)
committer thufir <thufir>2002-10-08 16:43:57 (UTC)
commit9475b63d025c1ca386764784b7dad460935f45b0 (patch) (side-by-side diff)
treef0b209ab08afb75e94f6d3f2b0ff4bc235774cbd
parent76fb8a57bf9fbae3a7073c8b0be1216f34adf99c (diff)
downloadopie-9475b63d025c1ca386764784b7dad460935f45b0.zip
opie-9475b63d025c1ca386764784b7dad460935f45b0.tar.gz
opie-9475b63d025c1ca386764784b7dad460935f45b0.tar.bz2
fixed bug #250
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/ChangeLog11
-rw-r--r--noncore/apps/opie-sheet/mainwindow.cpp3
-rw-r--r--noncore/apps/opie-sheet/opie-sheet.control2
-rw-r--r--noncore/apps/opie-sheet/sheet.cpp32
-rw-r--r--noncore/apps/opie-sheet/sheet.h4
5 files changed, 36 insertions, 16 deletions
diff --git a/noncore/apps/opie-sheet/ChangeLog b/noncore/apps/opie-sheet/ChangeLog
index c12a6db..90060e2 100644
--- a/noncore/apps/opie-sheet/ChangeLog
+++ b/noncore/apps/opie-sheet/ChangeLog
@@ -1,25 +1,34 @@
+October 08, 2002
+
+ * Release 1.0.2 (by thufir)
+ - Fixed bug #250 (exhibiting re-calculation error in multi-level calculation). (by thufir)
+
+October 06, 2002
+
+ - Fixed data edit box clear problem. (by thufir)
+
October 05, 2002
- - Fixed bug #252. (by thufir)
+ - Fixed bug #252 (starting up in 'mouse button' mode). (by thufir)
August 31, 2002
- Fixed and updated opie-sheet.pro file. (by cniehaus)
August 01, 2002
- Fixed gcc3 compile problems. (by harlekin)
July 06, 2002
- Fixed DocLnk management to save documents correctly. (by leseb)
July 04, 2002
* Release 1.0.1 (by thufir)
- Sheet/Qt is now a part of Opie, so its name is changed to Opie Sheet. (by thufir)
- Fixed sorting bug. (by thufir)
April 14, 2002
* Release 1.0.0 (by thufir)
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp
index 2f07bae..b9f8e57 100644
--- a/noncore/apps/opie-sheet/mainwindow.cpp
+++ b/noncore/apps/opie-sheet/mainwindow.cpp
@@ -174,48 +174,49 @@ int MainWindow::saveCurrentFile(bool ask)
if (result!=QMessageBox::Yes) return result;
}
if (!currentDoc->isValid())
{
TextDialog dialogText(this);
if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel;
currentDoc->setName(dialogText.getValue());
currentDoc->setFile(QString::null);
currentDoc->setLinkFile(QString::null);
}
documentSave(currentDoc);
return QMessageBox::Yes;
}
void MainWindow::selectorFileNew(const DocLnk &lnkDoc)
{
selectorHide();
if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
if (currentDoc) delete currentDoc;
currentDoc = new DocLnk(lnkDoc);
+ editData->clear();
listSheets.clear();
comboSheets->clear();
typeSheet *newSheet=createNewSheet();
newSheet->data.setAutoDelete(TRUE);
sheet->setName(newSheet->name);
sheet->setSheetData(&newSheet->data);
for (int i=1; i<DEFAULT_NUM_SHEETS; ++i)
createNewSheet();
documentModified=FALSE;
}
void MainWindow::closeEvent(QCloseEvent *e)
{
if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore();
else e->accept();
}
void MainWindow::selectorFileOpen(const DocLnk &lnkDoc)
{
selectorHide();
if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
if (currentDoc) delete currentDoc;
@@ -512,49 +513,49 @@ void MainWindow::initEditToolbar()
editData=new QLineEdit(toolbarEdit);
toolbarEdit->setStretchableWidget(editData);
connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept()));
editCellSelect->addTo(toolbarEdit);
}
void MainWindow::slotHelpGeneral()
{
if (QFile::exists(helpFile))
{
QCopEnvelope e("QPE/Application/helpbrowser", "showFile(QString)");
e << helpFile;
}
else
QMessageBox::critical(this, tr("Error"), tr("Help file not found!"));
}
void MainWindow::slotHelpAbout()
{
QDialog dialogAbout(this, 0, TRUE);
dialogAbout.resize(width()-40, height()-80);
dialogAbout.setCaption(tr("About Opie Sheet"));
- QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.1\nRelease Date: July 04, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout);
+ QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.2\nRelease Date: October 08, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout);
label.setGeometry(dialogAbout.rect());
label.setAlignment(Qt::AlignCenter | Qt::WordBreak);
dialogAbout.exec();
}
void MainWindow::initSheet()
{
sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this);
setCentralWidget(sheet);
connect(sheet, SIGNAL(currentDataChanged(const QString &)), editData, SLOT(setText(const QString &)));
connect(sheet, SIGNAL(cellClicked(const QString &)), this, SLOT(slotCellClicked(const QString &)));
connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified()));
connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut()));
connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy()));
connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear()));
}
void MainWindow::slotEditAccept()
{
sheet->setData(editData->text());
}
diff --git a/noncore/apps/opie-sheet/opie-sheet.control b/noncore/apps/opie-sheet/opie-sheet.control
index 38f9083..cc322bb 100644
--- a/noncore/apps/opie-sheet/opie-sheet.control
+++ b/noncore/apps/opie-sheet/opie-sheet.control
@@ -1,10 +1,10 @@
Files: bin/sheetqt apps/Applications/opie-sheet.desktop help/sheetqt.html help/sheetqt/* pics/opie-sheet/sheetqt.png
Priority: optional
Section: opie/applications
Maintainer: Serdar Ozler <sozler@sitebest.com>
Architecture: arm
-Version: 1.0.1
+Version: 1.0.2
Depends: opie-base ($QPE_VERSION)
License: Public Domain
Description: Opie Sheet
Spreadsheet software for Opie.
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
@@ -67,64 +67,64 @@ void Sheet::slotCellSelected(int row, int col)
}
typeCellData *Sheet::createCellData(int row, int col)
{
if (row<0 || col<0) return NULL;
typeCellData *cellData=new typeCellData;
cellData->row=row;
cellData->col=col;
cellData->data=defaultCellData.data;
cellData->borders=defaultCellData.borders;
cellData->alignment=defaultCellData.alignment;
cellData->font=defaultCellData.font;
cellData->fontColor=defaultCellData.fontColor;
cellData->background=defaultCellData.background;
sheetData.append(cellData);
return cellData;
}
void Sheet::slotCellChanged(int row, int col)
{
typeCellData *cellData=findCellData(row, col);
if (!cellData) cellData=createCellData(row, col);
if (cellData) cellData->data=text(row, col);
for (cellData=sheetData.first(); cellData; cellData=sheetData.next())
- setText(cellData->row, cellData->col, dataParser(cellData->data));
+ setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data));
emit sheetModified();
}
void Sheet::swapCells(int row1, int col1, int row2, int col2)
{
typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2);
if (!cellData1) cellData1=createCellData(row1, col1);
if (!cellData2) cellData2=createCellData(row2, col2);
if (cellData1 && cellData2)
{
QString tempData(cellData1->data);
cellData1->data=cellData2->data;
cellData2->data=tempData;
- setText(cellData1->row, cellData1->col, dataParser(cellData1->data));
- setText(cellData2->row, cellData2->col, dataParser(cellData2->data));
+ setText(cellData1->row, cellData1->col, dataParser(findCellName(cellData1->row, cellData1->col), cellData1->data));
+ setText(cellData2->row, cellData2->col, dataParser(findCellName(cellData2->row, cellData2->col), cellData2->data));
emit sheetModified();
}
}
QString Sheet::getParameter(const QString &parameters, int paramNo, bool giveError, const QString funcName)
{
QString params(parameters);
int position;
for (int i=0; i<paramNo; ++i)
{
position=params.find(',');
if (position<0)
{
if (giveError) QMessageBox::critical(this, tr("Error"), tr("Too few arguments to function '"+funcName+'\''));
return QString();
}
params=params.mid(position+1);
}
position=params.find(',');
if (position<0) return params;
return params.left(position);
}
bool Sheet::findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2)
@@ -145,49 +145,49 @@ bool Sheet::findRange(const QString &variable1, const QString &variable2, int *r
}
return TRUE;
}
bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError)
{
int position=variable.find(QRegExp("\\d"));
if (position<1)
{
if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\''));
return FALSE;
}
*row=variable.mid(position).toInt()-1;
*col=getHeaderColumn(variable.left(position))-1;
return TRUE;
}
double Sheet::calculateVariable(const QString &variable)
{
bool ok;
double tempResult=variable.toDouble(&ok);
if (ok) return tempResult;
int row, col;
- return (findRowColumn(variable, &row, &col, TRUE) ? text(row, col).toDouble() : 0);
+ return (findRowColumn(variable, &row, &col, TRUE) ? dataParser(variable, text(row, col)).toDouble() : 0);
}
double Sheet::functionSum(const QString &param1, const QString &param2)
{
int row1, col1, row2, col2, row, col;
if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
double result=0, tempResult;
bool ok;
for (row=row1; row<=row2; ++row)
for (col=col1; col<=col2; ++col)
{
tempResult=text(row, col).toDouble(&ok);
if (ok) result+=tempResult;
}
return result;
}
double Sheet::functionMin(const QString &param1, const QString &param2)
{
int row1, col1, row2, col2, row, col;
if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
@@ -399,63 +399,66 @@ QString Sheet::dataParserHelper(const QString &data)
if (tempElement.isEmpty())
tempElement=temp2Element;
else
tempElement.setNum(calculateFunction(tempElement, temp2Element));
--i;
}
else
tempElement+=data[i];
}
if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement);
while (!stackOperators.isEmpty())
{
secondElement=popStringStack(&stackElements);
firstElement=popStringStack(&stackElements);
pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement)));
}
if (!stackElements.isEmpty())
tempElement=popStringStack(&stackElements);
while (!stackElements.isEmpty())
tempElement.prepend(popStringStack(&stackElements)+",");
return tempElement;
}
-QString Sheet::dataParser(const QString &data)
+QString Sheet::dataParser(const QString &cell, const QString &data)
{
QString strippedData(data);
strippedData.replace(QRegExp("\\s"), "");
if (strippedData.isEmpty() || strippedData[0]!='=') return data;
+ if (listDataParser.find(cell)!=listDataParser.end()) return "0";
+ listDataParser.append(cell);
strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ","));
int i=0;
QString tempParameter(getParameter(strippedData, i)), result="";
do
{
result+=","+QString::number(calculateVariable(tempParameter));
tempParameter=getParameter(strippedData, ++i);
}
while (!tempParameter.isNull());
+ listDataParser.remove(cell);
return result.mid(1);
}
void Sheet::setData(const QString &data)
{
setText(currentRow(), currentColumn(), data);
slotCellChanged(currentRow(), currentColumn());
activateNextCell();
}
QString Sheet::getData()
{
typeCellData *cellData=findCellData(currentRow(), currentColumn());
if (cellData)
return cellData->data;
return "";
}
void Sheet::lockClicks(bool lock)
{
clicksLocked=lock;
}
void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected)
@@ -518,86 +521,91 @@ void Sheet::viewportMouseMoveEvent(QMouseEvent *e)
{
QTableSelection oldSelection(selection(selectionNo));
oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
if (!(oldSelection==selection(selectionNo)))
{
removeSelection(selectionNo);
selectionNo=addSelection(oldSelection);
}
}
}
else
QTable::contentsMouseMoveEvent(&ce);
}
void Sheet::viewportMouseReleaseEvent(QMouseEvent *e)
{
QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
if (clicksLocked && selectionNo>=0)
{
QTableSelection oldSelection(selection(selectionNo));
oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
removeSelection(selectionNo);
selectionNo=-1;
if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol())
- emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1));
+ emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol()));
else
- emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)+','+getHeaderString(oldSelection.rightCol()+1)+QString::number(oldSelection.bottomRow()+1));
+ emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol()));
}
else
QTable::contentsMouseReleaseEvent(&ce);
}
+QString Sheet::findCellName(int row, int col)
+{
+ return (getHeaderString(col+1)+QString::number(row+1));
+}
+
void Sheet::copySheetData(QList<typeCellData> *destSheetData)
{
typeCellData *tempCellData, *newCellData;
destSheetData->clear();
for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
{
newCellData=new typeCellData;
*newCellData=*tempCellData;
destSheetData->append(newCellData);
}
}
void Sheet::setSheetData(QList<typeCellData> *srcSheetData)
{
typeCellData *tempCellData, *newCellData;
for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
{
clearCell(tempCellData->row, tempCellData->col);
updateCell(tempCellData->row, tempCellData->col);
}
sheetData.clear();
for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next())
{
newCellData=new typeCellData;
*newCellData=*tempCellData;
sheetData.append(newCellData);
- setText(newCellData->row, newCellData->col, dataParser(newCellData->data));
+ setText(newCellData->row, newCellData->col, dataParser(findCellName(newCellData->row, newCellData->col), newCellData->data));
}
emit sheetModified();
}
void Sheet::setName(const QString &name)
{
sheetName=name;
emit sheetModified();
}
QString Sheet::getName()
{
return sheetName;
}
void Sheet::setBrush(int row, int col, const QBrush &brush)
{
typeCellData *cellData=findCellData(row, col);
if (!cellData) cellData=createCellData(row, col);
if (cellData)
{
cellData->background=brush;
emit sheetModified();
}
@@ -735,125 +743,125 @@ void Sheet::editCut()
{
editCopy();
editClear();
}
void Sheet::editPaste(bool onlyContents)
{
int row1=currentRow(), col1=currentColumn();
typeCellData *cellData, *tempCellData;
for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next())
{
cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1);
if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1);
if (cellData)
{
if (onlyContents)
cellData->data=tempCellData->data;
else
{
*cellData=*tempCellData;
cellData->row+=row1;
cellData->col+=col1;
}
- setText(cellData->row, cellData->col, dataParser(cellData->data));
+ setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data));
emit sheetModified();
}
}
}
void Sheet::insertRows(int no, bool allColumns)
{
setNumRows(numRows()+no);
typeCellData *tempCellData;
int row=currentRow(), col=currentColumn();
for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
if (tempCellData->row>=row && (allColumns || tempCellData->col==col))
{
clearCell(tempCellData->row, tempCellData->col);
tempCellData->row+=no;
}
for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
if (tempCellData->row>=row && (allColumns || tempCellData->col==col))
{
updateCell(tempCellData->row-no, tempCellData->col);
- setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data));
+ setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data));
}
emit sheetModified();
}
void Sheet::insertColumns(int no, bool allRows)
{
int noCols=numCols();
int newCols=noCols+no;
setNumCols(newCols);
for (int i=noCols; i<newCols; ++i)
horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH);
typeCellData *tempCellData;
int col=currentColumn(), row=currentRow();
for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
if (tempCellData->col>=col && (allRows || tempCellData->row==row))
{
clearCell(tempCellData->row, tempCellData->col);
tempCellData->col+=no;
}
for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
if (tempCellData->col>=col && (allRows || tempCellData->row==row))
{
updateCell(tempCellData->row, tempCellData->col-no);
- setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data));
+ setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data));
}
emit sheetModified();
}
void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase, bool allCells, bool entireCell, bool replace, bool replaceAll)
{
typeCellData *tempCellData;
int row1, col1, row2, col2;
getSelection(&row1, &col1, &row2, &col2);
bool found=FALSE;
for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2))
{
QTableItem *cellItem=item(tempCellData->row, tempCellData->col);
if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0))
{
if (!found)
{
found=TRUE;
clearSelection();
}
setCurrentCell(tempCellData->row, tempCellData->col);
if (replace)
{
tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr);
- setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data));
+ setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data));
}
if (!replace || !replaceAll) break;
}
}
if (found)
{
if (replace)
slotCellChanged(currentRow(), currentColumn());
}
else
QMessageBox::warning(this, tr("Error"), tr("Search key not found!"));
}
//
// Static functions
//
QString Sheet::getHeaderString(int section)
{
if (section<1) return "";
return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26);
}
diff --git a/noncore/apps/opie-sheet/sheet.h b/noncore/apps/opie-sheet/sheet.h
index f78a684..f4e9d38 100644
--- a/noncore/apps/opie-sheet/sheet.h
+++ b/noncore/apps/opie-sheet/sheet.h
@@ -26,59 +26,61 @@ typedef struct typeCellBorders
typedef struct typeCellData
{
int col, row;
typeCellBorders borders;
QBrush background;
Qt::AlignmentFlags alignment;
QColor fontColor;
QFont font;
QString data;
};
class Sheet: public QTable
{
Q_OBJECT
// Variables
bool clicksLocked;
int selectionNo;
typeCellBorders defaultBorders;
typeCellData defaultCellData;
// QT objects
QList<typeCellData> sheetData, clipboardData;
QString pressedCell, releasedCell, sheetName;
+ QStringList listDataParser;
// Private functions
int getOperatorPriority(char oper);
bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE);
+ QString findCellName(int row, int col);
bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2);
double calculateVariable(const QString &variable);
double calculateFunction(const QString &function, const QString &parameters);
QChar popCharStack(QStack<QChar> *stackChars);
QString popStringStack(QStack<QString> *stackStrings);
QString getParameter(const QString &parameters, int paramNo, bool giveError=FALSE, const QString funcName="");
- QString dataParser(const QString &data);
+ QString dataParser(const QString &cell, const QString &data);
QString dataParserHelper(const QString &data);
typeCellData *createCellData(int row, int col);
typeCellData *findCellData(int row, int col);
void pushCharStack(QStack<QChar> *stackChars, const QChar &character);
void pushStringStack(QStack<QString> *stackStrings, const QString &string);
// Sheet/Qt parser functions
double functionSum(const QString &param1, const QString &param2);
double functionAvg(const QString &param1, const QString &param2);
double functionMax(const QString &param1, const QString &param2);
double functionMin(const QString &param1, const QString &param2);
double functionCount(const QString &param1, const QString &param2);
// Reimplemented QTable functions
void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected);
void viewportMousePressEvent(QMouseEvent *e);
void viewportMouseMoveEvent(QMouseEvent *e);
void viewportMouseReleaseEvent(QMouseEvent *e);
private slots:
void slotCellSelected(int row, int col);
void slotCellChanged(int row, int col);
public: