File indexing completed on 2024-04-28 04:41:50
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 0019 #include <adapters/geometryadapter.h> 0020 0021 //Qt 0022 class QAbstractItemModel; 0023 0024 class GeoStrategySelectorPrivate; 0025 0026 /** 0027 * The "real" strategy adapter. 0028 * 0029 * It acts as a proxy with a built-in chain of responsibilities to select the 0030 * best geometry hints strategy automatically. 0031 * 0032 * For this, it uses runtime data introspection to auto-detect features that 0033 * allows to make a better strategy choice. 0034 */ 0035 class GeoStrategySelector final : public GeometryAdapter 0036 { 0037 Q_OBJECT 0038 public: 0039 0040 /** 0041 * Auto detected and provided features. 0042 */ 0043 enum Features { 0044 NONE = 0x0 << 0 , /*!< No features to make en enlighten choice */ 0045 HAS_MODEL = 0x1 << 0 , /*!< Has a model */ 0046 HAS_SHP_MODEL = 0x1 << 1 , /*!< Has a QSizeHintProxyModel */ 0047 HAS_MODEL_CONTENT = 0x1 << 2 , /*!< Has a model with content to introspect */ 0048 HAS_SIZE_ROLE = 0x1 << 3 , /*!< Has a model with valid size hints */ 0049 HAS_DELEGATE = 0x1 << 4 , /*!< Has a delegate instance */ 0050 HAS_OVERRIDE = 0x1 << 5 , /*!< A GeometryAdapter was manually set */ 0051 HAS_SCROLLBAR = 0x1 << 6 , /*!< The view need the full geometry */ 0052 HAS_CHILDREN = 0x1 << 7 , /*!< The model only has top level */ 0053 HAS_COLUMNS = 0x1 << 8 , /*!< The model has more than 1 column */ 0054 HAS_MAX_DEPTH = 0x1 << 9 , /*!< There is a known maximum recursion */ 0055 IS_FULLY_COLLAPSED = 0x1 << 10, /*!< It is a tree, but nothing is expanded */ 0056 }; 0057 Q_FLAGS(Features) 0058 0059 explicit GeoStrategySelector(Viewport *parent = nullptr); 0060 virtual ~GeoStrategySelector(); 0061 0062 virtual QSizeF sizeHint(const QModelIndex& index, AbstractItemAdapter *adapter) const override; 0063 virtual QPointF positionHint(const QModelIndex& index, AbstractItemAdapter *adapter) const override; 0064 0065 virtual int capabilities() const override; 0066 0067 virtual bool isSizeForced() const override; 0068 virtual void setSizeForced(bool f) override; 0069 0070 void setModel(QAbstractItemModel *m); 0071 0072 void setHasScrollbar(bool v); 0073 0074 /// Return true when the currentAdapter is selected using the capabilities. 0075 bool isAutomatic() const; 0076 0077 GeometryAdapter *currentAdapter() const; 0078 void setCurrentAdapter(GeometryAdapter *a); 0079 0080 private: 0081 GeoStrategySelectorPrivate *d_ptr; 0082 Q_DECLARE_PRIVATE(GeoStrategySelector) 0083 };