File indexing completed on 2024-05-19 04:00:02
0001 /* 0002 SPDX-FileCopyrightText: 2008 Andreas Pakulat <apaku@gmx.de> 0003 SPDX-FileCopyrightText: 2008-2018 Dominik Haumann <dhaumann@kde.org> 0004 SPDX-FileCopyrightText: 2017-2018 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KTEXTEDITOR_ANNOTATIONINTERFACE_H 0010 #define KTEXTEDITOR_ANNOTATIONINTERFACE_H 0011 0012 #include <ktexteditor_export.h> 0013 0014 #include <QObject> 0015 0016 class QMenu; 0017 0018 namespace KTextEditor 0019 { 0020 class View; 0021 class AbstractAnnotationItemDelegate; 0022 0023 /** 0024 * \brief An model for providing line annotation information 0025 * 0026 * \section annomodel_intro Introduction 0027 * 0028 * AnnotationModel is a model-like interface that can be implemented 0029 * to provide annotation information for each line in a document. It provides 0030 * means to retrieve several kinds of data for a given line in the document. 0031 * 0032 * \section annomodel_impl Implementing a AnnotationModel 0033 * 0034 * The public interface of this class is loosely based on the QAbstractItemModel 0035 * interfaces. It only has a single method to override which is the \ref data() 0036 * method to provide the actual data for a line and role combination. 0037 * 0038 * \since 4.1 0039 * \see KTextEditor::AnnotationInterface, KTextEditor::AnnotationViewInterface 0040 */ 0041 class KTEXTEDITOR_EXPORT AnnotationModel : public QObject 0042 { 0043 Q_OBJECT 0044 public: 0045 ~AnnotationModel() override; 0046 0047 enum { GroupIdentifierRole = Qt::UserRole }; 0048 // KF6: add AnnotationModelUserRole = Qt::UserRole + 0x100 0049 0050 /** 0051 * data() is used to retrieve the information needed to present the 0052 * annotation information from the annotation model. The provider 0053 * should return useful information for the line and the data role. 0054 * 0055 * The following roles are supported: 0056 * - Qt::DisplayRole - a short display text to be placed in the border 0057 * - Qt::TooltipRole - a tooltip information, longer text possible 0058 * - Qt::BackgroundRole - a brush to be used to paint the background on the border 0059 * - Qt::ForegroundRole - a brush to be used to paint the text on the border 0060 * - AnnotationModel::GroupIdentifierRole - a string which identifies a 0061 * group of items which will be highlighted on mouseover; return the same 0062 * string for all items in a group (KDevelop uses a VCS revision number, for example) 0063 * 0064 * 0065 * \param line the line for which the data is to be retrieved 0066 * \param role the role to identify which kind of annotation is to be retrieved 0067 * 0068 * \returns a QVariant that contains the data for the given role. 0069 */ 0070 virtual QVariant data(int line, Qt::ItemDataRole role) const = 0; // KF6: use int for role 0071 0072 Q_SIGNALS: 0073 /** 0074 * The model should emit the signal reset() when the text of almost all 0075 * lines changes. In most cases it is enough to call lineChanged(). 0076 * 0077 * \note Kate Part implementation details: Whenever reset() is emitted Kate 0078 * Part iterates over all lines of the document. Kate Part searches 0079 * for the longest text to determine the annotation border's width. 0080 * 0081 * \see lineChanged() 0082 */ 0083 void reset(); 0084 0085 /** 0086 * The model should emit the signal lineChanged() when a line has to be 0087 * updated. 0088 * 0089 * \note Kate Part implementation details: lineChanged() repaints the whole 0090 * annotation border automatically. 0091 */ 0092 void lineChanged(int line); 0093 }; 0094 0095 } // namespace KTextEditor 0096 0097 #endif