author | thufir <thufir> | 2002-10-05 17:49:18 (UTC) |
---|---|---|
committer | thufir <thufir> | 2002-10-05 17:49:18 (UTC) |
commit | 39d6aaa554efe1fbeffa3e3fe966f6d4f446c123 (patch) (side-by-side diff) | |
tree | 19924095d125fbda2d881046491b2adc5ad60398 | |
parent | fbe0200df248c5b6677483c4f42a801002bb151e (diff) | |
download | opie-39d6aaa554efe1fbeffa3e3fe966f6d4f446c123.zip opie-39d6aaa554efe1fbeffa3e3fe966f6d4f446c123.tar.gz opie-39d6aaa554efe1fbeffa3e3fe966f6d4f446c123.tar.bz2 |
fixed bug #252
-rw-r--r-- | noncore/apps/opie-sheet/ChangeLog | 4 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/noncore/apps/opie-sheet/ChangeLog b/noncore/apps/opie-sheet/ChangeLog index d3c5c84..c12a6db 100644 --- a/noncore/apps/opie-sheet/ChangeLog +++ b/noncore/apps/opie-sheet/ChangeLog @@ -1,21 +1,25 @@ +October 05, 2002 + + - Fixed bug #252. (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/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index 2279191..be4046b 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp @@ -1,225 +1,226 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * Opie Sheet (formerly Sheet/Qt) * by Serdar Ozler <sozler@sitebest.com> */ #include "sheet.h" #include <qmainwindow.h> #include <qmessagebox.h> #include <math.h> #define DEFAULT_COL_WIDTH 50 Sheet::Sheet(int numRows, int numCols, QWidget *parent) :QTable(numRows, numCols, parent) { defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); defaultCellData.data=""; defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern); defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); defaultCellData.fontColor=Qt::black; defaultCellData.font=font(); defaultCellData.borders=defaultBorders; + clicksLocked=FALSE; selectionNo=-1; setSelectionMode(QTable::Single); sheetData.setAutoDelete(TRUE); clipboardData.setAutoDelete(TRUE); for (int i=0; i<numCols; ++i) horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCellSelected(int, int))); connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(slotCellChanged(int, int))); } Sheet::~Sheet() { } typeCellData *Sheet::findCellData(int row, int col) { typeCellData *tempCellData; for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) if (tempCellData->row==row && tempCellData->col==col) return tempCellData; return NULL; } void Sheet::slotCellSelected(int row, int col) { typeCellData *cellData=findCellData(row, col); if (cellData) emit currentDataChanged(cellData->data); else emit currentDataChanged(""); } 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)); 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)); emit sheetModified(); } } QString Sheet::getParameter(const QString ¶meters, 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) { int row, col; if (!findRowColumn(variable1, row1, col1, TRUE) || !findRowColumn(variable2, row2, col2, TRUE)) return FALSE; if (*row1>*row2) { row=*row1; *row1=*row2; *row2=row; } if (*col1>*col2) { col=*col1; *col1=*col2; *col2=col; } 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); } double Sheet::functionSum(const QString ¶m1, const QString ¶m2) { 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 ¶m1, const QString ¶m2) { int row1, col1, row2, col2, row, col; if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; double min=0, tempMin; bool ok, init=FALSE; for (row=row1; row<=row2; ++row) for (col=col1; col<=col2; ++col) { tempMin=text(row, col).toDouble(&ok); if (ok && (!init || tempMin<min)) { min=tempMin; init=TRUE; } } return min; } double Sheet::functionMax(const QString ¶m1, const QString ¶m2) { int row1, col1, row2, col2, row, col; if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; double max=0, tempMax; bool ok, init=FALSE; for (row=row1; row<=row2; ++row) for (col=col1; col<=col2; ++col) { tempMax=text(row, col).toDouble(&ok); if (ok && (!init || tempMax>max)) { max=tempMax; init=TRUE; } } |