[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: PATCH: Increasing data size in KChart
From: Kalle Dalheimer <kalle () dalheimer ! de>
Date: 2000-10-14 10:50:58
[Download RAW message or body]
Hi,
the attached patch fixes the problem that you could not decrease the number
of displayed rows and columns in the KChart data editor (decreasing always
worked).
I know it's sort of big, but this was the only way to allow resizing of the
displayable data area without losing data while decreasing.
Please check and possible approve.
Kalle
--
Matthias Kalle Dalheimer
President & CEO/VD
Klarälvdalens Datakonsult AB
Fax +46-563-540028
Email kalle@dalheimer.de
["patch" (text/x-c)]
Index: sheetdlg.h
===================================================================
RCS file: /home/kde/koffice/kchart/sheetdlg.h,v
retrieving revision 1.6
diff -u -r1.6 sheetdlg.h
--- sheetdlg.h 1999/11/14 18:46:47 1.6
+++ sheetdlg.h 2000/10/14 10:25:56
@@ -36,7 +36,9 @@
int rows();
int usedCols();
int usedRows();
-
+ void setUsedCols( int );
+ void setUsedRows( int );
+
QString getX(int);
QString getY(int);
double getCell(int,int);
@@ -48,7 +50,7 @@
private:
- Sheet *t;
+ Sheet *t;
QPushButton *cancel,*ok;
void resizeHandle( QSize );
QLabel *usedrowsLA, *usedcolsLA;
Index: kchartDataEditor.cc
===================================================================
RCS file: /home/kde/koffice/kchart/kchartDataEditor.cc,v
retrieving revision 1.12
diff -u -r1.12 kchartDataEditor.cc
--- kchartDataEditor.cc 2000/09/22 20:59:48 1.12
+++ kchartDataEditor.cc 2000/10/14 10:30:11
@@ -16,6 +16,9 @@
}
void kchartDataEditor::setData(KoChart::Data* dat) {
+ _widget->setUsedRows( dat->usedRows() );
+ _widget->setUsedCols( dat->usedCols() );
+
for (unsigned int row = 0;row != dat->rows();row++)
for (unsigned int col = 0; col !=dat->cols(); col++) {
kdDebug(35001) << "Set dialog cell for " << row << "," << col << endl;
@@ -38,13 +41,21 @@
}
void kchartDataEditor::getData(KoChart::Data* dat) {
+ // Make sure that the data table is not smaller than the used data
+ if( dat->rows() < _widget->usedRows() ||
+ dat->cols() < _widget->usedCols() )
+ dat->expand( _widget->usedRows(), _widget->usedCols() );
+
+ dat->setUsedRows( _widget->usedRows() );
+ dat->setUsedCols( _widget->usedCols() );
+
for (int row = 0;row < _widget->rows();row++) {
for (int col = 0;col < _widget->cols();col++) {
// m_pData->setYValue( row, col, _widget->getCell(row,col) );
KoChart::Value t;
double val = _widget->getCell(row,col);
- if( ( row >= _widget->usedRows() ) ||
- ( col >= _widget->usedCols() ) )
+ if( ( row >= _widget->rows() ) ||
+ ( col >= _widget->cols() ) )
{ /*t.exists = false; */ }
else
t = QVariant( val );
Index: kchartEngine_Grids.cc
===================================================================
RCS file: /home/kde/koffice/kchart/kchartEngine_Grids.cc,v
retrieving revision 1.28
diff -u -r1.28 kchartEngine_Grids.cc
--- kchartEngine_Grids.cc 2000/08/31 19:15:42 1.28
+++ kchartEngine_Grids.cc 2000/10/14 10:32:37
@@ -19,10 +19,10 @@
int KChartEngine::doLabels() {
// Finally, the x labels are taken from the first row
- QArray<QString> xlbl( data->cols() );
+ QArray<QString> xlbl( data->usedCols() );
#ifdef NOXLABELSFORNOW
- kdDebug(35001) << "Creating xlbl with " << data->cols() << " entries" << endl;
- for( int labels = 0; labels < data->cols(); labels++ ) {
+ kdDebug(35001) << "Creating xlbl with " << data->usedCols() << " entries" << \
endl; + for( int labels = 0; labels < data->usedCols(); labels++ ) {
kdDebug(35001) << "Retrieving value at position " << labels << endl;
const KChartValue& cellval = data->cell( 0, labels );
kdDebug(35001) << "type of field " << labels << " in row 0 is "
Index: kchartEngine.cc
===================================================================
RCS file: /home/kde/koffice/kchart/kchartEngine.cc,v
retrieving revision 1.11
diff -u -r1.11 kchartEngine.cc
--- kchartEngine.cc 2000/07/14 11:41:17 1.11
+++ kchartEngine.cc 2000/10/14 10:34:50
@@ -54,7 +54,7 @@
num_hlc_sets = params->has_hlc_sets() ? 1 : 0;
// And num_points is the number of columns
- num_points = data->cols();
+ num_points = data->usedCols();
/* idiot checks */
if( imagewidth <= 0 || imageheight <=0 || !p )
Index: sheetdlg.cc
===================================================================
RCS file: /home/kde/koffice/kchart/sheetdlg.cc,v
retrieving revision 1.7
diff -u -r1.7 sheetdlg.cc
--- sheetdlg.cc 1999/11/14 18:46:47 1.7
+++ sheetdlg.cc 2000/10/14 10:36:43
@@ -101,6 +101,18 @@
}
+void SheetDlg::setUsedCols( int val )
+{
+ usedcolsSB->setValue( val );
+}
+
+
+void SheetDlg::setUsedRows( int val )
+{
+ usedrowsSB->setValue( val );
+}
+
+
QString SheetDlg::getX(int col)
{
return t->getX(col);
Index: kchart_part.cc
===================================================================
RCS file: /home/kde/koffice/kchart/kchart_part.cc,v
retrieving revision 1.49
diff -u -r1.49 kchart_part.cc
--- kchart_part.cc 2000/09/23 21:37:36 1.49
+++ kchart_part.cc 2000/10/14 10:40:11
@@ -71,6 +71,8 @@
if (currentData.rows() == 0) {
kdDebug(35001) << "Initialize with some data!!!" << endl;
currentData.expand(4,4);
+ currentData.setUsedRows( 4 );
+ currentData.setUsedCols( 4 );
for (row = 0;row < 4;row++)
for (col = 0;col < 4;col++) {
KoChart::Value t( (double)row+col );
@@ -103,7 +105,7 @@
// kdDebug(35001) << "KChartPart::paintContent called, rows = "
// << currentData.rows() << ", cols = "
- // << currentData.cols() << endl;
+ // << currentData.usedCols() << endl;
// Need to draw only the document rectangle described in the parameter rect.
// return;
@@ -143,17 +145,17 @@
}
if( _params->xlbl.isEmpty() ) {
- for(unsigned int i=0;i<currentData.cols();i++) {
+ for( unsigned int i=0;i<currentData.usedCols();i++) {
QString tmp;
tmp="Year 200"+tmp.setNum(i);
_params->xlbl+=tmp;
}
}
- QArray<int> tmpExp(currentData.cols()*currentData.rows());
- QArray<bool> tmpMissing(currentData.cols()*currentData.rows());
+ QArray<int> tmpExp(currentData.usedCols()*currentData.rows());
+ QArray<bool> tmpMissing(currentData.usedCols()*currentData.rows());
- for(unsigned int i=0; i<(currentData.cols()*currentData.rows()); ++i )
+ for(unsigned int i=0; i<(currentData.usedCols()*currentData.rows()); ++i )
{
tmpExp[i]=0;
tmpMissing[i]=FALSE;
@@ -195,6 +197,8 @@
QDomElement data = doc.createElement("data");
data.setAttribute("rows", currentData.rows());
data.setAttribute("cols", currentData.cols());
+ data.setAttribute("usedRows", currentData.usedRows() );
+ data.setAttribute("usedCols", currentData.usedCols() );
for (unsigned int row = 0;row < currentData.rows();row++) {
for (unsigned int col = 0;col < currentData.cols();col++) {
// later we need a value
@@ -431,13 +435,21 @@
QDomElement data = chart.namedItem("data").toElement();
bool ok;
int cols = data.attribute("cols").toInt(&ok);
- kdDebug(35001) << "cols readed as:" << cols << endl;
if (!ok) { return false; }
+ kdDebug(35001) << "cols read as:" << cols << endl;
+ int usedCols = data.attribute( "usedCols" ).toInt( &ok );
+ if( !ok )
+ usedCols = cols;
int rows = data.attribute("rows").toInt(&ok);
if (!ok) { return false; }
kdDebug(35001) << rows << " x " << cols << endl;
+ int usedRows = data.attribute( "usedRows" ).toInt( &ok );
+ if( !ok )
+ usedRows = rows;
currentData.expand(rows, cols);
kdDebug(35001) << "Expanded!" << endl;
+ currentData.setUsedCols( usedCols );
+ currentData.setUsedRows( usedRows );
QDomNode n = data.firstChild();
QArray<int> tmpExp(rows*cols);
QArray<bool> tmpMissing(rows*cols);
Index: kchart_view.cc
===================================================================
RCS file: /home/kde/koffice/kchart/kchart_view.cc,v
retrieving revision 1.49
diff -u -r1.49 kchart_view.cc
--- kchart_view.cc 2000/09/22 20:59:48 1.49
+++ kchart_view.cc 2000/10/14 10:44:11
@@ -115,6 +115,8 @@
{
kdDebug(35001) << "Initialize with some data!!!" << endl;
dat->expand(4,4);
+ dat->setUsedCols( 4 );
+ dat->setUsedRows( 4 );
for (row = 0;row < nbrow;row++)
for (col = 0;col < nbcol;col++)
{
@@ -173,6 +175,7 @@
KChartParameters* params=((KChartPart*)koDocument())->params();
KoChart::Data *dat = (( (KChartPart*)koDocument())->data());
+ qDebug( "***Before calling editor: cols = %d, rows = %d, usedCols = %d, usedRows = \
%d", dat->cols(), dat->rows(), dat->usedCols(), dat->usedRows() ); ed.setData(dat);
ed.setLegend(params->legend);
ed.setXLabel(params->xlbl);
@@ -180,6 +183,7 @@
return;
}
ed.getData(dat);
+ qDebug( "***Before calling editor: cols = %d, rows = %d, usedCols = %d, usedRows = \
%d", dat->cols(), dat->rows(), dat->usedCols(), dat->usedRows() ); \
ed.getLegend(params); ed.getXLabel(params);
repaint();
Index: ktable.h
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/ktable.h,v
retrieving revision 1.5
diff -u -r1.5 ktable.h
--- ktable.h 2000/09/18 09:57:40 1.5
+++ ktable.h 2000/10/14 10:48:19
@@ -174,6 +174,7 @@
{
private:
typedef KTablePrivate<RowT,ColT,CellT> Priv;
+ uint _usedRows, _usedCols;
public:
/**
@@ -191,8 +192,8 @@
/**
* API
*/
- KTable() { sh = new Priv; }
- KTable( uint _rows, uint _cols ) { sh = new Priv( _rows, _cols ); }
+ KTable() { sh = new Priv; _usedCols = 0; _usedRows = 0; }
+ KTable( uint _rows, uint _cols ) { sh = new Priv( _rows, _cols ); usedRows = \
_rows; usedCols = _cols; } KTable( const KTable& _t ) { sh = _t.sh; sh->ref(); }
~KTable() { if ( sh->deref() ) delete sh; }
@@ -236,6 +237,22 @@
void removeRow( uint _r ) { detach(); sh->removeRow( _r ); }
void expand( uint _rows, uint _cols ) { detach(); sh->expand( _rows, _cols ); }
+
+ void setUsedRows( uint _rows ) {
+ ASSERT( _rows <= rows() );
+ _usedRows = _rows;
+ }
+ uint usedRows() const {
+ return _usedRows;
+ }
+ void setUsedCols( uint _cols ) {
+ ASSERT( _cols <= cols() );
+ _usedCols = _cols;
+ }
+ uint usedCols() const {
+ return _usedCols;
+ }
+
private:
/**
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic