void mainScreen::printreport()
{
model->setTable("instreportview");
model->select();
"/home",
// | QFileDialog::DontResolveSymlinks);
checkdialog=false;
QString note
="Please enter below the file name by which you want to save the report.";
note+=" The report will be saved on the desktop";
userinfo->setText(note);
//QLabel *directory
_cancelInfo->setDefault(true);
_saveInfo->setDefault(true);
buttonlay->addWidget(_cancelInfo);
buttonlay->addWidget(_saveInfo);
labellay->addWidget(fnamelabel);
labellay->addWidget(fname);
//leftlay->addWidget(userinfo);
//leftlay->addLayout(labellay);
mainlay->addLayout(labellay);
mainlay->addLayout(buttonlay);
userprompt->setLayout(mainlay);
connect(_cancelInfo,SIGNAL(clicked()),this,SLOT(dialogcancel()));
connect(_saveInfo,SIGNAL(clicked()),this,SLOT(dialogsave()));
userprompt->exec();
head1.setBold(true);
head1.setPixelSize(18);
heading=" Bank Relationship Management System";
charformat.setFont(head1);
cursor->insertText(heading,charformat);
tableFormat.setCellPadding(5);
tableFormat.setHeaderRowCount(1);
tableFormat.setBorderStyle(
int rows=model->rowCount();
int cols=model->columnCount();
cursor->insertTable(rows,cols,tableFormat);
cursor
->insertText
(QObject::tr("Instrument Number"));
cursor
->insertText
(QObject::tr("Opening Bank"));
cursor
->insertText
(QObject::tr("Opening Branch"));
cursor
->insertText
(QObject::tr("Second Party"));
cursor
->insertText
(QObject::tr("Type"));
cursor
->insertText
(QObject::tr("Sub Type"));
cursor
->insertText
(QObject::tr("Status"));
cursor
->insertText
(QObject::tr("Amount"));
cursor
->insertText
(QObject::tr("Local Comptuted Cost"));
cursor
->insertText
(QObject::tr("Computed Cost"));
cursor
->insertText
(QObject::tr("Negotiated Cost"));
cursor
->insertText
(QObject::tr("Currency"));
cursor
->insertText
(QObject::tr("Opening Date"));
cursor
->insertText
(QObject::tr("Closing Date"));
for(int i=0;i<model->rowCount();i++)
{
table->appendRows(1);
//cursor->movePosition(QTextCursor::PreviousRow);
cursor->insertText(model->record(i).value(0).toString());
cursor->insertText(model->record(i).value(1).toString());
cursor->insertText(model->record(i).value(2).toString());
cursor->insertText(model->record(i).value(3).toString());
cursor->insertText(model->record(i).value(4).toString());
cursor->insertText(model->record(i).value(5).toString());
cursor->insertText(model->record(i).value(6).toString());
cursor->insertText(model->record(i).value(7).toString());
cursor->insertText(model->record(i).value(8).toString());
cursor->insertText(model->record(i).value(9).toString());
cursor->insertText(model->record(i).value(10).toString());
cursor->insertText(model->record(i).value(11).toString());
cursor->insertText(model->record(i).value(12).toString());
cursor->insertText(model->record(i).value(13).toString());
}
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.
setOrientation(QPrinter::Landscape);
//printer.setResolution(QPrinter::HighResolution);
QString fpathname
="C:/Documents and Settings/fredy/Desktop/";
QString fullname
= dir
+filename
+".pdf";
printer.setOutputFileName(fullname);
rect.setWidth(printer.width());//doc->textWidth());
rect.setHeight(printer.height());
if (! painter.begin(&printer)) { // failed to open file
qWarning("failed to open file, is it writable?");
//return 1;
}
else
{
if(checkdialog==true)
{
doc->drawContents(&painter, rect);
msg.setText(mess);
msg.exec();
checkdialog=false;
}
}
painter.end();
}
void mainScreen::printreport()
{
QSqlTableModel *model;
QPrinter printer;
model = new QSqlTableModel(this);
model->setTable("instreportview");
model->select();
QString dir = QFileDialog::getExistingDirectory(this, tr("Folder to store report in"),
"/home",
QFileDialog::ShowDirsOnly);
// | QFileDialog::DontResolveSymlinks);
checkdialog=false;
userprompt = new QDialog(this);
QString note="Please enter below the file name by which you want to save the report.";
note+=" The report will be saved on the desktop";
QLabel *userinfo=new QLabel(this);
userinfo->setText(note);
//QLabel *directory
QLabel *fnamelabel= new QLabel(tr("File Name"));
fname= new QLineEdit(this);
QPushButton *_cancelInfo = new QPushButton(tr("&Cancel"));
QPushButton *_saveInfo = new QPushButton(tr("&Save"));
QVBoxLayout *buttonlay = new QVBoxLayout(this);
QVBoxLayout *leftlay = new QVBoxLayout(this);
QHBoxLayout *labellay = new QHBoxLayout(this);
QHBoxLayout *mainlay = new QHBoxLayout(this);
_cancelInfo->setDefault(true);
_saveInfo->setDefault(true);
buttonlay->addWidget(_cancelInfo);
buttonlay->addWidget(_saveInfo);
labellay->addWidget(fnamelabel);
labellay->addWidget(fname);
//leftlay->addWidget(userinfo);
//leftlay->addLayout(labellay);
mainlay->addLayout(labellay);
mainlay->addLayout(buttonlay);
userprompt->setLayout(mainlay);
connect(_cancelInfo,SIGNAL(clicked()),this,SLOT(dialogcancel()));
connect(_saveInfo,SIGNAL(clicked()),this,SLOT(dialogsave()));
userprompt->exec();
QString filename=fname->text();
QFont head1;
head1.setBold(true);
head1.setPixelSize(18);
QString heading;//=head.bold();
heading=" Bank Relationship Management System";
QTextCharFormat charformat;
charformat.setFont(head1);
charformat.setVerticalAlignment(QTextCharFormat::AlignMiddle);
doc=new QTextDocument();
cursor= new QTextCursor(doc);
cursor->movePosition(QTextCursor::WordRight,QTextCursor::MoveAnchor,2);
cursor->insertText(heading,charformat);
cursor->movePosition(QTextCursor::Down,QTextCursor::MoveAnchor,2);
QTextTableFormat tableFormat;
tableFormat.setCellPadding(5);
tableFormat.setHeaderRowCount(1);
tableFormat.setBorderStyle(
QTextFrameFormat::BorderStyle_Solid);
tableFormat.setWidth(QTextLength(
QTextLength::PercentageLength, 100));
int rows=model->rowCount();
int cols=model->columnCount();
cursor->insertTable(rows,cols,tableFormat);
cursor->insertText(QObject::tr("Instrument Number"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Opening Bank"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Opening Branch"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Second Party"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Type"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Sub Type"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Status"));
cursor->movePosition(QTextCursor::NextCell);
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Amount"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Local Comptuted Cost"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Computed Cost"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Negotiated Cost"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Currency"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Opening Date"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Closing Date"));
QTextTable *table = cursor->currentTable();
for(int i=0;i<model->rowCount();i++)
{
table->appendRows(1);
//cursor->movePosition(QTextCursor::PreviousRow);
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(0).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(1).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(2).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(3).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(4).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(5).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(6).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(7).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(8).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(9).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(10).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(11).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(12).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(13).toString());
}
doc->setMetaInformation(QTextDocument::DocumentTitle,heading);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOrientation(QPrinter::Landscape);
printer.setPaperSize(QPrinter::A4);
//printer.setResolution(QPrinter::HighResolution);
QString fpathname="C:/Documents and Settings/fredy/Desktop/";
QString fullname= dir+filename+".pdf";
printer.setOutputFileName(fullname);
QPainter painter;
QRectF rect=QRectF();
rect.setWidth(printer.width());//doc->textWidth());
rect.setHeight(printer.height());
if (! painter.begin(&printer)) { // failed to open file
qWarning("failed to open file, is it writable?");
//return 1;
}
else
{
if(checkdialog==true)
{
doc->drawContents(&painter, rect);
QString mess="Report Saved!";
QMessageBox msg(this);
msg.setText(mess);
msg.exec();
checkdialog=false;
}
}
painter.end();
}
To copy to clipboard, switch view to plain text mode
Bookmarks