private: int m_iCntTbls; int m_iColCnt; QTextDocument *const m_document; QTextCursor m_cursor;
void Reporter::setCompanyDoc(QString str){ // - m_cursor.movePosition(QTextCursor::End); if(m_iCntTbls>0){ m_cursor.insertBlock(); m_cursor.insertBlock(); m_cursor.movePosition(QTextCursor::End); } // QTextBlockFormat blockFrm; blockFrm.setTopMargin(5); blockFrm.setBottomMargin(5); blockFrm.setAlignment(Qt::AlignLeft); blockFrm.setBackground(QBrush(QColor("lightGray"))); // m_cursor.insertBlock(blockFrm); m_cursor.insertText(str); }
void Reporter::setDataHeader(QStringList strLst){ // - m_cursor.movePosition(QTextCursor::End); if(m_iCntTbls>0){ m_cursor.insertBlock(); m_cursor.insertBlock(); m_cursor.movePosition(QTextCursor::End); } // QBrush borderBrush(Qt::SolidPattern); // QTextTableFormat tableFormat; tableFormat.setCellPadding(5); tableFormat.setCellSpacing(0); tableFormat.setHeaderRowCount(1); tableFormat.setBorderBrush(borderBrush); tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Ridge); tableFormat.setBorder(1); tableFormat.setWidth(QTextLength(QTextLength::PercentageLength,100)); // m_cursor.insertTable(1,strLst.count(),tableFormat); foreach(QString str, strLst){ m_cursor.insertText(str); m_cursor.movePosition(QTextCursor::NextCell); } m_iCntTbls++; m_iColCnt=strLst.count(); }
void Reporter::addData(QStringList strLst){ // , if(strLst.count()<m_iColCnt){ int iAdd=m_iColCnt-strLst.count(); while(iAdd>0){ iAdd--; strLst<<""; } }else // - if(strLst.count()>m_iColCnt){ QMessageBox::critical(0, tr("AddData"), tr("Too many elements to paste wait %1 got %2").arg(m_iColCnt).arg(strLst.count()), QMessageBox::Ok,QMessageBox::Ok ); return; } // QTextTable *tbl=m_cursor.currentTable(); tbl->appendRows(1); m_cursor.movePosition(QTextCursor::PreviousRow); foreach(QString str, strLst){ m_cursor.movePosition(QTextCursor::NextCell); m_cursor.insertText(str); } }
m_reporter->setCompanyDoc(QString::fromLocal8Bit(" ")); m_reporter->setCaptionDoc(QString::fromLocal8Bit(" №0")); strLst<<QString::fromLocal8Bit(" ")<<setStr(" ")<<setStr(" ")<<setStr(" ") <<setStr(" .")<<setStr(" .")<<setStr(""); .....
QPainter painter(this); QRect rec(0,0,this->width(),this->height()); m_reporter->getTextDoc()->drawContents(&painter,rec);
Source: https://habr.com/ru/post/308126/
All Articles