KSyntaxHighlighting

foldingregion.h
1 /*
2  SPDX-FileCopyrightText: 2016 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: MIT
5 */
6 
7 #ifndef KSYNTAXHIGHLIGHTING_FOLDINGREGION_H
8 #define KSYNTAXHIGHLIGHTING_FOLDINGREGION_H
9 
10 #include "ksyntaxhighlighting_export.h"
11 
12 #include <QTypeInfo>
13 
14 namespace KSyntaxHighlighting
15 {
16 /** Represents a begin or end of a folding region.
17  * @since 5.28 */
18 class KSYNTAXHIGHLIGHTING_EXPORT FoldingRegion
19 {
20 public:
21  /**
22  * Defines whether a FoldingRegion starts or ends a folding region.
23  */
24  enum Type {
25  //! Used internally as indicator for invalid FoldingRegion%s.
27  //! Indicates the start of a FoldingRegion.
29  //! Indicates the end of a FoldingRegion.
30  End
31  };
32 
33  /**
34  * Constructs an invalid folding region, meaning that isValid() returns @e false.
35  * To obtain valid instances, see AbstractHighlighter::applyFolding().
36  */
37  FoldingRegion();
38 
39  /** Compares two FoldingRegion instances for equality. */
40  bool operator==(const FoldingRegion &other) const;
41 
42  /**
43  * Returns @c true if this is a valid folding region.
44  * A valid FoldingRegion is defined by a type() other than Type::None.
45  *
46  * @note The FoldingRegion%s passed in AbstractHighlighter::applyFolding()
47  * are always valid.
48  */
49  bool isValid() const;
50 
51  /**
52  * Returns a unique identifier for this folding region.
53  *
54  * As example, the C/C++ highlighter starts and ends a folding region for
55  * scopes, e.g.:
56  * \code
57  * void foo() { // '{' starts a folding region
58  * if (bar()) { // '{' starts a (nested) folding region
59  * } // '}' ends the (nested) folding region
60  * } // '}' ends the outer folding region
61  * \endcode
62  * In this example, all braces '{' and '}' have the same id(), meaning that
63  * if you want to find the matching closing region for the first opening
64  * brace, you need to do kind of a reference counting to find the correct
65  * closing brace.
66  */
67  quint16 id() const;
68 
69  /**
70  * Returns whether this is the begin or end of a region.
71  *
72  * @note The FoldingRegion%s passed in AbstractHighlighter::applyFolding()
73  * are always valid, i.e. either Type::Begin or Type::End.
74  */
75  Type type() const;
76 
77 private:
78  friend class Rule;
79  FoldingRegion(Type type, quint16 id);
80 
81  quint16 m_type : 2;
82  quint16 m_id : 14;
83 };
84 
85 }
86 
87 QT_BEGIN_NAMESPACE
88 Q_DECLARE_TYPEINFO(KSyntaxHighlighting::FoldingRegion, Q_PRIMITIVE_TYPE);
89 QT_END_NAMESPACE
90 
91 #endif
Represents a begin or end of a folding region.
Definition: foldingregion.h:18
@ None
Used internally as indicator for invalid FoldingRegions.
Definition: foldingregion.h:26
@ Begin
Indicates the start of a FoldingRegion.
Definition: foldingregion.h:28
Type
Defines whether a FoldingRegion starts or ends a folding region.
Definition: foldingregion.h:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 26 2022 03:57:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.