void FindBagDuration::Init(void)
{
...
// Start and end dates and times
ui_duration_start_dateEdit
->setDate
(QDate::currentDate().
addMonths(-1));
ui_duration_start_timeEdit
->setTime
(QTime(0,
0,
0));
ui_duration_end_dateEdit
->setDate
(QDate::currentDate());
ui_duration_end_timeEdit
->setTime
(QTime(23,
59,
59));
connect(ui_duration_start_dateEdit,
SIGNAL(dateChanged
(QDate)),
this,
SLOT(SlotSetFromDateTime
()));
connect(ui_duration_start_timeEdit,
SIGNAL(timeChanged
(QTime)),
this,
SLOT(SlotSetFromDateTime
()));
connect(ui_duration_end_dateEdit,
SIGNAL(dateChanged
(QDate)),
this,
SLOT(SlotSetToDateTime
()));
connect(ui_duration_end_timeEdit,
SIGNAL(timeChanged
(QTime)),
this,
SLOT(SlotSetToDateTime
()));
connect(ui_duration_start_dateEdit->calendarWidget(), SIGNAL(selectionChanged()), this, SLOT(SlotUpdateDates()));
connect(ui_duration_end_dateEdit->calendarWidget(), SIGNAL(selectionChanged()), this, SLOT(SlotUpdateDates()));
connect(this,
SIGNAL(SignalSynchDateChanged
(const QDate,
bool)),
this,
SLOT(SlotSynchDateChanged
(const QDate,
bool)));
connect(this,
SIGNAL(SignalSynchTimeChanged
(const QTime,
bool)),
this,
SLOT(SlotSynchTimeChanged
(const QTime,
bool)));
...
}
void FindBagDuration::SlotSetFromDateTime(void)
{
QDate start_date
= ui_duration_start_dateEdit
->date
();
// Used to make comparisons easier to read. QTime start_time
= ui_duration_start_timeEdit
->time
();
QDate end_date
= ui_duration_end_dateEdit
->date
();
QTime end_time
= ui_duration_end_timeEdit
->time
();
ui_duration_stackedWidget->setCurrentWidget(ui_duration_blank_page);
// Clear \todo do we need to clear the widget first?
if(end_date < start_date)
{
ui_duration_end_dateEdit->setDate(start_date);
emit SignalSynchDateChanged(start_date, false);
}
emit SignalSynchDateChanged(start_date, true);
if(end_date == start_date)
{
if(end_time < start_time)
{
ui_duration_end_timeEdit->setTime(start_time);
emit SignalSynchTimeChanged(start_time, false);
}
}
m_duration_model
->SlotSetFromDateTime
(QDateTime(start_date, start_time
));
emit SignalSynchTimeChanged(start_time, true);
emit SignalSynchDateChanged(start_date, true);
}
void FindBagDuration::SlotSetToDateTime(void)
{
QDate start_date
= ui_duration_start_dateEdit
->date
();
// Used to make comparisons easier to read. QTime start_time
= ui_duration_start_timeEdit
->time
();
QDate end_date
= ui_duration_end_dateEdit
->date
();
QTime end_time
= ui_duration_end_timeEdit
->time
();
ui_duration_stackedWidget->setCurrentWidget(ui_duration_blank_page);
// Clear \todo do we need to clear the widget?
// don't allow the start and end date to be the same
if(start_date > end_date)
{
ui_duration_start_dateEdit->setDate(end_date);
emit SignalSynchDateChanged(end_date, true);
}
if(end_date == start_date)
{
// don't allow the start and end time to be the same
if(start_time >= end_time)
{
if(start_time.hour() >= end_time.hour())
{
ui_duration_start_timeEdit->setTime(end_time.addSecs(-360));
emit SignalSynchTimeChanged(end_time.addSecs(-360), true);
}
else if(start_time.minute() >= end_time.minute())
{
ui_duration_start_timeEdit->setTime(end_time.addSecs(-60));
emit SignalSynchTimeChanged(end_time.addSecs(-60), true);
}
else
{
ui_duration_start_timeEdit->setTime(end_time.addSecs(-1));
emit SignalSynchTimeChanged(end_time.addSecs(-1), true);
}
}
}
emit SignalSynchTimeChanged(end_time, false);
emit SignalSynchDateChanged(end_date, false);
m_duration_model
->SlotSetToDateTime
(QDateTime(end_date, end_time
));
}
void FindBagDuration::SlotSynchDateChanged(const QDate& date, bool start_date )
{
// Clear(); \todo ?
if(start_date == true)
{
if(ui_duration_end_dateEdit->date() < date)
{
ui_duration_end_dateEdit->setDate(date);
}
ui_duration_start_dateEdit->setDate(date);
}
else
{
// don't allow the start and end date to be the same
if(ui_duration_start_dateEdit->date() >= date)
{
ui_duration_start_dateEdit->setDate(date);
}
ui_duration_end_dateEdit->setDate(date);
}
if(ui_duration_start_dateEdit->date() == date)
{
if(ui_duration_start_timeEdit->time() > ui_duration_end_timeEdit->time())
{
ui_duration_start_timeEdit
->setTime
(QTime(0,
0,
0));
}
}
}
void FindBagDuration::SlotSynchTimeChanged(const QTime& time, bool start_time )
{
// Clear(); \todo ?
if(start_time == true)
{
if(ui_duration_end_dateEdit->date() == ui_duration_start_dateEdit->date())
{
if(ui_duration_end_timeEdit->time() < time)
{
ui_duration_end_timeEdit->setTime(time);
}
}
ui_duration_start_timeEdit->setTime(time);
}
else
{
if(ui_duration_end_dateEdit->date() == ui_duration_start_dateEdit->date())
{
// don't allow the start and end time to be the same
if(ui_duration_start_timeEdit->time() >= time)
{
ui_duration_start_timeEdit
->setTime
(QTime(0,
0,
0));
}
}
ui_duration_end_timeEdit->setTime(time);
}
}
void FindBagDuration::SlotUpdateDates(void)
{
if(ui_duration_start_dateEdit->date() == ui_duration_end_dateEdit->date())
{
// don't allow the start and end time to be the same
if(ui_duration_start_timeEdit->time() >= ui_duration_end_timeEdit->time())
{
ui_duration_start_timeEdit
->setTime
(QTime(0,
0,
0));
}
}
}
void FindBagDuration::Init(void)
{
...
// Start and end dates and times
ui_duration_start_dateEdit->setDate(QDate::currentDate().addMonths(-1));
ui_duration_start_timeEdit->setTime(QTime(0,0,0));
ui_duration_end_dateEdit->setDate(QDate::currentDate());
ui_duration_end_timeEdit->setTime(QTime(23,59,59));
connect(ui_duration_start_dateEdit, SIGNAL(dateChanged(QDate)), this, SLOT(SlotSetFromDateTime()));
connect(ui_duration_start_timeEdit, SIGNAL(timeChanged(QTime)), this, SLOT(SlotSetFromDateTime()));
connect(ui_duration_end_dateEdit, SIGNAL(dateChanged(QDate)), this, SLOT(SlotSetToDateTime()));
connect(ui_duration_end_timeEdit, SIGNAL(timeChanged(QTime)), this, SLOT(SlotSetToDateTime()));
connect(ui_duration_start_dateEdit->calendarWidget(), SIGNAL(selectionChanged()), this, SLOT(SlotUpdateDates()));
connect(ui_duration_end_dateEdit->calendarWidget(), SIGNAL(selectionChanged()), this, SLOT(SlotUpdateDates()));
connect(this, SIGNAL(SignalSynchDateChanged(const QDate, bool)), this, SLOT(SlotSynchDateChanged(const QDate, bool)));
connect(this, SIGNAL(SignalSynchTimeChanged(const QTime, bool)), this, SLOT(SlotSynchTimeChanged(const QTime, bool)));
...
}
void FindBagDuration::SlotSetFromDateTime(void)
{
QDate start_date = ui_duration_start_dateEdit->date();// Used to make comparisons easier to read.
QTime start_time = ui_duration_start_timeEdit->time();
QDate end_date = ui_duration_end_dateEdit->date();
QTime end_time = ui_duration_end_timeEdit->time();
ui_duration_stackedWidget->setCurrentWidget(ui_duration_blank_page);
// Clear \todo do we need to clear the widget first?
if(end_date < start_date)
{
ui_duration_end_dateEdit->setDate(start_date);
emit SignalSynchDateChanged(start_date, false);
}
emit SignalSynchDateChanged(start_date, true);
if(end_date == start_date)
{
if(end_time < start_time)
{
ui_duration_end_timeEdit->setTime(start_time);
emit SignalSynchTimeChanged(start_time, false);
}
}
m_duration_model->SlotSetFromDateTime(QDateTime(start_date, start_time));
emit SignalSynchTimeChanged(start_time, true);
emit SignalSynchDateChanged(start_date, true);
}
void FindBagDuration::SlotSetToDateTime(void)
{
QDate start_date = ui_duration_start_dateEdit->date(); // Used to make comparisons easier to read.
QTime start_time = ui_duration_start_timeEdit->time();
QDate end_date = ui_duration_end_dateEdit->date();
QTime end_time = ui_duration_end_timeEdit->time();
ui_duration_stackedWidget->setCurrentWidget(ui_duration_blank_page);
// Clear \todo do we need to clear the widget?
// don't allow the start and end date to be the same
if(start_date > end_date)
{
ui_duration_start_dateEdit->setDate(end_date);
emit SignalSynchDateChanged(end_date, true);
}
if(end_date == start_date)
{
// don't allow the start and end time to be the same
if(start_time >= end_time)
{
if(start_time.hour() >= end_time.hour())
{
ui_duration_start_timeEdit->setTime(end_time.addSecs(-360));
emit SignalSynchTimeChanged(end_time.addSecs(-360), true);
}
else if(start_time.minute() >= end_time.minute())
{
ui_duration_start_timeEdit->setTime(end_time.addSecs(-60));
emit SignalSynchTimeChanged(end_time.addSecs(-60), true);
}
else
{
ui_duration_start_timeEdit->setTime(end_time.addSecs(-1));
emit SignalSynchTimeChanged(end_time.addSecs(-1), true);
}
}
}
emit SignalSynchTimeChanged(end_time, false);
emit SignalSynchDateChanged(end_date, false);
m_duration_model->SlotSetToDateTime(QDateTime(end_date, end_time));
}
void FindBagDuration::SlotSynchDateChanged(const QDate& date, bool start_date )
{
// Clear(); \todo ?
if(start_date == true)
{
if(ui_duration_end_dateEdit->date() < date)
{
ui_duration_end_dateEdit->setDate(date);
}
ui_duration_start_dateEdit->setDate(date);
}
else
{
// don't allow the start and end date to be the same
if(ui_duration_start_dateEdit->date() >= date)
{
ui_duration_start_dateEdit->setDate(date);
}
ui_duration_end_dateEdit->setDate(date);
}
if(ui_duration_start_dateEdit->date() == date)
{
if(ui_duration_start_timeEdit->time() > ui_duration_end_timeEdit->time())
{
ui_duration_start_timeEdit->setTime(QTime(0, 0, 0));
}
}
}
void FindBagDuration::SlotSynchTimeChanged(const QTime& time, bool start_time )
{
// Clear(); \todo ?
if(start_time == true)
{
if(ui_duration_end_dateEdit->date() == ui_duration_start_dateEdit->date())
{
if(ui_duration_end_timeEdit->time() < time)
{
ui_duration_end_timeEdit->setTime(time);
}
}
ui_duration_start_timeEdit->setTime(time);
}
else
{
if(ui_duration_end_dateEdit->date() == ui_duration_start_dateEdit->date())
{
// don't allow the start and end time to be the same
if(ui_duration_start_timeEdit->time() >= time)
{
ui_duration_start_timeEdit->setTime(QTime(0, 0, 0));
}
}
ui_duration_end_timeEdit->setTime(time);
}
}
void FindBagDuration::SlotUpdateDates(void)
{
if(ui_duration_start_dateEdit->date() == ui_duration_end_dateEdit->date())
{
// don't allow the start and end time to be the same
if(ui_duration_start_timeEdit->time() >= ui_duration_end_timeEdit->time())
{
ui_duration_start_timeEdit->setTime(QTime(0, 0, 0));
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks