mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-05 10:40:42 +00:00
Clean up journal notes save logic, fix QTextBrowsers image handling
This commit is contained in:
parent
1e20d02444
commit
f11f5fe284
@ -19,6 +19,7 @@
|
||||
#include <QSpacerItem>
|
||||
#include <QFontMetrics>
|
||||
#include <QLabel>
|
||||
#include <QMutexLocker>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@ -117,7 +118,7 @@ Daily::Daily(QWidget *parent,gGraphView * shared)
|
||||
layout2->setMargin(0);
|
||||
widget->setLayout(layout2);
|
||||
|
||||
webView=new QTextBrowser(widget);
|
||||
webView=new MyTextBrowser(widget);
|
||||
webView->setOpenLinks(false);
|
||||
layout2->insertWidget(0,webView, 1);
|
||||
layout2->insertWidget(1,sessionbar,0);
|
||||
@ -754,6 +755,12 @@ void Daily::on_calendar_selectionChanged()
|
||||
|
||||
void Daily::on_ReloadDay()
|
||||
{
|
||||
static volatile bool inReload = false;
|
||||
|
||||
if (inReload) {
|
||||
qDebug() << "attempt to renter on_ReloadDay()";
|
||||
}
|
||||
inReload = true;
|
||||
graphView()->releaseKeyboard();
|
||||
QTime time;
|
||||
time_t unload_time, load_time, other_time;
|
||||
@ -789,6 +796,7 @@ void Daily::on_ReloadDay()
|
||||
other_time=time.restart();
|
||||
|
||||
qDebug() << "Page change time (in ms): Unload ="<<unload_time<<"Load =" << load_time << "Other =" << other_time;
|
||||
inReload = false;
|
||||
}
|
||||
void Daily::ResetGraphLayout()
|
||||
{
|
||||
@ -875,8 +883,13 @@ QString Daily::getSessionInformation(Day * day)
|
||||
QString tooltip = QObject::tr("Click to %1 this session.").arg(sess->enabled() ? QObject::tr("disable") : QObject::tr("enable"));
|
||||
html+=QString("<tr><td colspan=5 align=center>%2</td></tr>"
|
||||
"<tr>"
|
||||
"<td width=26><a href='toggle"+type+"session=%1'>"
|
||||
"<img src='qrc:/icons/session-%4.png' title=\""+tooltip+"\"></a></td>"
|
||||
"<td width=26>"
|
||||
#ifdef DITCH_ICONS
|
||||
"[<a href='toggle"+type+"session=%1'><b title='"+tooltip+"'>%4</b></a>]"
|
||||
#else
|
||||
"<a href='toggle"+type+"session=%1'><img src='qrc:/icons/session-%4.png' title=\""+tooltip+"\"></a>"
|
||||
#endif
|
||||
"</td>"
|
||||
"<td align=left>%5</td>"
|
||||
"<td align=left>%6</td>"
|
||||
"<td align=left>%7</td>"
|
||||
@ -1269,6 +1282,18 @@ QString Daily::getSleepTime(Day * day)
|
||||
return html;
|
||||
}
|
||||
|
||||
QVariant MyTextBrowser::loadResource(int type, const QUrl &url)
|
||||
{
|
||||
if (type == QTextDocument::ImageResource
|
||||
&& url.scheme().compare(QLatin1String("data"), Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
static QRegularExpression re("^image/[^;]+;base64,.+={0,2}$");
|
||||
QRegularExpressionMatch match = re.match(url.path());
|
||||
if (match.hasMatch())
|
||||
return QVariant();
|
||||
}
|
||||
return QTextBrowser::loadResource(type, url);
|
||||
}
|
||||
|
||||
|
||||
void Daily::Load(QDate date)
|
||||
@ -1440,7 +1465,7 @@ void Daily::Load(QDate date)
|
||||
QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
pixmap.save(&buffer, "PNG");
|
||||
html += "<tr><td align=center><img src=\"data:image/png;base64," + byteArray.toBase64() + QString("\"></td></tr>\n");
|
||||
html += "<tr><td align=center><img src=\"data:image/png;base64," + byteArray.toBase64() + "\"></td></tr>\n";
|
||||
} else {
|
||||
html += "<tr><td align=center>Unable to display Pie Chart on this system</td></tr>\n";
|
||||
}
|
||||
@ -1465,7 +1490,7 @@ void Daily::Load(QDate date)
|
||||
html+="<tr><td colspan='5'> </td></tr>\n";
|
||||
if (day->size()>0) {
|
||||
html+="<tr><td colspan=5 align='center'><font size='+3'>"+tr("Sessions all off!")+"</font></td></tr>";
|
||||
html+="<tr><td colspan=5 align='center><img src='qrc:/docs/sheep.png' align=center></td></tr>";
|
||||
html+="<tr><td colspan=5 align='center><img src='qrc:/docs/sheep.png'></td></tr>";
|
||||
html+="<tr bgcolor='#89abcd'><td colspan=5 align='center'><i><font color=white size=+1>"+tr("Sessions exist for this day but are switched off.")+"</font></i></td></tr>\n";
|
||||
GraphView->setEmptyText(STR_Empty_NoSessions);
|
||||
} else {
|
||||
@ -1494,7 +1519,7 @@ void Daily::Load(QDate date)
|
||||
html+="<table cellspacing=0 cellpadding=0 border=0 height=100% width=100%>";
|
||||
html+="<tr height=25%><td align=center></td></tr>";
|
||||
html+="<tr><td align=center><font size='+3'>"+tr("\"Nothing's here!\"")+"</font></td></tr>";
|
||||
html+="<tr><td align=center><img src='qrc:/docs/sheep.png' width=120px></td></tr>";
|
||||
html+="<tr><td align=center><img src='qrc:/docs/sheep.png'></td></tr>";
|
||||
html+="<tr height=5px><td align=center></td></tr>";
|
||||
html+="<tr bgcolor='#89abcd'><td align=center><i><font size=+1 color=white>"+tr("Bob is bored with this days lack of data.")+"</font></i></td></tr>";
|
||||
html+="<tr height=25%><td align=center></td></tr>";
|
||||
@ -1531,6 +1556,16 @@ void Daily::Load(QDate date)
|
||||
}
|
||||
//sessbar->update();
|
||||
|
||||
#ifdef DEBUG_DAILY_HTML
|
||||
QString name = GetAppRoot()+"/test.html";
|
||||
QFile file(name);
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
const QByteArray & b = html.toLocal8Bit();
|
||||
file.write(b.data(), b.size());
|
||||
file.close();
|
||||
}
|
||||
#endif
|
||||
|
||||
webView->setHtml(html);
|
||||
|
||||
ui->JournalNotes->clear();
|
||||
@ -1679,39 +1714,43 @@ void Daily::Unload(QDate date)
|
||||
}
|
||||
}
|
||||
|
||||
webView->setHtml("");
|
||||
// Update the journal notes
|
||||
Session *journal = GetJournalSession(date);
|
||||
|
||||
bool nonotes=ui->JournalNotes->toPlainText().isEmpty();
|
||||
bool editorHasContent = !ui->JournalNotes->toPlainText().isEmpty(); // have a look as plaintext to see if really empty.
|
||||
|
||||
if (!journal && editorHasContent) {
|
||||
journal = CreateJournalSession(date);
|
||||
}
|
||||
|
||||
if (journal) {
|
||||
QString jhtml=ui->JournalNotes->toHtml();
|
||||
if ((!journal->settings.contains(Journal_Notes) && !nonotes) || (journal->settings[Journal_Notes]!=jhtml)) {
|
||||
journal->settings[Journal_Notes]=jhtml;
|
||||
auto jit = journal->settings.find(Journal_Notes);
|
||||
|
||||
if (jit != journal->settings.end()) {
|
||||
// we do have a journal_notes record
|
||||
if (editorHasContent) {
|
||||
const QString & html = ui->JournalNotes->toHtml();
|
||||
|
||||
if (jit.value() != html) { // has the content of it changed?
|
||||
jit.value() = html;
|
||||
journal->SetChanged(true);
|
||||
}
|
||||
} else {
|
||||
if (!nonotes) {
|
||||
journal=CreateJournalSession(date);
|
||||
if (!nonotes) {
|
||||
// empty, so don't need this notes setting anymore
|
||||
journal->settings.erase(jit);
|
||||
journal->SetChanged(true);
|
||||
}
|
||||
} else if (editorHasContent) {
|
||||
// Create the note
|
||||
journal->settings[Journal_Notes] = ui->JournalNotes->toHtml();
|
||||
journal->SetChanged(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (journal) {
|
||||
if (nonotes) {
|
||||
QHash<ChannelID,QVariant>::iterator it=journal->settings.find(Journal_Notes);
|
||||
if (it!=journal->settings.end()) {
|
||||
journal->settings.erase(it);
|
||||
}
|
||||
}
|
||||
if (journal->IsChanged()) {
|
||||
journal->settings[LastUpdated] = QDateTime::currentDateTime();
|
||||
// blah.. was updating overview graphs here.. Was too slow.
|
||||
journal->machine()->SaveSummary();
|
||||
journal->SetChanged(false); // save summary doesn't automatically do this
|
||||
}
|
||||
Machine *jm=p_profile->GetMachine(MT_JOURNAL);
|
||||
if (jm) jm->SaveSummary(); //(journal);
|
||||
}
|
||||
UpdateCalendarDay(date);
|
||||
}
|
||||
@ -2269,7 +2308,6 @@ void Daily::updateCube()
|
||||
ui->toggleGraphs->setChecked(true);
|
||||
ui->toggleGraphs->blockSignals(false);
|
||||
|
||||
|
||||
if (ui->graphCombo->count() > 0) {
|
||||
GraphView->setEmptyText(STR_Empty_NoGraphs);
|
||||
} else {
|
||||
|
@ -35,6 +35,16 @@ namespace Ui {
|
||||
|
||||
class MainWindow;
|
||||
|
||||
|
||||
class MyTextBrowser:public QTextBrowser
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MyTextBrowser(QWidget * parent):QTextBrowser(parent) {}
|
||||
virtual ~MyTextBrowser() {}
|
||||
virtual QVariant loadResource(int type, const QUrl &url) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
/*! \class Daily
|
||||
\brief SleepyHead's Daily view which displays the calendar and all the graphs relative to a selected Day
|
||||
*/
|
||||
@ -341,7 +351,7 @@ private:
|
||||
SessionBar * sessionbar;
|
||||
MyLabel * dateDisplay;
|
||||
|
||||
QTextBrowser * webView;
|
||||
MyTextBrowser * webView;
|
||||
Day * lastcpapday;
|
||||
|
||||
gLineChart *leakchart;
|
||||
@ -350,4 +360,5 @@ private:
|
||||
bool BookmarksChanged;
|
||||
};
|
||||
|
||||
|
||||
#endif // DAILY_H
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 114 B |
Binary file not shown.
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 121 B |
@ -105,6 +105,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
daily = nullptr;
|
||||
prefdialog = nullptr;
|
||||
profileSelector = nullptr;
|
||||
welcome = nullptr;
|
||||
|
||||
ui->oximetryButton->setDisabled(true);
|
||||
ui->dailyButton->setDisabled(true);
|
||||
@ -1917,7 +1918,7 @@ void MainWindow::on_actionRebuildCPAP(QAction *action)
|
||||
daily->clearLastDay(); // otherwise Daily will crash
|
||||
daily->ReloadGraphs();
|
||||
}
|
||||
welcome->refreshPage();
|
||||
if (welcome) welcome->refreshPage();
|
||||
PopulatePurgeMenu();
|
||||
GenerateStatistics();
|
||||
p_profile->StoreMachines();
|
||||
@ -2002,6 +2003,8 @@ void MainWindow::purgeMachine(Machine * mach)
|
||||
daily->clearLastDay(); // otherwise Daily will crash
|
||||
daily->ReloadGraphs();
|
||||
}
|
||||
if (welcome) welcome->refreshPage();
|
||||
|
||||
//GenerateStatistics();
|
||||
return;
|
||||
}
|
||||
@ -2015,14 +2018,9 @@ void MainWindow::purgeMachine(Machine * mach)
|
||||
daily->clearLastDay(); // otherwise Daily will crash
|
||||
daily->ReloadGraphs();
|
||||
}
|
||||
|
||||
welcome->refreshPage();
|
||||
if (welcome) welcome->refreshPage();
|
||||
|
||||
QApplication::processEvents();
|
||||
|
||||
|
||||
|
||||
// GenerateStatistics();
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent *event)
|
||||
@ -2532,16 +2530,18 @@ void MainWindow::on_actionPurgeCurrentDaysOximetry_triggered()
|
||||
QList<Session *> sessionlist;
|
||||
sessionlist.append(day->sessions);
|
||||
|
||||
for (int i=0; i < sessionlist.size(); ++i) {
|
||||
Session * sess = sessionlist.at(i);
|
||||
for (auto & sess : sessionlist) {
|
||||
sess->Destroy();
|
||||
delete sess;
|
||||
}
|
||||
|
||||
|
||||
if (daily) {
|
||||
daily->clearLastDay(); // otherwise Daily will crash
|
||||
|
||||
getDaily()->ReloadGraphs();
|
||||
daily->ReloadGraphs();
|
||||
}
|
||||
if (overview) overview->ReloadGraphs();
|
||||
if (welcome) welcome->refreshPage();
|
||||
} else {
|
||||
QMessageBox::information(this, STR_MessageBox_Information,
|
||||
tr("Select the day with valid oximetry data in daily view first."),QMessageBox::Ok);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Multilingual Support files
|
||||
/* Multilingual Support files
|
||||
*
|
||||
* Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net>
|
||||
*
|
||||
@ -64,8 +64,7 @@ void initTranslations(QSettings & settings) {
|
||||
langNames[en]="English US";
|
||||
|
||||
// Scan through available translations, and add them to the list
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QFileInfo fi = list.at(i);
|
||||
for (const auto & fi : list) {
|
||||
QString name = fi.fileName().section('.', 0, 0);
|
||||
QString code = fi.fileName().section('.', 1, 1);
|
||||
|
||||
|
@ -112,7 +112,7 @@ QString Welcome::GenerateCPAPHTML()
|
||||
"p,a,td,body { font-size: "+QString::number(QApplication::font().pointSize() + 2)+"px; }"
|
||||
"</style>"
|
||||
"</head>"
|
||||
"<body leftmargin=5 topmargin=5 rightmargin=5 bottommargin=5 valign=center align=center>";
|
||||
"<body leftmargin=5 topmargin=10 rightmargin=5 bottommargin=5 vertical-align=center align=center>";
|
||||
|
||||
Machine * cpap = nullptr;
|
||||
if (!havecpapdata && !haveoximeterdata) {
|
||||
@ -240,22 +240,6 @@ QString Welcome::GenerateCPAPHTML()
|
||||
}
|
||||
}
|
||||
|
||||
/* html += QString("<div align=center><table class=curved cellpadding=3 width=75%>")+
|
||||
"<tr>"
|
||||
"<td align=center colspan=2><b>"+QObject::tr("Very Important Warning For ResMed S9 Users")+"</b></font></td></tr>"
|
||||
"<tr><td align=center>"+
|
||||
"<p>"+QObject::tr("ALWAYS <font color=red><b>write protect</b></font> CPAP SDCards before inserting them into your computer.")+"</p><p>"+
|
||||
+"<span title=\""+QObject::tr("Mac OSX and Win8.1")+"\" onmouseover='ChangeColor(this, \"#eeeeee\");' onmouseout='ChangeColor(this, \"#ffffff\");'>"+
|
||||
QObject::tr("<font color=blue>Certain operating systems</font></span> write index files to the card without asking, which can render your card unreadable by your cpap machine.")+ " "+
|
||||
QObject::tr("As a second line of protection, make sure to <font color=red><b>unmount</b></font> the data card properly before removing it!")+"</p>"
|
||||
"</td>"
|
||||
"<td><img src=\"qrc:/icons/sdcard-lock.png\" width=64px></td>"
|
||||
"</tr>"
|
||||
"</table>"
|
||||
"</td></tr></table></div>";*/
|
||||
// } else {
|
||||
// }
|
||||
|
||||
html += "</body></html>";
|
||||
return html;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>965</width>
|
||||
<height>719</height>
|
||||
<height>742</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -259,7 +259,7 @@ border: 2px solid #56789a; border-radius: 10px;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>View Daily</string>
|
||||
<string>Daily View</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Resources.qrc">
|
||||
@ -297,7 +297,7 @@ border: 2px solid #56789a; border-radius: 10px;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>View Overview</string>
|
||||
<string>Overview</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Resources.qrc">
|
||||
@ -335,7 +335,7 @@ border: 2px solid #56789a; border-radius: 10px;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>View Statistics</string>
|
||||
<string>Statistics</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Resources.qrc">
|
||||
@ -435,7 +435,7 @@ border: 2px solid #56789a; border-radius: 10px;
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border: 1px solid; border-radius:20px; background-color: palette(base); </string>
|
||||
<string notr="true">border: 1px solid; border-radius:20px; background-color: #ffffd0; </string>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
@ -513,7 +513,7 @@ p, li { white-space: pre-wrap; }
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border: 1px solid; border-radius:20px; background-color: palette(base); </string>
|
||||
<string notr="true">border: 1px solid; border-radius:20px; background-color: #ffffd0; </string>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
|
Loading…
Reference in New Issue
Block a user