File indexing completed on 2024-05-19 05:42:13
0001 // ct_lvtmdl_basetreemodel.h -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #ifndef DEFINED_CT_LVTMDL_BASETREEMODEL 0021 #define DEFINED_CT_LVTMDL_BASETREEMODEL 0022 0023 #include <lvtmdl_export.h> 0024 0025 #include <ct_lvtclr_colormanagement.h> 0026 0027 #include <QStandardItemModel> 0028 0029 #include <utility> 0030 #include <vector> 0031 0032 namespace Codethink::lvtldr { 0033 class LakosianNode; 0034 } 0035 0036 namespace Codethink::lvtmdl { 0037 0038 class LVTMDL_EXPORT BaseTreeModel : public QStandardItemModel 0039 // A tree model that lazy loads inner data. 0040 { 0041 Q_OBJECT 0042 // DATA TYPES 0043 struct BaseTreeModelPrivate; 0044 0045 public: 0046 BaseTreeModel(); 0047 ~BaseTreeModel() noexcept override; 0048 0049 virtual void reload() = 0; 0050 // should refresh the data on the model. 0051 0052 [[nodiscard]] bool isLoaded(const QString& identifier, const QModelIndex& parent = {}); 0053 // checks if there is a branch or a leaf with the specified text. 0054 // TODO: Check if we hit false positives. 0055 0056 [[nodiscard]] bool isLoaded(const std::string& identifier, const QModelIndex& parent = {}); 0057 // converts to QString and calls the method above. 0058 0059 [[nodiscard]] QModelIndex indexForData(const std::vector<std::pair<QVariant, int>>& variantToRole, 0060 const QModelIndex& parent = {}); 0061 0062 [[nodiscard]] QModelIndex indexForData(const std::vector<std::pair<std::string, int>>& strToRole, 0063 const QModelIndex& parent = {}); 0064 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index) const override; 0065 0066 // returns the index of the first element that satisfies the 0067 // data for the specified role. 0068 0069 void setColorManagement(std::shared_ptr<lvtclr::ColorManagement> colorManagement); 0070 0071 QStringList mimeTypes() const override; 0072 QMimeData *mimeData(const QModelIndexList& indexes) const override; 0073 0074 private: 0075 std::unique_ptr<BaseTreeModelPrivate> d; 0076 }; 0077 0078 } // end namespace Codethink::lvtmdl 0079 0080 #endif