Oximeter Fixes, New Print engine (graphs only)

This commit is contained in:
Mark Watkins 2011-12-02 01:40:32 +10:00
parent 3d7ced4250
commit c330aa6eea
13 changed files with 185 additions and 16 deletions

View File

@ -11,6 +11,9 @@
#include <QTimer>
#include <QLabel>
#include <QDir>
#include "mainwindow.h"
extern MainWindow *mainwin;
#ifdef Q_WS_MAC
#define USE_RENDERTEXT
@ -1095,10 +1098,11 @@ void gGraphView::queGraph(gGraph * g,int left, int top, int width, int height)
}
void gGraphView::trashGraphs()
{
for (int i=0;i<m_graphs.size();i++) {
//for (int i=0;i<m_graphs.size();i++) {
//delete m_graphs[i];
}
//}
m_graphs.clear();
m_graphsbytitle.clear();
}
gGraph * gGraphView::popGraph()
{
@ -1569,6 +1573,52 @@ GLShortBuffer * gGraph::quads()
return m_graphview->quads;
}
QPixmap gGraph::renderPixmap(int w, int h)
{
QFont * _defaultfont=defaultfont;
QFont * _mediumfont=mediumfont;
QFont * _bigfont=bigfont;
QFont fa=*defaultfont;
QFont fb=*mediumfont;
QFont fc=*bigfont;
//fa.setPointSizeF(fa.pointSizeF()*4.0);
//fb.setPointSizeF(fb.pointSizeF()*4.0);
//fc.setPointSizeF(fc.pointSizeF()*4.0);
defaultfont=&fa;
mediumfont=&fb;
bigfont=&fc;
gGraphView *sg=mainwin->snapshotGraph();
if (!sg) return QPixmap();
sg->hideSplitter();
gGraphView *tgv=m_graphview;
m_graphview=sg;
//qint64 rmx=rmin_x,rMx=rmax_x;
//qint64 mx=min_x, Mx=max_x;
float tmp=m_height;
sg->trashGraphs();
sg->addGraph(this);
//sg->ResetBounds();
//sg->SetXBounds(mx,Mx);
sg->updateScale();
QPixmap pm=sg->renderPixmap(w,h,false);
sg->trashGraphs();
m_graphview=tgv;
m_height=tmp;
defaultfont=_defaultfont;
mediumfont=_mediumfont;
bigfont=_bigfont;
return pm;
}
// Sets a new Min & Max X clipping, refreshing the graph and all it's layers.
void gGraph::SetXBounds(qint64 minx, qint64 maxx)

View File

@ -15,6 +15,7 @@
#include <QMutex>
#include <QSemaphore>
#include <QWaitCondition>
#include <QPixmap>
#include <Graphs/glcommon.h>
@ -269,6 +270,7 @@ public:
virtual ~gGraph();
void deselect();
void Trigger(int ms);
QPixmap renderPixmap(int width, int height);
void setVisible(bool b) { m_visible=b; }
bool visible() { return m_visible; }

View File

@ -57,7 +57,7 @@ class gYAxis:public Layer
bool ShowMinorTicks() { return m_show_minor_ticks; }
bool ShowMajorTicks() { return m_show_major_ticks; }
virtual const QString Format(EventDataType v, int dp);
static const int Margin=50; // Left margin space
static const int Margin=55; // Left margin space
void SetScale(float f) { m_yaxis_scale=f; } // Scale yaxis ticker values (only what's displayed)
float Scale() { return m_yaxis_scale; }

View File

@ -320,13 +320,17 @@ int CalcAHIGraph::calculate(Session *session)
EventDataType ahi;
qint64 ti;
for (ti=first;ti<=last;ti+=winsize) {
for (ti=first;ti<last;ti+=winsize) {
f=ti-3600000L;
ahi=calcAHI(session,f,ti);
if (ti>=last) {
AHI->AddEvent(last,ahi);
break;
}
AHI->AddEvent(ti,ahi);
ti+=winsize;
}
AHI->AddEvent(ti,0);
AHI->AddEvent(last,0);
return AHI->count();
}

View File

@ -240,7 +240,7 @@ int IntellipapLoader::Open(QString & path,Profile *profile)
for (int j=0;j<SessionStart.size();j++) {
sid=SessionStart[j];
if (!sid) continue;
if ((ts1>=(quint32)sid) && (ts1<SessionEnd[j])){
if ((ts1>=(quint32)sid) && (ts1<=SessionEnd[j])){
Session *sess=Sessions[sid];
qint64 time=quint64(ts1)*1000L;
sess->eventlist[CPAP_Pressure][0]->AddEvent(time,m_buffer[pos+0xd]/10.0); // current pressure
@ -317,8 +317,8 @@ int IntellipapLoader::Open(QString & path,Profile *profile)
// delete sess;
// continue;
//}
quint64 first=quint64(sid)*1000L;
quint64 last=quint64(SessionEnd[i])*1000L;
quint64 first=qint64(sid)*1000L;
quint64 last=qint64(SessionEnd[i])*1000L;
quint64 len=last-first;
//if (len>0) {
//if (!sess->first()) {

View File

@ -255,8 +255,11 @@ int ResmedLoader::Open(QString & path,Profile *profile)
} else {
newpath=path+QDir::separator()+dirtag;
}
if (!QDir().exists(newpath)) return 0;
QString idfile=path+QDir::separator()+"Identification.tgt";
QFile f(idfile);
if (!f.exists()) return 0;
QHash<QString,QString> idmap;
if (f.open(QIODevice::ReadOnly)) {
if (!f.isReadable())

View File

@ -15,6 +15,8 @@
#include <QResizeEvent>
#include <QScrollBar>
#include <QSpacerItem>
//#include <QPrinter>
//#include <QProgressBar>
#include "daily.h"
#include "ui_daily.h"
@ -31,6 +33,8 @@
#include "Graphs/gSegmentChart.h"
#include "Graphs/gStatsLine.h"
//extern QProgressBar *qprogress;
const int min_height=150;
Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
@ -618,7 +622,7 @@ void Daily::Load(QDate date)
.arg(QString().sprintf("%02i:%02i:%02i",h,m,s));
QString cs;
if (cpap->machine->GetClass()!="PRS1") {
if (cpap->machine->GetClass()=="ResMed") {
cs="4 width='100%' align=center>";
} else cs="2 width='50%'>";
html+="<tr><td colspan="+cs+"<table cellspacing=0 cellpadding=1 border=0 width='100%'>"
@ -1108,3 +1112,4 @@ void Daily::on_evViewSlider_valueChanged(int value)
GraphView->SetXBounds(st,et);
}
}

View File

@ -44,6 +44,9 @@ public:
void RedrawGraphs();
void LoadDate(QDate date);
QDate getDate() { return previous_date; }
void PrintReport();
private slots:
void on_calendar_currentPageChanged(int year, int month);

View File

@ -17,6 +17,8 @@
#include <QPixmap>
#include <QDesktopWidget>
#include <QListView>
#include <QPrinter>
#include <QPainter>
#include "mainwindow.h"
#include "ui_mainwindow.h"
@ -210,6 +212,14 @@ void MainWindow::Startup()
oximetry=new Oximetry(ui->tabWidget,daily->graphView());
ui->tabWidget->insertTab(3,oximetry,tr("Oximetry"));
}
SnapshotGraph=new gGraphView(this,daily->graphView());
SnapshotGraph->setMaximumSize(1024,512);
SnapshotGraph->setMinimumSize(1024,512);
//ReportGraph->setMaximumSize(graph_print_width,graph_print_height);
//ReportGraph->setMinimumSize(graph_print_width,graph_print_height);
SnapshotGraph->hide();
if (daily) daily->ReloadGraphs();
if (overview) overview->ReloadGraphs();
qprogress->hide();
@ -555,9 +565,15 @@ void MainWindow::updatestatusBarMessage (const QString & text)
void MainWindow::on_actionPrint_Report_triggered()
{
if (ui->tabWidget->currentWidget()==overview) {
overview->on_printButton_clicked();
//} else if (ui->tabWidget->currentWidget()==daily) {
PrintReport(overview->graphView(),"Overview");
} else if (ui->tabWidget->currentWidget()==daily) {
PrintReport(daily->graphView(),"Daily");
} else if (ui->tabWidget->currentWidget()==oximetry) {
if (oximetry)
PrintReport(oximetry->graphView(),"Oximetry");
} else {
//QPrinter printer();
//ui->webView->print(printer)
QMessageBox::information(this,"Not supported Yet","Sorry, printing from this page is not supported yet",QMessageBox::Ok);
}
}
@ -632,6 +648,61 @@ EventList *packEventList(EventList *ev)
return nev;
}
void MainWindow::PrintReport(gGraphView *gv,QString name)
{
if (!gv) return;
QString filename=PREF.Get("{home}/"+name+"_{user}.pdf");
QPrinter printer(QPrinter::ScreenResolution); //QPrinter::HighResolution); //QPrinter::ScreenResolution);
printer.setOutputFileName(filename);
printer.setOrientation(QPrinter::Portrait);
QPainter painter;
painter.begin(&printer);
QRect res=printer.pageRect();
qDebug() << "Printer Resolution is" << res.width() << "x" << res.height();
const int graphs_per_page=5;
float gw=res.width();
float gh=res.height()/graphs_per_page;
mainwin->snapshotGraph()->setMinimumSize(gw,gh);
mainwin->snapshotGraph()->setMaximumSize(gw,gh);
int page=0;
int i=0;
int top=0;
int gcnt=0;
if (qprogress) {
qprogress->setValue(0);
qprogress->setMaximum(gv->size());
qprogress->show();
}
do {
gGraph *g=(*gv)[i];
if (g->isEmpty()) continue;
if (!g->visible()) continue;
g->deselect();
QPixmap pm=g->renderPixmap(gw,gh);
//QPixmap pm2=pm.scaledToWidth(res.width());
painter.drawPixmap(0,top,pm.width(),pm.height(),pm);
top+=pm.height();
gcnt++;
if (gcnt>=graphs_per_page) { //top+pm.height()>res.height()) {
top=0;
gcnt=0;
if (!printer.newPage()) {
qWarning("failed in flushing page to disk, disk full?");
break;
}
}
if (qprogress) {
qprogress->setValue(i);
QApplication::processEvents();
}
} while (++i<gv->size());
qprogress->hide();
painter.end();
}
void MainWindow::on_action_Rebuild_Oximetry_Index_triggered()
{
Day *day;
@ -708,5 +779,4 @@ void MainWindow::on_action_Rebuild_Oximetry_Index_triggered()
}
getDaily()->ReloadGraphs();
getOverview()->ReloadGraphs();
}

View File

@ -45,6 +45,7 @@ public:
QMenu * CreateMenu(QString title);
void CheckForUpdates();
void Notify(QString s);
gGraphView *snapshotGraph() { return SnapshotGraph; }
Daily *getDaily() { return daily; }
Overview *getOverview() { return overview; }
Oximetry *getOximetry() { return oximetry; }
@ -113,6 +114,8 @@ private slots:
void on_action_Rebuild_Oximetry_Index_triggered();
private:
void PrintReport(gGraphView *gv,QString name);
Ui::MainWindow *ui;
Daily * daily;
Overview * overview;
@ -126,6 +129,7 @@ private:
QTime logtime;
QSystemTrayIcon *systray;
QMenu *systraymenu;
gGraphView *SnapshotGraph;
};
#endif // MAINWINDOW_H

View File

@ -11,6 +11,8 @@
#include <QDateTimeEdit>
#include <QCalendarWidget>
#include <QFileDialog>
//#include <QProgressBar>
#include "SleepLib/profiles.h"
#include "overview.h"
#include "ui_overview.h"
@ -20,6 +22,10 @@
#include "Graphs/gYAxis.h"
#include "Graphs/gSessionTime.h"
//#include "mainwindow.h"
//extern MainWindow * mainwin;
//extern QProgressBar * qprogress;
Overview::Overview(QWidget *parent,gGraphView * shared) :
QWidget(parent),
ui(new Ui::Overview),
@ -335,7 +341,25 @@ void Overview::on_printButton_clicked()
void Overview::on_htmlButton_clicked()
{
QString html=GetHTML();
QString filename;
for (int i=0;i<GraphView->size();i++) {
gGraph *g=(*GraphView)[i];
if (g->isEmpty()) continue;
if (!g->visible()) continue;
g->deselect();
QPixmap pm=g->renderPixmap(1024,512);
filename=PREF.Get("{home}/graph_"+g->title()+".png");
pm.save(filename,"png");
}
//QString filename=QFileDialog::getSaveFileName(this,tr("Save PNG Test"),PREF.Get("{home}"),tr("PNG Pictures(*.png)"));
//if (!filename.isEmpty()) {
// pm.save(filename,"png");
// }
/*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);
@ -344,10 +368,11 @@ void Overview::on_htmlButton_clicked()
ba.append(html);
file.write(ba);
file.close();
}
} */
}
void Overview::ResetGraphLayout()
{
GraphView->resetLayout();
}

View File

@ -35,6 +35,7 @@ public:
void RedrawGraphs();
gGraph * createGraph(QString name);
void PrintReport();
gGraph *AHI,*UC, *US, *PR,*LK,*NPB,*SET,*SES,*RR,*MV,*TV,*PTB,*PULSE,*SPO2;
SummaryChart *bc,*uc, *us, *pr,*lk,*npb,*set,*ses,*rr,*mv,*tv,*ptb,*pulse,*spo2;

View File

@ -762,6 +762,7 @@ void Oximetry::on_RunButton_toggled(bool checked)
disconnect(oximeter,SIGNAL(updatePulse(float)),this,SLOT(onPulseChanged(float)));
disconnect(oximeter,SIGNAL(updateSpO2(float)),this,SLOT(onSpO2Changed(float)));
ui->saveButton->setEnabled(true);
ui->ImportButton->setEnabled(true);
lo2->SetDay(day);
lo1->SetDay(day);
@ -795,7 +796,7 @@ void Oximetry::on_RunButton_toggled(bool checked)
mainwin->Notify("Oximetry Error!\n\nSomething is wrong with the device connection.");
return;
}
QTimer::singleShot(100,this,SLOT(oximeter_running_check()));
QTimer::singleShot(1000,this,SLOT(oximeter_running_check()));
ui->saveButton->setEnabled(false);
day->AddSession(oximeter->getSession());
@ -829,6 +830,7 @@ void Oximetry::on_RunButton_toggled(bool checked)
// connect.
ui->RunButton->setText("&Stop");
ui->SerialPortsCombo->setEnabled(false);
ui->ImportButton->setEnabled(false);
}
}
@ -939,7 +941,7 @@ void Oximetry::on_ImportButton_clicked()
//qDebug() << "Error starting oximetry serial import process";
return;
}
QTimer::singleShot(100,this,SLOT(oximeter_running_check()));
QTimer::singleShot(1000,this,SLOT(oximeter_running_check()));
day->getSessions().clear();
day->AddSession(oximeter->getSession());