Loading...
Searching...
No Matches
QtableWriter Class Reference

`#include <qtablewriter.h>`

## Public Member Functions

| QtableWriter (CalcWriterInterface *p_writer, const QAbstractProxyModel *p_table_model)
void | writeSheet (const QString &sheetName)
| write the entire table in a sheet
void | setFormatPercentForColumn (const QString &column_title)
void | setFormatPercentForColumn (const QModelIndex &column_index)

## Private Attributes

CalcWriterInterface * | mp_writer
const QAbstractProxyModel * | mp_tableModel
std::map< int, bool > | m_percentColumns

## Detailed Description

Definition at line 37 of file qtablewriter.h.

## Constructor & Destructor Documentation

## QtableWriter()

QtableWriter::QtableWriter | ( | CalcWriterInterface * | p_writer,
|  | const QAbstractProxyModel * | p_table_model )

Definition at line 34 of file qtablewriter.cpp.

: mp_writer(p_writer), mp_tableModel(p_table_model)
{
for(int i = 0; i < mp_tableModel->columnCount(); i++)
{
m_percentColumns.insert(std::pair<int, bool>(i, false));
}
}
QtableWriter::m_percentColumns
std::map< int, bool > m_percentColumns
Definition qtablewriter.h:42
QtableWriter::mp_tableModel
const QAbstractProxyModel * mp_tableModel
Definition qtablewriter.h:41
QtableWriter::mp_writer
CalcWriterInterface * mp_writer
Definition qtablewriter.h:40

References m_percentColumns, mp_tableModel, and mp_writer.

## Member Function Documentation

## setFormatPercentForColumn() [1/2]

void QtableWriter::setFormatPercentForColumn | ( | const QModelIndex & | column_index | ) |

Definition at line 63 of file qtablewriter.cpp.

{
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " col=" << column_index.column();
QModelIndex nIndex = mp_tableModel->mapFromSource(column_index);
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " col=" << nIndex.column();
m_percentColumns[nIndex.column()] = true;
}

References m_percentColumns, and mp_tableModel.

## setFormatPercentForColumn() [2/2]

void QtableWriter::setFormatPercentForColumn | ( | const QString & | column_title | ) |

Definition at line 45 of file qtablewriter.cpp.

{
int col_number = mp_tableModel->columnCount();
for(int j = 0; j < col_number; j++)
{
QVariant head_var =
mp_tableModel->headerData(j, Qt::Horizontal, Qt::DisplayRole);
if(head_var.toString() == column_title)
{
m_percentColumns[j] = true;
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " col=" << j;
}
}
}

References m_percentColumns, and mp_tableModel.

## writeSheet()

void QtableWriter::writeSheet | ( | const QString & | sheetName | ) |

write the entire table in a sheet

Parameters

  sheetName | the sheet name

Definition at line 75 of file qtablewriter.cpp.

{
mp_writer->writeSheet(sheetName);
OdsTableSettings settings;
// settings.setHorizontalWindowSplit(4);
settings.setVerticalSplit(1);
mp_writer->setCurrentOdsTableSettings(settings);
int col_number = mp_tableModel->columnCount();
int line_number = mp_tableModel->rowCount();
bool ok = false;
for(int j = 0; j < col_number; j++)
{
QVariant head_var =
mp_tableModel->headerData(j, Qt::Horizontal, Qt::ToolTipRole);
if(head_var.isNull())
{
}
else
{
mp_writer->setCellAnnotation(head_var.toString());
}
head_var = mp_tableModel->headerData(j, Qt::Horizontal, Qt::DisplayRole);
if(head_var.isNull())
{
mp_writer->writeEmptyCell();
}
else
{
mp_writer->writeCell(head_var.toString());
}
}
for(int i = 0; i < line_number; i++)
{
mp_writer->writeLine();
for(int j = 0; j < col_number; j++)
{
QModelIndex index = mp_tableModel->index(i, j);
QVariant var = mp_tableModel->data(index, Qt::CheckStateRole);
if(var.isNull())
{
var = mp_tableModel->data(index, Qt::DisplayRole);
ok = false;
if(var.isNull())
{
mp_writer->writeEmptyCell();
}
else
{
double var_float = var.toDouble(&ok);
if(ok)
{
if(m_percentColumns[j])
{
mp_writer->writeCellPercentage(var_float);
}
else
{
mp_writer->writeCell(var_float);
}
}
else
{
mp_writer->writeCell(var.toString());
}
}
}
else
{
if(var == Qt::Checked)
{
mp_writer->writeCell(true);
}
else
{
mp_writer->writeCell(false);
}
}
}
}
}
OdsTableSettings::setVerticalSplit
void setVerticalSplit(unsigned int position)
Definition odstablesettings.cpp:81

References m_percentColumns, mp_tableModel, mp_writer, and OdsTableSettings::setVerticalSplit().

## Member Data Documentation

## m_percentColumns

std::map<int, bool> QtableWriter::m_percentColumns

private

Definition at line 42 of file qtablewriter.h.

Referenced by QtableWriter(), setFormatPercentForColumn(), setFormatPercentForColumn(), and writeSheet().

## mp_tableModel

const QAbstractProxyModel* QtableWriter::mp_tableModel

private

Definition at line 41 of file qtablewriter.h.

Referenced by QtableWriter(), setFormatPercentForColumn(), setFormatPercentForColumn(), and writeSheet().

## mp_writer

CalcWriterInterface* QtableWriter::mp_writer

private

Definition at line 40 of file qtablewriter.h.

Referenced by QtableWriter(), and writeSheet().

The documentation for this class was generated from the following files:

- odsstream/qtablewriter.h
- odsstream/qtablewriter.cpp