From e8fe6c7af0906233e86b9d0d215b38e102f88294 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Fri, 25 Apr 2014 15:28:10 +1000 Subject: [PATCH] Only open active profile after selection, rather than parsing all at startup. Also cleaned up the last references to summary when statistics was meant. --- sleepyhead/Graphs/gGraphView.cpp | 14 ++- sleepyhead/SleepLib/event.cpp | 2 +- .../SleepLib/loader_plugins/prs1_loader.cpp | 2 +- sleepyhead/SleepLib/machine.cpp | 4 +- sleepyhead/SleepLib/preferences.h | 7 ++ sleepyhead/SleepLib/profiles.cpp | 55 +++++---- sleepyhead/SleepLib/profiles.h | 9 +- sleepyhead/main.cpp | 31 ++--- sleepyhead/mainwindow.cpp | 89 +++++++------- sleepyhead/mainwindow.h | 19 ++- sleepyhead/mainwindow.ui | 22 +++- sleepyhead/preferencesdialog.cpp | 4 - sleepyhead/profileselect.cpp | 3 + sleepyhead/sleepyhead.pro | 8 +- sleepyhead/{summary.cpp => statistics.cpp} | 111 +++++++++--------- sleepyhead/{summary.h => statistics.h} | 4 +- sleepyhead/translation.cpp | 25 ++-- 17 files changed, 218 insertions(+), 191 deletions(-) rename sleepyhead/{summary.cpp => statistics.cpp} (94%) rename sleepyhead/{summary.h => statistics.h} (87%) diff --git a/sleepyhead/Graphs/gGraphView.cpp b/sleepyhead/Graphs/gGraphView.cpp index f396bd6e..8dc717f5 100644 --- a/sleepyhead/Graphs/gGraphView.cpp +++ b/sleepyhead/Graphs/gGraphView.cpp @@ -453,6 +453,12 @@ gGraphView::gGraphView(QWidget *parent, gGraphView *shared) gGraphView::~gGraphView() { + timer->stop(); + redrawtimer->stop(); + + disconnect(redrawtimer, 0, 0, 0); + disconnect(timer, 0, 0, 0); + #ifdef ENABLE_THREADED_DRAWING for (int i = 0; i < m_threads.size(); i++) { @@ -465,6 +471,7 @@ gGraphView::~gGraphView() // Note: This will cause a crash if two graphs accidentally have the same name for (int i = 0; i < m_graphs.size(); i++) { delete m_graphs[i]; + m_graphs[i]=NULL; } QHash::iterator it; @@ -477,8 +484,7 @@ gGraphView::~gGraphView() delete m_tooltip; m_graphs.clear(); - //delete vlines; - //delete stippled; + delete frontlines; delete lines; delete backlines; @@ -488,10 +494,8 @@ gGraphView::~gGraphView() this->disconnect(m_scrollbar, SIGNAL(sliderMoved(int)), 0, 0); } - disconnect(redrawtimer, 0, 0, 0); - disconnect(timer, 0, 0, 0); - timer->stop(); delete timer; + delete redrawtimer; } bool gGraphView::usePixmapCache() diff --git a/sleepyhead/SleepLib/event.cpp b/sleepyhead/SleepLib/event.cpp index 6b97dbca..5bf0b0f2 100644 --- a/sleepyhead/SleepLib/event.cpp +++ b/sleepyhead/SleepLib/event.cpp @@ -170,7 +170,7 @@ void EventList::AddWaveform(qint64 start, qint16 *data, int recs, qint64 duratio EventStoreType *dp = &edata[r]; if (m_update_minmax) { - register EventDataType min = m_min, max = m_max, val, gain = m_gain; + EventDataType min = m_min, max = m_max, val, gain = m_gain; //if (m_offset; for (sp = data; sp < ep; sp++) { diff --git a/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp b/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp index e8302dee..b37edfd7 100644 --- a/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/prs1_loader.cpp @@ -1651,7 +1651,7 @@ bool PRS1Loader::OpenWaveforms(SessionID sid, QString filename) do { timestamp = m_buffer[pos + 0xb] | m_buffer[pos + 0xc] << 8 | m_buffer[pos + 0xd] << 16 | m_buffer[pos + 0x0e] << 24; - register unsigned char sum8 = 0; + unsigned char sum8 = 0; for (int i = 0; i < hl; i++) { sum8 += m_buffer[pos + i]; } diff --git a/sleepyhead/SleepLib/machine.cpp b/sleepyhead/SleepLib/machine.cpp index bcdccd50..601608ab 100644 --- a/sleepyhead/SleepLib/machine.cpp +++ b/sleepyhead/SleepLib/machine.cpp @@ -45,13 +45,13 @@ Machine::Machine(Profile *p, MachineID id) } else { m_id = id; } - //qDebug() << "Create Machine: " << hex << m_id; //%lx",m_id); + qDebug() << "Create Machine: " << hex << m_id; //%lx",m_id); m_type = MT_UNKNOWN; firstsession = true; } Machine::~Machine() { - qDebug() << "Destroy Machine" << m_class; + qDebug() << "Destroy Machine" << m_class << hex << m_id; for (QMap::iterator d = day.begin(); d != day.end(); d++) { delete d.value(); diff --git a/sleepyhead/SleepLib/preferences.h b/sleepyhead/SleepLib/preferences.h index b47b9c11..26a06229 100644 --- a/sleepyhead/SleepLib/preferences.h +++ b/sleepyhead/SleepLib/preferences.h @@ -62,6 +62,13 @@ class Preferences return (p_preferences.contains(name)); } + //! \brief Create a preference and set the default if it doesn't exists + void init(QString name, QVariant value) { + if (!contains(name)) { + p_preferences[name] = value; + } + } + //! \brief Returns true if preference 'name' exists, and contains a boolean true value bool ExistsAndTrue(QString name) { QHash::iterator i = p_preferences.find(name); diff --git a/sleepyhead/SleepLib/profiles.cpp b/sleepyhead/SleepLib/profiles.cpp index 4fd40a3b..786052da 100644 --- a/sleepyhead/SleepLib/profiles.cpp +++ b/sleepyhead/SleepLib/profiles.cpp @@ -31,7 +31,8 @@ Preferences *p_layout; Profile *p_profile; Profile::Profile(QString path) - : is_first_day(true) + : is_first_day(true), + m_opened(false) { p_name = STR_GEN_Profile; @@ -62,27 +63,41 @@ Profile::Profile(QString path) Profile::~Profile() { - delete user; - delete doctor; - delete cpap; - delete oxi; - delete appearance; - delete session; - delete general; + if (m_opened) { + delete user; + delete doctor; + delete cpap; + delete oxi; + delete appearance; + delete session; + delete general; - for (QHash::iterator i = machlist.begin(); i != machlist.end(); i++) { - delete i.value(); + for (auto it = machlist.begin(); it != machlist.end(); it++) { + delete it.value(); + } + m_opened=false; } } bool Profile::Save(QString filename) { - return Preferences::Save(filename); + if (m_opened) { + return Preferences::Save(filename); + } else return false; } bool Profile::Open(QString filename) { + if (filename.isEmpty()) { + filename=p_filename; + } + if (m_opened) { + qDebug() << "Profile" << filename << "all ready open"; + return true; + } bool b = Preferences::Open(filename); + + m_opened=true; doctor = new DoctorInfo(this); user = new UserInfo(this); cpap = new CPAPSettings(this); @@ -549,20 +564,10 @@ Profile *Get() */ void Scan() { - //InitMapsWithoutAwesomeInitializerLists(); - p_pref = new Preferences("Preferences"); - p_layout = new Preferences("Layout"); - - PREF.Open(); - LAYOUT.Open(); - QString path = PREF.Get("{home}/Profiles"); QDir dir(path); if (!dir.exists(path)) { - //dir.mkpath(path); - // Just silently create a new user record and get on with it. - //Create(getUserName(),getUserName(),""); return; } @@ -576,18 +581,12 @@ void Scan() QFileInfoList list = dir.entryInfoList(); - //QString username=getUserName(); - //if (list.size()==0) { // No profiles.. Create one. - //Create(username,username,""); - //return; - //} - // Iterate through subdirectories and load profiles.. for (int i = 0; i < list.size(); i++) { QFileInfo fi = list.at(i); QString npath = fi.canonicalFilePath(); Profile *prof = new Profile(npath); - prof->Open(); // Read it's XML file.. +// prof->Open(); // Read it's XML file.. profiles[fi.fileName()] = prof; } diff --git a/sleepyhead/SleepLib/profiles.h b/sleepyhead/SleepLib/profiles.h index 4e4e7bb8..973407f5 100644 --- a/sleepyhead/SleepLib/profiles.h +++ b/sleepyhead/SleepLib/profiles.h @@ -132,7 +132,8 @@ class Profile : public Preferences QString dataFolder() { return (*this).Get("{DataFolder}"); } - public: + bool isOpen() { return m_opened; } + QMap > daylist; // Red-Black tree of Days (iterates in order). QHash machlist; // List of machines, indexed by MachineID. @@ -149,6 +150,8 @@ class Profile : public Preferences protected: QDate m_first; QDate m_last; + + bool m_opened; }; class MachineLoader; @@ -267,9 +270,7 @@ class ProfileSettings } void initPref(QString name, QVariant value) { - if (!m_profile->contains(name)) { - setPref(name, value); - } + m_profile->init(name, value); } QVariant getPref(QString name) const { diff --git a/sleepyhead/main.cpp b/sleepyhead/main.cpp index 627799c8..09ecfc96 100644 --- a/sleepyhead/main.cpp +++ b/sleepyhead/main.cpp @@ -269,8 +269,16 @@ retry_directory: IntellipapLoader::Register(); FPIconLoader::Register(); + p_pref = new Preferences("Preferences"); + p_layout = new Preferences("Layout"); + + PREF.Open(); + LAYOUT.Open(); + // Scan for user profiles Profiles::Scan(); + + //qRegisterMetaType("Preference"); PREF["AppName"] = STR_TR_SleepyHead; @@ -282,16 +290,9 @@ retry_directory: // Todo: Make a wrapper for Preference settings, like Profile settings have.. QDateTime lastchecked, today = QDateTime::currentDateTime(); - if (!PREF.contains(STR_GEN_UpdatesAutoCheck)) { - PREF[STR_GEN_UpdatesAutoCheck] = true; - PREF[STR_GEN_UpdateCheckFrequency] = 7; - } - - if (!PREF.contains(STR_PREF_AllowEarlyUpdates)) { - PREF[STR_PREF_AllowEarlyUpdates] = false; - } - - + PREF.init(STR_GEN_UpdatesAutoCheck, true); + PREF.init(STR_GEN_UpdateCheckFrequency, 7); // days + PREF.init(STR_PREF_AllowEarlyUpdates, false); //////////////////////////////////////////////////////////////////////////////////////////// // Check when last checked for updates.. @@ -314,6 +315,7 @@ retry_directory: } if (!Profiles::profiles.size()) { + // Show New User wizard.. NewProfile newprof(0); if (newprof.exec() == NewProfile::Rejected) { @@ -321,8 +323,6 @@ retry_directory: } release_notes(); - - // Show New User wizard.. } else { if (PREF.contains(STR_PREF_VersionString)) { QString V = PREF[STR_PREF_VersionString].toString(); @@ -364,7 +364,7 @@ retry_directory: p_profile = Profiles::Get(PREF[STR_GEN_Profile].toString()); - qDebug() << "Selected Profile" << p_profile->user->userName(); + qDebug() << "Opened Profile" << p_profile->user->userName(); // int id=QFontDatabase::addApplicationFont(":/fonts/FreeSans.ttf"); // QFontDatabase fdb; @@ -386,14 +386,15 @@ retry_directory: PREF["Fonts_Application_Bold"].toBool() ? QFont::Bold : QFont::Normal, PREF["Fonts_Application_Italic"].toBool())); - qDebug() << "Selected" << QApplication::font().family(); + qDebug() << "Selected Font" << QApplication::font().family(); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) qInstallMessageHandler(MyOutputHandler); #else qInstallMsgHandler(MyOutputHandler); #endif - //#endif + + // Must be initialized AFTER profile creation MainWindow w; mainwin = &w; diff --git a/sleepyhead/mainwindow.cpp b/sleepyhead/mainwindow.cpp index 6c41ed11..298a9fa0 100644 --- a/sleepyhead/mainwindow.cpp +++ b/sleepyhead/mainwindow.cpp @@ -52,7 +52,7 @@ #include "version.h" #include "reports.h" -#include "summary.h" +#include "statistics.h" QProgressBar *qprogress; QLabel *qstatus; @@ -161,8 +161,7 @@ MainWindow::MainWindow(QWidget *parent) : // Start with the Summary Tab - ui->tabWidget->setCurrentWidget( - ui->summaryTab); // setting this to daily shows the cube during loading.. + ui->tabWidget->setCurrentWidget(ui->statisticsTab); // setting this to daily shows the cube during loading.. // Nifty Notification popups in System Tray (uses Growl on Mac) if (QSystemTrayIcon::isSystemTrayAvailable() && QSystemTrayIcon::supportsMessages()) { @@ -191,14 +190,14 @@ MainWindow::MainWindow(QWidget *parent) : } ui->recordsBox->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); - ui->summaryView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); + ui->statisticsView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); ui->bookmarkView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); QString loadingtxt = "

" + tr("Loading...") + "

"; - ui->summaryView->setHtml(loadingtxt); + ui->statisticsView->setHtml(loadingtxt); on_tabWidget_currentChanged(0); #ifndef REMSTAR_M_SUPPORT @@ -298,8 +297,8 @@ void MainWindow::Startup() ui->tabWidget->insertTab(3, oximetry, STR_TR_Oximetry); } - - ui->tabWidget->setCurrentWidget(ui->summaryTab); + GenerateStatistics(); + ui->tabWidget->setCurrentWidget(ui->statisticsTab); if (daily) { daily->ReloadGraphs(); } @@ -307,7 +306,6 @@ void MainWindow::Startup() qprogress->hide(); qstatus->setText(""); - on_summaryButton_clicked(); } @@ -437,7 +435,7 @@ void MainWindow::on_action_Import_Data_triggered() if (overview) { overview->ReloadGraphs(); } - on_summaryButton_clicked(); + GenerateStatistics(); if (daily) { daily->ReloadGraphs(); } @@ -613,26 +611,6 @@ void MainWindow::on_homeButton_clicked() //ui->webView->setUrl(QUrl(infourl)); } - -void MainWindow::on_summaryButton_clicked() -{ - QString html = Summary::GenerateHTML(); - - updateFavourites(); - - //QWebFrame *frame=ui->summaryView->page()->currentFrame(); - //frame->addToJavaScriptWindowObject("mainwin",this); - //ui->summaryView->setHtml(html); - MyStatsPage *page = new MyStatsPage(this); - page->currentFrame()->setHtml(html); - ui->summaryView->setPage(page); - // connect(ui->summaryView->page()->currentFrame(),SIGNAL(javaScriptWindowObjectCleared()) - // QString file="qrc:/docs/index.html"; - // QUrl url(file); - // ui->webView->setUrl(url); -} - - void MainWindow::updateFavourites() { QDate date = PROFILE.LastDay(MT_JOURNAL); @@ -1058,8 +1036,8 @@ void MainWindow::on_actionPrint_Report_triggered() QString name; QString datestr; - if (ui->tabWidget->currentWidget() == ui->summaryTab) { - name = "Summary"; + if (ui->tabWidget->currentWidget() == ui->statisticsTab) { + name = "Statistics"; datestr = QDate::currentDate().toString(Qt::ISODate); } else if (ui->tabWidget->currentWidget() == ui->helpTab) { name = "Help"; @@ -1081,8 +1059,8 @@ void MainWindow::on_actionPrint_Report_triggered() if (pdlg.exec() == QPrintDialog::Accepted) { - if (ui->tabWidget->currentWidget() == ui->summaryTab) { - ui->summaryView->print(&printer); + if (ui->tabWidget->currentWidget() == ui->statisticsTab) { + ui->statisticsView->print(&printer); } else if (ui->tabWidget->currentWidget() == ui->helpTab) { ui->webView->print(&printer); } @@ -1500,12 +1478,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event) //qDebug() << "Keypress:" << event->key(); } -void MainWindow::on_summaryButton_2_clicked() -{ - ui->tabWidget->setCurrentWidget(ui->summaryTab); - on_summaryButton_clicked(); -} - void MainWindow::on_action_Sidebar_Toggle_toggled(bool visible) { ui->toolBox->setVisible(visible); @@ -1540,7 +1512,7 @@ void MainWindow::on_helpButton_clicked() void MainWindow::on_actionView_Statistics_triggered() { - ui->tabWidget->setCurrentWidget(ui->summaryTab); + ui->tabWidget->setCurrentWidget(ui->statisticsTab); } void MainWindow::on_webView_linkClicked(const QUrl &url) @@ -1572,7 +1544,7 @@ void MainWindow::on_tabWidget_currentChanged(int index) Q_UNUSED(index); QWidget *widget = ui->tabWidget->currentWidget(); - if ((widget == ui->summaryTab) || (widget == ui->helpTab)) { + if ((widget == ui->statisticsTab) || (widget == ui->helpTab)) { qstatus2->setVisible(false); } else if (widget == daily) { qstatus2->setVisible(true); @@ -1586,11 +1558,6 @@ void MainWindow::on_tabWidget_currentChanged(int index) } } -void MainWindow::on_summaryView_linkClicked(const QUrl &arg1) -{ - //qDebug() << arg1; - on_recordsBox_linkClicked(arg1); -} void MainWindow::on_bookmarkView_linkClicked(const QUrl &arg1) { @@ -1859,3 +1826,33 @@ void MainWindow::on_actionImport_Somnopose_Data_triggered() } } + +void MainWindow::GenerateStatistics() +{ + QString html = Statistics::GenerateHTML(); + + updateFavourites(); + + //QWebFrame *frame=ui->statisticsView->page()->currentFrame(); + //frame->addToJavaScriptWindowObject("mainwin",this); + //ui->statisticsView->setHtml(html); + MyStatsPage *page = new MyStatsPage(this); + page->currentFrame()->setHtml(html); + ui->statisticsView->setPage(page); + // connect(ui->statisticsView->page()->currentFrame(),SIGNAL(javaScriptWindowObjectCleared()) + // QString file="qrc:/docs/index.html"; + // QUrl url(file); + // ui->webView->setUrl(url); +} + + +void MainWindow::on_statisticsButton_clicked() +{ + ui->tabWidget->setCurrentWidget(ui->statisticsTab); +} + +void MainWindow::on_statisticsView_linkClicked(const QUrl &arg1) +{ + //qDebug() << arg1; + on_recordsBox_linkClicked(arg1); +} diff --git a/sleepyhead/mainwindow.h b/sleepyhead/mainwindow.h index 9e6a46de..192780f8 100644 --- a/sleepyhead/mainwindow.h +++ b/sleepyhead/mainwindow.h @@ -91,7 +91,7 @@ class MainWindow : public QMainWindow void CheckForUpdates(); //! \brief Refresh the statistics page - void refreshStatistics() { on_summaryButton_clicked(); } + void refreshStatistics() { on_statisticsButton_clicked(); } /*! \fn Notify(QString s,int ms=5000, QString title="SleepyHead v"+VersionString()); \brief Pops up a message box near the system tray @@ -139,7 +139,7 @@ class MainWindow : public QMainWindow void reprocessEvents(bool restart = false); - //! \brief Internal function to set Records Box html from summary module + //! \brief Internal function to set Records Box html from statistics module void setRecBoxHTML(QString html); public slots: @@ -258,11 +258,6 @@ class MainWindow : public QMainWindow //! \brief Destroy ALL the CPAP data for the currently selected machine, so it can be freshly imported again void on_actionAll_Data_for_current_CPAP_machine_triggered(); - //! \brief Populates the statistics with information. - void on_summaryButton_clicked(); - - void on_summaryButton_2_clicked(); - void on_action_Sidebar_Toggle_toggled(bool arg1); void on_recordsBox_linkClicked(const QUrl &arg1); @@ -283,8 +278,6 @@ class MainWindow : public QMainWindow void LinkHovered(const QString &link, const QString &title, const QString &textContent); void on_tabWidget_currentChanged(int index); - void on_summaryView_linkClicked(const QUrl &arg1); - void on_bookmarkView_linkClicked(const QUrl &arg1); void on_filterBookmarks_editingFinished(); @@ -307,9 +300,15 @@ class MainWindow : public QMainWindow void on_actionImport_Somnopose_Data_triggered(); - private: + //! \brief Populates the statistics with information. + void on_statisticsButton_clicked(); + + void on_statisticsView_linkClicked(const QUrl &arg1); + +private: QString getWelcomeHTML(); void FreeSessions(); + void GenerateStatistics(); Ui::MainWindow *ui; Daily *daily; diff --git a/sleepyhead/mainwindow.ui b/sleepyhead/mainwindow.ui index 98388676..e1cdd71f 100644 --- a/sleepyhead/mainwindow.ui +++ b/sleepyhead/mainwindow.ui @@ -98,7 +98,7 @@ false - + &Statistics @@ -141,7 +141,7 @@ color: yellow; - + 0 @@ -614,7 +614,7 @@ QToolBox::tab:selected { - + 0 @@ -2525,5 +2525,21 @@ border-radius: 10px; + + actionView_Statistics + triggered() + statisticsButton + click() + + + -1 + -1 + + + 772 + 101 + + + diff --git a/sleepyhead/preferencesdialog.cpp b/sleepyhead/preferencesdialog.cpp index 987ddcb3..fe444b99 100644 --- a/sleepyhead/preferencesdialog.cpp +++ b/sleepyhead/preferencesdialog.cpp @@ -219,12 +219,8 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Profile *_profile) : ui->graphHeight->setValue(profile->appearance->graphHeight()); - if (!PREF.contains(STR_GEN_UpdatesAutoCheck)) { PREF[STR_GEN_UpdatesAutoCheck] = true; } - ui->automaticallyCheckUpdates->setChecked(PREF[STR_GEN_UpdatesAutoCheck].toBool()); - if (!PREF.contains(STR_GEN_UpdateCheckFrequency)) { PREF[STR_GEN_UpdateCheckFrequency] = 3; } - ui->updateCheckEvery->setValue(PREF[STR_GEN_UpdateCheckFrequency].toInt()); if (PREF.contains(STR_GEN_UpdatesLastChecked)) { diff --git a/sleepyhead/profileselect.cpp b/sleepyhead/profileselect.cpp index 5960e64c..db82ded8 100644 --- a/sleepyhead/profileselect.cpp +++ b/sleepyhead/profileselect.cpp @@ -261,6 +261,9 @@ void ProfileSelect::on_listView_activated(const QModelIndex &index) Profile *profile = Profiles::profiles[name]; if (!profile) { return; } + if (!profile->isOpen()) { + profile->Open(); + } if (!profile->user->hasPassword()) { m_selectedProfile = name; diff --git a/sleepyhead/sleepyhead.pro b/sleepyhead/sleepyhead.pro index 91f68a4f..f010d064 100644 --- a/sleepyhead/sleepyhead.pro +++ b/sleepyhead/sleepyhead.pro @@ -87,7 +87,6 @@ SOURCES += \ profileselect.cpp \ reports.cpp \ sessionbar.cpp \ - summary.cpp \ updateparser.cpp \ UpdaterWindow.cpp \ Graphs/gFlagsLine.cpp \ @@ -124,7 +123,8 @@ SOURCES += \ SleepLib/loader_plugins/resmed_loader.cpp \ SleepLib/loader_plugins/somnopose_loader.cpp \ SleepLib/loader_plugins/zeo_loader.cpp \ - translation.cpp + translation.cpp \ + statistics.cpp HEADERS += \ common_gui.h \ @@ -138,7 +138,6 @@ HEADERS += \ profileselect.h \ reports.h \ sessionbar.h \ - summary.h \ updateparser.h \ UpdaterWindow.h \ version.h \ @@ -177,7 +176,8 @@ HEADERS += \ SleepLib/loader_plugins/resmed_loader.h \ SleepLib/loader_plugins/somnopose_loader.h \ SleepLib/loader_plugins/zeo_loader.h \ - translation.h + translation.h \ + statistics.h FORMS += \ daily.ui \ diff --git a/sleepyhead/summary.cpp b/sleepyhead/statistics.cpp similarity index 94% rename from sleepyhead/summary.cpp rename to sleepyhead/statistics.cpp index 06af7f3e..ec6b93d1 100644 --- a/sleepyhead/summary.cpp +++ b/sleepyhead/statistics.cpp @@ -1,7 +1,7 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * vim: set ts=8 sts=4 et sw=4 tw=99: * - * Summary Module + * Statistics Report Generator * * Copyright (c) 2011 Mark Watkins * @@ -13,14 +13,14 @@ #include #include "mainwindow.h" -#include "summary.h" +#include "statistics.h" #include "SleepLib/schema.h" extern MainWindow *mainwin; -Summary::Summary(QObject *parent) : +Statistics::Statistics(QObject *parent) : QObject(parent) { } @@ -382,7 +382,7 @@ bool operator <(const UsageData &c1, const UsageData &c2) //return c1.value < c2.value; } -QString Summary::GenerateHTML() +QString Statistics::GenerateHTML() { QString html = htmlHeader(); @@ -411,7 +411,6 @@ QString Summary::GenerateHTML() if (mach.size() == 0) { html += ""; - QString datacard; html += "").arg(lastcpap.toString(Qt::SystemLocaleLongDate)); if (cpap_machines.size() > 0) { - // html+=QString("").arg(tr("CPAP Summary")); + // html+=QString("").arg(tr("CPAP Statistics")); if (!cpapdays) { html += QString("").arg( @@ -485,31 +484,31 @@ QString Summary::GenerateHTML() if (PROFILE.calcCount(CPAP_RERA, MT_CPAP, cpapyear, lastcpap)) { html += QString("") .arg(tr("RERA Index")) - .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, lastcpap, lastcpap) / PROFILE.calcHours(MT_CPAP, - lastcpap, lastcpap), 0, 'f', decimals) - .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, cpapweek, lastcpap) / PROFILE.calcHours(MT_CPAP, - cpapweek, lastcpap), 0, 'f', decimals) - .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, cpapmonth, lastcpap) / PROFILE.calcHours(MT_CPAP, - cpapmonth, lastcpap), 0, 'f', decimals) - .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, cpap6month, lastcpap) / PROFILE.calcHours(MT_CPAP, - cpap6month, lastcpap), 0, 'f', decimals) - .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, cpapyear, lastcpap) / PROFILE.calcHours(MT_CPAP, - cpapyear, lastcpap), 0, 'f', decimals); + .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, lastcpap, lastcpap) + / PROFILE.calcHours(MT_CPAP, lastcpap, lastcpap), 0, 'f', decimals) + .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, cpapweek, lastcpap) + / PROFILE.calcHours(MT_CPAP, cpapweek, lastcpap), 0, 'f', decimals) + .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, cpapmonth, lastcpap) + / PROFILE.calcHours(MT_CPAP, cpapmonth, lastcpap), 0, 'f', decimals) + .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, cpap6month, lastcpap) + / PROFILE.calcHours(MT_CPAP, cpap6month, lastcpap), 0, 'f', decimals) + .arg(PROFILE.calcCount(CPAP_RERA, MT_CPAP, cpapyear, lastcpap) + / PROFILE.calcHours(MT_CPAP, cpapyear, lastcpap), 0, 'f', decimals); } if (PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, cpapyear, lastcpap)) { html += QString("") .arg(tr("Flow Limit Index")) - .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, lastcpap, lastcpap) / PROFILE.calcHours(MT_CPAP, - lastcpap, lastcpap), 0, 'f', decimals) - .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, cpapweek, lastcpap) / PROFILE.calcHours(MT_CPAP, - cpapweek, lastcpap), 0, 'f', decimals) - .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, cpapmonth, lastcpap) / PROFILE.calcHours(MT_CPAP, - cpapmonth, lastcpap), 0, 'f', decimals) - .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, cpap6month, lastcpap) / PROFILE.calcHours(MT_CPAP, - cpap6month, lastcpap), 0, 'f', decimals) - .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, cpapyear, lastcpap) / PROFILE.calcHours(MT_CPAP, - cpapyear, lastcpap), 0, 'f', decimals); + .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, lastcpap, lastcpap) + / PROFILE.calcHours(MT_CPAP, lastcpap, lastcpap), 0, 'f', decimals) + .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, cpapweek, lastcpap) + / PROFILE.calcHours(MT_CPAP, cpapweek, lastcpap), 0, 'f', decimals) + .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, cpapmonth, lastcpap) + / PROFILE.calcHours(MT_CPAP, cpapmonth, lastcpap), 0, 'f', decimals) + .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, cpap6month, lastcpap) + / PROFILE.calcHours(MT_CPAP, cpap6month, lastcpap), 0, 'f', decimals) + .arg(PROFILE.calcCount(CPAP_FlowLimit, MT_CPAP, cpapyear, lastcpap) + / PROFILE.calcHours(MT_CPAP, cpapyear, lastcpap), 0, 'f', decimals); } @@ -622,7 +621,7 @@ QString Summary::GenerateHTML() int days = PROFILE.countDays(MT_OXIMETER, firstoxi, lastoxi); if (days > 0) { - html += QString("").arg(tr("Oximetry Summary")); + html += QString("").arg(tr("Oximetry Statistics")); if (days == 1) { html += QString("").arg(QString( @@ -666,30 +665,32 @@ QString Summary::GenerateHTML() .arg(p_profile->calcMin(OXI_SPO2, MT_OXIMETER, oxiyear, lastoxi), 0, 'f', decimals); html += QString("") .arg(tr("SpO2 Events / Hour")) - .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER) / p_profile->calcHours(MT_OXIMETER), 0, 'f', - decimals) - .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER, oxiweek, - lastoxi) / p_profile->calcHours(MT_OXIMETER, oxiweek, lastoxi), 0, 'f', decimals) - .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER, oximonth, - lastoxi) / p_profile->calcHours(MT_OXIMETER, oximonth, lastoxi), 0, 'f', decimals) - .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER, oxi6month, - lastoxi) / p_profile->calcHours(MT_OXIMETER, oxi6month, lastoxi), 0, 'f', decimals) - .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER, oxiyear, - lastoxi) / p_profile->calcHours(MT_OXIMETER, oxiyear, lastoxi), 0, 'f', decimals); + .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER) + / p_profile->calcHours(MT_OXIMETER), 0, 'f', decimals) + .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER, oxiweek, lastoxi) + / p_profile->calcHours(MT_OXIMETER, oxiweek, lastoxi), 0, 'f', decimals) + .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER, oximonth, lastoxi) + / p_profile->calcHours(MT_OXIMETER, oximonth, lastoxi), 0, 'f', decimals) + .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER, oxi6month, lastoxi) + / p_profile->calcHours(MT_OXIMETER, oxi6month, lastoxi), 0, 'f', decimals) + .arg(p_profile->calcCount(OXI_SPO2Drop, MT_OXIMETER, oxiyear, lastoxi) + / p_profile->calcHours(MT_OXIMETER, oxiyear, lastoxi), 0, 'f', decimals); html += QString("") .arg(tr("% of time in SpO2 Events")) .arg(100.0 / p_profile->calcHours(MT_OXIMETER) * p_profile->calcSum(OXI_SPO2Drop, MT_OXIMETER) / 3600.0, 0, 'f', decimals) - .arg(100.0 / p_profile->calcHours(MT_OXIMETER, oxiweek, lastoxi) * p_profile->calcSum(OXI_SPO2Drop, - MT_OXIMETER, oxiweek, lastoxi) / 3600.0, 0, 'f', decimals) - .arg(100.0 / p_profile->calcHours(MT_OXIMETER, oximonth, - lastoxi) * p_profile->calcSum(OXI_SPO2Drop, MT_OXIMETER, oximonth, lastoxi) / 3600.0, 0, 'f', - decimals) - .arg(100.0 / p_profile->calcHours(MT_OXIMETER, oxi6month, - lastoxi) * p_profile->calcSum(OXI_SPO2Drop, MT_OXIMETER, oxi6month, lastoxi) / 3600.0, 0, 'f', - decimals) - .arg(100.0 / p_profile->calcHours(MT_OXIMETER, oxiyear, lastoxi) * p_profile->calcSum(OXI_SPO2Drop, - MT_OXIMETER, oxiyear, lastoxi) / 3600.0, 0, 'f', decimals); + .arg(100.0 / p_profile->calcHours(MT_OXIMETER, oxiweek, lastoxi) + * p_profile->calcSum(OXI_SPO2Drop, MT_OXIMETER, oxiweek, lastoxi) + / 3600.0, 0, 'f', decimals) + .arg(100.0 / p_profile->calcHours(MT_OXIMETER, oximonth, lastoxi) + * p_profile->calcSum(OXI_SPO2Drop, MT_OXIMETER, oximonth, lastoxi) + / 3600.0, 0, 'f', decimals) + .arg(100.0 / p_profile->calcHours(MT_OXIMETER, oxi6month, lastoxi) + * p_profile->calcSum(OXI_SPO2Drop, MT_OXIMETER, oxi6month, lastoxi) + / 3600.0, 0, 'f',decimals) + .arg(100.0 / p_profile->calcHours(MT_OXIMETER, oxiyear, lastoxi) + * p_profile->calcSum(OXI_SPO2Drop, MT_OXIMETER, oxiyear, lastoxi) + / 3600.0, 0, 'f', decimals); html += QString("") .arg(tr("Average Pulse Rate")) .arg(p_profile->calcWavg(OXI_Pulse, MT_OXIMETER), 0, 'f', decimals) @@ -1101,7 +1102,7 @@ QString Summary::GenerateHTML() .arg(STR_TR_Machine) .arg(tr("Pr. Rel.")) .arg(STR_TR_Mode) - .arg("Pressure Settings"); + .arg(tr("Pressure Settings")); for (int i = 0; i < rxchange.size(); i++) { RXChange rx = rxchange.at(i); @@ -1139,7 +1140,7 @@ QString Summary::GenerateHTML() // STR_TR_IPAP+QString("=%1").arg(rx.per2,0,'f',decimals); if (mode >= MODE_BIPAP) { if (rx.min > 0) { - extratxt += QString(""; if (rx.maxipap > 0) { - extratxt += QString("") + extratxt += "") .arg(rx.maxipap, 4, 'f', 1); } @@ -1173,7 +1172,7 @@ QString Summary::GenerateHTML() .arg(percentile * 100.0) + STR_TR_IPAP + QString("=%1").arg(rx.per2, 0, 'f', decimals); } else if (mode > MODE_CPAP) { - extratxt += QString("") + extratxt += "") .arg(rx.min, 4, 'f', 1) .arg(rx.max, 4, 'f', 1); tooltip = QString("%1 %2% ").arg(machstr).arg(percentile * 100.0) + STR_TR_Pressure + @@ -1181,7 +1180,7 @@ QString Summary::GenerateHTML() } else { if (cpapmode > MODE_CPAP) { - extratxt += QString("").arg(rx.min, 4, 'f', 1); + extratxt += "").arg(rx.min, 4, 'f', 1); tooltip = QString("%1").arg(machstr); } else { extratxt += ""; diff --git a/sleepyhead/summary.h b/sleepyhead/statistics.h similarity index 87% rename from sleepyhead/summary.h rename to sleepyhead/statistics.h index 7305c0e7..40802112 100644 --- a/sleepyhead/summary.h +++ b/sleepyhead/statistics.h @@ -14,11 +14,11 @@ #include -class Summary : public QObject +class Statistics : public QObject { Q_OBJECT public: - explicit Summary(QObject *parent = 0); + explicit Statistics(QObject *parent = 0); static QString GenerateHTML(); diff --git a/sleepyhead/translation.cpp b/sleepyhead/translation.cpp index 03075146..3d5112a6 100644 --- a/sleepyhead/translation.cpp +++ b/sleepyhead/translation.cpp @@ -26,16 +26,21 @@ void initTranslations(QSettings & settings) { + QStringList welcome={"Welcome", "Welkom", "Willkommen", "Bienvenue", u8"歡迎", u8"ようこそ!"}; - // Add any special language names here - // Ordinary character sets will just use the name before the first '.' in the filename. + // (Ordinary character sets will just use the name before the first '.' in the filename.) + // (This u8 stuff deliberately kills Qt4.x build support - if you know another way feel free to + // change it, but Qt4 support is still going to die sooner or later) + // Add any languages with special character set needs to this list QHash langNames={ { "cn", u8"漢語繁體字" }, { "es", u8"Español" }, { "bg", u8"български" }, { "fr", u8"Français" }, }; + // CHECK: Will the above break with MS VisualC++ compiler? + QHash langFiles; #ifdef Q_OS_MAC @@ -51,7 +56,6 @@ void initTranslations(QSettings & settings) { dir.setFilter(QDir::Files); dir.setNameFilters(QStringList("*.qm")); - qDebug() << "Available Translations"; QFileInfoList list = dir.entryInfoList(); QString language = settings.value("Settings/Language").toString(); @@ -62,12 +66,15 @@ void initTranslations(QSettings & settings) { langFiles[en]=""; langNames[en]="English"; - // Scan translation directory + + // Scan through available translations, and add them to the list for (int i = 0; i < list.size(); ++i) { QFileInfo fi = list.at(i); QString name = fi.fileName().section('.', 0, 0); QString code = fi.fileName().section('.', 1, 1); + qDebug() << "Detected" << name << "Translation"; + if (langNames.contains(code)) { name = langNames[code]; } else { @@ -76,7 +83,6 @@ void initTranslations(QSettings & settings) { langFiles[code]=fi.fileName(); - qDebug() << "Detected" << name << "Translation"; } if (language.isEmpty() || !langNames.contains(language)) { @@ -95,8 +101,8 @@ void initTranslations(QSettings & settings) { QComboBox lang_combo(&langsel); QPushButton lang_okbtn("->", &langsel); - QVBoxLayout layout1; - QVBoxLayout layout2; + QVBoxLayout layout1(&langsel); + QVBoxLayout layout2(&langsel); lang_layout.addLayout(&layout1); lang_layout.addLayout(&layout2); @@ -135,9 +141,8 @@ void initTranslations(QSettings & settings) { qDebug() << "Loading " << langname << " Translation" << langfile << "from" << transdir; QTranslator * translator = new QTranslator(); - if (!translator->load(langfile, transdir)) { - qDebug() << "Could not load translation" << langfile << "reverting to english :("; - + if (!langfile.isEmpty() && !translator->load(langfile, transdir)) { + qWarning() << "Could not load translation" << langfile << "reverting to english :("; } qApp->installTranslator(translator);

" + tr("Please Import Some Data") + "

" + tr("SleepyHead is pretty much useless without it.") + "

" + tr("It might be a good idea to check preferences first,
as there are some options that affect import.") @@ -456,7 +455,7 @@ QString Summary::GenerateHTML() QString(" %1

%1
%1
%1
%1%2%3%4%5%6
%1%2%3%4%5%6
%1
%1
%1
%1%2%3%4%5%6
%1%2\%%3\%%4\%%5\%%6\%
%1%2%3%4%5%6
EPAP %1") + extratxt += ""+QString(tr("EPAP %1")) .arg(rx.min, 4, 'f', 1); } @@ -1151,19 +1152,17 @@ QString Summary::GenerateHTML() extratxt += ""; if (rx.ps > 0) { - extratxt += QString("PS %1") - .arg(rx.ps, 4, 'f', 1); + extratxt += ""+QString(tr("PS %1")).arg(rx.ps, 4, 'f', 1); } if ((rx.pshi > 0) && (rx.ps != rx.pshi)) { - extratxt += QString(" - %2") - .arg(rx.pshi, 4, 'f', 1); + extratxt += QString(" - %2").arg(rx.pshi, 4, 'f', 1); } extratxt += "IPAP %1"+QString(tr("IPAP %1")+"APAP %1 - %2"+QString(tr("APAP %1 - %2")+"CPAP %1"+QString(tr("CPAP %1")+"