KTextEditor

katetextfolding.h
1 /*
2  SPDX-FileCopyrightText: 2013 Christoph Cullmann <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KATE_TEXTFOLDING_H
8 #define KATE_TEXTFOLDING_H
9 
10 #include <ktexteditor_export.h>
11 
12 #include "ktexteditor/range.h"
13 
14 #include <QFlags>
15 #include <QJsonArray>
16 #include <QJsonDocument>
17 #include <QObject>
18 
19 namespace Kate
20 {
21 class TextBuffer;
22 class TextCursor;
23 
30 class KTEXTEDITOR_EXPORT TextFolding : public QObject
31 {
32  Q_OBJECT
33 
34 public:
39  explicit TextFolding(TextBuffer &buffer);
40 
44  ~TextFolding();
45 
53  Persistent = 0x1,
54 
58  Folded = 0x2
59  };
60  Q_DECLARE_FLAGS(FoldingRangeFlags, FoldingRangeFlag)
61 
62 
69  qint64 newFoldingRange(const KTextEditor::Range &range, FoldingRangeFlags flags = FoldingRangeFlags());
70 
79  KTextEditor::Range foldingRange(qint64 id) const;
80 
86  bool foldRange(qint64 id);
87 
95  bool unfoldRange(qint64 id, bool remove = false);
96 
105  bool isLineVisible(int line, qint64 *foldedRangeId = nullptr) const;
106 
112  void ensureLineIsVisible(int line);
113 
119  int visibleLines() const;
120 
128  int lineToVisibleLine(int line) const;
129 
137  int visibleLineToLine(int visibleLine) const;
138 
145  QVector<QPair<qint64, FoldingRangeFlags>> foldingRangesStartingOnLine(int line) const;
146 
153  QVector<QPair<qint64, FoldingRangeFlags>> foldingRangesForParentRange(qint64 parentRangeId = -1) const;
154 
159  QJsonDocument exportFoldingRanges() const;
160 
165  void importFoldingRanges(const QJsonDocument &folds);
166 
171  QString debugDump() const;
172 
176  void debugPrint(const QString &title) const;
177 
178 public Q_SLOTS:
183  void clear();
184 
185 Q_SIGNALS:
190  void foldingRangesChanged();
191 
192 private:
196  class FoldingRange
197  {
198  public:
205  FoldingRange(TextBuffer &buffer, const KTextEditor::Range &range, FoldingRangeFlags flags);
206 
210  ~FoldingRange();
211 
212  FoldingRange(const FoldingRange &) = delete;
213  FoldingRange &operator=(const FoldingRange &) = delete;
214 
218  typedef QVector<FoldingRange *> Vector;
219 
224  Kate::TextCursor *start;
225 
230  Kate::TextCursor *end;
231 
235  FoldingRange *parent;
236 
242  FoldingRange::Vector nestedRanges;
243 
247  FoldingRangeFlags flags;
248 
252  qint64 id;
253  };
254 
260  static void exportFoldingRanges(const TextFolding::FoldingRange::Vector &ranges, QJsonArray &folds);
261 
269  static QString debugDump(const TextFolding::FoldingRange::Vector &ranges, bool recurse);
270 
281  bool insertNewFoldingRange(FoldingRange *parent, TextFolding::FoldingRange::Vector &existingRanges, TextFolding::FoldingRange *newRange);
282 
288  bool updateFoldedRangesForNewRange(TextFolding::FoldingRange *newRange);
289 
295  bool updateFoldedRangesForRemovedRange(TextFolding::FoldingRange *oldRange);
296 
302  void appendFoldedRanges(TextFolding::FoldingRange::Vector &newFoldedFoldingRanges, const TextFolding::FoldingRange::Vector &ranges) const;
303 
309  static bool compareRangeByStart(FoldingRange *a, FoldingRange *b);
310 
316  static bool compareRangeByEnd(FoldingRange *a, FoldingRange *b);
317 
323  static bool compareRangeByStartWithLine(int line, FoldingRange *range);
324 
330  static bool compareRangeByLineWithStart(FoldingRange *range, int line);
331 
339  void foldingRangesStartingOnLine(QVector<QPair<qint64, FoldingRangeFlags>> &results, const TextFolding::FoldingRange::Vector &ranges, int line) const;
340 
341 private:
347  TextBuffer &m_buffer;
348 
354  FoldingRange::Vector m_foldingRanges;
355 
361  FoldingRange::Vector m_foldedFoldingRanges;
362 
366  qint64 m_idCounter;
367 
371  QHash<qint64, FoldingRange *> m_idToFoldingRange;
372 };
373 
374 Q_DECLARE_OPERATORS_FOR_FLAGS(TextFolding::FoldingRangeFlags)
375 
376 }
377 
378 #endif
Class representing the folding information for a TextBuffer.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
An object representing a section of text, from one Cursor to another.
FoldingRangeFlag
Folding state of a range.
Class representing a &#39;clever&#39; text cursor.
Class representing a text buffer.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Oct 19 2020 23:03:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.