Fix opengl screenshots on windows, remove the last of qprogress and statusbar, and add progressdialog to recompress/recalc

This commit is contained in:
Mark Watkins 2018-06-06 10:48:31 +10:00
parent ad0905db07
commit 63e4b1a643
14 changed files with 134 additions and 270 deletions

View File

@ -33,8 +33,6 @@ using namespace std;
#include "SleepLib/machine.h"
#include "SleepLib/session.h"
extern QProgressBar *qprogress;
CMS50F37Loader::CMS50F37Loader()
{
m_type = MT_OXIMETER;

View File

@ -32,8 +32,6 @@ using namespace std;
#include "SleepLib/machine.h"
#include "SleepLib/session.h"
extern QProgressBar *qprogress;
MD300W1Loader::MD300W1Loader()
{
m_type = MT_OXIMETER;

View File

@ -10,8 +10,6 @@
#include <QProgressBar>
#include "mseries_loader.h"
extern QProgressBar *qprogress;
MSeries::MSeries(Profile *profile, MachineID id)

View File

@ -1135,7 +1135,7 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
EDForder.push_back(EDF_SAD);
QHash<EDFType, QStringList>::iterator gi;
qprogress->setMaximum(filesbytype[EDF_PLD].size() + filesbytype[EDF_BRP].size() + filesbytype[EDF_SAD].size());
emit setProgressMax(filesbytype[EDF_PLD].size() + filesbytype[EDF_BRP].size() + filesbytype[EDF_SAD].size());
cnt = 0;
for (int i=0; i<3; i++) {
@ -1146,7 +1146,7 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
int base_size = LIST.size();
for (int f=0; f < base_size; ++f) {
if ((cnt % 50) == 0) {
qprogress->setValue(cnt);
emit setProgressValue(cnt);
QApplication::processEvents();
}
cnt++;

View File

@ -16,8 +16,6 @@
#include "weinmann_loader.h"
extern QProgressBar *qprogress;
Weinmann::Weinmann(Profile *profile, MachineID id)
: CPAP(profile, id)
{

View File

@ -36,7 +36,6 @@
#include "mainwindow.h"
extern MainWindow * mainwin;
extern QProgressBar *qprogress;
//////////////////////////////////////////////////////////////////////////////////////////
// Machine Base-Class implmementation
@ -739,13 +738,14 @@ bool Machine::SaveSession(Session *sess)
return true;
}
void Machine::queSaveList(Session * sess)
/*void Machine::queSaveList(Session * sess)
{
if (!m_save_threads_running) {
// Threads aren't being used.. so run the actual immediately...
int i = (float(m_donetasks) / float(m_totaltasks) * 100.0);
qprogress->setValue(i);
QApplication::processEvents();
//qprogress->setValue(i);
//QApplication::processEvents();
sess->UpdateSummaries();
sess->Store(getDataPath());
@ -759,7 +759,7 @@ void Machine::queSaveList(Session * sess)
m_savelist.append(sess);
listMutex.unlock();
}
}
}*/
Session *Machine::popSaveList()
{
@ -776,7 +776,7 @@ Session *Machine::popSaveList()
return sess;
}
// Call any time queing starts
/*// Call any time queing starts
void Machine::StartSaveThreads()
{
m_savelist.clear();
@ -827,7 +827,7 @@ void Machine::FinishSaveThreads()
}
delete savelistSem;
}
} */
void SaveThread::run()
{
@ -898,14 +898,16 @@ void Machine::runTasks()
return;
QThreadPool * threadpool = QThreadPool::globalInstance();
int m_totaltasks=m_tasklist.size();
int m_currenttask=0;
qprogress->setMaximum(m_totaltasks);
//int m_totaltasks=m_tasklist.size();
//int m_currenttask=0;
// if (loader()) emit loader()->setProgressMax(m_totaltasks);
while (!m_tasklist.isEmpty()) {
if (threadpool->tryStart(m_tasklist.at(0))) {
m_tasklist.pop_front();
qprogress->setValue(m_currenttask++);
/* if (loader()) {
emit loader()->setProgressValue(++m_currenttask);
QApplication::processEvents();
}*/
}
}
QThreadPool::globalInstance()->waitForDone(-1);

View File

@ -18,7 +18,6 @@
#include <QThread>
#include <QMutex>
#include <QSemaphore>
#include <QProgressBar>
#include <QHash>
#include <QVector>
@ -160,19 +159,19 @@ class Machine
//! \brief Returns the date of the most recent loaded Session
const QDate &LastDay() { return lastday; }
//! \brief Add a new task to the multithreaded save code
void queSaveList(Session * sess);
// //! \brief Add a new task to the multithreaded save code
//void queSaveList(Session * sess);
bool hasModifiedSessions();
//! \brief Grab the next task in the multithreaded save code
Session *popSaveList();
//! \brief Start the save threads which handle indexing, file storage and waveform processing
void StartSaveThreads();
// //! \brief Start the save threads which handle indexing, file storage and waveform processing
//void StartSaveThreads();
//! \brief Finish the save threads and safely close them
void FinishSaveThreads();
// //! \brief Finish the save threads and safely close them
//void FinishSaveThreads();
//! \brief The list of sessions that need saving (for multithreaded save code)
QList<Session *> m_savelist;

View File

@ -40,7 +40,6 @@
#include "Graphs/gdailysummary.h"
#include "Graphs/MinutesAtPressure.h"
//extern QProgressBar *qprogress;
extern MainWindow * mainwin;
// This was Sean Stangl's idea.. but I couldn't apply that patch.

View File

@ -16,7 +16,6 @@
#include "version.h"
#include "logger.h"
#include "SleepLib/schema.h"
#include "mainwindow.h"
#include "SleepLib/profiles.h"
#include "translation.h"
@ -264,7 +263,6 @@ retry_directory:
CMS50Loader::Register();
CMS50F37Loader::Register();
MD300W1Loader::Register();
//ZEOLoader::Register(); // Use outside of directory importer..
schema::setOrders(); // could be called in init...

View File

@ -29,6 +29,7 @@
#include <QTextBrowser>
#include <QStandardPaths>
#include <QDesktopServices>
#include <QScreen>
#include <cmath>
#include "common_gui.h"
@ -63,10 +64,6 @@
#include <QOpenGLFunctions>
#endif
QProgressBar *qprogress;
QLabel *qstatus;
QStatusBar *qstatusbar;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
@ -113,15 +110,6 @@ MainWindow::MainWindow(QWidget *parent) :
m_inRecalculation = false;
m_restartRequired = false;
// Initialize Status Bar objects
qstatusbar = ui->statusbar;
qprogress = new QProgressBar(this);
qprogress->setMaximum(100);
qstatus = new QLabel("", this);
qprogress->hide();
//ui->statusbar->setMinimumWidth(200);
ui->statusbar->addPermanentWidget(qstatus, 0);
ui->statusbar->addPermanentWidget(qprogress, 1);
QTextCharFormat format = ui->statStartDate->calendarWidget()->weekdayTextFormat(Qt::Saturday);
format.setForeground(QBrush(Qt::black, Qt::SolidPattern));
@ -217,10 +205,10 @@ MainWindow::MainWindow(QWidget *parent) :
QString loadingtxt =
"<HTML><body style='text-align: center; vertical-align: center'><table width='100%' height='100%'>"
"<tr><td align=center>"
"<img src='qrc:/docs/sheep.png' heigh=300px>"
//"<h1>" + tr("Please Wait, Loading...") + "</h1>"
"<img src='qrc:/docs/sheep.png'>"
"<h1>" + tr("Under construction...") + "</h1>"
"</td></tr></table></body></HTML>";
ui->statisticsView->setHtml(loadingtxt);
ui->helpBrowser->setHtml(loadingtxt);
on_tabWidget_currentChanged(0);
#ifndef REMSTAR_M_SUPPORT
@ -322,8 +310,6 @@ void MainWindow::Notify(QString s, QString title, int ms)
#endif
systray->showMessage(title, msg, QSystemTrayIcon::Information, ms);
} else {
ui->statusbar->showMessage(s, ms);
}
}
@ -427,9 +413,6 @@ bool MainWindow::OpenProfile(QString profileName, bool skippassword)
prof->removeLock();
}
// qstatus->setText(tr("Loading Data"));
// qprogress->show();
p_profile = prof;
ProgressDialog * progress = new ProgressDialog(this);
@ -524,9 +507,6 @@ bool MainWindow::OpenProfile(QString profileName, bool skippassword)
progress->close();
delete progress;
//qprogress->hide();
//qstatus->setText("");
return true;
}
@ -962,10 +942,6 @@ void MainWindow::on_action_Import_Data_triggered()
// QStringList goodlocations;
// waitmsg.setText(tr("Please wait, SleepyHead is importing data..."));
// qprogress->setVisible(true);
// popup.show();
ProgressDialog * prog = new ProgressDialog(this);
prog->setMessage(tr("Processing import list..."));
prog->addAbortButton();
@ -1329,10 +1305,18 @@ void MainWindow::on_action_Screenshot_triggered()
void MainWindow::DelayedScreenshot()
{
// Make sure to scale for high resolution displays (like Retina)
qreal pr = devicePixelRatio();
// qreal pr = devicePixelRatio();
QPixmap pixmap=grab();
QScreen * screen = QApplication::primaryScreen();
int titleBarHeight = -QApplication::style()->pixelMetric(QStyle::PM_TitleBarHeight);
#ifdef Q_OS_WIN
titleBarHeight += 6;
#endif
QPixmap pixmap = screen->grabWindow(winId(),0,titleBarHeight);
/*#if defined(Q_OS_WIN) || defined(Q_OS_LINUX) || defined(Q_OS_HAIKU)
// grab the whole screen
@ -1370,10 +1354,6 @@ void MainWindow::on_actionView_Oximetry_triggered()
{
on_oximetryButton_clicked();
}
void MainWindow::updatestatusBarMessage(const QString &text)
{
ui->statusbar->showMessage(text, 1000);
}
void MainWindow::on_actionPrint_Report_triggered()
{
@ -2030,13 +2010,6 @@ void MainWindow::on_actionView_Statistics_triggered()
ui->tabWidget->setCurrentWidget(ui->statisticsTab);
}
void MainWindow::LinkHovered(const QString &link, const QString &title, const QString &textContent)
{
Q_UNUSED(title);
Q_UNUSED(textContent);
ui->statusbar->showMessage(link);
}
void MainWindow::on_tabWidget_currentChanged(int index)
{
Q_UNUSED(index);
@ -2101,42 +2074,21 @@ void MainWindow::MachineUnsupported(Machine * m)
void MainWindow::doRecompressEvents()
{
if (p_profile->countDays(MT_CPAP, p_profile->FirstDay(), p_profile->LastDay()) == 0) {
return;
}
m_inRecalculation = true;
QDate first = p_profile->FirstDay();
QDate date = p_profile->LastDay();
Session *sess;
Day *day;
//FlowParser flowparser;
mainwin->Notify(tr("Performance will be degraded during these recalculations."),
tr("Recalculating Indices"));
// For each day in history
int daycount = first.daysTo(date);
int idx = 0;
qstatus->setText(tr("Re/Decompressing Session Event Data"));
if (qprogress) {
qprogress->setValue(0);
qprogress->setVisible(true);
qprogress->setMaximum(daycount);
}
if (!p_profile) return;
ProgressDialog progress(this);
progress.setMessage("Recompressing Session Files");
progress.setProgressMax(p_profile->daylist.size());
QPixmap icon = QPixmap(":/docs/sheep.png").scaled(64,64);
progress.setPixmap(icon);
progress.open();
bool isopen;
do {
day = p_profile->GetDay(date, MT_CPAP);
if (day) {
for (int i = 0; i < day->size(); i++) {
sess = (*day)[i];
int idx = 0;
for (Day * day : p_profile->daylist) {
for (Session * sess : day->sessions) {
isopen = sess->eventsLoaded();
// Load the events if they aren't loaded already
// Load the events and summary if they aren't loaded already
sess->LoadSummary();
sess->OpenEvents();
sess->SetChanged(true);
sess->machine()->SaveSession(sess);
@ -2145,75 +2097,45 @@ void MainWindow::doRecompressEvents()
sess->TrashEvents();
}
}
}
date = date.addDays(-1);
qprogress->setValue(idx);
progress.setProgressValue(++idx);
QApplication::processEvents();
idx++;
} while (date >= first);
qstatus->setText(tr(""));
qprogress->setVisible(false);
m_inRecalculation = false;
Notify(tr("Session re/decompression are now complete."), tr("Task Completed"));
}
progress.close();
}
void MainWindow::doReprocessEvents()
{
if (p_profile->countDays(MT_CPAP, p_profile->FirstDay(), p_profile->LastDay()) == 0) {
return;
if (!p_profile) return;
ProgressDialog progress(this);
progress.setMessage("Recalculating summaries");
progress.setProgressMax(p_profile->daylist.size());
QPixmap icon = QPixmap(":/docs/sheep.png").scaled(64,64);
progress.setPixmap(icon);
progress.open();
if (daily) {
daily->Unload();
daily->clearLastDay(); // otherwise Daily will crash
delete daily;
daily = nullptr;
}
if (welcome) {
delete welcome;
welcome = nullptr;
}
if (overview) {
delete overview;
overview = nullptr;
}
m_inRecalculation = true;
QDate first = p_profile->FirstDay();
QDate date = p_profile->LastDay();
Session *sess;
Day *day;
//FlowParser flowparser;
mainwin->Notify(tr("Performance will be degraded during these recalculations."),
tr("Recompressing Session Data"));
// For each day in history
int daycount = first.daysTo(date);
int idx = 0;
QList<Machine *> machines = p_profile->GetMachines(MT_CPAP);
// Disabling multithreaded save as it appears it's causing problems
bool cache_sessions = false; //p_profile->session->cacheSessions();
if (cache_sessions) { // Use multithreaded save to handle reindexing.. (hogs memory like hell)
qstatus->setText(tr("Loading Event Data"));
} else {
qstatus->setText(tr("Recalculating Summaries"));
}
if (qprogress) {
qprogress->setValue(0);
qprogress->setVisible(true);
qprogress->setMaximum(daycount);
}
bool isopen;
do {
day = p_profile->GetDay(date, MT_CPAP);
if (day) {
for (int i = 0; i < day->size(); i++) {
sess = (*day)[i];
isopen = sess->eventsLoaded();
for (Day * day : p_profile->daylist) {
for (Session * sess : day->sessions) {
bool isopen = sess->eventsLoaded();
// Load the events if they aren't loaded already
sess->LoadSummary();
sess->OpenEvents();
//if (!sess->channelDataExists(CPAP_FlowRate)) continue;
//QVector<EventList *> & flowlist=sess->eventlist[CPAP_FlowRate];
// Destroy any current user flags..
sess->destroyEvent(CPAP_UserFlag1);
sess->destroyEvent(CPAP_UserFlag2);
@ -2231,7 +2153,6 @@ void MainWindow::doReprocessEvents()
sess->SetChanged(true);
if (!cache_sessions) {
sess->UpdateSummaries();
sess->machine()->SaveSession(sess);
@ -2240,42 +2161,24 @@ void MainWindow::doReprocessEvents()
}
}
}
}
progress.close();
date = date.addDays(-1);
welcome = new Welcome(ui->tabWidget);
ui->tabWidget->insertTab(1, welcome, tr("Welcome"));
qprogress->setValue(++idx);
QApplication::processEvents();
daily = new Daily(ui->tabWidget, nullptr);
ui->tabWidget->insertTab(2, daily, STR_TR_Daily);
daily->ReloadGraphs();
} while (date >= first);
overview = new Overview(ui->tabWidget, daily->graphView());
ui->tabWidget->insertTab(3, overview, STR_TR_Overview);
overview->ReloadGraphs();
if (cache_sessions) {
qstatus->setText(tr("Recalculating Summaries"));
// Should really create welcome and statistics here, but they need redoing later anyway to kill off webkit
ui->tabWidget->setCurrentIndex(AppSetting->openTabAtStart());
GenerateStatistics();
PopulatePurgeMenu();
for (int i = 0; i < machines.size(); i++) {
machines.at(i)->Save();
}
}
qstatus->setText(tr(""));
qprogress->setVisible(false);
m_inRecalculation = false;
if (m_restartRequired) {
QMessageBox::information(this, tr("Restart Required"),
tr("Recalculations are complete, the application now needs to restart to display the changes."),
QMessageBox::Ok);
RestartApplication();
return;
} else {
Notify(tr("Recalculations are now complete."), tr("Task Completed"));
FreeSessions();
QDate current = daily->getDate();
daily->LoadDate(current);
if (overview) { overview->ReloadGraphs(); }
}
}
void MainWindow::on_actionImport_ZEO_Data_triggered()

View File

@ -223,9 +223,6 @@ class MainWindow : public QMainWindow
//! \brief a slot that calls the real Oximetry tab selector
void on_actionView_Oximetry_triggered();
//! \brief Updates the Statusbar message with the QString message contained in Text
void updatestatusBarMessage(const QString &text);
//! \brief Passes the Daily, Overview & Oximetry object to Print Report, based on current tab
void on_actionPrint_Report_triggered();
@ -259,8 +256,6 @@ class MainWindow : public QMainWindow
//void on_favouritesList_itemClicked(QListWidgetItem *item);
//! \brief Display Help WebView Link in statusbar.
void LinkHovered(const QString &link, const QString &title, const QString &textContent);
void on_tabWidget_currentChanged(int index);
void on_filterBookmarks_editingFinished();

View File

@ -1403,8 +1403,8 @@ QToolBox::tab:selected {
<rect>
<x>0</x>
<y>0</y>
<width>310</width>
<height>676</height>
<width>327</width>
<height>687</height>
</rect>
</property>
<property name="palette">
@ -1862,7 +1862,7 @@ border: 2px solid #56789a; border-radius: 30px;
<x>0</x>
<y>0</y>
<width>327</width>
<height>667</height>
<height>687</height>
</rect>
</property>
<property name="palette">
@ -2918,7 +2918,7 @@ p, li { white-space: pre-wrap; }
<x>0</x>
<y>0</y>
<width>327</width>
<height>667</height>
<height>687</height>
</rect>
</property>
<property name="mouseTracking">
@ -3097,23 +3097,6 @@ p, li { white-space: pre-wrap; }
<addaction name="menu_Data"/>
<addaction name="menu_Help"/>
</widget>
<widget class="QStatusBar" name="statusbar">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>20</height>
</size>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
</widget>
<action name="action_Import_Data">
<property name="text">
<string>&amp;Import Data</string>

View File

@ -1,4 +1,4 @@
/* Overview GUI Implementation
/* Overview GUI Implementation
*
* Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -26,7 +26,6 @@
#include "mainwindow.h"
extern MainWindow *mainwin;
//extern QProgressBar * qprogress;
Overview::Overview(QWidget *parent, gGraphView *shared) :
QWidget(parent),

View File

@ -10,15 +10,14 @@
#include <QtPrintSupport/qprinter.h>
#include <QtPrintSupport/qprintdialog.h>
#include <QTextDocument>
#include <QProgressBar>
#include <QApplication>
#include <cmath>
#include "reports.h"
#include "mainwindow.h"
#include "common_gui.h"
#include "SleepLib/progressdialog.h"
extern QProgressBar *qprogress;
extern MainWindow *mainwin;
@ -93,12 +92,14 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
return;
}
QPainter painter(printer);
ProgressDialog progress(mainwin);
progress.setMessage(QObject::tr("Printing %1 Report").arg(name));
QPixmap icon = QPixmap(":/docs/sheep.png").scaled(64,64);
progress.setPixmap(icon);
progress.open();
mainwin->Notify(
QObject::tr("This make take some time to complete..\nPlease don't touch anything until it's done."),
QObject::tr("Printing %1 Report").arg(name), 20000);
QPainter painter;
painter.begin(printer);
GLint gw;
gw = 2048; // Rough guess.. No GL_MAX_RENDERBUFFER_SIZE in mingw.. :(
@ -526,11 +527,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
int pages = ceil(float(graphs.size() + graph_slots) / float(graphs_per_page));
if (qprogress) {
qprogress->setValue(0);
qprogress->setMaximum(graphs.size());
qprogress->show();
}
progress.setProgressMax(graphs.size());
int page = 1;
int gcnt = 0;
@ -614,17 +611,14 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
gcnt++;
if (qprogress) {
qprogress->setValue(i);
progress.setProgressValue(i);
QApplication::processEvents();
}
}
gv->SetXBounds(savest, saveet);
qprogress->hide();
painter.end();
progress.close();
delete printer;
mainwin->Notify(QObject::tr("SleepyHead has finished sending the job to the printer."));
AppSetting->setLineCursorMode(lineCursorMode);
}