qprogress global progress bar misuse cleanup for importers

This commit is contained in:
Mark Watkins 2018-05-08 04:42:23 +10:00
parent 2df5987ca6
commit ea2e0cb147
10 changed files with 83 additions and 84 deletions

View File

@ -7,7 +7,6 @@
* distribution for more details. */ * distribution for more details. */
#include <QDir> #include <QDir>
#include <QProgressBar>
#include <QMessageBox> #include <QMessageBox>
#include <QDataStream> #include <QDataStream>
#include <QTextStream> #include <QTextStream>
@ -15,8 +14,6 @@
#include "icon_loader.h" #include "icon_loader.h"
extern QProgressBar *qprogress;
const QString FPHCARE = "FPHCARE"; const QString FPHCARE = "FPHCARE";
FPIcon::FPIcon(MachineID id) FPIcon::FPIcon(MachineID id)
@ -195,7 +192,7 @@ int FPIconLoader::OpenMachine(Machine *mach, const QString & path)
QString filename, fpath; QString filename, fpath;
if (qprogress) { qprogress->setValue(0); } emit setProgressValue(0);
QStringList summary, log, flw, det; QStringList summary, log, flw, det;
Sessions.clear(); Sessions.clear();

View File

@ -9,12 +9,9 @@
* distribution for more details. */ * distribution for more details. */
#include <QDir> #include <QDir>
#include <QProgressBar>
#include "intellipap_loader.h" #include "intellipap_loader.h"
extern QProgressBar *qprogress;
ChannelID INTP_SmartFlexMode, INTP_SmartFlexLevel; ChannelID INTP_SmartFlexMode, INTP_SmartFlexLevel;
Intellipap::Intellipap(MachineID id) Intellipap::Intellipap(MachineID id)
@ -588,8 +585,6 @@ int IntellipapLoader::OpenDV5(const QString & path)
delete [] m_buffer; delete [] m_buffer;
if (qprogress) { qprogress->setValue(100); }
f.close(); f.close();
int c = Sessions.size(); int c = Sessions.size();

View File

@ -13,9 +13,9 @@
#include <QFile> #include <QFile>
#include <QDataStream> #include <QDataStream>
#include <QMessageBox> #include <QMessageBox>
#include <QProgressBar>
#include <QDebug> #include <QDebug>
#include <cmath> #include <cmath>
#include "SleepLib/schema.h" #include "SleepLib/schema.h"
#include "prs1_loader.h" #include "prs1_loader.h"
#include "SleepLib/session.h" #include "SleepLib/session.h"
@ -40,9 +40,6 @@
// that change loader behaviour or modify channels. // that change loader behaviour or modify channels.
//******************************************************************************************** //********************************************************************************************
extern QProgressBar *qprogress;
QHash<int, QString> ModelMap; QHash<int, QString> ModelMap;
#define PRS1_CRC_CHECK #define PRS1_CRC_CHECK
@ -524,7 +521,7 @@ int PRS1Loader::OpenMachine(const QString & path)
QString filename; QString filename;
if (qprogress) { qprogress->setValue(0); } emit setProgressValue(0);
QStringList paths; QStringList paths;

View File

@ -12,7 +12,6 @@
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QMessageBox> #include <QMessageBox>
#include <QProgressBar>
#include <QTextStream> #include <QTextStream>
#include <QDebug> #include <QDebug>
#include <QStringList> #include <QStringList>
@ -27,8 +26,6 @@
#include <QElapsedTimer> // only available in 4.8 #include <QElapsedTimer> // only available in 4.8
#endif #endif
extern QProgressBar *qprogress;
QHash<QString, QList<quint16> > Resmed_Model_Map; QHash<QString, QList<quint16> > Resmed_Model_Map;
ChannelID RMS9_EPR, RMS9_EPRLevel, RMS9_Mode, RMS9_SmartStart, RMS9_HumidStatus, RMS9_HumidLevel, ChannelID RMS9_EPR, RMS9_EPRLevel, RMS9_Mode, RMS9_SmartStart, RMS9_HumidStatus, RMS9_HumidLevel,
@ -113,14 +110,22 @@ void ResmedLoader::ParseSTR(Machine *mach, QMap<QDate, STRFile> & STRmap)
{ {
Q_UNUSED(mach) Q_UNUSED(mach)
if (!qprogress) {
qWarning() << "What happened to qprogress object in ResmedLoader::ParseSTR()";
return;
}
QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate(); QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate();
bool ignoreOldSessions = p_profile->session->ignoreOlderSessions(); bool ignoreOldSessions = p_profile->session->ignoreOlderSessions();
int totalRecs = 0;
for (auto it=STRmap.begin(), end=STRmap.end(); it != end; ++it) {
STRFile & file = it.value();
ResMedEDFParser & str = *file.edf;
totalRecs += str.GetNumDataRecords();
}
emit updateMessage("Parsing STR.edf records...");
emit setProgressMax(totalRecs);
QCoreApplication::processEvents();
int currentRec = 0;
for (auto it=STRmap.begin(), end=STRmap.end(); it != end; ++it) { for (auto it=STRmap.begin(), end=STRmap.end(); it != end; ++it) {
STRFile & file = it.value(); STRFile & file = it.value();
QString & strfile = file.filename; QString & strfile = file.filename;
@ -143,10 +148,12 @@ void ResmedLoader::ParseSTR(Machine *mach, QMap<QDate, STRFile> & STRmap)
EDFSignal *sig = nullptr; EDFSignal *sig = nullptr;
int size = str.GetNumDataRecords(); int size = str.GetNumDataRecords();
int cnt=0;
// For each data record, representing 1 day each // For each data record, representing 1 day each
for (int rec = 0; rec < size; ++rec, date = date.addDays(1)) { for (int rec = 0; rec < size; ++rec, date = date.addDays(1)) {
emit setProgressValue(++currentRec);
QCoreApplication::processEvents();
if (ignoreOldSessions) { if (ignoreOldSessions) {
if (date < ignoreBefore.date()) { if (date < ignoreBefore.date()) {
continue; continue;
@ -180,11 +187,7 @@ void ResmedLoader::ParseSTR(Machine *mach, QMap<QDate, STRFile> & STRmap)
uint timestamp = QDateTime(date,QTime(12,0,0)).toTime_t(); uint timestamp = QDateTime(date,QTime(12,0,0)).toTime_t();
R.date = date; R.date = date;
// skipday = false; // skipday = false;
if ((cnt++ % 10) == 0) {
qprogress->setValue(10.0 + (float(cnt) / float(size) * 90.0));
QApplication::processEvents();
}
// For every mask on, there will be a session within 1 minute either way // For every mask on, there will be a session within 1 minute either way
// We can use that for data matching // We can use that for data matching
@ -1414,6 +1417,7 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
filename.toInt(&ok); filename.toInt(&ok);
if (ok) { if (ok) {
// Get file lists under this directory // Get file lists under this directory
dir.setPath(fi.canonicalFilePath()); dir.setPath(fi.canonicalFilePath());
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
dir.setSorting(QDir::Name); dir.setSorting(QDir::Name);
@ -1444,10 +1448,10 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
int pbarFreq = totalfiles / 50; int pbarFreq = totalfiles / 50;
if (pbarFreq < 1) pbarFreq = 1; // stop a divide by zero if (pbarFreq < 1) pbarFreq = 1; // stop a divide by zero
qprogress->setMaximum(totalfiles); emit setProgressValue(0);
qprogress->setValue(0); emit setProgressMax(totalfiles);
QCoreApplication::processEvents();
int cnt = 0;
// Scan through all folders looking for EDF files, skip any already imported and peek inside to get durations // Scan through all folders looking for EDF files, skip any already imported and peek inside to get durations
QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate(); QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate();
bool ignoreOldSessions = p_profile->session->ignoreOlderSessions(); bool ignoreOldSessions = p_profile->session->ignoreOlderSessions();
@ -1459,9 +1463,9 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
const QFileInfo & fi = EDFfiles.at(i); const QFileInfo & fi = EDFfiles.at(i);
// Update progress bar // Update progress bar
if ((cnt++ % pbarFreq) == 0) { if ((i % pbarFreq) == 0) {
qprogress->setValue(cnt); emit setProgressValue(i);
QApplication::processEvents(); QCoreApplication::processEvents();
} }
// Forget about it if it can't be read. // Forget about it if it can't be read.
@ -2554,8 +2558,6 @@ int ResmedLoader::Open(const QString & dirpath)
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
// Build a Date map of all records in STR.edf files, populating ResDayList // Build a Date map of all records in STR.edf files, populating ResDayList
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
emit updateMessage(QObject::tr("Processing STR.edf File(s)..."));
QApplication::processEvents();
ParseSTR(mach, STRmap); ParseSTR(mach, STRmap);
@ -2607,7 +2609,7 @@ int ResmedLoader::Open(const QString & dirpath)
// Now at this point we have resdayList populated with processable summary and EDF files data // Now at this point we have resdayList populated with processable summary and EDF files data
// that can be processed in threads.. // that can be processed in threads..
emit updateMessage(QObject::tr("Queing Import Jobs...")); emit updateMessage(QObject::tr("Queueing Import Tasks..."));
QApplication::processEvents(); QApplication::processEvents();
for (auto rdi=resdayList.begin(), rend=resdayList.end(); rdi != rend; rdi++) { for (auto rdi=resdayList.begin(), rend=resdayList.end(); rdi != rend; rdi++) {
@ -2808,8 +2810,6 @@ int ResmedLoader::Open(const QString & dirpath)
} }
#endif #endif
if (qprogress) { qprogress->setValue(100); }
sessfiles.clear(); sessfiles.clear();
strsess.clear(); strsess.clear();

View File

@ -6,14 +6,11 @@
* License. See the file COPYING in the main directory of the Linux * License. See the file COPYING in the main directory of the Linux
* distribution for more details. */ * distribution for more details. */
#include <QProgressBar>
#include <QApplication> #include <QApplication>
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QThreadPool> #include <QThreadPool>
extern QProgressBar *qprogress;
#include "machine_loader.h" #include "machine_loader.h"
bool genpixmapinit = false; bool genpixmapinit = false;
@ -209,7 +206,7 @@ void MachineLoader::runTasks(bool threaded)
m_totaltasks=m_tasklist.size(); m_totaltasks=m_tasklist.size();
if (m_totaltasks == 0) return; if (m_totaltasks == 0) return;
qprogress->setMaximum(m_totaltasks); emit setProgressMax(m_totaltasks);
m_currenttask=0; m_currenttask=0;
threaded=AppSetting->multithreading(); threaded=AppSetting->multithreading();
@ -221,8 +218,9 @@ void MachineLoader::runTasks(bool threaded)
// update progress bar // update progress bar
m_currenttask++; m_currenttask++;
qprogress->setValue(m_currenttask); emit setProgressValue(++m_currenttask);
QApplication::processEvents(); QApplication::processEvents();
delete task; delete task;
} }
} else { } else {
@ -240,8 +238,7 @@ void MachineLoader::runTasks(bool threaded)
task = m_tasklist[0]; task = m_tasklist[0];
// update progress bar // update progress bar
m_currenttask++; emit setProgressValue(++m_currenttask);
qprogress->setValue(m_currenttask);
QApplication::processEvents(); QApplication::processEvents();
} else { } else {
// job list finished // job list finished

View File

@ -111,6 +111,8 @@ public slots:
signals: signals:
void updateProgress(int cnt, int total); void updateProgress(int cnt, int total);
void setProgressMax(int max);
void setProgressValue(int val);
void updateMessage(QString); void updateMessage(QString);
void machineUnsupported(Machine *); void machineUnsupported(Machine *);

View File

@ -34,10 +34,14 @@ ProgressDialog::~ProgressDialog()
} }
} }
void ProgressDialog::doUpdateProgress(int cnt, int total) void ProgressDialog::setProgressMax(int max)
{ {
progress->setMaximum(total); progress->setMaximum(max);
progress->setValue(cnt); }
void ProgressDialog::setProgressValue(int val)
{
progress->setValue(val);
} }

View File

@ -28,8 +28,11 @@ public:
QProgressBar * progress; QProgressBar * progress;
public slots: public slots:
void setMessage(QString msg); void setMessage(QString msg);
void doUpdateProgress(int cnt, int total);
void onAbortClicked(); void onAbortClicked();
void setProgressMax(int max);
void setProgressValue(int val);
signals: signals:
void abortClicked(); void abortClicked();
protected: protected:

View File

@ -589,8 +589,6 @@ int MainWindow::importCPAP(ImportPath import, const QString &message)
image = image.scaled(64,64); image = image.scaled(64,64);
progdlg->setPixmap(image); progdlg->setPixmap(image);
QProgressBar *saveQprogress = qprogress;
qprogress = progdlg->progress;
progdlg->addAbortButton(); progdlg->addAbortButton();
progdlg->setWindowModality(Qt::ApplicationModal); progdlg->setWindowModality(Qt::ApplicationModal);
@ -598,6 +596,8 @@ int MainWindow::importCPAP(ImportPath import, const QString &message)
progdlg->setMessage(message); progdlg->setMessage(message);
connect(import.loader, SIGNAL(updateMessage(QString)), progdlg, SLOT(setMessage(QString))); connect(import.loader, SIGNAL(updateMessage(QString)), progdlg, SLOT(setMessage(QString)));
connect(import.loader, SIGNAL(setProgressMax(int)), progdlg, SLOT(setProgressMax(int)));
connect(import.loader, SIGNAL(setProgressValue(int)), progdlg, SLOT(setProgressValue(int)));
connect(progdlg, SIGNAL(abortClicked()), import.loader, SLOT(abortImport())); connect(progdlg, SIGNAL(abortClicked()), import.loader, SLOT(abortImport()));
int c = import.loader->Open(import.path); int c = import.loader->Open(import.path);
@ -610,6 +610,8 @@ int MainWindow::importCPAP(ImportPath import, const QString &message)
Notify(tr("Couldn't find any valid Machine Data at\n\n%1").arg(import.path),tr("Import Problem")); Notify(tr("Couldn't find any valid Machine Data at\n\n%1").arg(import.path),tr("Import Problem"));
} }
disconnect(progdlg, SIGNAL(abortClicked()), import.loader, SLOT(abortImport())); disconnect(progdlg, SIGNAL(abortClicked()), import.loader, SLOT(abortImport()));
disconnect(import.loader, SIGNAL(setProgressMax(int)), progdlg, SLOT(setProgressMax(int)));
disconnect(import.loader, SIGNAL(setProgressValue(int)), progdlg, SLOT(setProgressValue(int)));
disconnect(import.loader, SIGNAL(updateMessage(QString)), progdlg, SLOT(setMessage(QString))); disconnect(import.loader, SIGNAL(updateMessage(QString)), progdlg, SLOT(setMessage(QString)));
progdlg->close(); progdlg->close();
@ -620,7 +622,6 @@ int MainWindow::importCPAP(ImportPath import, const QString &message)
ui->tabWidget->setCurrentIndex(AppSetting->openTabAfterImport()); ui->tabWidget->setCurrentIndex(AppSetting->openTabAfterImport());
} }
qprogress = saveQprogress;
return c; return c;
} }
@ -844,16 +845,9 @@ void MainWindow::on_action_Import_Data_triggered()
QTime time; QTime time;
time.start(); time.start();
QDialog popup(this, Qt::FramelessWindowHint);
popup.setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
QLabel * waitmsg = new QLabel(tr("Please wait, scanning for CPAP data cards..."));
QVBoxLayout *waitlayout = new QVBoxLayout();
waitlayout->addWidget(waitmsg,1,Qt::AlignCenter);
waitlayout->addWidget(qprogress,1);
popup.setLayout(waitlayout);
bool asknew = false; bool asknew = false;
qprogress->setVisible(false);
if (datacards.size() > 0) { if (datacards.size() > 0) {
MachineInfo info = datacards[0].loader->PeekInfo(datacards[0].path); MachineInfo info = datacards[0].loader->PeekInfo(datacards[0].path);
@ -883,22 +877,21 @@ void MainWindow::on_action_Import_Data_triggered()
if (res == QMessageBox::Cancel) { if (res == QMessageBox::Cancel) {
// Give the communal progress bar back // Give the communal progress bar back
ui->statusbar->insertWidget(1,qprogress,1);
in_import=false; in_import=false;
return; return;
} else if (res == QMessageBox::No) { } else if (res == QMessageBox::No) {
waitmsg->setText(tr("Please wait, launching file dialog...")); //waitmsg->setText(tr("Please wait, launching file dialog..."));
datacards.clear(); datacards.clear();
asknew = true; asknew = true;
} }
} }
} else { } else {
waitmsg->setText(tr("No CPAP data card detected, launching file dialog...")); //waitmsg->setText(tr("No CPAP data card detected, launching file dialog..."));
asknew = true; asknew = true;
} }
if (asknew) { if (asknew) {
popup.show(); // popup.show();
mainwin->Notify(tr("Please remember to point the importer at the root folder or drive letter of your data-card, and not a subfolder."), mainwin->Notify(tr("Please remember to point the importer at the root folder or drive letter of your data-card, and not a subfolder."),
tr("Import Reminder"),8000); tr("Import Reminder"),8000);
@ -942,14 +935,11 @@ void MainWindow::on_action_Import_Data_triggered()
//#endif //#endif
if (w.exec() != QDialog::Accepted) { if (w.exec() != QDialog::Accepted) {
popup.hide();
ui->statusbar->insertWidget(1,qprogress,1);
in_import=false; in_import=false;
return; return;
} }
popup.hide();
for (int i = 0; i < w.selectedFiles().size(); i++) { for (int i = 0; i < w.selectedFiles().size(); i++) {
Q_FOREACH(MachineLoader * loader, loaders) { Q_FOREACH(MachineLoader * loader, loaders) {
@ -969,17 +959,28 @@ void MainWindow::on_action_Import_Data_triggered()
// qprogress->setVisible(true); // qprogress->setVisible(true);
// popup.show(); // popup.show();
ProgressDialog * prog = new ProgressDialog(this);
prog->setMessage(tr("Processing import list..."));
prog->addAbortButton();
prog->setWindowModality(Qt::ApplicationModal);
prog->open();
int c = -1; int c = -1;
for (int i = 0; i < datacards.size(); i++) { for (int i = 0; i < datacards.size(); i++) {
QString dir = datacards[i].path; QString dir = datacards[i].path;
MachineLoader * loader = datacards[i].loader; MachineLoader * loader = datacards[i].loader;
if (!loader) continue; if (!loader) continue;
connect(loader, SIGNAL(updateMessage(QString)), prog, SLOT(setMessage(QString)));
connect(loader, SIGNAL(setProgressMax(int)), prog, SLOT(setProgressMax(int)));
connect(loader, SIGNAL(setProgressValue(int)), prog, SLOT(setProgressValue(int)));
connect(prog, SIGNAL(abortClicked()), loader, SLOT(abortImport()));
QPixmap image = loader->getPixmap(loader->PeekInfo(dir).series);
image = image.scaled(64,64);
prog->setPixmap(image);
if (!dir.isEmpty()) { if (!dir.isEmpty()) {
// qprogress->setValue(0);
// qprogress->show();
// qstatus->setText(tr("Importing Data"));
c = importCPAP(datacards[i], tr("Importing Data")); c = importCPAP(datacards[i], tr("Importing Data"));
qDebug() << "Finished Importing data" << c; qDebug() << "Finished Importing data" << c;
@ -992,19 +993,20 @@ void MainWindow::on_action_Import_Data_triggered()
if (c > 0) { if (c > 0) {
newdata = true; newdata = true;
} }
// qstatus->setText("");
// qprogress->hide();
} }
disconnect(prog, SIGNAL(abortClicked()), loader, SLOT(abortImport()));
disconnect(loader, SIGNAL(setProgressMax(int)), prog, SLOT(setProgressMax(int)));
disconnect(loader, SIGNAL(setProgressValue(int)), prog, SLOT(setProgressValue(int)));
disconnect(loader, SIGNAL(updateMessage(QString)), prog, SLOT(setMessage(QString)));
} }
// popup.hide();
// ui->statusbar->insertWidget(1, qprogress,1);
if (newdata) { if (newdata) {
finishCPAPImport(); finishCPAPImport();
PopulatePurgeMenu(); PopulatePurgeMenu();
} }
prog->close();
prog->deleteLater();
in_import=false; in_import=false;
} }
@ -1895,10 +1897,13 @@ void MainWindow::on_actionRebuildCPAP(QAction *action)
} }
} }
purgeMachine(mach); QString path = mach->getBackupPath();
MachineLoader *loader = lookupLoader(mach);
purgeMachine(mach); // purge destroys machine record
if (backups) { if (backups) {
importCPAP(ImportPath(mach->getBackupPath(), lookupLoader(mach)), tr("Please wait, importing from backup folder(s)...")); importCPAP(ImportPath(path, loader), tr("Please wait, importing from backup folder(s)..."));
} else { } else {
if (QMessageBox::information(this, STR_MessageBox_Warning, if (QMessageBox::information(this, STR_MessageBox_Warning,
tr("Because there are no internal backups to rebuild from, you will have to restore from your own.")+"\n\n"+ tr("Because there are no internal backups to rebuild from, you will have to restore from your own.")+"\n\n"+
@ -1914,6 +1919,8 @@ void MainWindow::on_actionRebuildCPAP(QAction *action)
daily->clearLastDay(); // otherwise Daily will crash daily->clearLastDay(); // otherwise Daily will crash
daily->ReloadGraphs(); daily->ReloadGraphs();
} }
welcome->refreshPage();
PopulatePurgeMenu();
GenerateStatistics(); GenerateStatistics();
p_profile->StoreMachines(); p_profile->StoreMachines();
} }
@ -2396,8 +2403,7 @@ void MainWindow::on_actionImport_RemStar_MSeries_Data_triggered()
void MainWindow::on_actionSleep_Disorder_Terms_Glossary_triggered() void MainWindow::on_actionSleep_Disorder_Terms_Glossary_triggered()
{ {
ui->webView->load( ui->webView->load(QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=Glossary"));
QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=Glossary"));
ui->tabWidget->setCurrentWidget(ui->helpTab); ui->tabWidget->setCurrentWidget(ui->helpTab);
} }
@ -2405,8 +2411,6 @@ void MainWindow::on_actionHelp_Support_SleepyHead_Development_triggered()
{ {
QUrl url = QUrl("https://sleepyhead.jedimark.net/donate.php"); QUrl url = QUrl("https://sleepyhead.jedimark.net/donate.php");
QDesktopServices().openUrl(url); QDesktopServices().openUrl(url);
// ui->webView->load(url);
// ui->tabWidget->setCurrentWidget(ui->helpTab);
} }
void MainWindow::on_actionChange_Language_triggered() void MainWindow::on_actionChange_Language_triggered()

View File

@ -57,7 +57,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="importTab"> <widget class="QWidget" name="importTab">
<attribute name="title"> <attribute name="title">