Skip to content

Commit

Permalink
HPlainDataMatrix header name based cell specifications
Browse files Browse the repository at this point in the history
HSqlHandler's submitNResultQuery function reads the header names
  • Loading branch information
hyper-prog committed Mar 2, 2021
1 parent edff130 commit 24ac5c5
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.3.30
-Improved HPlainDataMatrix class with row index and header name based cell specifications
Make this possible for cell set & get functions
-HSqlHandler submitNResultQuery reads and set header names in the resulted HPlainDataMatrix.
-Added HPlainDataMatrix full header reset method.

1.3.29
-Improved dconsole text coloring

Expand Down
60 changes: 58 additions & 2 deletions datalib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ QVariant HSqlHandler::submit1ResultQuery(QString q,QString err,bool tdisabled)

HPlainDataMatrix* HSqlHandler::submitNResultQuery(int N,QString q,QString err,bool tdisabled)
{
int i;
int i,r;
QList<QVariant> list;
HPlainDataMatrix* dm=NULL;

Expand All @@ -1332,7 +1332,6 @@ HPlainDataMatrix* HSqlHandler::submitNResultQuery(int N,QString q,QString err,bo
if((myInterface()->hsqli_usequerysize && qi->numRowsAffected() < 0) ||
qi->lastError().type() != QSqlError::NoError )
{

if(!tdisabled)
rollback();

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

r = 0;
while(qi->next())
{
if(r == 0)
{
QList<QString> headers;
int cc = qi->record().count();
for(i=0;i<cc;++i)
headers.push_back(qi->record().field(i).name());
dm->setHeader(headers);
}

list.clear();
for(i=0 ; i < qi->record().count() ; ++i)
list.push_back( qi->value(i) );
dm->addRow(list);
++r;
}

if(!tdisabled)
Expand Down Expand Up @@ -1470,6 +1480,22 @@ void HPlainDataMatrix::setHeader(QList<QString> strlistdata)
}
}

void HPlainDataMatrix::clearHeader(void)
{
int i;
for(i = 0; i < col_count;++i)
hheader[i] = "";
}

int HPlainDataMatrix::getHeaderColIndex(QString headertext)
{
int i;
for(i = 0; i < col_count;++i)
if(hheader[i] == headertext)
return i;
return -1;
}

void HPlainDataMatrix::setHeader(QString d1,QString d2,QString d3
,QString d4,QString d5,QString d6
,QString d7,QString d8,QString d9
Expand Down Expand Up @@ -1662,6 +1688,36 @@ void HPlainDataMatrix::setCell(int row,int col,QVariant vdata)
(data.at(row))[col] = vdata;
}

QVariant HPlainDataMatrix::getCellH(int row,QString colheader)
{
int colIdx = getHeaderColIndex(colheader);
if(colIdx < 0)
return QVariant();
return getCell(row,colIdx);
}

QString HPlainDataMatrix::getCellHStr(int row,QString colheader)
{
int colIdx = getHeaderColIndex(colheader);
if(colIdx < 0)
return QString();
return getCellStr(row,colIdx);
}

void HPlainDataMatrix::setCellH(int row,QString colheader,QVariant vdata)
{
int colIdx = getHeaderColIndex(colheader);
if(colIdx >= 0)
setCell(row,colIdx,vdata);
}

void HPlainDataMatrix::setCellHStr(int row,QString colheader,QString strdata)
{
int colIdx = getHeaderColIndex(colheader);
if(colIdx >= 0)
setCellStr(row,colIdx,strdata);
}

void HPlainDataMatrix::setRowControl(int row,QString ctrl)
{
if(row < 0 )
Expand Down
20 changes: 19 additions & 1 deletion datalib.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "gstexts.h"

/** The version of gsafe */
#define GSAFE_VERSION "1.3.29"
#define GSAFE_VERSION "1.3.30"

// ///////////////////////////////////
// BEGIN - CONFIG/MODIFIERS/MODULES //
Expand Down Expand Up @@ -421,6 +421,8 @@ class HPlainDataMatrix : public HBase

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

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

/** Returns the content of the cell, the column is specified by the header text.
If the headers are not set or not found this function returns empty value. */
QVariant getCellH(int row,QString colheader);
/** Returns the content of the cell, the column is specified by the header text.
If the headers are not set or not found this function returns empty value. */
QString getCellHStr(int row,QString colheader);
/** Sets the content of the cell, the column is specified by the header text.
If the headers are not set or not found this function does nothing. */
void setCellH(int row,QString colheader,QVariant vdata);
/** Sets the content of the cell the column is specified by the header text.
If the headers are not set or not found this function does nothing. */
void setCellHStr(int row,QString colheader,QString strdata);

/** Sets the control string of the specified row */
void setRowControl(int row,QString ctrl);

Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.29
1.3.30

0 comments on commit 24ac5c5

Please sign in to comment.