mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-06 19:20:45 +00:00
Merge branch 'master' into fix-cms50dplus
This commit is contained in:
commit
8b6d11f6f4
@ -596,7 +596,7 @@ QString Statistics::getUserInfo () {
|
|||||||
QString address = p_profile->user->address();
|
QString address = p_profile->user->address();
|
||||||
address.replace("\n", "<br/>");
|
address.replace("\n", "<br/>");
|
||||||
|
|
||||||
QString userinfo;
|
QString userinfo = "";
|
||||||
|
|
||||||
if (!p_profile->user->firstName().isEmpty()) {
|
if (!p_profile->user->firstName().isEmpty()) {
|
||||||
userinfo = tr("Name: %1, %2").arg(p_profile->user->lastName()).arg(p_profile->user->firstName()) + "<br/>";
|
userinfo = tr("Name: %1, %2").arg(p_profile->user->lastName()).arg(p_profile->user->firstName()) + "<br/>";
|
||||||
@ -614,13 +614,16 @@ QString Statistics::getUserInfo () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (userinfo.length() > 0 && userinfo.endsWith("<br/>")) // Strip trailing newlines
|
||||||
|
userinfo = userinfo.mid(0, userinfo.length()-5);
|
||||||
|
|
||||||
return userinfo;
|
return userinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString table_width = "width=99%";
|
const QString table_width = "width=99%";
|
||||||
|
|
||||||
// Create the page header in HTML. Includes everything from <head> through <body>
|
// Create the page header in HTML. Includes everything from <head> through <body>
|
||||||
QString Statistics::htmlHeader(bool showheader)
|
QString Statistics::generateHeader(bool showheader)
|
||||||
{
|
{
|
||||||
QString html = QString("<html><head>")+
|
QString html = QString("<html><head>")+
|
||||||
"</head>"
|
"</head>"
|
||||||
@ -633,21 +636,21 @@ QString Statistics::htmlHeader(bool showheader)
|
|||||||
html += "<div align=center><table class=curved width='99%'>"
|
html += "<div align=center><table class=curved width='99%'>"
|
||||||
"<tr>"
|
"<tr>"
|
||||||
"<td align='left' valign='middle'>" + getUserInfo() + "</td>"
|
"<td align='left' valign='middle'>" + getUserInfo() + "</td>"
|
||||||
"<td align='right' valign='middle' width='150'>"
|
"<td align='right' valign='middle' width='200'>"
|
||||||
"<font size='+2'>" + STR_TR_OSCAR + " </font><br/>"
|
"<font size='+2'>" + STR_TR_OSCAR + " </font><br/>"
|
||||||
"<font size='+1'>" + QObject::tr("Usage Statistics") + " </font>"
|
"<font size='+1'>" + QObject::tr("Usage Statistics") + " </font>"
|
||||||
"</td>"
|
"</td>"
|
||||||
"<td align='right' valign='middle' width='150'>" + resizeHTMLPixmap(logoPixmap,120,120)+" <br/>"
|
"<td align='right' valign='middle' width='110'>" + resizeHTMLPixmap(logoPixmap,80,80)+" <br/>"
|
||||||
"</td>"
|
"</td>"
|
||||||
"</tr>"
|
"</tr>"
|
||||||
"</table>"
|
"</table>"
|
||||||
"</div><br/>";
|
"</div>";
|
||||||
}
|
}
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTML for page footer
|
// HTML for page footer
|
||||||
QString Statistics::htmlFooter(bool showinfo)
|
QString Statistics::generateFooter(bool showinfo)
|
||||||
{
|
{
|
||||||
QString html;
|
QString html;
|
||||||
|
|
||||||
@ -1177,8 +1180,8 @@ QString Statistics::GenerateCPAPUsage()
|
|||||||
// Create the HTML that will be the Statistics page.
|
// Create the HTML that will be the Statistics page.
|
||||||
QString Statistics::GenerateHTML()
|
QString Statistics::GenerateHTML()
|
||||||
{
|
{
|
||||||
htmlReportHeader = htmlHeader(true);
|
htmlReportHeader = generateHeader(true);
|
||||||
htmlReportFooter = htmlFooter(true);
|
htmlReportFooter = generateFooter(true);
|
||||||
|
|
||||||
htmlUsage = GenerateCPAPUsage();
|
htmlUsage = GenerateCPAPUsage();
|
||||||
|
|
||||||
@ -1189,16 +1192,16 @@ QString Statistics::GenerateHTML()
|
|||||||
htmlMachineSettings = GenerateRXChanges();
|
htmlMachineSettings = GenerateRXChanges();
|
||||||
htmlMachines = GenerateMachineList();
|
htmlMachines = GenerateMachineList();
|
||||||
|
|
||||||
UpdateRecordsBox();
|
|
||||||
|
|
||||||
QString htmlScript = "<script type='text/javascript' language='javascript' src='qrc:/docs/script.js'></script>";
|
QString htmlScript = "<script type='text/javascript' language='javascript' src='qrc:/docs/script.js'></script>";
|
||||||
|
|
||||||
return htmlReportHeader + htmlUsage + htmlMachineSettings + htmlMachines + htmlScript + htmlReportFooter;
|
return htmlReportHeader + htmlUsage + htmlMachineSettings + htmlMachines + htmlScript + htmlReportFooter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print the Statistics page on printer
|
||||||
void Statistics::printReport(QWidget * parent) {
|
void Statistics::printReport(QWidget * parent) {
|
||||||
|
|
||||||
QPrinter printer(QPrinter::HighResolution);
|
QPrinter printer(QPrinter::ScreenResolution); // ScreenResolution required for graphics sizing
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
printer.setPrinterName("Print to File (PDF)");
|
printer.setPrinterName("Print to File (PDF)");
|
||||||
printer.setOutputFormat(QPrinter::PdfFormat);
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
||||||
@ -1217,41 +1220,28 @@ void Statistics::printReport(QWidget * parent) {
|
|||||||
|
|
||||||
printer.setOutputFileName(filename);
|
printer.setOutputFileName(filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printer.setPrintRange(QPrinter::AllPages);
|
printer.setPrintRange(QPrinter::AllPages);
|
||||||
// if (ui->tabWidget->currentWidget() == ui->statisticsTab) {
|
printer.setOrientation(QPrinter::Portrait);
|
||||||
// printer.setOrientation(QPrinter::Landscape);
|
printer.setFullPage(false); // Print only on printable area of page and not in non-printable margins
|
||||||
// } else {
|
|
||||||
printer.setOrientation(QPrinter::Portrait);
|
|
||||||
//}
|
|
||||||
printer.setFullPage(false); // This has nothing to do with scaling
|
|
||||||
printer.setNumCopies(1);
|
printer.setNumCopies(1);
|
||||||
printer.setResolution(1200);
|
printer.setPageMargins(10, 10, 10, 10, QPrinter::Millimeter);
|
||||||
//printer.setPaperSize(QPrinter::A4);
|
|
||||||
//printer.setOutputFormat(QPrinter::PdfFormat);
|
// Show print dialog to user and allow them to change settings as desired
|
||||||
printer.setPageMargins(5, 5, 5, 5, QPrinter::Millimeter);
|
|
||||||
QPrintDialog pdlg(&printer, parent);
|
QPrintDialog pdlg(&printer, parent);
|
||||||
|
|
||||||
if (pdlg.exec() == QPrintDialog::Accepted) {
|
if (pdlg.exec() == QPrintDialog::Accepted) {
|
||||||
|
|
||||||
QTextBrowser b;
|
QTextDocument doc;
|
||||||
QPainter painter;
|
QSizeF printArea = printer.pageRect().size();
|
||||||
painter.begin(&printer);
|
qDebug() << "print area" << printArea;
|
||||||
|
doc.setPageSize(printArea); // Set document to print area, removing default 2cm margins
|
||||||
QRect rect = printer.pageRect();
|
QFont sansFont;
|
||||||
b.setHtml(htmlReportHeader + htmlUsage + htmlMachineSettings + htmlMachines + htmlReportFooter);
|
sansFont.setPointSize(10 * (printArea.width()/1200.0)); // Scale the font
|
||||||
b.resize(rect.width()/4, rect.height()/4);
|
doc.setDefaultFont(sansFont);
|
||||||
b.setFrameShape(QFrame::NoFrame);
|
qDebug() << "Default print font is" << doc.defaultFont();
|
||||||
|
doc.setHtml(htmlReportHeader + htmlUsage + htmlMachineSettings + htmlMachines + htmlReportFooter);
|
||||||
double xscale = printer.pageRect().width()/double(b.width());
|
doc.print(&printer);
|
||||||
double yscale = printer.pageRect().height()/double(b.height());
|
|
||||||
double scale = qMin(xscale, yscale);
|
|
||||||
painter.translate(printer.paperRect().x() + printer.pageRect().width()/2, printer.paperRect().y() + printer.pageRect().height()/2);
|
|
||||||
painter.scale(scale, scale);
|
|
||||||
painter.translate(-b.width()/2, -b.height()/2);
|
|
||||||
|
|
||||||
b.render(&painter, QPoint(0,0));
|
|
||||||
painter.end();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include <QPainter>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include "SleepLib/schema.h"
|
#include "SleepLib/schema.h"
|
||||||
@ -164,12 +166,7 @@ class Statistics : public QObject
|
|||||||
void saveRXChanges();
|
void saveRXChanges();
|
||||||
void updateRXChanges();
|
void updateRXChanges();
|
||||||
|
|
||||||
QString getUserInfo();
|
|
||||||
QString getRDIorAHIText();
|
|
||||||
QString GenerateHTML();
|
QString GenerateHTML();
|
||||||
QString GenerateMachineList();
|
|
||||||
QString GenerateRXChanges();
|
|
||||||
QString GenerateCPAPUsage();
|
|
||||||
|
|
||||||
QString UpdateRecordsBox();
|
QString UpdateRecordsBox();
|
||||||
|
|
||||||
@ -177,9 +174,16 @@ class Statistics : public QObject
|
|||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QString getUserInfo();
|
||||||
|
QString getRDIorAHIText();
|
||||||
|
|
||||||
QString htmlNoData();
|
QString htmlNoData();
|
||||||
QString htmlHeader(bool showheader);
|
QString generateHeader(bool showheader);
|
||||||
QString htmlFooter(bool showinfo=true);
|
QString generateFooter(bool showinfo=true);
|
||||||
|
|
||||||
|
QString GenerateMachineList();
|
||||||
|
QString GenerateRXChanges();
|
||||||
|
QString GenerateCPAPUsage();
|
||||||
|
|
||||||
// Using a map to maintain order
|
// Using a map to maintain order
|
||||||
QList<StatisticsRow> rows;
|
QList<StatisticsRow> rows;
|
||||||
|
Loading…
Reference in New Issue
Block a user