1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:27:45 +00:00

Calendar: Move MonthListModel into Calendar.h

Previously, we had two versions of MonthListModel for the AddEventDialog
and the DatePickerDialog. Now, a unified version is in the Calendar.h
file, which can be used easily by anyone. Since that model and the
MeridiemListModel weren't used anymore in the AddEventDialog, I have
also removed them from there.
This commit is contained in:
david072 2023-11-17 21:10:13 +01:00 committed by Andrew Kaster
parent 5ed334e13a
commit 039114b728
5 changed files with 91 additions and 55 deletions

View file

@ -2,6 +2,7 @@
* Copyright (c) 2019-2020, Ryan Grieb <ryan.m.grieb@gmail.com>
* Copyright (c) 2020-2022, the SerenityOS developers.
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2023, David Ganz <david.g.ganz@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -857,4 +858,28 @@ bool Calendar::is_day_in_weekend(DayOfWeek day)
return day_index < weekend_end_index;
}
ErrorOr<String> MonthListModel::column_name(int column) const
{
switch (column) {
case Column::Month:
return "Month"_string;
default:
VERIFY_NOT_REACHED();
}
}
GUI::Variant MonthListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
{
auto const& month = (m_mode == MonthListModel::DisplayMode::Short ? AK::short_month_names : AK::long_month_names)[index.row()];
if (role == GUI::ModelRole::Display) {
switch (index.column()) {
case Column::Month:
return month;
default:
VERIFY_NOT_REACHED();
}
}
return {};
}
}