KTextEditor

katetextrange.h
1 /*
2  SPDX-FileCopyrightText: 2010 Christoph Cullmann <[email protected]>
3 
4  Based on code of the SmartCursor/Range by:
5  SPDX-FileCopyrightText: 2003-2005 Hamish Rodda <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef KATE_TEXTRANGE_H
11 #define KATE_TEXTRANGE_H
12 
13 #include <ktexteditor/movingrange.h>
14 #include <ktexteditor/movingrangefeedback.h>
15 #include <ktexteditor/view.h>
16 
17 #include "katetextcursor.h"
18 #include <ktexteditor_export.h>
19 
20 namespace Kate
21 {
22 class TextBuffer;
23 
32 class KTEXTEDITOR_EXPORT TextRange : public KTextEditor::MovingRange
33 {
34  // this is a friend, block changes might invalidate ranges...
35  friend class TextBlock;
36 
37 public:
47  TextRange(TextBuffer &buffer, const KTextEditor::Range &range, InsertBehaviors insertBehavior, EmptyBehavior emptyBehavior = AllowEmpty);
48 
52  ~TextRange() override;
53 
58  void setInsertBehaviors(InsertBehaviors insertBehaviors) override;
59 
64  InsertBehaviors insertBehaviors() const override;
65 
70  void setEmptyBehavior(EmptyBehavior emptyBehavior) override;
71 
76  EmptyBehavior emptyBehavior() const override
77  {
78  return m_invalidateIfEmpty ? InvalidateIfEmpty : AllowEmpty;
79  }
80 
85  KTextEditor::Document *document() const override;
86 
93  void setRange(const KTextEditor::Range &range) override;
94 
103  void setRange(const KTextEditor::Cursor &start, const KTextEditor::Cursor &end)
104  {
106  }
107 
112  const KTextEditor::MovingCursor &start() const override
113  {
114  return m_start;
115  }
116 
121  const TextCursor &startInternal() const
122  {
123  return m_start;
124  }
125 
130  const KTextEditor::MovingCursor &end() const override
131  {
132  return m_end;
133  }
134 
139  const TextCursor &endInternal() const
140  {
141  return m_end;
142  }
143 
149  {
150  return KTextEditor::Range(start().toCursor(), end().toCursor());
151  }
152 
157  operator KTextEditor::Range() const
158  {
159  return KTextEditor::Range(start().toCursor(), end().toCursor());
160  }
161 
167  KTextEditor::View *view() const override
168  {
169  return m_view;
170  }
171 
180  void setView(KTextEditor::View *view) override;
181 
188  {
189  return m_attribute;
190  }
191 
196  bool hasAttribute() const
197  {
198  return m_attribute.constData();
199  }
200 
208  void setAttribute(KTextEditor::Attribute::Ptr attribute) override;
209 
216  {
217  return m_feedback;
218  }
219 
227  void setFeedback(KTextEditor::MovingRangeFeedback *feedback) override;
228 
234  bool attributeOnlyForViews() const override
235  {
236  return m_attributeOnlyForViews;
237  }
238 
243  void setAttributeOnlyForViews(bool onlyForViews) override;
244 
252  qreal zDepth() const override
253  {
254  return m_zDepth;
255  }
256 
266  void setZDepth(qreal zDepth) override;
267 
268 private:
272  TextRange(const TextRange &) = delete;
273 
277  TextRange &operator=(const TextRange &) = delete;
278 
289  void checkValidity(KTextEditor::LineRange oldLineRange = KTextEditor::LineRange::invalid(), bool notifyAboutChange = true);
290 
296  void fixLookup(KTextEditor::LineRange oldLineRange, KTextEditor::LineRange lineRange);
297 
301  void setValidityCheckRequired()
302  {
303  m_isCheckValidityRequired = true;
304  }
305 
310  bool isValidityCheckRequired() const
311  {
312  return m_isCheckValidityRequired;
313  }
314 
315 private:
320  TextBuffer &m_buffer;
321 
325  TextCursor m_start;
326 
330  TextCursor m_end;
331 
335  KTextEditor::View *m_view;
336 
340  KTextEditor::Attribute::Ptr m_attribute;
341 
346 
350  qreal m_zDepth;
351 
355  bool m_attributeOnlyForViews;
356 
360  bool m_invalidateIfEmpty;
361 
367  bool m_isCheckValidityRequired = false;
368 };
369 
370 }
371 
372 #endif
const TextCursor & startInternal() const
Non-virtual version of start(), which is faster.
static constexpr LineRange invalid() Q_DECL_NOEXCEPT
Returns an invalid line range.
Definition: linerange.h:70
KTextEditor::View * view() const override
Gets the active view for this range.
EmptyBehavior
Behavior of range if it becomes empty.
Definition: movingrange.h:166
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:54
A class which provides notifications of state changes to a MovingRange.
A range that is bound to a specific Document, and maintains its position.
Definition: movingrange.h:144
const KTextEditor::MovingCursor & start() const override
Retrieve start cursor of this range, read-only.
The Cursor represents a position in a Document.
Definition: cursor.h:71
const TextCursor & endInternal() const
Nonvirtual version of end(), which is faster.
KTextEditor::Attribute::Ptr attribute() const override
Gets the active Attribute for this range.
A KParts derived class representing a text document.
Definition: document.h:185
An object representing lines from a start line to an end line.
Definition: linerange.h:37
const KTextEditor::Range toRange() const
Convert this clever range into a dumb one.
KTextEditor::MovingRangeFeedback * feedback() const override
Gets the active MovingRangeFeedback for this range.
virtual void setRange(const KTextEditor::Range &range)=0
Set the range of this range.
An object representing a section of text, from one Cursor to another.
EmptyBehavior emptyBehavior() const override
Will this range invalidate itself if it becomes empty?
Definition: katetextrange.h:76
bool attributeOnlyForViews() const override
Is this range&#39;s attribute only visible in views, not for example prints? Default is false...
bool hasAttribute() const
const KTextEditor::MovingCursor & end() const override
Retrieve end cursor of this range, read-only.
qreal zDepth() const override
Gets the current Z-depth of this range.
Class representing a &#39;clever&#39; text cursor.
void setRange(const KTextEditor::Cursor &start, const KTextEditor::Cursor &end)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Class representing a text buffer.
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:146
Class representing a &#39;clever&#39; text range.
Definition: katetextrange.h:32
Class representing a text block.
Definition: katetextblock.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jan 27 2021 22:56:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.