File indexing completed on 2024-05-19 05:42:13

0001 // ct_lvtmdl_basetablemodel.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_BASETABLEMODEL
0021 #define DEFINED_CT_LVTMDL_BASETABLEMODEL
0022 
0023 #include <lvtmdl_export.h>
0024 
0025 #include <ct_lvtclr_colormanagement.h>
0026 #include <ct_lvtshr_graphenums.h>
0027 
0028 #include <QAbstractTableModel>
0029 
0030 #include <memory>
0031 
0032 namespace Codethink::lvtmdl {
0033 
0034 class LVTMDL_EXPORT BaseTableModel : public QAbstractTableModel {
0035     Q_OBJECT
0036   public:
0037     BaseTableModel(int columnCount, QObject *parent = nullptr);
0038     ~BaseTableModel() override;
0039 
0040     [[nodiscard]] std::string fullyQualifiedName() const;
0041     [[nodiscard]] lvtshr::DiagramType type() const;
0042 
0043     [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0044     [[nodiscard]] int columnCount(const QModelIndex& unused = QModelIndex()) const override;
0045 
0046     [[nodiscard]] QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
0047     [[nodiscard]] QVariant
0048     headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0049 
0050     void clear();
0051 
0052   protected:
0053     void addRow(const std::vector<QString>& row);
0054     // add a new row for this model's data.
0055 
0056     void addRow(const std::string& row);
0057     // overload for a common case
0058 
0059     void setHeader(const std::vector<QString>& header);
0060     // set the header information on this model.
0061 
0062     virtual void refreshData() = 0;
0063 
0064   private:
0065     struct Private;
0066     std::unique_ptr<Private> d;
0067 };
0068 
0069 } // end namespace Codethink::lvtmdl
0070 
0071 #endif