Skip to content

Commit 24ac5c5

Browse files
committed
HPlainDataMatrix header name based cell specifications
HSqlHandler's submitNResultQuery function reads the header names
1 parent edff130 commit 24ac5c5

File tree

4 files changed

+84
-4
lines changed

4 files changed

+84
-4
lines changed

ChangeLog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
1.3.30
2+
-Improved HPlainDataMatrix class with row index and header name based cell specifications
3+
Make this possible for cell set & get functions
4+
-HSqlHandler submitNResultQuery reads and set header names in the resulted HPlainDataMatrix.
5+
-Added HPlainDataMatrix full header reset method.
6+
17
1.3.29
28
-Improved dconsole text coloring
39

datalib.cpp

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ QVariant HSqlHandler::submit1ResultQuery(QString q,QString err,bool tdisabled)
13141314

13151315
HPlainDataMatrix* HSqlHandler::submitNResultQuery(int N,QString q,QString err,bool tdisabled)
13161316
{
1317-
int i;
1317+
int i,r;
13181318
QList<QVariant> list;
13191319
HPlainDataMatrix* dm=NULL;
13201320

@@ -1332,7 +1332,6 @@ HPlainDataMatrix* HSqlHandler::submitNResultQuery(int N,QString q,QString err,bo
13321332
if((myInterface()->hsqli_usequerysize && qi->numRowsAffected() < 0) ||
13331333
qi->lastError().type() != QSqlError::NoError )
13341334
{
1335-
13361335
if(!tdisabled)
13371336
rollback();
13381337

@@ -1348,12 +1347,23 @@ HPlainDataMatrix* HSqlHandler::submitNResultQuery(int N,QString q,QString err,bo
13481347
return NULL;
13491348
}
13501349

1350+
r = 0;
13511351
while(qi->next())
13521352
{
1353+
if(r == 0)
1354+
{
1355+
QList<QString> headers;
1356+
int cc = qi->record().count();
1357+
for(i=0;i<cc;++i)
1358+
headers.push_back(qi->record().field(i).name());
1359+
dm->setHeader(headers);
1360+
}
1361+
13531362
list.clear();
13541363
for(i=0 ; i < qi->record().count() ; ++i)
13551364
list.push_back( qi->value(i) );
13561365
dm->addRow(list);
1366+
++r;
13571367
}
13581368

13591369
if(!tdisabled)
@@ -1470,6 +1480,22 @@ void HPlainDataMatrix::setHeader(QList<QString> strlistdata)
14701480
}
14711481
}
14721482

1483+
void HPlainDataMatrix::clearHeader(void)
1484+
{
1485+
int i;
1486+
for(i = 0; i < col_count;++i)
1487+
hheader[i] = "";
1488+
}
1489+
1490+
int HPlainDataMatrix::getHeaderColIndex(QString headertext)
1491+
{
1492+
int i;
1493+
for(i = 0; i < col_count;++i)
1494+
if(hheader[i] == headertext)
1495+
return i;
1496+
return -1;
1497+
}
1498+
14731499
void HPlainDataMatrix::setHeader(QString d1,QString d2,QString d3
14741500
,QString d4,QString d5,QString d6
14751501
,QString d7,QString d8,QString d9
@@ -1662,6 +1688,36 @@ void HPlainDataMatrix::setCell(int row,int col,QVariant vdata)
16621688
(data.at(row))[col] = vdata;
16631689
}
16641690

1691+
QVariant HPlainDataMatrix::getCellH(int row,QString colheader)
1692+
{
1693+
int colIdx = getHeaderColIndex(colheader);
1694+
if(colIdx < 0)
1695+
return QVariant();
1696+
return getCell(row,colIdx);
1697+
}
1698+
1699+
QString HPlainDataMatrix::getCellHStr(int row,QString colheader)
1700+
{
1701+
int colIdx = getHeaderColIndex(colheader);
1702+
if(colIdx < 0)
1703+
return QString();
1704+
return getCellStr(row,colIdx);
1705+
}
1706+
1707+
void HPlainDataMatrix::setCellH(int row,QString colheader,QVariant vdata)
1708+
{
1709+
int colIdx = getHeaderColIndex(colheader);
1710+
if(colIdx >= 0)
1711+
setCell(row,colIdx,vdata);
1712+
}
1713+
1714+
void HPlainDataMatrix::setCellHStr(int row,QString colheader,QString strdata)
1715+
{
1716+
int colIdx = getHeaderColIndex(colheader);
1717+
if(colIdx >= 0)
1718+
setCellStr(row,colIdx,strdata);
1719+
}
1720+
16651721
void HPlainDataMatrix::setRowControl(int row,QString ctrl)
16661722
{
16671723
if(row < 0 )

datalib.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "gstexts.h"
3737

3838
/** The version of gsafe */
39-
#define GSAFE_VERSION "1.3.29"
39+
#define GSAFE_VERSION "1.3.30"
4040

4141
// ///////////////////////////////////
4242
// BEGIN - CONFIG/MODIFIERS/MODULES //
@@ -421,6 +421,8 @@ class HPlainDataMatrix : public HBase
421421

422422
/** Sets the whole table header text with a QString list */
423423
void setHeader(QList<QString> strlistdata);
424+
/** Clears the whole table header texts */
425+
void clearHeader(void);
424426
/** Sets the whole table header text with a list of QStrings */
425427
void setHeader(QString d1="",QString d2="",QString d3=""
426428
,QString d4="",QString d5="",QString d6=""
@@ -431,6 +433,9 @@ class HPlainDataMatrix : public HBase
431433
QString getHeaderItem(int col);
432434
/** Returns the whole table header */
433435
QList<QString> getHeader(void);
436+
/** Returns the column index of the passed header text.
437+
* If the header text not found it returns -1. */
438+
int getHeaderColIndex(QString headertext);
434439

435440
/** Sets wrap settings for the specified column which is needed for printing */
436441
void setColumnPrintWrap(int col,bool wrap) { if(col <= col_count) printCellWrap[col] = wrap; }
@@ -507,6 +512,19 @@ class HPlainDataMatrix : public HBase
507512
/** Sets the content of the specified cell */
508513
void setCellStr(int row,int col,QString strdata);
509514

515+
/** Returns the content of the cell, the column is specified by the header text.
516+
If the headers are not set or not found this function returns empty value. */
517+
QVariant getCellH(int row,QString colheader);
518+
/** Returns the content of the cell, the column is specified by the header text.
519+
If the headers are not set or not found this function returns empty value. */
520+
QString getCellHStr(int row,QString colheader);
521+
/** Sets the content of the cell, the column is specified by the header text.
522+
If the headers are not set or not found this function does nothing. */
523+
void setCellH(int row,QString colheader,QVariant vdata);
524+
/** Sets the content of the cell the column is specified by the header text.
525+
If the headers are not set or not found this function does nothing. */
526+
void setCellHStr(int row,QString colheader,QString strdata);
527+
510528
/** Sets the control string of the specified row */
511529
void setRowControl(int row,QString ctrl);
512530

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.29
1+
1.3.30

0 commit comments

Comments
 (0)