File indexing completed on 2024-04-14 04:29:52
0001 /* 0002 * This file is part of KDevelop Krazy2 Plugin. 0003 * 0004 * Copyright 2012 Daniel Calviño Sánchez <danxuliu@gmail.com> 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License 0008 * as published by the Free Software Foundation; either version 2 0009 * of the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef CHECKERMODEL_H 0021 #define CHECKERMODEL_H 0022 0023 #include <QAbstractItemModel> 0024 0025 class Checker; 0026 class Item; 0027 0028 /** 0029 * A tree model for a list of checkers. 0030 * The model is a read only model. It provides three levels of items: the first 0031 * level are the file types, the second level are the checkers, and the third 0032 * level are the extra checkers. The last item in each second level group is a 0033 * header for the extra items. That is the only item out of order; all the other 0034 * items with the same parent are sorted alphabetically. Only one column is 0035 * shown for each item in all levels. 0036 * 0037 * An example of the structure of this model: 0038 * -cpp 0039 * |-foreach 0040 * |-includes 0041 * |-strings 0042 * |-[EXTRA] 0043 * |-contractions 0044 * -desktop 0045 * |-validate 0046 */ 0047 class CheckerModel: public QAbstractItemModel { 0048 Q_OBJECT 0049 public: 0050 0051 /** 0052 * Creates a new CheckerModel. 0053 * 0054 * @param parent The parent object. 0055 */ 0056 explicit CheckerModel(QObject* parent = nullptr); 0057 0058 /** 0059 * Destroys all the items (but not the checkers). 0060 */ 0061 ~CheckerModel() override; 0062 0063 //<QAbstractItemModel> 0064 0065 /** 0066 * Returns the index of the item in the model specified by the given row, 0067 * column and parent index. 0068 * 0069 * @return The index of the item. 0070 */ 0071 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; 0072 0073 /** 0074 * Returns the parent of the model item with the given index. 0075 * 0076 * @return The parent of the model item with the given index. 0077 */ 0078 QModelIndex parent(const QModelIndex& index) const override; 0079 0080 /** 0081 * Returns the number of rows under the given parent. 0082 * Depending on the parent, it will be the number of file types, the number 0083 * of checkers for a file type (plus one) or the number of extra checkers 0084 * for a file type. 0085 * 0086 * @param parent The parent index. 0087 * @return The number of rows under the given parent. 0088 */ 0089 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0090 0091 /** 0092 * Returns the number of columns, which is one. 0093 * 0094 * @param parent Unused. 0095 * @return One column. 0096 */ 0097 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0098 0099 /** 0100 * Returns the data stored under the given role for the item referred to by 0101 * the index. 0102 * Display role shows the file type, the "extra" header or the name of the 0103 * checker, and ToolTip role shows the checker description. 0104 * 0105 * Invalid indexes or roles other than Display and ToolTip are ignored (an 0106 * empty variant is returned). 0107 * 0108 * @param index The index of the item. 0109 * @param role The role for the data. 0110 * @return The data for the given role and index. 0111 */ 0112 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 0113 0114 //</QAbstractItemModel> 0115 0116 /** 0117 * Returns the checker associated to the given index. 0118 * Indexes for file types or extra headers have no associated checker, so a 0119 * null pointer is returned in those cases. 0120 * 0121 * @param index The index to get its associated Checker. 0122 * @return The Checker associated to the given index. 0123 */ 0124 const Checker* checkerForIndex(const QModelIndex& index) const; 0125 0126 /** 0127 * Sets the checkers to use. 0128 * 0129 * @param checkers The checkers to use. 0130 */ 0131 void setCheckers(const QList<const Checker*>& checkers); 0132 0133 private: 0134 0135 /** 0136 * The internal items that represent the file type entries. 0137 */ 0138 QList<Item*> m_fileTypeItems; 0139 0140 }; 0141 0142 #endif