File indexing completed on 2024-09-22 04:37:32
0001 /* 0002 SPDX-FileCopyrightText: Bernd Gonsior <bernd.gonsior@googlemail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 #ifndef TOCITEM_H 0006 #define TOCITEM_H 0007 0008 // ---------------------------------------------------------------------------- 0009 // QT Includes 0010 0011 #include <QStringList> 0012 #include <QTreeWidgetItem> 0013 0014 // ---------------------------------------------------------------------------- 0015 // KDE Includes 0016 0017 0018 // ---------------------------------------------------------------------------- 0019 // Project Includes 0020 0021 /** 0022 * Base class for items in reports table of contents (TOC). 0023 * It provides the type of the item (reportgroup or report) 0024 * and an operator for sorting. 0025 */ 0026 class TocItem : public QTreeWidgetItem 0027 { 0028 public: 0029 0030 /** Type of TOC-item */ 0031 enum ItemType { 0032 /** item represents a reportgroup */ 0033 GROUP = QTreeWidgetItem::UserType + 10, 0034 /** item represents a report */ 0035 REPORT = QTreeWidgetItem::UserType + 20, 0036 } type; 0037 0038 /** Constructor. 0039 * 0040 * @param parent pointer to the parent QWidget 0041 * @param columns List of texts in columns 0042 */ 0043 TocItem(QTreeWidget* parent, QStringList columns); 0044 0045 /** Constructor. 0046 * 0047 * @param parent pointer to the parent QWidget 0048 * @param columns List of texts in columns 0049 */ 0050 TocItem(QTreeWidgetItem* parent, QStringList columns); 0051 0052 /** Indicates, whether the item represents a report or a reportgroup. 0053 * 0054 * @retval true the item represents a report 0055 * @retval false the item represents a reportgroup 0056 */ 0057 bool isReport(); 0058 0059 private: 0060 0061 /** Operator used to sort TocItems. 0062 * TOC has to be sorted in a quite special way: 0063 * @li @c reportgroups numerically by group-number 0064 * @li @c reports alphabetically by text of column 0 0065 * 0066 * Because the operator is defined @c const it is not possible, 0067 * to use a property of a class derived from @c QTreeWidgetItem. 0068 * So we use the @c QVariant data of @c QTreeWidgetItem in following way: 0069 * 0070 * QVariant contains a QStringList at position 0 with 0071 * role @c Qt::UserRole. 0072 * The first entry of this list is the item-type (report or 0073 * reportgroup). The second entry is the item-type-specific sort-key, for 0074 * reports simply the text of column 0, for reportgroups the groupnumber as 0075 * string with leading zeros. 0076 * 0077 * Examples: 0078 * <pre> 0079 * reportgroup: 0080 * list.at(0) = QString::number(TocItem::GROUP); 0081 * list.at(1) = "001" 0082 * 0083 * report: 0084 * list.at(0) = QString::number(TocItem::REPORT); 0085 * list.at(1) = "<the-name-of-the-report>" 0086 * </pre> 0087 */ 0088 bool operator<(const QTreeWidgetItem &other) const final override; 0089 }; 0090 0091 #endif