Activated Session Preferences

This commit is contained in:
Mark Watkins 2011-08-05 17:52:32 +10:00
parent f2af25faaf
commit 0f331ad50a
10 changed files with 150 additions and 100 deletions

View File

@ -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 {

View File

@ -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;
}

View File

@ -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_length<ignore_sessions) {
return NULL;
}
QDateTime d1,d2=QDateTime::fromMSecsSinceEpoch(s->first());
QDate date=d2.date();
QTime time=d2.time();
if (s->session()==1311991200) {
int q=03;
}
QMap<QDate,Day *>::iterator dit;
QMap<QDate,Day *>::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<split_time) {
date=date.addDays(-1);
const int hours_since_last_session=4;
const int hours_since_midnight=12;
bool previous=false;
// Find what day session belongs to.
dit=day.find(date);
} else if (combine_sessions > 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_session<combine_sessions) {
date=date.addDays(-1);
}
}
if (!previous) {
// Calculate Hours since midnight.
d1=d2;
d1.setTime(QTime(0,0,0));
float secsto=d1.secsTo(d2);
span=secsto/3600.0;
// Bedtime was late last night.
if (span < hours_since_midnight) {
previous=true;
} else {
nextday=day.find(date.addDays(1));// Check Day Afterwards
if (nextday!=day.end()) {
QDateTime lt=QDateTime::fromMSecsSinceEpoch(nextday.value()->first());
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<Session *>::iterator i=nextday.value()->begin();i!=nextday.value()->end();i++) {
dd->AddSession(*i);
}
QMap<QDate,QVector<Day *> >::iterator nd=p->daylist.find(date.addDays(1));
for (QVector<Day *>::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<QDate,Day *>::iterator d;
QVector<Session *>::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<SessionID,Session *>::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;
}

View File

@ -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()));
}

View File

@ -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;

View File

@ -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);

View File

@ -594,7 +594,6 @@
<addaction name="actionOverlay_Bars"/>
<addaction name="actionDisplay_Graph_Snapshots"/>
<addaction name="action_Link_Graphs"/>
<addaction name="action_Noon_Date_Split"/>
<addaction name="action_Memory_Hog"/>
<addaction name="separator"/>
<addaction name="action_Fullscreen"/>

View File

@ -1,5 +1,6 @@
#include <QLabel>
#include <QColorDialog>
#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;
}

View File

@ -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;
};

View File

@ -29,7 +29,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -82,7 +82,7 @@
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="memoryHogCheckbox">
<property name="toolTip">
<string>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. </string>