diff --git a/src/adapters/geometryadapter.h b/src/adapters/geometryadapter.h index 2375397..f999174 100644 --- a/src/adapters/geometryadapter.h +++ b/src/adapters/geometryadapter.h @@ -1,164 +1,183 @@ /*************************************************************************** * Copyright (C) 2018 by Emmanuel Lepage Vallee * * Author : Emmanuel Lepage Vallee * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * **************************************************************************/ #ifndef KQUICKITEMVIEWS_GEOMETRYADAPTER_H #define KQUICKITEMVIEWS_GEOMETRYADAPTER_H #include #include #include class GeometryAdapterPrivate; class AbstractItemAdapter; class Viewport; /** * Add strategies to get the size (and optionally position) hints. * * One size don't fit everything here. QtWidgets had a `sizeHint` method. * However getting this information in QML is a lot harder for many reasons. */ class Q_DECL_EXPORT GeometryAdapter : public QObject { Q_OBJECT public: Q_INVOKABLE explicit GeometryAdapter(Viewport *parent = nullptr); virtual ~GeometryAdapter(); /** * Features this adapter provide and requires. */ enum Capabilities { NONE = 0x0 << 0, /** * Most GeometryAdapter only provide size hints. * * However some views might not have built-in layouts and then the position * is also necessary. * * This property only state that the adapter *can* provide positions. * `alwaysHasPositionHints` will tell if this is always the case. */ HAS_POSITION_HINTS = 0x1 << 0, /** * Allow the view to skip the GeometryAdapter when they only need the height. * * It will be called once, then the view will assume the result will always * be the same. */ HAS_UNIFORM_HEIGHT = 0x1 << 1, /** * Allow the view to skip the GeometryAdapter when they only need the width. * * It will be called once, then the view will assume the result will always * be the same. */ HAS_UNIFORM_WIDTH = 0x1 << 2, /** * The sizeHint will *always* return a valid size. * * Some GeometryAdapter may only provide size hints when some preconditions * are met. For example something that depends on the current delegate * will only work once the delegate is created. */ ALWAYS_HAS_SIZE_HINTS = 0x1 << 3, /** @see alwaysHasSizeHints */ ALWAYS_HAS_POSITION_HINTS = 0x1 << 4, /** * This GeometryAdapter allows to query the size before creating a * delegate instance. */ HAS_AHEAD_OF_TIME = 0x1 << 5, /** * This GeometryAdapter requires the view to track each QQuickItem * delegate geometry. */ TRACKS_QQUICKITEM_GEOMETRY= 0x1 << 6, /** * This GeometryAdapter requires a single delegate instance to work. */ REQUIRES_SINGLE_INSTANCE = 0x1 << 7, /** * Apply the size hints instead of using the delegate implicit size. */ FORCE_DELEGATE_SIZE = 0x1 << 8, + + /** + * Each QModelIndex, including the children QModelIndex or positioned + * one after the other in a Cartesian plane. This capability is only + * relevant when HAS_POSITION_HINTS is set and implies + * HAS_ORDERED_SIBLINGS. + * + * Do not set this hint if the + */ + IS_ORDERED = 0x1 << 9, + + /** + * When the QModelIndex with the same parent are positioned next to + * each other on a Cartesian plane. + * + * Use IS_ORDERED if this is also true among QModelIndex of different + * parent. + */ + HAS_ORDERED_SIBLINGS = 0x1 << 10, }; // Q_FLAGS(Capabilities) /** * A feature set provided by this adapter. */ Q_PROPERTY(int capabilities READ capabilities NOTIFY flagsChanged) /** * If the GeometryAdapter should override the delegate implicit size * with the size hints. */ Q_PROPERTY(bool forceSize READ isSizeForced WRITE setSizeForced NOTIFY flagsChanged) virtual int capabilities() const; virtual bool isSizeForced() const; virtual void setSizeForced(bool f); /** * Get the size hints for an AbstractItemAdapter. */ Q_INVOKABLE virtual QSizeF sizeHint(const QModelIndex &index, AbstractItemAdapter *adapter) const; /** * Get the position hints for an AbstractItemAdapter. */ Q_INVOKABLE virtual QPointF positionHint(const QModelIndex &index, AbstractItemAdapter *adapter) const; Viewport *viewport() const; protected: /** * Set the flags to be used by the internal optimization engine. */ void setCapabilities(int f); void addCapabilities(int f); void removeCapabilities(int f); Q_SIGNALS: /** * Tell the view to disregard previously returned values and start over. */ void dismissResult(); void flagsChanged(); private: GeometryAdapterPrivate *d_ptr; Q_DECLARE_PRIVATE(GeometryAdapter) }; #endif