KTextEditor

katetextrange.h
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2010 Christoph Cullmann <[email protected]>
4 
5  Based on code of the SmartCursor/Range by:
6  Copyright (C) 2003-2005 Hamish Rodda <[email protected]>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #ifndef KATE_TEXTRANGE_H
25 #define KATE_TEXTRANGE_H
26 
27 #include <ktexteditor/movingrange.h>
28 #include <ktexteditor/movingrangefeedback.h>
29 #include <ktexteditor/view.h>
30 
31 #include "katetextcursor.h"
32 #include <ktexteditor_export.h>
33 
34 namespace Kate
35 {
36 class TextBuffer;
37 
46 class KTEXTEDITOR_EXPORT TextRange : public KTextEditor::MovingRange
47 {
48  // this is a friend, block changes might invalidate ranges...
49  friend class TextBlock;
50 
51 public:
61  TextRange(TextBuffer &buffer, const KTextEditor::Range &range, InsertBehaviors insertBehavior, EmptyBehavior emptyBehavior = AllowEmpty);
62 
66  ~TextRange() override;
67 
72  void setInsertBehaviors(InsertBehaviors insertBehaviors) override;
73 
78  InsertBehaviors insertBehaviors() const override;
79 
84  void setEmptyBehavior(EmptyBehavior emptyBehavior) override;
85 
90  EmptyBehavior emptyBehavior() const override
91  {
92  return m_invalidateIfEmpty ? InvalidateIfEmpty : AllowEmpty;
93  }
94 
99  KTextEditor::Document *document() const override;
100 
107  void setRange(const KTextEditor::Range &range) override;
108 
117  void setRange(const KTextEditor::Cursor &start, const KTextEditor::Cursor &end)
118  {
120  }
121 
126  const KTextEditor::MovingCursor &start() const override
127  {
128  return m_start;
129  }
130 
135  const TextCursor &startInternal() const
136  {
137  return m_start;
138  }
139 
144  const KTextEditor::MovingCursor &end() const override
145  {
146  return m_end;
147  }
148 
153  const TextCursor &endInternal() const
154  {
155  return m_end;
156  }
157 
163  {
164  return KTextEditor::Range(start().toCursor(), end().toCursor());
165  }
166 
171  operator KTextEditor::Range() const
172  {
173  return KTextEditor::Range(start().toCursor(), end().toCursor());
174  }
175 
181  KTextEditor::View *view() const override
182  {
183  return m_view;
184  }
185 
194  void setView(KTextEditor::View *view) override;
195 
202  {
203  return m_attribute;
204  }
205 
210  bool hasAttribute() const
211  {
212  return m_attribute.constData();
213  }
214 
222  void setAttribute(KTextEditor::Attribute::Ptr attribute) override;
223 
230  {
231  return m_feedback;
232  }
233 
241  void setFeedback(KTextEditor::MovingRangeFeedback *feedback) override;
242 
248  bool attributeOnlyForViews() const override
249  {
250  return m_attributeOnlyForViews;
251  }
252 
257  void setAttributeOnlyForViews(bool onlyForViews) override;
258 
266  qreal zDepth() const override
267  {
268  return m_zDepth;
269  }
270 
280  void setZDepth(qreal zDepth) override;
281 
282 private:
286  TextRange(const TextRange &) = delete;
287 
291  TextRange &operator=(const TextRange &) = delete;
292 
304  void checkValidity(int oldStartLine = -1, int oldEndLine = -1, bool notifyAboutChange = true);
305 
313  void fixLookup(int oldStartLine, int oldEndLine, int startLine, int endLine);
314 
318  void setValidityCheckRequired()
319  {
320  m_isCheckValidityRequired = true;
321  }
322 
327  bool isValidityCheckRequired() const
328  {
329  return m_isCheckValidityRequired;
330  }
331 
332 private:
337  TextBuffer &m_buffer;
338 
342  TextCursor m_start;
343 
347  TextCursor m_end;
348 
352  KTextEditor::View *m_view;
353 
357  KTextEditor::Attribute::Ptr m_attribute;
358 
363 
367  qreal m_zDepth;
368 
372  bool m_attributeOnlyForViews;
373 
377  bool m_invalidateIfEmpty;
378 
384  bool m_isCheckValidityRequired = false;
385 };
386 
387 }
388 
389 #endif
const TextCursor & startInternal() const
Non-virtual version of start(), which is faster.
KTextEditor::View * view() const override
Gets the active view for this range.
EmptyBehavior
Behavior of range if it becomes empty.
Definition: movingrange.h:179
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:68
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:157
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:85
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:199
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:90
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:155
Class representing a &#39;clever&#39; text range.
Definition: katetextrange.h:46
Class representing a text block.
Definition: katetextblock.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 23:00:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.