mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-05 10:40:42 +00:00
Save report as HTML button
This commit is contained in:
parent
b058da6c18
commit
8eae064dcc
@ -346,7 +346,7 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
w.renderText(z,left,top-1);
|
w.renderText(z,left,top-3);
|
||||||
}
|
}
|
||||||
bool SummaryChart::mouseMoveEvent(QMouseEvent *event)
|
bool SummaryChart::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
@ -538,10 +538,10 @@ gGraph::gGraph(gGraphView *graphview,QString title,int height,short group) :
|
|||||||
} else {
|
} else {
|
||||||
qWarning() << "gGraph created without a gGraphView container.. Naughty programmer!! Bad!!!";
|
qWarning() << "gGraph created without a gGraphView container.. Naughty programmer!! Bad!!!";
|
||||||
}
|
}
|
||||||
m_margintop=10;
|
m_margintop=12;
|
||||||
m_marginbottom=5;
|
m_marginbottom=5;
|
||||||
m_marginleft=5;
|
m_marginleft=10;
|
||||||
m_marginright=10;
|
m_marginright=15;
|
||||||
m_selecting_area=m_blockzoom=false;
|
m_selecting_area=m_blockzoom=false;
|
||||||
m_lastx23=0;
|
m_lastx23=0;
|
||||||
|
|
||||||
|
@ -6,20 +6,20 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body leftmargin=0 rightmargin=0 topmargin=0 marginwidth=0 marginheight=0>
|
<body leftmargin=0 rightmargin=0 topmargin=0 marginwidth=0 marginheight=0>
|
||||||
<table width={{local.width}} cellpadding=0 cellspacing=0>
|
<table width="100%" cellpadding=0 cellspacing=0>
|
||||||
<tr>
|
<tr>
|
||||||
<td valign=top><h2>CPAP Overview</h2>
|
<td valign="top"><h2>CPAP Overview</h2>
|
||||||
<table cell_padding=0 cell_spacing=0 rules=cols border=1>
|
<table cell_padding=0 cell_spacing=0 rules=cols border=1>
|
||||||
<tr>
|
<tr>
|
||||||
<td valign=top width=50%>
|
<td valign="middle" width=50%>
|
||||||
<table rules=none border=0 cell_padding=0 cell_spacing=0 width=100%>
|
<table rules="none" border=0 cell_padding=0 cell_spacing=0 width="100%">
|
||||||
<tr><td>Name:</td><td>{{profile.FirstName}} {{profile.LastName}}</td></tr>
|
<tr><td>Name:</td><td>{{profile.FirstName}} {{profile.LastName}}</td></tr>
|
||||||
<tr><td valign=top>Address:</td><td valign=top>{{profile.Address}}</td></tr>
|
<tr><td valign="top">Address:</td><td valign="top">{{profile.Address}}</td></tr>
|
||||||
<tr><td>Phone:</td><td>{{profile.Phone}}</td></tr>
|
<tr><td>Phone:</td><td>{{profile.Phone}}</td></tr>
|
||||||
<tr><td>Email:</td><td>{{profile.EmailAddress}}</td></tr>
|
<tr><td>Email:</td><td>{{profile.EmailAddress}}</td></tr>
|
||||||
</table></td>
|
</table></td>
|
||||||
<td valign=top width=50%>
|
<td valign="middle" width="50%">
|
||||||
<table width=100% height=100% rules=none border=0>
|
<table width="100%" height="100%" rules="none" border=0>
|
||||||
<tr><td>Gender:</td><td>{{profile.Gender}}</td></tr>
|
<tr><td>Gender:</td><td>{{profile.Gender}}</td></tr>
|
||||||
<tr><td>Age:</td><td>{{local.Age}} years</td></tr>
|
<tr><td>Age:</td><td>{{local.Age}} years</td></tr>
|
||||||
<tr><td>Height:</td><td>{{profile.Height}}{{local.DistanceMeasure}}</td></tr>
|
<tr><td>Height:</td><td>{{profile.Height}}{{local.DistanceMeasure}}</td></tr>
|
||||||
@ -27,16 +27,16 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<td valign=center align=center>
|
<td valign="middle" align="center">
|
||||||
<img src='qrc:/docs/sheep.png' width=100px height=100px'>
|
{{logo}}
|
||||||
<br/>{{pref.AppName}} v{{pref.VersionString}}
|
<br/>SleepyHead v{{pref.VersionString}}
|
||||||
<br/>http://sleepyhead.sf.net
|
<br/>http://sleepyhead.sf.net
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan=2>
|
<td colspan=2>
|
||||||
Reporting from <b>{{local.start}}</b> to <b>{{local.end}}</b>
|
Reporting from <b>{{local.start}}</b> to <b>{{local.end}}</b>
|
||||||
<hr width={{local.width}}px>
|
<hr width="100%">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
29
overview.cpp
29
overview.cpp
@ -10,6 +10,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDateTimeEdit>
|
#include <QDateTimeEdit>
|
||||||
#include <QCalendarWidget>
|
#include <QCalendarWidget>
|
||||||
|
#include <QFileDialog>
|
||||||
#include "overview.h"
|
#include "overview.h"
|
||||||
#include "ui_overview.h"
|
#include "ui_overview.h"
|
||||||
#include "Graphs/gXAxis.h"
|
#include "Graphs/gXAxis.h"
|
||||||
@ -226,14 +227,14 @@ void Overview::on_toolButton_clicked()
|
|||||||
GraphView->SetXBounds(d1,d2);
|
GraphView->SetXBounds(d1,d2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Overview::on_printButton_clicked()
|
QString Overview::GetHTML()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!report) {
|
if (!report) {
|
||||||
report=new Report(this,profile,m_shared,this);
|
report=new Report(this,profile,m_shared,this);
|
||||||
report->hide();
|
report->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString html;
|
||||||
if (report) {
|
if (report) {
|
||||||
bc->deselect();
|
bc->deselect();
|
||||||
uc->deselect();
|
uc->deselect();
|
||||||
@ -243,14 +244,30 @@ void Overview::on_printButton_clicked()
|
|||||||
|
|
||||||
report->ReloadGraphs();
|
report->ReloadGraphs();
|
||||||
QString reportname="overview";
|
QString reportname="overview";
|
||||||
if (report->GenerateReport(reportname,ui->dateStart->date(),ui->dateEnd->date())) {
|
html=report->GenerateReport(reportname,ui->dateStart->date(),ui->dateEnd->date());
|
||||||
report->Print();
|
if (html.isEmpty()) {
|
||||||
} else {
|
|
||||||
qDebug() << "Faulty Report" << reportname;
|
qDebug() << "Faulty Report" << reportname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
void Overview::on_printButton_clicked()
|
||||||
|
{
|
||||||
|
|
||||||
|
report->Print(GetHTML());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Overview::readyToPrint(bool)
|
void Overview::on_htmlButton_clicked()
|
||||||
{
|
{
|
||||||
|
QString html=GetHTML();
|
||||||
|
QString filename=QFileDialog::getSaveFileName(this,tr("Save HTML Report"),pref.Get("{home}"),tr("HTML Documents (*.html)"));
|
||||||
|
if (!filename.isEmpty()) {
|
||||||
|
QFile file(filename);
|
||||||
|
file.open(QIODevice::WriteOnly);
|
||||||
|
QByteArray ba;
|
||||||
|
ba.append(html);
|
||||||
|
file.write(ba);
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,8 @@ private slots:
|
|||||||
|
|
||||||
void on_toolButton_clicked();
|
void on_toolButton_clicked();
|
||||||
|
|
||||||
void readyToPrint(bool);
|
void on_htmlButton_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Overview *ui;
|
Ui::Overview *ui;
|
||||||
Profile *profile;
|
Profile *profile;
|
||||||
@ -67,6 +68,9 @@ private:
|
|||||||
void UpdateHTML();
|
void UpdateHTML();
|
||||||
void UpdateCalendarDay(QDateEdit * calendar,QDate date);
|
void UpdateCalendarDay(QDateEdit * calendar,QDate date);
|
||||||
|
|
||||||
|
|
||||||
|
QString GetHTML();
|
||||||
|
|
||||||
//SessionTimes *session_times;
|
//SessionTimes *session_times;
|
||||||
//,*PRESSURE,*LEAK,*SESSTIMES;
|
//,*PRESSURE,*LEAK,*SESSTIMES;
|
||||||
|
|
||||||
|
13
overview.ui
13
overview.ui
@ -119,8 +119,21 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="htmlButton">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Save a HTML report</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>HTML</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="printButton">
|
<widget class="QPushButton" name="printButton">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Send a Report to your Printer</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Print</string>
|
<string>&Print</string>
|
||||||
</property>
|
</property>
|
||||||
|
33
report.cpp
33
report.cpp
@ -156,13 +156,21 @@ QString Report::ParseTemplate(QString input)
|
|||||||
QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray
|
QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray
|
||||||
buffer.open(QIODevice::WriteOnly);
|
buffer.open(QIODevice::WriteOnly);
|
||||||
pixmap.save(&buffer, "PNG");
|
pixmap.save(&buffer, "PNG");
|
||||||
//html += "<div align=center><img src=\"data:image/png;base64," + byteArray.toBase64() + "\" width=\""+QString::number(graph_print_width)+"px\" height=\""+QString::number(graph_print_height)+"px\"></div>\n"; //
|
//output += "<div align=center><img src=\"data:image/png;base64," + byteArray.toBase64() + "\" width="+QString::number(graph_print_width)+"px height=\""+QString::number(graph_print_height)+"px\"></div>\n";
|
||||||
output += "<div align=center><img src=\"data:image/png;base64," + byteArray.toBase64() + "\" width="+QString::number(graph_print_width)+"px height=\""+QString::number(graph_print_height)+"px\"></div>\n";
|
output += "<div align=center><img src=\"data:image/png;base64," + byteArray.toBase64() + "\" width=\"100%\" height=\""+QString::number(graph_print_height)+"\"></div>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Graph not found" << key << "in template";
|
qDebug() << "Graph not found" << key << "in template";
|
||||||
}
|
}
|
||||||
|
} else if (code=="logo") {
|
||||||
|
QPixmap pixmap(":/docs/sheep.png");
|
||||||
|
QByteArray byteArray;
|
||||||
|
QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray
|
||||||
|
buffer.open(QIODevice::WriteOnly);
|
||||||
|
pixmap.save(&buffer, "PNG");
|
||||||
|
output += "<img src=\"data:image/png;base64," + byteArray.toBase64() + "\" width=\"100\" height=\"100\">";
|
||||||
|
|
||||||
}
|
}
|
||||||
pos+=rx.matchedLength();
|
pos+=rx.matchedLength();
|
||||||
lastpos=pos;
|
lastpos=pos;
|
||||||
@ -172,13 +180,13 @@ QString Report::ParseTemplate(QString input)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Report::GenerateReport(QString templ,QDate start, QDate end)
|
QString Report::GenerateReport(QString templ,QDate start, QDate end)
|
||||||
{
|
{
|
||||||
//if (!m_ready) return;
|
//if (!m_ready) return;
|
||||||
//startDate=start;
|
startDate=start;
|
||||||
//endDate=end;
|
endDate=end;
|
||||||
|
|
||||||
QString filename=pref.Get("{home}/reports");
|
QString filename=pref.Get("{home}/Reports");
|
||||||
QDir dir(filename);
|
QDir dir(filename);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
dir.mkdir(filename);
|
dir.mkdir(filename);
|
||||||
@ -195,7 +203,7 @@ bool Report::GenerateReport(QString templ,QDate start, QDate end)
|
|||||||
} else {
|
} else {
|
||||||
QString f2=":/docs/template_"+templ+".sht";
|
QString f2=":/docs/template_"+templ+".sht";
|
||||||
file.setFileName(f2);
|
file.setFileName(f2);
|
||||||
if (!file.exists()) return false;
|
if (!file.exists()) return "";
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
input=file.readAll();
|
input=file.readAll();
|
||||||
file.close();
|
file.close();
|
||||||
@ -228,15 +236,14 @@ bool Report::GenerateReport(QString templ,QDate start, QDate end)
|
|||||||
//QFile file(":/docs/template_overview.sht");
|
//QFile file(":/docs/template_overview.sht");
|
||||||
//file.open(QIODevice::ReadOnly);
|
//file.open(QIODevice::ReadOnly);
|
||||||
//QString html=file.readAll();
|
//QString html=file.readAll();
|
||||||
|
//ui->webView->setHtml(output);
|
||||||
QString output=ParseTemplate(html);
|
return ParseTemplate(html);
|
||||||
|
|
||||||
ui->webView->setHtml(output);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Report::Print()
|
void Report::Print(QString html)
|
||||||
{
|
{
|
||||||
|
if (html.isEmpty()) return;
|
||||||
|
ui->webView->setHtml(html);
|
||||||
QPrinter printer;
|
QPrinter printer;
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
printer.setPrinterName("Print to File (PDF)");
|
printer.setPrinterName("Print to File (PDF)");
|
||||||
|
8
report.h
8
report.h
@ -11,8 +11,8 @@ namespace Ui {
|
|||||||
class Report;
|
class Report;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int graph_print_width=1280;
|
const int graph_print_width=1024;
|
||||||
const int graph_print_height=256;
|
const int graph_print_height=150;
|
||||||
|
|
||||||
class Daily;
|
class Daily;
|
||||||
class Overview;
|
class Overview;
|
||||||
@ -23,12 +23,12 @@ class Report : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit Report(QWidget *parent, Profile * _profile, gGraphView * shared, Overview * overview);
|
explicit Report(QWidget *parent, Profile * _profile, gGraphView * shared, Overview * overview);
|
||||||
~Report();
|
~Report();
|
||||||
bool GenerateReport(QString templ,QDate start, QDate end);
|
QString GenerateReport(QString templ,QDate start, QDate end);
|
||||||
void ReloadGraphs();
|
void ReloadGraphs();
|
||||||
QString ParseTemplate(QString input);
|
QString ParseTemplate(QString input);
|
||||||
|
|
||||||
QPixmap Snapshot(gGraph * graph);
|
QPixmap Snapshot(gGraph * graph);
|
||||||
void Print();
|
void Print(QString html);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Report *ui;
|
Ui::Report *ui;
|
||||||
|
Loading…
Reference in New Issue
Block a user