File indexing completed on 2024-05-12 05:13:27
0001 /* 0002 SPDX-FileCopyrightText: 2000, 2001 Cornelius Schumacher <schumacher@kde.org> 0003 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 0004 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0005 SPDX-FileContributor: Kevin Krammer <krake@kdab.com> 0006 SPDX-FileContributor: Sergio Martins <sergio@kdab.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0009 */ 0010 0011 #include "eventview_p.h" 0012 #include "calendarview_debug.h" 0013 #include "prefs.h" 0014 0015 #include <CalendarSupport/CollectionSelection> 0016 #include <CalendarSupport/KCalPrefs> 0017 0018 #include <Akonadi/EntityTreeModel> 0019 0020 #include <KHolidays/HolidayRegion> 0021 0022 #include <KCheckableProxyModel> 0023 0024 #include <QAbstractProxyModel> 0025 #include <QApplication> 0026 0027 #include <ranges> 0028 0029 using namespace EventViews; 0030 0031 EventViewPrivate::EventViewPrivate(EventView *qq) 0032 : q(qq) 0033 , mPrefs(QSharedPointer<Prefs>::create()) 0034 , mKCalPrefs(QSharedPointer<CalendarSupport::KCalPrefs>::create()) 0035 { 0036 } 0037 0038 EventViewPrivate::~EventViewPrivate() = default; 0039 0040 void EventViewPrivate::finishTypeAhead() 0041 { 0042 if (mTypeAheadReceiver) { 0043 for (QEvent *e : std::as_const(mTypeAheadEvents)) { 0044 QApplication::sendEvent(mTypeAheadReceiver, e); 0045 } 0046 } 0047 qDeleteAll(mTypeAheadEvents); 0048 mTypeAheadEvents.clear(); 0049 mTypeAhead = false; 0050 } 0051 0052 void EventViewPrivate::setUpModels() 0053 { 0054 q->collectionSelection()->disconnect(q); 0055 0056 customCollectionSelection.reset(); 0057 if (collectionSelectionModel) { 0058 customCollectionSelection = std::make_unique<CalendarSupport::CollectionSelection>(collectionSelectionModel->selectionModel()); 0059 } 0060 } 0061 0062 void EventViewPrivate::setEtm(QAbstractItemModel *model) 0063 { 0064 while (model) { 0065 if (const auto *proxy = qobject_cast<QAbstractProxyModel *>(model); proxy != nullptr) { 0066 model = proxy->sourceModel(); 0067 } else if (auto *etm = qobject_cast<Akonadi::EntityTreeModel *>(model); etm != nullptr) { 0068 this->etm = etm; 0069 break; 0070 } else { 0071 model = nullptr; 0072 } 0073 } 0074 0075 Q_ASSERT_X(this->etm != nullptr, "EventView", "Model is not ETM, ETM-derived or a proxy chain on top of an ETM or an ETM-derived model"); 0076 }