int index=ui->m_tableWidgetLogger->currentRow();
if(index<0)
return;
int screenResolution = screenPrinter.resolution();
printer.
setOrientation(QPrinter::Portrait);
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
painter.begin(&printer);
QPen pen
(Qt
::black,
2, Qt
::SolidLine);
painter.setPen(pen);
painter.drawRoundRect(0,0,7400,1050,25,25);
// QPen pen(Qt::black, 20, Qt::SolidLine);
// painter.setPen(pen);
// QLineF line(10,10,15000,10);
// painter.drawLine(line);
painter.scale(0.75f,0.75f);
// painter.setFont(QFont("Helvetica",24,QFont::Bold));
// QRect rect(0,0,painter.viewport().width(),painter.fontMetrics().height());
// painter.drawText(rect,"report",QTextOption(Qt::AlignCenter));
// Print Summary
m_mainApp->m_table->SetTableWidget(summaryTab);
summaryTab->setGeometry(6,8,printer.pageRect().width(),printer.pageRect().height());
summaryTab->setAutoScroll(false);
m_mainApp->m_table->InitTableSummary(summaryTab);
m_mainApp->m_table->FillTableSummary(summaryTab,index);
summaryTab->setAlternatingRowColors(true);
summaryTab
->setFrameShape
(QFrame::NoFrame);
painter.save();
painter.scale(printer.resolution()/(screenResolution*2.5f),printer.resolution()/screenResolution*.5f);
editor->drawContents(&painter);
painter.restore();
if(m_mainApp->mLoggerList[index].recCurrentAddress)
{
// Print Graph
QwtPlotRenderer renderer;
renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground,false);
renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames,true);
renderer.
render(m_plot,
&painter,
QRect(0,printer.
height()/2,printer.
width(),printer.
height()/2.2));
printer.newPage();
// Print Table
m_mainApp->m_table->SetTableWidget(table);
table->setGeometry(0,0,printer.pageRect().width(),printer.pageRect().height());
table->setAutoScroll(true);
m_mainApp->m_table->InitTablePrint(index,printer.pageRect().width());
int nbPage=m_mainApp->m_table->GetNbPrintPage(index,printer.pageRect().height());
for(int page=0;page<nbPage;page++)
{
m_mainApp->m_table->currentIndex=-1;
m_mainApp->m_table->InitTablePrint(index,printer.pageRect().width());
m_mainApp->m_table->FillTablePrint(index,printer.pageRect().height(),page);
painter.save();
painter.scale(printer.resolution()/(screenResolution*1.5f),printer.resolution()/screenResolution*.45f);
editor->drawContents(&painter);
painter.restore();
printer.newPage();
}
// Print Histogram
renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground,false);
renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames,true);
// renderer.render(m_histogram,&painter,QRect(0,0,printer.width(),printer.height()/2.2));
renderer.
render(m_histogram,
&painter,
QRect(0,printer.
height()/2,printer.
width(),printer.
height()/2.2));
painter.end();
}
int index=ui->m_tableWidgetLogger->currentRow();
if(index<0)
return;
QPrinter screenPrinter(QPrinter::ScreenResolution);
int screenResolution = screenPrinter.resolution();
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Portrait);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
QPainter painter;
painter.begin(&printer);
QPen pen(Qt::black, 2, Qt::SolidLine);
painter.setPen(pen);
painter.drawRoundRect(0,0,7400,1050,25,25);
// QPen pen(Qt::black, 20, Qt::SolidLine);
// painter.setPen(pen);
// QLineF line(10,10,15000,10);
// painter.drawLine(line);
painter.scale(0.75f,0.75f);
// painter.setFont(QFont("Helvetica",24,QFont::Bold));
// QRect rect(0,0,painter.viewport().width(),painter.fontMetrics().height());
// painter.drawText(rect,"report",QTextOption(Qt::AlignCenter));
// Print Summary
QTableWidget *summaryTab=new QTableWidget();
m_mainApp->m_table->SetTableWidget(summaryTab);
summaryTab->setGeometry(6,8,printer.pageRect().width(),printer.pageRect().height());
summaryTab->setAutoScroll(false);
m_mainApp->m_table->InitTableSummary(summaryTab);
m_mainApp->m_table->FillTableSummary(summaryTab,index);
summaryTab->setAlternatingRowColors(true);
summaryTab->setFrameShape(QFrame::NoFrame);
painter.save();
QTextDocument *editor = QTableWidget2QTextBrowser(summaryTab);
painter.scale(printer.resolution()/(screenResolution*2.5f),printer.resolution()/screenResolution*.5f);
editor->drawContents(&painter);
painter.restore();
if(m_mainApp->mLoggerList[index].recCurrentAddress)
{
// Print Graph
QwtPlotRenderer renderer;
renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground,false);
renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames,true);
renderer.render(m_plot,&painter,QRect(0,printer.height()/2,printer.width(),printer.height()/2.2));
printer.newPage();
// Print Table
QTableWidget *table=new QTableWidget();
m_mainApp->m_table->SetTableWidget(table);
table->setGeometry(0,0,printer.pageRect().width(),printer.pageRect().height());
table->setAutoScroll(true);
m_mainApp->m_table->InitTablePrint(index,printer.pageRect().width());
int nbPage=m_mainApp->m_table->GetNbPrintPage(index,printer.pageRect().height());
for(int page=0;page<nbPage;page++)
{
m_mainApp->m_table->currentIndex=-1;
m_mainApp->m_table->InitTablePrint(index,printer.pageRect().width());
m_mainApp->m_table->FillTablePrint(index,printer.pageRect().height(),page);
painter.save();
QTextDocument *editor = QTableWidget2QTextBrowser(table);
painter.scale(printer.resolution()/(screenResolution*1.5f),printer.resolution()/screenResolution*.45f);
editor->drawContents(&painter);
painter.restore();
printer.newPage();
}
// Print Histogram
renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground,false);
renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames,true);
// renderer.render(m_histogram,&painter,QRect(0,0,printer.width(),printer.height()/2.2));
renderer.render(m_histogram,&painter,QRect(0,printer.height()/2,printer.width(),printer.height()/2.2));
painter.end();
}
To copy to clipboard, switch view to plain text mode
editor->setDocumentMargin(25);
//creates writing format
NormalFormat.
setFont(QFont("Helvetica",
24,
QFont::Bold));
NormalFormat.setFontWordSpacing(20);
NormalFormat.setTableCellRowSpan(200);
//create pointer to current cursor location
cursor.beginEditBlock();
cursor.
insertImage(QImage(":/Pictures/escort.png"));
cursor.insertText("Escort Data Logger Report",NormalFormat);
// QTextBlockFormat block = cursor.blockFormat();
// Qt::Alignment vertAlign = block.alignment() & Qt::AlignVertical_Mask;
// Qt::Alignment horzAlign = block.alignment() & Qt::AlignHorizontal_Mask;
// Qt::Alignment combAlign = horzAlign | vertAlign;
// block.setAlignment(combAlign);
// cursor.setBlockFormat(block);
// tableFormat.setAlignment(Qt::AlignCenter);
tableFormat.
setBackground(QColor("#ffffff"));
tableFormat.setCellPadding(4);
tableFormat.setCellSpacing(3);
tableFormat.setRightMargin(9000);
QTextTable *tab
=cursor.
insertTable(tabW
->rowCount
()+1,tabW
->columnCount
(),tableFormat
);
//QTextTable *tab=cursor.insertTable(tabW->setRowCount(200),tabW->setColumnCount(10));
frameFormat.setBorder(0);
frame->setFrameFormat(frameFormat);
frameFormat.
setPageBreakPolicy(QTextFormat::PageBreak_Auto);
// frameFormat.setBottomMargin(3);
frameFormat.setLeftMargin(5);
format_entete_tab.setFontPointSize(15);
format_entete_tab.
setFontWeight(QFont::Bold);
format_cellule.setFontPointSize(11);
for(int i=0;i<tabW->columnCount();i++)
{
cellCursor.insertText(tabW->horizontalHeaderItem(i)->text(),format_entete_tab);
}
for(int row=1;row<tab->rows();row++)
{
for(int col=0;col<tab->columns();col++)
{
cell=tab->cellAt(row,col);
cellCursor=cell.firstCursorPosition();
}
}
cursor.endEditBlock();
QTextDocument *editor = new QTextDocument;
editor->setDocumentMargin(25);
//creates writing format
QTextCharFormat NormalFormat;
NormalFormat.setFont(QFont("Helvetica",24,QFont::Bold));
NormalFormat.setFontWordSpacing(20);
NormalFormat.setTableCellRowSpan(200);
//create pointer to current cursor location
QTextCursor cursor (editor);
cursor.beginEditBlock();
cursor.insertImage(QImage(":/Pictures/escort.png"));
cursor.insertText("Escort Data Logger Report",NormalFormat);
// QTextBlockFormat block = cursor.blockFormat();
// Qt::Alignment vertAlign = block.alignment() & Qt::AlignVertical_Mask;
// Qt::Alignment horzAlign = block.alignment() & Qt::AlignHorizontal_Mask;
// Qt::Alignment combAlign = horzAlign | vertAlign;
// block.setAlignment(combAlign);
// cursor.setBlockFormat(block);
QTextTableFormat tableFormat;
// tableFormat.setAlignment(Qt::AlignCenter);
tableFormat.setBackground(QColor("#ffffff"));
tableFormat.setCellPadding(4);
tableFormat.setCellSpacing(3);
tableFormat.setRightMargin(9000);
QTextTable *tab=cursor.insertTable(tabW->rowCount()+1,tabW->columnCount(),tableFormat);
//QTextTable *tab=cursor.insertTable(tabW->setRowCount(200),tabW->setColumnCount(10));
QTextFrame *frame=cursor.currentFrame();
QTextFrameFormat frameFormat=frame->frameFormat();
frameFormat.setBorder(0);
frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Inset);
frame->setFrameFormat(frameFormat);
frameFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
cursor.movePosition(QTextCursor::NextBlock);
// frameFormat.setBottomMargin(3);
frameFormat.setLeftMargin(5);
QTextCharFormat format_entete_tab;
format_entete_tab.setFontPointSize(15);
format_entete_tab.setFontWeight(QFont::Bold);
QTextCharFormat format_cellule;
format_cellule.setFontPointSize(11);
for(int i=0;i<tabW->columnCount();i++)
{
QTextTableCell titre = tab->cellAt(0,i);
QTextCursor cellCursor=titre.firstCursorPosition();
cellCursor.insertText(tabW->horizontalHeaderItem(i)->text(),format_entete_tab);
}
QTextTableCell cell;
QTextCursor cellCursor;
for(int row=1;row<tab->rows();row++)
{
for(int col=0;col<tab->columns();col++)
{
cell=tab->cellAt(row,col);
cellCursor=cell.firstCursorPosition();
}
}
cursor.endEditBlock();
To copy to clipboard, switch view to plain text mode
int CTable::GetNbPrintPage(int index,int maxVerticalSizes)
{
int nbPage;
int currentRowHeight=18;
int nbRowInPage=(maxVerticalSizes-mTab->horizontalHeader()->height())/currentRowHeight;
nbRowInPage*=3;
int nbRec=m_main->mLoggerList[index].recCurrentAddress;
nbPage=nbRec/nbRowInPage;
if(nbRec%nbRowInPage)
nbPage++;
return nbPage;
}
void CTable::FillTablePrint(int index,int maxVerticalSizes ,int page)
{
QString strDate,strValue,strElapsed;
int nbRec,startRec,col,nbRowInPage;
int currentRowHeight=18;
double data;
int val;
if(index==-1)
return;
///// newItem->setTextAlignment(30);
nbRowInPage=(maxVerticalSizes-mTab->horizontalHeader()->height())/currentRowHeight;
nbRec=m_main->mLoggerList[index].recCurrentAddress;
startRec=nbRowInPage*page*2;
if((nbRec-startRec)<(nbRowInPage*2))
nbRowInPage=(nbRec-startRec)/2;
// mTab->resizeRowsToContents();
mTab->setRowCount(nbRowInPage);
QFont font
("Courrier",
8,
8,
false);
font.setBold(true);
// mTab->setFont(font);
startTime=m_main->mLoggerList[index].recStartTime;
if(page)
{
startTime=startTime.addSecs(m_main->mLoggerList[index].prgInterval*startRec);
elapsedTime=elapsedTime.addSecs(m_main->mLoggerList[index].prgInterval*startRec);
}
for(int i=0;nbRowInPage && (startRec<nbRec);i++)
{
col=!(i&0x01)?0:6;
int CTable::GetNbPrintPage(int index,int maxVerticalSizes)
{
int nbPage;
int currentRowHeight=18;
int nbRowInPage=(maxVerticalSizes-mTab->horizontalHeader()->height())/currentRowHeight;
nbRowInPage*=3;
int nbRec=m_main->mLoggerList[index].recCurrentAddress;
nbPage=nbRec/nbRowInPage;
if(nbRec%nbRowInPage)
nbPage++;
return nbPage;
}
void CTable::FillTablePrint(int index,int maxVerticalSizes ,int page)
{
QTableWidgetItem *newItem;
QString strDate,strValue,strElapsed;
QDateTime startTime;
QTime elapsedTime;
int nbRec,startRec,col,nbRowInPage;
int currentRowHeight=18;
double data;
int val;
if(index==-1)
return;
///// newItem->setTextAlignment(30);
nbRowInPage=(maxVerticalSizes-mTab->horizontalHeader()->height())/currentRowHeight;
nbRec=m_main->mLoggerList[index].recCurrentAddress;
startRec=nbRowInPage*page*2;
if((nbRec-startRec)<(nbRowInPage*2))
nbRowInPage=(nbRec-startRec)/2;
// mTab->resizeRowsToContents();
mTab->setRowCount(nbRowInPage);
QFont font("Courrier",8,8,false);
font.setBold(true);
// mTab->setFont(font);
startTime=m_main->mLoggerList[index].recStartTime;
if(page)
{
startTime=startTime.addSecs(m_main->mLoggerList[index].prgInterval*startRec);
elapsedTime=elapsedTime.addSecs(m_main->mLoggerList[index].prgInterval*startRec);
}
for(int i=0;nbRowInPage && (startRec<nbRec);i++)
{
col=!(i&0x01)?0:6;
To copy to clipboard, switch view to plain text mode
Bookmarks