/* Copyright (c) 2016 Michael Bohlender Copyright (c) 2016 Christian Mollekopf This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #pragma once #include #include #include #include #include // Implementation notes // ==================== // // On the model side // ----------------- // // Columns are never used. // // Top-level items just contains the ".events" attribute, and their rows // correspond to their day of week. In that case the internalId contains // DAY_ID. // // Direct children are events, and their rows corresponds to their index in // their partition. In that case no internalId / internalPointer is used. // // Internally: // ----------- // // On construction and on dataChanged, all events are processed and partitioned // in partitionedEvents: // // QVector< QList > // ~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // | | // | '--- List of event pointers for that day // '--- Partition / day // class EventTreeModel : public QAbstractItemModel { Q_OBJECT public: using Event = Sink::ApplicationDomain::Event; enum Roles { Events = Qt::UserRole + 1, Summary, Description, StartTime, Duration, }; Q_ENUM(Roles); EventTreeModel(QObject *parent = nullptr); ~EventTreeModel() = default; QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; QModelIndex parent(const QModelIndex &index) const override; int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override; bool hasChildren(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; QHash roleNames() const override; private: void partitionData(); QSharedPointer eventModel; QVector>> partitionedEvents; static const constexpr quintptr DAY_ID = 7; };