File indexing completed on 2024-04-28 12:30:05

0001 /***************************************************************************
0002  *   Copyright (C) 2018 by Emmanuel Lepage Vallee                          *
0003  *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@kde.org>             *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 3 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0017  **************************************************************************/
0018 #ifndef KQUICKITEMVIEWS_VIEWPORT_H
0019 #define KQUICKITEMVIEWS_VIEWPORT_H
0020 
0021 // Qt
0022 #include <QtCore/QAbstractItemModel>
0023 #include <QtCore/QRectF>
0024 
0025 // KQuickItemViews
0026 #include <viewbase.h>
0027 class ViewportPrivate;
0028 class ViewportSync;
0029 class AbstractItemAdapter;
0030 class GeometryAdapter;
0031 
0032 /**
0033 * This class exposes a way to track and iterate a subset of the model.
0034 *
0035 * It prevents all of the model reflection to have to be loaded in memory
0036 * and offers a simpler API to access the loaded sections.
0037 *
0038 * This class is for internal use and should not be used by views. Please use
0039 * `ViewBase` for all relevant use cases.
0040 */
0041 class Q_DECL_EXPORT Viewport : public QObject
0042 {
0043     friend class AbstractItemAdapter; // for the getters defined in viewport.cpp
0044     friend class ViewportSync; // its own internal API
0045 
0046     Q_OBJECT
0047 public:
0048     explicit Viewport(ModelAdapter* ma);
0049     virtual ~Viewport();
0050 
0051     /**
0052      * Get the current (cartesian) rectangle represented by this range.
0053      */
0054     QRectF currentRect() const;
0055 
0056     ModelAdapter *modelAdapter() const;
0057 
0058     QSizeF size() const;
0059 
0060     QPointF position() const;
0061 
0062     QSizeF totalSize() const;
0063 
0064     Qt::Edges availableEdges() const;
0065 
0066     GeometryAdapter *geometryAdapter() const;
0067     void setGeometryAdapter(GeometryAdapter *a);
0068 
0069     void setItemFactory(ViewBase::ItemFactoryBase *factory);
0070 
0071     void resize(const QRectF& rect);
0072 
0073     QModelIndex indexAt(const QPoint & point) const;
0074     QModelIndex indexAt(Qt::Corner corner) const;
0075     QModelIndex indexAt(Qt::Edge edge) const;
0076 
0077     QRectF itemRect(const QModelIndex& i) const;
0078 
0079     ViewportSync *s_ptr;
0080 
0081 Q_SIGNALS:
0082     void contentChanged();
0083     void cornerChanged();
0084 
0085 public:
0086     ViewportPrivate *d_ptr;
0087 };
0088 
0089 #endif