Skip to content

Conversation

@TimGroeneboom
Copy link
Contributor

  • calendar items now emit an item changed signal whenever it's changed in someway
  • comparison operators added to both Date and Time structs for readable comparison
  • the operational calendar emits and item changed signal whenever it's changed in someway

The following PR solves a long standing feature that I wanted to implement. Often in installations I need to perform a certain action when a user changes something in the operation calendar, either in the app or using the web client. This way I can listen to an update of the operation calendar when the user changes the calendar. Most of the times, I just want to save the operational calendar instantly then.

…d in someway

- comparison operators added to both Date and Time structs for readable comparison
@cklosters cklosters added the enhancement New feature or request label Feb 3, 2025
@cklosters cklosters changed the base branch from main to 0.8 March 20, 2025 12:46
@cklosters
Copy link
Member

Changed target to 0.8 - 0.7.X is locked except for bug fixes

@cklosters cklosters added this to the 0.8 milestone May 29, 2025
Copy link
Member

@cklosters cklosters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I welcome the change there are some obvious and avoidable issues that hould shouldn't be there

Time backup = mPoint.mTime;
mPoint.mTime = time;

if (!mPoint.valid())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You check the currently stored value for validity, not the new one, which is wrong. Should be:

// Apply and validate
auto cache = mPoint.mTime;
mPoint.mTime = time;
if (mPoint.valid())
{
	if (mPoint.mTime != cache)
		changed(*this);
	return true;
}

// Restore if not valid
mPoint.mTime = cache;
return false;

bool WeeklyCalendarItem::setDay(EDay day)
{
if (day != EDay::Unknown)
if (day != EDay::Unknown && day != mDay)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns false when the day is not different from the current one, which is wrong. Should be:

if (day != EDay::Unknown)
{
	if (day != mDay)
	{
		mDay = day;
		changed(*this);
	}
	return true;
}
return false;

if (!date.valid()) { return false; }
mDate = date;
if (date != mDate)
changed(*this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never trigger changed because you compare the same (now stored) value? Should be:

if (date.valid())
{
	if(mDate != date)
	{
		mDate = date;
		changed(*this);
	}
	return true;
}
return false;

mDay = day;
if (mDay!= day)
changed(*this);
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, changed will never be triggered

mDay = day; mMonth = month;
if (mDay != day || mMonth != month)
changed(*this);
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, changed will never be triggered

// Comparison operators
bool operator == (const Time &c) const
{
if (mHour == c.mHour && mMinute == c.mMinute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify -> return c.mHour == mHour...

bool valid() const; ///< Returns if time is valid

// Comparison operators
bool operator == (const Point &c) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify -> return c.mTime == mTime ...

@cklosters
Copy link
Member

I fixed the above issues here: aecd546, feel free to merge the calendar_itemchanged_fixes branch into this one if you accept my changes.

Base automatically changed from 0.8 to main October 22, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants