Bug Fix: in statistics: allow user to select report date. Invalid statistics after creating new profile.

This commit is contained in:
LoudSnorer 2023-06-20 08:37:00 -04:00
parent 4ddddaef89
commit e16f6fd4d3
2 changed files with 30 additions and 22 deletions

View File

@ -181,14 +181,7 @@ void MainWindow::SetupGUI()
QTextCharFormat format = ui->statStartDate->calendarWidget()->weekdayTextFormat(Qt::Saturday); QTextCharFormat format = ui->statStartDate->calendarWidget()->weekdayTextFormat(Qt::Saturday);
format.setForeground(QBrush(Qt::black, Qt::SolidPattern)); format.setForeground(QBrush(Qt::black, Qt::SolidPattern));
Qt::DayOfWeek dow=firstDayOfWeekFromLocale(); Qt::DayOfWeek dow=firstDayOfWeekFromLocale();
ui->statStartDate->calendarWidget()->setWeekdayTextFormat(Qt::Saturday, format); init_reportModeUi() ;
ui->statStartDate->calendarWidget()->setWeekdayTextFormat(Qt::Sunday, format);
ui->statStartDate->calendarWidget()->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
ui->statStartDate->calendarWidget()->setFirstDayOfWeek(dow);
ui->statEndDate->calendarWidget()->setWeekdayTextFormat(Qt::Saturday, format);
ui->statEndDate->calendarWidget()->setWeekdayTextFormat(Qt::Sunday, format);
ui->statEndDate->calendarWidget()->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
ui->statEndDate->calendarWidget()->setFirstDayOfWeek(dow);
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
//p_profile->appearance->setAntiAliasing(false); //p_profile->appearance->setAntiAliasing(false);
@ -256,7 +249,7 @@ void MainWindow::SetupGUI()
ui->actionReport_a_Bug->setVisible(false); // remove this once we actually implement it ui->actionReport_a_Bug->setVisible(false); // remove this once we actually implement it
ui->actionExport_Review->setVisible(false); // remove this once we actually implement it ui->actionExport_Review->setVisible(false); // remove this once we actually implement it
set_reportModeStandard_mode() ; reset_reportModeUi() ;
if (!AppSetting->showDebug()) { if (!AppSetting->showDebug()) {
ui->logText->hide(); ui->logText->hide();
} }
@ -563,13 +556,10 @@ bool MainWindow::OpenProfile(QString profileName, bool skippassword)
QDate first = p_profile->FirstDay(); QDate first = p_profile->FirstDay();
QDate last = p_profile->LastDay(); QDate last = p_profile->LastDay();
ui->statStartDate->setDate(first);
ui->statEndDate->setDate(last);
p_profile->general->setStatReportRangeStart(first); p_profile->general->setStatReportRangeStart(first);
p_profile->general->setStatReportRangeEnd(last); p_profile->general->setStatReportRangeEnd(last);
p_profile->general->setStatReportDate(last); p_profile->general->setStatReportDate(last);
p_profile->general->setStatReportMode(STAT_MODE_STANDARD); p_profile->general->setStatReportMode(STAT_MODE_STANDARD);
set_reportModeStandard_mode();
GenerateStatistics(); GenerateStatistics();
PopulatePurgeMenu(); PopulatePurgeMenu();
@ -2378,15 +2368,12 @@ void MainWindow::on_actionImport_Viatom_Data_triggered()
void MainWindow::GenerateStatistics() void MainWindow::GenerateStatistics()
{ {
reset_reportModeUi() ;
Statistics stats; Statistics stats;
QString htmlStats = stats.GenerateHTML(); QString htmlStats = stats.GenerateHTML();
QString htmlRecords = stats.UpdateRecordsBox(); QString htmlRecords = stats.UpdateRecordsBox();
set_reportModeStandard_mode() ;
if (!AppSetting->showDebug()) {
ui->logText->hide();
}
updateFavourites(); updateFavourites();
setStatsHTML(htmlStats); setStatsHTML(htmlStats);
@ -2426,9 +2413,27 @@ void MainWindow::on_statisticsButton_clicked()
} }
} }
void MainWindow::set_reportModeStandard_mode() void MainWindow::init_reportModeUi()
{
ui->statStartDate->blockSignals(true);
ui->statEndDate->blockSignals(true);
ui->statStartDate->calendarWidget()->setWeekdayTextFormat(Qt::Saturday, format);
ui->statStartDate->calendarWidget()->setWeekdayTextFormat(Qt::Sunday, format);
ui->statStartDate->calendarWidget()->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
ui->statStartDate->calendarWidget()->setFirstDayOfWeek(dow);
ui->statEndDate->calendarWidget()->setWeekdayTextFormat(Qt::Saturday, format);
ui->statEndDate->calendarWidget()->setWeekdayTextFormat(Qt::Sunday, format);
ui->statEndDate->calendarWidget()->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
ui->statEndDate->calendarWidget()->setFirstDayOfWeek(dow);
ui->statStartDate->blockSignals(false);
ui->statEndDate->blockSignals(false);
}
void MainWindow::reset_reportModeUi()
{ {
int mode = STAT_MODE_STANDARD; int mode = STAT_MODE_STANDARD;
ui->statStartDate->blockSignals(true);
ui->statEndDate->blockSignals(true);
if (p_profile) { if (p_profile) {
mode = p_profile->general->statReportMode(); mode = p_profile->general->statReportMode();
@ -2438,6 +2443,9 @@ void MainWindow::set_reportModeStandard_mode()
ui->statStartDate->setMaximumDate(last); ui->statStartDate->setMaximumDate(last);
ui->statEndDate->setMinimumDate(first); ui->statEndDate->setMinimumDate(first);
ui->statEndDate->setMaximumDate(last); ui->statEndDate->setMaximumDate(last);
if (!p_profile->general->statReportDate().isValid()) {
p_profile->general->setStatReportDate(last);
}
} }
switch (mode) { switch (mode) {
default: default:
@ -2473,6 +2481,8 @@ void MainWindow::set_reportModeStandard_mode()
} }
break; break;
} }
ui->statStartDate->blockSignals(false);
ui->statEndDate->blockSignals(false);
return; return;
}; };
@ -2480,7 +2490,6 @@ void MainWindow::on_reportModeMonthly_clicked()
{ {
if (p_profile->general->statReportMode() != STAT_MODE_MONTHLY) { if (p_profile->general->statReportMode() != STAT_MODE_MONTHLY) {
p_profile->general->setStatReportMode(STAT_MODE_MONTHLY); p_profile->general->setStatReportMode(STAT_MODE_MONTHLY);
set_reportModeStandard_mode();
GenerateStatistics(); GenerateStatistics();
} }
} }
@ -2489,7 +2498,6 @@ void MainWindow::on_reportModeStandard_clicked()
{ {
if (p_profile->general->statReportMode() != STAT_MODE_STANDARD) { if (p_profile->general->statReportMode() != STAT_MODE_STANDARD) {
p_profile->general->setStatReportMode(STAT_MODE_STANDARD); p_profile->general->setStatReportMode(STAT_MODE_STANDARD);
set_reportModeStandard_mode();
GenerateStatistics(); GenerateStatistics();
} }
} }
@ -2499,7 +2507,6 @@ void MainWindow::on_reportModeRange_clicked()
{ {
if (p_profile->general->statReportMode() != STAT_MODE_RANGE) { if (p_profile->general->statReportMode() != STAT_MODE_RANGE) {
p_profile->general->setStatReportMode(STAT_MODE_RANGE); p_profile->general->setStatReportMode(STAT_MODE_RANGE);
set_reportModeStandard_mode();
GenerateStatistics(); GenerateStatistics();
} }
} }

View File

@ -318,7 +318,8 @@ class MainWindow : public QMainWindow
void on_reportModeStandard_clicked(); void on_reportModeStandard_clicked();
void set_reportModeStandard_mode(); void init_reportModeUi();
void reset_reportModeUi();
void on_actionRebuildCPAP(QAction *action); void on_actionRebuildCPAP(QAction *action);