summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-sheet/sheet.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/opie-sheet/sheet.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/sheet.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp
index 1d7ec6f..2279191 100644
--- a/noncore/apps/opie-sheet/sheet.cpp
+++ b/noncore/apps/opie-sheet/sheet.cpp
@@ -86,87 +86,87 @@ 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 &parameters, int paramNo, bool giveError=FALSE, const QString funcName="")
+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)
{
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=FALSE)
+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 &param1, const QString &param2)
{
@@ -431,49 +431,49 @@ QString Sheet::dataParser(const QString &data)
do
{
result+=","+QString::number(calculateVariable(tempParameter));
tempParameter=getParameter(strippedData, ++i);
}
while (!tempParameter.isNull());
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=TRUE)
+void Sheet::lockClicks(bool lock)
{
clicksLocked=lock;
}
void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected)
{
if (selected && row==currentRow() && col==currentColumn()) selected=FALSE;
int sheetDataCurrent=sheetData.at();
typeCellData *cellData=findCellData(row, col);
if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent);
if (!cellData) cellData=&defaultCellData;
if (selected)
p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight());
else
{
p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base());
p->fillRect(0, 0, cr.width(), cr.height(), cellData->background);
}
QTableItem *cellItem=item(row, col);
if (cellItem)
{
p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor);
@@ -715,122 +715,122 @@ void Sheet::editCopy()
typeCellData *cellData, *newCellData;
int row, col;
for (row=row1; row<=row2; ++row)
for (col=col1; col<=col2; ++col)
{
cellData=findCellData(row, col);
if (cellData)
{
newCellData=new typeCellData;
*newCellData=*cellData;
newCellData->row-=row1;
newCellData->col-=col1;
clipboardData.append(newCellData);
}
}
}
void Sheet::editCut()
{
editCopy();
editClear();
}
-void Sheet::editPaste(bool onlyContents=FALSE)
+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));
emit sheetModified();
}
}
}
-void Sheet::insertRows(int no=1, bool allColumns=TRUE)
+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));
}
emit sheetModified();
}
-void Sheet::insertColumns(int no=1, bool allRows=TRUE)
+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));
}
emit sheetModified();
}
-void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE)
+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));
}
if (!replace || !replaceAll) break;