From 0f331ad50a1d5ab0103cbe7e5f144624bcdd0d65 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Fri, 5 Aug 2011 17:52:32 +1000 Subject: [PATCH] Activated Session Preferences --- Graphs/gXAxis.cpp | 2 +- SleepLib/loader_plugins/prs1_loader.cpp | 7 +- SleepLib/machine.cpp | 124 ++++++++++++------------ SleepLib/preferences.cpp | 23 ++++- mainwindow.cpp | 8 -- mainwindow.h | 2 - mainwindow.ui | 1 - preferencesdialog.cpp | 66 ++++++++++--- preferencesdialog.h | 13 ++- preferencesdialog.ui | 4 +- 10 files changed, 150 insertions(+), 100 deletions(-) diff --git a/Graphs/gXAxis.cpp b/Graphs/gXAxis.cpp index 52c3c7f4..22cd4739 100644 --- a/Graphs/gXAxis.cpp +++ b/Graphs/gXAxis.cpp @@ -157,7 +157,7 @@ void gXAxis::Plot(gGraphWindow & w,float scrx,float scry) millisecond=d.time().msec(); if (show_milliseconds) { - fd.sprintf("%02i:%02i:%02i:%04i",hour,minute,second,millisecond); + fd.sprintf("%02i:%02i:%02i:%03i",hour,minute,second,millisecond); } else if (show_seconds) { fd.sprintf("%02i:%02i:%02i",hour,minute,second); } else { diff --git a/SleepLib/loader_plugins/prs1_loader.cpp b/SleepLib/loader_plugins/prs1_loader.cpp index c48459d1..2046427c 100644 --- a/SleepLib/loader_plugins/prs1_loader.cpp +++ b/SleepLib/loader_plugins/prs1_loader.cpp @@ -308,9 +308,10 @@ int PRS1Loader::OpenMachine(Machine *m,QString path,Profile *profile) qWarning() << "PRS1Loader: Couldn't open event file " << s.value()[2]; } } - const double ignore_thresh=300.0/3600.0;// Ignore useless sessions under 5 minute - if (sess->hours()<=ignore_thresh) { - qDebug() << "Ignoring short session" << session << "which is only" << (sess->hours()*60.0) << "minute(s) long"; + if ((sess->last() - sess->first()) == 0) { + //const double ignore_thresh=300.0/3600.0;// Ignore useless sessions under 5 minute + //if (sess->hours()<=ignore_thresh) { + qDebug() << "Ignoring empty session" << session;// << "which is only" << (sess->hours()*60.0) << "minute(s) long"; delete sess; continue; } diff --git a/SleepLib/machine.cpp b/SleepLib/machine.cpp index 98057d41..bb051480 100644 --- a/SleepLib/machine.cpp +++ b/SleepLib/machine.cpp @@ -347,62 +347,62 @@ Day *Machine::AddSession(Session *s,Profile *p) highest_sessionid=s->session(); + QTime split_time(12,0,0); + if (pref.Exists("DaySplitTime")) { + split_time=pref["DaySplitTime"].toTime(); + } + int combine_sessions; + if (pref.Exists("CombineCloserSessions")) { + combine_sessions=pref["CombineCloserSessions"].toInt(); // In Minutes + } else combine_sessions=0; + + int ignore_sessions; + if (pref.Exists("IgnoreShorterSessions")) { + ignore_sessions=pref["IgnoreShorterSessions"].toInt(); // In Minutes + } else ignore_sessions=0; + + int session_length=s->last()-s->first(); + session_length/=60000; + + sessionlist[s->session()]=s; // To make sure it get's saved later even if it's not wanted. + + if (session_lengthfirst()); QDate date=d2.date(); QTime time=d2.time(); - if (s->session()==1311991200) { - int q=03; - } - QMap::iterator dit; + QMap::iterator dit,nextday; - if (pref.Exists("NoonDateSplit") && pref["NoonDateSplit"].toBool()) { - int hour=d2.time().hour(); - if (hour<12) - date=date.addDays(-1); - //date=date.addDays(1); - } else { + + bool combine_next_day=false; + int closest_session=-1; + + if (time 0) { + dit=day.find(date.addDays(-1)); // Check Day Before if (dit!=day.end()) { - // Previous day record exists... - - // Calculate time since end of previous days last session - span=(s->first() - (*dit)->last())/3600000.0; - - // less than n hours since last session yesterday? - if (span < hours_since_last_session) { - previous=true; + QDateTime lt=QDateTime::fromMSecsSinceEpoch(dit.value()->last()); + closest_session=lt.secsTo(d2)/60; + if (closest_sessionfirst()); + closest_session=d2.secsTo(lt)/60; + if (closest_session < combine_sessions) { + // add todays here. pull all tomorrows records to this date. + combine_next_day=true; + } } } - - if (!previous) { - // Revert to sessions original day. - date=date.addDays(1); - } } - sessionlist[s->session()]=s; if (!firstsession) { if (firstday>date) firstday=date; @@ -429,6 +429,18 @@ Day *Machine::AddSession(Session *s,Profile *p) } dd->AddSession(s); + if (combine_next_day) { + for (QVector::iterator i=nextday.value()->begin();i!=nextday.value()->end();i++) { + dd->AddSession(*i); + } + QMap >::iterator nd=p->daylist.find(date.addDays(1)); + for (QVector::iterator i=nd->begin();i!=nd->end();i++) { + if (*i==nextday.value()) { + nd.value().erase(i); + } + } + day.erase(nextday); + } return dd; } @@ -542,30 +554,22 @@ bool Machine::SaveSession(Session *sess) } bool Machine::Save() { - QMap::iterator d; - QVector::iterator s; int size=0; int cnt=0; QString path=profile->Get("DataFolder")+"/"+hexid(); // Calculate size for progress bar - for (d=day.begin();d!=day.end();d++) - size+=d.value()->size(); + size=sessionlist.size(); - for (d=day.begin();d!=day.end();d++) { - - //qDebug() << "Day Save Commenced"; - for (s=d.value()->begin(); s!=d.value()->end(); s++) { - cnt++; - if (qprogress) qprogress->setValue(66.0+(float(cnt)/float(size)*33.0)); - if ((*s)->IsChanged()) (*s)->Store(path); - (*s)->TrashEvents(); - QApplication::processEvents(); - - } - //qDebug() << "Day Save Completed"; + QHash::iterator s; + for (s=sessionlist.begin(); s!=sessionlist.end(); s++) { + cnt++; + if (qprogress) qprogress->setValue(66.0+(float(cnt)/float(size)*33.0)); + if ((*s)->IsChanged()) (*s)->Store(path); + (*s)->TrashEvents(); + QApplication::processEvents(); } return true; } diff --git a/SleepLib/preferences.cpp b/SleepLib/preferences.cpp index 3fd71f4f..0da73508 100644 --- a/SleepLib/preferences.cpp +++ b/SleepLib/preferences.cpp @@ -196,8 +196,7 @@ bool Preferences::Open(QString filename) } else { qDebug() << "XML Error:" << name << "=" << value << "??"; } - } else - if (type=="qlonglong") { + } else if (type=="qlonglong") { qint64 d; d=value.toLongLong(&ok); if (ok) { @@ -205,6 +204,14 @@ bool Preferences::Open(QString filename) } else { qDebug() << "XML Error:" << name << "=" << value << "??"; } + } else if (type=="int") { + int d; + d=value.toInt(&ok); + if (ok) { + p_preferences[name]=d; + } else { + qDebug() << "XML Error:" << name << "=" << value << "??"; + } } else if (type=="bool") { QString v=value.toLower(); @@ -224,12 +231,20 @@ bool Preferences::Open(QString filename) } } else if (type=="qdatetime") { QDateTime d; - d.fromString(value,"yyyy-MM-dd HH:mm:ss"); + d=QDateTime::fromString(value,"yyyy-MM-dd HH:mm:ss"); if (d.isValid()) p_preferences[name]=d; else qWarning() << "XML Error: Invalid DateTime record" << name << value; + } else if (type=="qtime") { + QTime d; + d=QTime::fromString(value,"hh:mm:ss"); + if (d.isValid()) + p_preferences[name]=d; + else + qWarning() << "XML Error: Invalid Time record" << name << value; + } else { p_preferences[name]=value; } @@ -263,6 +278,8 @@ bool Preferences::Save(QString filename) cn.setAttribute("type",i.value().typeName()); if (type==QVariant::DateTime) { cn.appendChild(doc.createTextNode(i.value().toDateTime().toString("yyyy-MM-dd HH:mm:ss"))); + } else if (type==QVariant::Time) { + cn.appendChild(doc.createTextNode(i.value().toTime().toString("hh:mm:ss"))); } else { cn.appendChild(doc.createTextNode(i.value().toString())); } diff --git a/mainwindow.cpp b/mainwindow.cpp index d50b0a4f..830e3a80 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -94,9 +94,6 @@ MainWindow::MainWindow(QWidget *parent) : ui->logText->hide(); } - if (!pref.Exists("NoonDateSplit")) pref["NoonDateSplit"]=false; - ui->action_Noon_Date_Split->setChecked(pref["NoonDateSplit"].toBool()); - if (!pref.Exists("EnableGraphSnapshots")) pref["EnableGraphSnapshots"]=false; ui->actionDisplay_Graph_Snapshots->setChecked(pref["EnableGraphSnapshots"].toBool()); @@ -325,11 +322,6 @@ void MainWindow::on_actionUse_AntiAliasing_triggered(bool checked) } -void MainWindow::on_action_Noon_Date_Split_toggled(bool checked) -{ - pref["NoonDateSplit"]=checked; -} - void MainWindow::on_actionDebug_toggled(bool checked) { pref["ShowDebug"]=checked; diff --git a/mainwindow.h b/mainwindow.h index 4754c513..ae73051b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -70,8 +70,6 @@ private slots: void on_actionUse_AntiAliasing_triggered(bool checked); - void on_action_Noon_Date_Split_toggled(bool ); - void on_actionDebug_toggled(bool arg1); void on_actionOverlay_Bars_toggled(bool arg1); diff --git a/mainwindow.ui b/mainwindow.ui index 87b9ad02..c3faa71a 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -594,7 +594,6 @@ - diff --git a/preferencesdialog.cpp b/preferencesdialog.cpp index bc506748..6173cda6 100644 --- a/preferencesdialog.cpp +++ b/preferencesdialog.cpp @@ -1,5 +1,6 @@ #include #include +#include "SleepLib/profiles.h" #include "preferencesdialog.h" #include "ui_preferencesdialog.h" #include "SleepLib/machine_common.h" @@ -9,6 +10,29 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : ui(new Ui::PreferencesDialog) { ui->setupUi(this); + + if (pref.Exists("DaySplitTime")) { + QTime t=pref["DaySplitTime"].toTime(); + ui->timeEdit->setTime(t); + } + if (pref.Exists("CombineCloserSessions")) { + int i=pref["CombineCloserSessions"].toInt(); + ui->combineSlider->setValue(i); + if (i>0) { + ui->combineLCD->display(i); + } else ui->combineLCD->display(tr("OFF")); + } + if (pref.Exists("IgnoreShorterSessions")) { + int i=pref["IgnoreShorterSessions"].toInt(); + ui->IgnoreSlider->setValue(i); + if (i>0) { + ui->IgnoreLCD->display(i); + } else ui->IgnoreLCD->display(tr("OFF")); + } + if (pref.Exists("MemoryHog")) { + ui->memoryHogCheckbox->setChecked(pref["MemoryHog"].toBool()); + } + ui->eventTable->setColumnWidth(0,40); ui->eventTable->setColumnWidth(1,55); int row=0; @@ -35,27 +59,13 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : } } } -void PreferencesDialog::on_eventColor_selected(QString col) -{ -} + PreferencesDialog::~PreferencesDialog() { delete ui; } -void PreferencesDialog::on_combineSlider_sliderMoved(int position) -{ - ui->combineLCD->display(position); -} - -void PreferencesDialog::on_IgnoreSlider_sliderMoved(int position) -{ - if (position>0) { - ui->IgnoreLCD->display(position); - } else ui->IgnoreLCD->display(tr("OFF")); -} - void PreferencesDialog::on_eventTable_doubleClicked(const QModelIndex &index) { int row=index.row(); @@ -73,3 +83,29 @@ void PreferencesDialog::on_eventTable_doubleClicked(const QModelIndex &index) } } } + +void PreferencesDialog::on_timeEdit_editingFinished() +{ + pref["DaySplitTime"]=ui->timeEdit->time(); +} + +void PreferencesDialog::on_memoryHogCheckbox_toggled(bool checked) +{ + pref["MemoryHog"]=checked; +} + +void PreferencesDialog::on_combineSlider_valueChanged(int position) +{ + if (position>0) { + ui->combineLCD->display(position); + } else ui->combineLCD->display(tr("OFF")); + pref["CombineCloserSessions"]=position; +} + +void PreferencesDialog::on_IgnoreSlider_valueChanged(int position) +{ + if (position>0) { + ui->IgnoreLCD->display(position); + } else ui->IgnoreLCD->display(tr("OFF")); + pref["IgnoreShorterSessions"]=position; +} diff --git a/preferencesdialog.h b/preferencesdialog.h index f2d7d9c6..25b412c3 100644 --- a/preferencesdialog.h +++ b/preferencesdialog.h @@ -22,13 +22,16 @@ public: ~PreferencesDialog(); private slots: - void on_combineSlider_sliderMoved(int position); - - void on_IgnoreSlider_sliderMoved(int position); - - void on_eventColor_selected(QString); void on_eventTable_doubleClicked(const QModelIndex &index); + void on_timeEdit_editingFinished(); + + void on_memoryHogCheckbox_toggled(bool checked); + + void on_combineSlider_valueChanged(int value); + + void on_IgnoreSlider_valueChanged(int value); + private: Ui::PreferencesDialog *ui; }; diff --git a/preferencesdialog.ui b/preferencesdialog.ui index 08780b87..82d2d09e 100644 --- a/preferencesdialog.ui +++ b/preferencesdialog.ui @@ -29,7 +29,7 @@ - 1 + 0 @@ -82,7 +82,7 @@ - + Turn this off if your worried about SleepyHead consuming too much memory. It will be faster changing to days you've already been to if you leave it on.