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.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp
index f303d33..d4419af 100644
--- a/noncore/apps/opie-sheet/sheet.cpp
+++ b/noncore/apps/opie-sheet/sheet.cpp
@@ -1,239 +1,239 @@
/***************************************************************************
* *
* 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 <qmessagebox.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.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)));
+ 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())
{
// modified by Toussis Manolis koppermind@panafonet.gr
// the parser was crashing if there were no closed parenthesis.
int w1,ii=0;
for(w1=0;w1<=(int)text(row, col).length();w1++)
{
if(text(row,col)[w1]=='(') ii++;
if(text(row,col)[w1]==')') ii--;
};
if(ii==0) setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data));
//end of modification
// old was plain:
//setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data));
};
emit sheetModified();
}
void Sheet::ReCalc(void)
{
typeCellData* cellData;
for (cellData=sheetData.first(); cellData; cellData=sheetData.next())
{
//printf("cellchanged:%d, %d\r\n",cellData->row,cellData->col);
slotCellChanged(cellData->row,cellData->col);
};
};
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(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+'\''));
//printf("params:%s\r\n",parameters.ascii());
return QString(NULL);
}
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, FALSE) || !findRowColumn(variable2, row2, col2, FALSE)) 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;
}
QString Sheet::calculateVariable(const QString &variable)
{
bool ok;
printf("calculateVariable=%s,len=%d\r\n",variable.ascii(),variable.length());
if(variable.left(1)=="\"") return QString(variable.mid(1,variable.length()-2));
double tempResult=variable.toDouble(&ok);
if (ok)
{
if(tempResult!=0.0)
{
return QString::number(tempResult);
}
else
{
if(variable!="0" || variable!="0.0") return QString(variable); // hereis a string variable
return QString::number(tempResult);
};
};
int row, col;
if(findRowColumn(variable, &row, &col, FALSE)) return dataParser(variable, text(row,col));
//return (findRowColumn(variable, &row, &col, TRUE) ? dataParser(variable, text(row, col)) : 0);
return QString(variable);
}
double Sheet::BesselI0(double x)
{
//Returns the modi ed Bessel function I0(x) for any real x.
double ax,ans;
double y;
if ((ax=fabs(x)) < 3.75)
{
y=x/3.75;
y*=y;
ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
}else
{
y=3.75/ax;
ans=(exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1 +y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2 +y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1 +y*0.392377e-2))))))));
}
return ans;
};
double Sheet::BesselI1(double x)