The code i modified was located at openRPT/renderapp folder in your source code posted in sourceforge (i used the version 3.2.0, because the 3.2.1 code wasn’t uploaded to your sourceforge project).
I just had to modify the main.cpp file, adding the run-time switch to the ones you had already defined, using a boolean called autoPrint to add the feature I needed.
After reading the command line parameters, i added the autoPrint boolean to the renderWindow class, so it could be aware when the users want to print without prompting the QPrintDialog or not, and set it with the value false if -autoPrint wasn’t in the arguments received or true if it was.
The changes I made to the code who is responsible to show the window and make it print or not are in the next lines:
If autoPrint is true, we don’t need to show the renderWindow.
if (!pdfOutput and !autoPrint)
mainwin.show();
If autoprint or print is true, we have to print numCopies of the report
if(print or autoPrint) //AUTOPRINT
mainwin.filePrint( numCopies );
The rest of the modifications are located in the renderWindow class. (renderwindow.h and renderwindow.cpp).
In the renderwindow.h i added a boolean parameter so the window is aware of the election of the user (autoprint or not). I declared this parameter in the public section:
public:
RenderWindow(QWidget* parent = 0, Qt::WindowFlags fl = 0);
~RenderWindow();
QString _printerName;
bool _autoPrint; //AUTOPRINT
In the renderwindow.cpp the modifications are located just in the print function:
void RenderWindow::print(bool showPreview, int numCopies ) //AUTOPRINT
{
ORPreRender pre;
pre.setDom(_doc);
pre.setParamList(getParameterList());
ORODocument * doc = pre.generate();
if(doc)
{
QPrinter printer(QPrinter::HighResolution);
printer.setNumCopies( numCopies );
if(!_printerName.isEmpty())
{
printer.setPrinterName(_printerName);
_printerName = QString::null;
}
if(showPreview)
{
PreviewDialog preview (doc, &printer, this);
if (preview.exec() == QDialog::Rejected)
return;
}
ORPrintRender render;
render.setupPrinter(doc, &printer);
if(_autoPrint){ //AUTOPRINT
render.setPrinter(&printer);
render.render(doc);
}
else{
QPrintDialog pd(&printer);
pd.setMinMax(1, doc->pages());
if(pd.exec() == QDialog::Accepted)
{
render.setPrinter(&printer);
render.render(doc);
}
}
delete doc;
}
}
as marked by the //AUTOPRINT comment, I added an if statement in which, if autoPrint is set, the report is directly printed without prompting the QPrintDialog. If autoPrint is not set, it just does the regular functionality
I attach a .zip with the three files i had to modify in your code.
Best regards.
Josep