mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-08 04:00:44 +00:00
qprogress global progress bar misuse cleanup for importers
This commit is contained in:
parent
2df5987ca6
commit
ea2e0cb147
@ -7,7 +7,6 @@
|
||||
* distribution for more details. */
|
||||
|
||||
#include <QDir>
|
||||
#include <QProgressBar>
|
||||
#include <QMessageBox>
|
||||
#include <QDataStream>
|
||||
#include <QTextStream>
|
||||
@ -15,8 +14,6 @@
|
||||
|
||||
#include "icon_loader.h"
|
||||
|
||||
extern QProgressBar *qprogress;
|
||||
|
||||
const QString FPHCARE = "FPHCARE";
|
||||
|
||||
FPIcon::FPIcon(MachineID id)
|
||||
@ -195,7 +192,7 @@ int FPIconLoader::OpenMachine(Machine *mach, const QString & path)
|
||||
|
||||
QString filename, fpath;
|
||||
|
||||
if (qprogress) { qprogress->setValue(0); }
|
||||
emit setProgressValue(0);
|
||||
|
||||
QStringList summary, log, flw, det;
|
||||
Sessions.clear();
|
||||
|
@ -9,12 +9,9 @@
|
||||
* distribution for more details. */
|
||||
|
||||
#include <QDir>
|
||||
#include <QProgressBar>
|
||||
|
||||
#include "intellipap_loader.h"
|
||||
|
||||
extern QProgressBar *qprogress;
|
||||
|
||||
ChannelID INTP_SmartFlexMode, INTP_SmartFlexLevel;
|
||||
|
||||
Intellipap::Intellipap(MachineID id)
|
||||
@ -588,8 +585,6 @@ int IntellipapLoader::OpenDV5(const QString & path)
|
||||
|
||||
delete [] m_buffer;
|
||||
|
||||
if (qprogress) { qprogress->setValue(100); }
|
||||
|
||||
f.close();
|
||||
|
||||
int c = Sessions.size();
|
||||
|
@ -13,9 +13,9 @@
|
||||
#include <QFile>
|
||||
#include <QDataStream>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressBar>
|
||||
#include <QDebug>
|
||||
#include <cmath>
|
||||
|
||||
#include "SleepLib/schema.h"
|
||||
#include "prs1_loader.h"
|
||||
#include "SleepLib/session.h"
|
||||
@ -40,9 +40,6 @@
|
||||
// that change loader behaviour or modify channels.
|
||||
//********************************************************************************************
|
||||
|
||||
|
||||
extern QProgressBar *qprogress;
|
||||
|
||||
QHash<int, QString> ModelMap;
|
||||
|
||||
#define PRS1_CRC_CHECK
|
||||
@ -524,7 +521,7 @@ int PRS1Loader::OpenMachine(const QString & path)
|
||||
|
||||
QString filename;
|
||||
|
||||
if (qprogress) { qprogress->setValue(0); }
|
||||
emit setProgressValue(0);
|
||||
|
||||
QStringList paths;
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressBar>
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
@ -27,8 +26,6 @@
|
||||
#include <QElapsedTimer> // only available in 4.8
|
||||
#endif
|
||||
|
||||
extern QProgressBar *qprogress;
|
||||
|
||||
QHash<QString, QList<quint16> > Resmed_Model_Map;
|
||||
|
||||
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)
|
||||
|
||||
if (!qprogress) {
|
||||
qWarning() << "What happened to qprogress object in ResmedLoader::ParseSTR()";
|
||||
return;
|
||||
}
|
||||
|
||||
QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate();
|
||||
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) {
|
||||
STRFile & file = it.value();
|
||||
QString & strfile = file.filename;
|
||||
@ -143,10 +148,12 @@ void ResmedLoader::ParseSTR(Machine *mach, QMap<QDate, STRFile> & STRmap)
|
||||
EDFSignal *sig = nullptr;
|
||||
|
||||
int size = str.GetNumDataRecords();
|
||||
int cnt=0;
|
||||
|
||||
// For each data record, representing 1 day each
|
||||
for (int rec = 0; rec < size; ++rec, date = date.addDays(1)) {
|
||||
emit setProgressValue(++currentRec);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
if (ignoreOldSessions) {
|
||||
if (date < ignoreBefore.date()) {
|
||||
continue;
|
||||
@ -181,10 +188,6 @@ void ResmedLoader::ParseSTR(Machine *mach, QMap<QDate, STRFile> & STRmap)
|
||||
R.date = date;
|
||||
|
||||
// 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
|
||||
// We can use that for data matching
|
||||
@ -1414,6 +1417,7 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
|
||||
filename.toInt(&ok);
|
||||
if (ok) {
|
||||
// Get file lists under this directory
|
||||
|
||||
dir.setPath(fi.canonicalFilePath());
|
||||
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
|
||||
dir.setSorting(QDir::Name);
|
||||
@ -1444,10 +1448,10 @@ int ResmedLoader::scanFiles(Machine * mach, const QString & datalog_path)
|
||||
int pbarFreq = totalfiles / 50;
|
||||
if (pbarFreq < 1) pbarFreq = 1; // stop a divide by zero
|
||||
|
||||
qprogress->setMaximum(totalfiles);
|
||||
qprogress->setValue(0);
|
||||
emit setProgressValue(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
|
||||
QDateTime ignoreBefore = p_profile->session->ignoreOlderSessionsDate();
|
||||
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);
|
||||
|
||||
// Update progress bar
|
||||
if ((cnt++ % pbarFreq) == 0) {
|
||||
qprogress->setValue(cnt);
|
||||
QApplication::processEvents();
|
||||
if ((i % pbarFreq) == 0) {
|
||||
emit setProgressValue(i);
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
|
||||
// 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
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
emit updateMessage(QObject::tr("Processing STR.edf File(s)..."));
|
||||
QApplication::processEvents();
|
||||
|
||||
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
|
||||
// that can be processed in threads..
|
||||
|
||||
emit updateMessage(QObject::tr("Queing Import Jobs..."));
|
||||
emit updateMessage(QObject::tr("Queueing Import Tasks..."));
|
||||
QApplication::processEvents();
|
||||
|
||||
for (auto rdi=resdayList.begin(), rend=resdayList.end(); rdi != rend; rdi++) {
|
||||
@ -2808,8 +2810,6 @@ int ResmedLoader::Open(const QString & dirpath)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (qprogress) { qprogress->setValue(100); }
|
||||
|
||||
sessfiles.clear();
|
||||
strsess.clear();
|
||||
|
||||
|
@ -6,14 +6,11 @@
|
||||
* License. See the file COPYING in the main directory of the Linux
|
||||
* distribution for more details. */
|
||||
|
||||
#include <QProgressBar>
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QThreadPool>
|
||||
|
||||
extern QProgressBar *qprogress;
|
||||
|
||||
#include "machine_loader.h"
|
||||
|
||||
bool genpixmapinit = false;
|
||||
@ -209,7 +206,7 @@ void MachineLoader::runTasks(bool threaded)
|
||||
|
||||
m_totaltasks=m_tasklist.size();
|
||||
if (m_totaltasks == 0) return;
|
||||
qprogress->setMaximum(m_totaltasks);
|
||||
emit setProgressMax(m_totaltasks);
|
||||
m_currenttask=0;
|
||||
|
||||
threaded=AppSetting->multithreading();
|
||||
@ -221,8 +218,9 @@ void MachineLoader::runTasks(bool threaded)
|
||||
|
||||
// update progress bar
|
||||
m_currenttask++;
|
||||
qprogress->setValue(m_currenttask);
|
||||
emit setProgressValue(++m_currenttask);
|
||||
QApplication::processEvents();
|
||||
|
||||
delete task;
|
||||
}
|
||||
} else {
|
||||
@ -240,8 +238,7 @@ void MachineLoader::runTasks(bool threaded)
|
||||
task = m_tasklist[0];
|
||||
|
||||
// update progress bar
|
||||
m_currenttask++;
|
||||
qprogress->setValue(m_currenttask);
|
||||
emit setProgressValue(++m_currenttask);
|
||||
QApplication::processEvents();
|
||||
} else {
|
||||
// job list finished
|
||||
|
@ -111,6 +111,8 @@ public slots:
|
||||
|
||||
signals:
|
||||
void updateProgress(int cnt, int total);
|
||||
void setProgressMax(int max);
|
||||
void setProgressValue(int val);
|
||||
void updateMessage(QString);
|
||||
void machineUnsupported(Machine *);
|
||||
|
||||
|
@ -34,10 +34,14 @@ ProgressDialog::~ProgressDialog()
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressDialog::doUpdateProgress(int cnt, int total)
|
||||
void ProgressDialog::setProgressMax(int max)
|
||||
{
|
||||
progress->setMaximum(total);
|
||||
progress->setValue(cnt);
|
||||
progress->setMaximum(max);
|
||||
}
|
||||
|
||||
void ProgressDialog::setProgressValue(int val)
|
||||
{
|
||||
progress->setValue(val);
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,8 +28,11 @@ public:
|
||||
QProgressBar * progress;
|
||||
public slots:
|
||||
void setMessage(QString msg);
|
||||
void doUpdateProgress(int cnt, int total);
|
||||
void onAbortClicked();
|
||||
|
||||
void setProgressMax(int max);
|
||||
void setProgressValue(int val);
|
||||
|
||||
signals:
|
||||
void abortClicked();
|
||||
protected:
|
||||
|
@ -589,8 +589,6 @@ int MainWindow::importCPAP(ImportPath import, const QString &message)
|
||||
image = image.scaled(64,64);
|
||||
progdlg->setPixmap(image);
|
||||
|
||||
QProgressBar *saveQprogress = qprogress;
|
||||
qprogress = progdlg->progress;
|
||||
progdlg->addAbortButton();
|
||||
|
||||
progdlg->setWindowModality(Qt::ApplicationModal);
|
||||
@ -598,6 +596,8 @@ int MainWindow::importCPAP(ImportPath import, const QString &message)
|
||||
progdlg->setMessage(message);
|
||||
|
||||
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()));
|
||||
|
||||
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"));
|
||||
}
|
||||
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)));
|
||||
|
||||
progdlg->close();
|
||||
@ -620,7 +622,6 @@ int MainWindow::importCPAP(ImportPath import, const QString &message)
|
||||
ui->tabWidget->setCurrentIndex(AppSetting->openTabAfterImport());
|
||||
}
|
||||
|
||||
qprogress = saveQprogress;
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -844,16 +845,9 @@ void MainWindow::on_action_Import_Data_triggered()
|
||||
|
||||
QTime time;
|
||||
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;
|
||||
qprogress->setVisible(false);
|
||||
|
||||
if (datacards.size() > 0) {
|
||||
MachineInfo info = datacards[0].loader->PeekInfo(datacards[0].path);
|
||||
@ -883,22 +877,21 @@ void MainWindow::on_action_Import_Data_triggered()
|
||||
|
||||
if (res == QMessageBox::Cancel) {
|
||||
// Give the communal progress bar back
|
||||
ui->statusbar->insertWidget(1,qprogress,1);
|
||||
in_import=false;
|
||||
return;
|
||||
} else if (res == QMessageBox::No) {
|
||||
waitmsg->setText(tr("Please wait, launching file dialog..."));
|
||||
//waitmsg->setText(tr("Please wait, launching file dialog..."));
|
||||
datacards.clear();
|
||||
asknew = true;
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
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."),
|
||||
tr("Import Reminder"),8000);
|
||||
|
||||
@ -942,14 +935,11 @@ void MainWindow::on_action_Import_Data_triggered()
|
||||
//#endif
|
||||
|
||||
if (w.exec() != QDialog::Accepted) {
|
||||
popup.hide();
|
||||
ui->statusbar->insertWidget(1,qprogress,1);
|
||||
in_import=false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
popup.hide();
|
||||
|
||||
for (int i = 0; i < w.selectedFiles().size(); i++) {
|
||||
Q_FOREACH(MachineLoader * loader, loaders) {
|
||||
@ -969,17 +959,28 @@ void MainWindow::on_action_Import_Data_triggered()
|
||||
// qprogress->setVisible(true);
|
||||
|
||||
// popup.show();
|
||||
ProgressDialog * prog = new ProgressDialog(this);
|
||||
prog->setMessage(tr("Processing import list..."));
|
||||
prog->addAbortButton();
|
||||
prog->setWindowModality(Qt::ApplicationModal);
|
||||
|
||||
prog->open();
|
||||
|
||||
int c = -1;
|
||||
for (int i = 0; i < datacards.size(); i++) {
|
||||
QString dir = datacards[i].path;
|
||||
MachineLoader * loader = datacards[i].loader;
|
||||
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()) {
|
||||
// qprogress->setValue(0);
|
||||
// qprogress->show();
|
||||
// qstatus->setText(tr("Importing Data"));
|
||||
c = importCPAP(datacards[i], tr("Importing Data"));
|
||||
qDebug() << "Finished Importing data" << c;
|
||||
|
||||
@ -992,19 +993,20 @@ void MainWindow::on_action_Import_Data_triggered()
|
||||
if (c > 0) {
|
||||
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) {
|
||||
finishCPAPImport();
|
||||
PopulatePurgeMenu();
|
||||
}
|
||||
|
||||
prog->close();
|
||||
prog->deleteLater();
|
||||
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) {
|
||||
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 {
|
||||
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"+
|
||||
@ -1914,6 +1919,8 @@ void MainWindow::on_actionRebuildCPAP(QAction *action)
|
||||
daily->clearLastDay(); // otherwise Daily will crash
|
||||
daily->ReloadGraphs();
|
||||
}
|
||||
welcome->refreshPage();
|
||||
PopulatePurgeMenu();
|
||||
GenerateStatistics();
|
||||
p_profile->StoreMachines();
|
||||
}
|
||||
@ -2396,8 +2403,7 @@ void MainWindow::on_actionImport_RemStar_MSeries_Data_triggered()
|
||||
|
||||
void MainWindow::on_actionSleep_Disorder_Terms_Glossary_triggered()
|
||||
{
|
||||
ui->webView->load(
|
||||
QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=Glossary"));
|
||||
ui->webView->load(QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=Glossary"));
|
||||
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");
|
||||
QDesktopServices().openUrl(url);
|
||||
// ui->webView->load(url);
|
||||
// ui->tabWidget->setCurrentWidget(ui->helpTab);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionChange_Language_triggered()
|
||||
|
@ -57,7 +57,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="importTab">
|
||||
<attribute name="title">
|
||||
|
Loading…
Reference in New Issue
Block a user