KTextEditor

movingrange.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 KTEXTEDITOR_MOVINGRANGE_H
11 #define KTEXTEDITOR_MOVINGRANGE_H
12 
13 #include <ktexteditor/attribute.h>
14 #include <ktexteditor/movingcursor.h>
15 #include <ktexteditor/range.h>
16 #include <ktexteditor_export.h>
17 
18 #include <QDebug>
19 
20 namespace KTextEditor
21 {
22 class Document;
23 class View;
25 
143 class KTEXTEDITOR_EXPORT MovingRange
144 {
145  //
146  // sub types
147  //
148 public:
153  DoNotExpand = 0x0,
155  ExpandLeft = 0x1,
157  ExpandRight = 0x2
158  };
160  Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior)
161 
162 
166  AllowEmpty = 0x0,
167  InvalidateIfEmpty = 0x1
168  };
169 
170  //
171  // stuff that needs to be implemented by editor part cursors
172  //
173 public:
178  virtual void setInsertBehaviors(InsertBehaviors insertBehaviors) = 0;
179 
184  virtual InsertBehaviors insertBehaviors() const = 0;
185 
190  virtual void setEmptyBehavior(EmptyBehavior emptyBehavior) = 0;
191 
196  virtual EmptyBehavior emptyBehavior() const = 0;
197 
202  virtual Document *document() const = 0;
203 
210  virtual void setRange(const KTextEditor::Range &range) = 0;
211 
216  virtual const MovingCursor &start() const = 0;
217 
222  virtual const MovingCursor &end() const = 0;
223 
229  virtual View *view() const = 0;
230 
239  virtual void setView(View *view) = 0;
240 
246  virtual Attribute::Ptr attribute() const = 0;
247 
255  virtual void setAttribute(Attribute::Ptr attribute) = 0;
256 
262  virtual bool attributeOnlyForViews() const = 0;
263 
268  virtual void setAttributeOnlyForViews(bool onlyForViews) = 0;
269 
275  virtual MovingRangeFeedback *feedback() const = 0;
276 
284  virtual void setFeedback(MovingRangeFeedback *feedback) = 0;
285 
300  virtual qreal zDepth() const = 0;
301 
311  virtual void setZDepth(qreal zDepth) = 0;
312 
316  virtual ~MovingRange();
317 
318  //
319  // forbidden stuff
320  //
321 protected:
325  MovingRange();
326 
327 private:
331  MovingRange(const MovingRange &);
332 
336  MovingRange &operator=(const MovingRange &);
337 
338  //
339  // convenience API
340  //
341 public:
350  void setRange(const Cursor &start, const Cursor &end);
351 
356  const Range toRange() const
357  {
358  return Range(start().toCursor(), end().toCursor());
359  }
360 
365  operator Range() const
366  {
367  return Range(start().toCursor(), end().toCursor());
368  }
369 
376  inline friend QDebug operator<<(QDebug s, const MovingRange *range)
377  {
378  if (range) {
379  s << "[" << range->start() << " -> " << range->end() << "]";
380  } else {
381  s << "(null range)";
382  }
383  return s.space();
384  }
385 
392  inline friend QDebug operator<<(QDebug s, const MovingRange &range)
393  {
394  return s << &range;
395  }
396 
403  inline bool isEmpty() const
404  {
405  return start() == end();
406  }
407 
408  // BEGIN comparison functions
422  inline bool contains(const Range &range) const
423  {
424  return range.start() >= start() && range.end() <= end();
425  }
426 
434  inline bool contains(const Cursor &cursor) const
435  {
436  return cursor >= start() && cursor < end();
437  }
438 
446  inline bool containsLine(int line) const
447  {
448  return (line > start().line() || (line == start().line() && !start().column())) && line < end().line();
449  }
450 
458  inline bool containsColumn(int column) const
459  {
460  return column >= start().column() && column < end().column();
461  }
462 
470  bool overlaps(const Range &range) const;
471 
479  inline bool overlapsLine(int line) const
480  {
481  return line >= start().line() && line <= end().line();
482  }
483 
494  inline bool overlapsColumn(int column) const
495  {
496  return start().column() <= column && end().column() > column;
497  }
498 
506  inline bool onSingleLine() const
507  {
508  return start().line() == end().line();
509  }
510 
517  inline int numberOfLines() const Q_DECL_NOEXCEPT
518  {
519  return end().line() - start().line();
520  }
521 
522  // END comparison functions
523 };
524 
525 Q_DECLARE_OPERATORS_FOR_FLAGS(MovingRange::InsertBehaviors)
526 
527 }
528 
529 #endif
MovingRangeFeedback()
Default constructor.
bool contains(const Cursor &cursor) const
Check to see if cursor is contained within this range, ie >= start() and < end(). ...
Definition: movingrange.h:434
virtual const MovingCursor & end() const =0
Retrieve end cursor of this range, read-only.
EmptyBehavior
Behavior of range if it becomes empty.
Definition: movingrange.h:165
virtual const MovingCursor & start() const =0
Retrieve start cursor of this range, read-only.
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:54
const Range toRange() const
Convert this clever range into a dumb one.
Definition: movingrange.h:356
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:143
The Cursor represents a position in a Document.
Definition: cursor.h:71
bool contains(const Range &range) const
Check whether the this range wholly encompasses range.
Definition: movingrange.h:422
int numberOfLines() const Q_DECL_NOEXCEPT
Returns the number of lines separating the start() and end() positions.
Definition: movingrange.h:517
bool overlapsLine(int line) const
Check whether the range overlaps at least part of line.
Definition: movingrange.h:479
bool overlapsColumn(int column) const
Check to see if this range overlaps column; that is, if column is between start().column() and end().column().
Definition: movingrange.h:494
A KParts derived class representing a text document.
Definition: document.h:185
bool isEmpty() const
Returns true if this range contains no characters, ie.
Definition: movingrange.h:403
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
constexpr Cursor start() const Q_DECL_NOEXCEPT
Get the start position of this range.
bool onSingleLine() const
Check whether the start() and end() cursors of this range are on the same line.
Definition: movingrange.h:506
An object representing a section of text, from one Cursor to another.
QDebug & space()
friend QDebug operator<<(QDebug s, const MovingRange &range)
qDebug() stream operator.
Definition: movingrange.h:392
bool containsLine(int line) const
Returns true if this range wholly encompasses line.
Definition: movingrange.h:446
bool containsColumn(int column) const
Check whether the range contains column.
Definition: movingrange.h:458
friend QDebug operator<<(QDebug s, const MovingRange *range)
qDebug() stream operator.
Definition: movingrange.h:376
InsertBehavior
Determine how the range reacts to characters inserted immediately outside the range.
Definition: movingrange.h:151
constexpr Cursor end() const Q_DECL_NOEXCEPT
Get the end position of this range.
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:143
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Dec 4 2020 22:58:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.