• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • kde-4.14
  • applications
  • kate
  • ktexteditor
range.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  * Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
3  * Copyright (C) 2001-2005 Christoph Cullmann <cullmann@kde.org>
4  * Copyright (C) 2002 Christian Couder <christian@kdevelop.org>
5  * Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
6  * Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
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 KDELIBS_KTEXTEDITOR_RANGE_H
25 #define KDELIBS_KTEXTEDITOR_RANGE_H
26 
27 #include <ktexteditor/ktexteditor_export.h>
28 #include <ktexteditor/cursor.h>
29 
30 
31 namespace KTextEditor
32 {
33 class SmartRange;
34 
54 class KTEXTEDITOR_EXPORT Range
55 {
56  friend class Cursor;
57 
58  public:
63  Range();
64 
72  Range(const Cursor& start, const Cursor& end);
73 
81  Range(const Cursor& start, int width);
82 
90  Range(const Cursor& start, int endLine, int endColumn);
91 
100  Range(int startLine, int startColumn, int endLine, int endColumn);
101 
107  Range(const Range& copy);
108 
112  //Do not remove! Needed for inheritance.
113  virtual ~Range();
114 
118  virtual bool isValid() const;
119 
123  static Range invalid();
124 
129  virtual bool isSmartRange() const;
130 
135  virtual SmartRange* toSmartRange() const;
136 
160  Cursor& start();
161 
167  const Cursor& start() const;
168 
186  Cursor& end();
187 
193  const Cursor& end() const;
194 
200  void setBothLines(int line);
201 
207  void setBothColumns(int column);
208 
214  virtual void setRange(const Range& range);
215 
226  void setRange(const Cursor& start, const Cursor& end);
227 
235  virtual bool expandToRange(const Range& range);
236 
244  virtual bool confineToRange(const Range& range);
245 
253  bool onSingleLine() const;
254 
261  int numberOfLines() const;
262 
269  int columnWidth() const;
270 
277  bool isEmpty() const;
278 
279 #if 0
280  // TODO: KDE5 if we have consistency cecks, the following is not needed.
281  // otherwise, if start could possibly be after end, then the following
282  // is handy:
291  inline bool isNormalized() const
292  { return m_start <= m_end; }
293 
302  inline void normalize()
303  {
304  if (isValid() && start > end) {
305  std::swap(m_start, m_end);
306  }
307  }
308 
318  KTextEditor::Range normalize() const
319  {
320  if (isValid()) {
321  if (m_start <= m_end) {
322  return *this;
323  } else {
324  return Range(m_end, m_start);
325  }
326  } else {
327  return invalid();
328  }
329  }
330 #endif
331 
332  //BEGIN comparison functions
349  bool contains(const Range& range) const;
350 
358  bool contains(const Cursor& cursor) const;
359 
367  bool containsLine(int line) const;
368 
376  bool containsColumn(int column) const;
377 
385  bool overlaps(const Range& range) const;
386 
394  bool overlapsLine(int line) const;
395 
406  bool overlapsColumn(int column) const;
407 
421  int positionRelativeToCursor(const Cursor& cursor) const;
422 
435  int positionRelativeToLine(int line) const;
436 
446  bool boundaryAtCursor(const Cursor& cursor) const;
447 
457  bool boundaryOnLine(int line) const;
458 
468  bool boundaryOnColumn(int column) const;
470  //END
471 
480  Range intersect(const Range& range) const;
481 
490  Range encompass(const Range& range) const;
491 
501  inline Range& operator=(const Range& rhs)
502  { setRange(rhs); return *this; }
503 
512  inline friend Range operator+(const Range& r1, const Range& r2)
513  { return Range(r1.start() + r2.start(), r1.end() + r2.end()); }
514 
523  inline friend Range& operator+=(Range& r1, const Range& r2)
524  { r1.setRange(r1.start() + r2.start(), r1.end() + r2.end()); return r1; }
525 
535  inline friend Range operator-(const Range& r1, const Range& r2)
536  { return Range(r1.start() - r2.start(), r1.end() - r2.end()); }
537 
546  inline friend Range& operator-=(Range& r1, const Range& r2)
547  { r1.setRange(r1.start() - r2.start(), r1.end() - r2.end()); return r1; }
548 
557  inline friend Range operator&(const Range& r1, const Range& r2)
558  { return r1.intersect(r2); }
559 
568  inline friend Range& operator&=(Range& r1, const Range& r2)
569  { r1.setRange(r1.intersect(r2)); return r1; }
570 
579  inline friend bool operator==(const Range& r1, const Range& r2)
580  { return r1.start() == r2.start() && r1.end() == r2.end(); }
581 
590  inline friend bool operator!=(const Range& r1, const Range& r2)
591  { return r1.start() != r2.start() || r1.end() != r2.end(); }
592 
602  inline friend bool operator>(const Range& r1, const Range& r2)
603  { return r1.start() > r2.end(); }
604 
614  inline friend bool operator<(const Range& r1, const Range& r2)
615  { return r1.end() < r2.start(); }
616 
620  inline friend QDebug operator<< (QDebug s, const Range& range) {
621  if (&range)
622  s << "[" << range.start() << " -> " << range.end() << "]";
623  else
624  s << "(null range)";
625  return s;
626  }
627 
628  protected:
637  Range(Cursor* start, Cursor* end);
638 
647  virtual void rangeChanged(Cursor* cursor, const Range& from);
648 
654  Cursor* m_start;
655 
661  Cursor* m_end;
662 };
663 
664 }
665 
666 #endif
667 
668 // kate: space-indent on; indent-width 2; replace-tabs on;
KTextEditor::Range::start
Cursor & start()
Get the start position of this range.
Definition: range.cpp:296
KTextEditor::Range::m_start
Cursor * m_start
This range's start cursor pointer.
Definition: range.h:654
cursor.h
KTextEditor::Range::operator==
friend bool operator==(const Range &r1, const Range &r2)
Equality operator.
Definition: range.h:579
KTextEditor::SmartRange
A Range which is bound to a specific Document, and maintains its position.
Definition: smartrange.h:94
KTextEditor::Range::operator+=
friend Range & operator+=(Range &r1, const Range &r2)
Addition assignment operator.
Definition: range.h:523
KTextEditor::Range::setRange
virtual void setRange(const Range &range)
Set the start and end cursors to range.start() and range.end() respectively.
Definition: range.cpp:126
KTextEditor::Cursor
An object which represents a position in a Document.
Definition: cursor.h:55
KTextEditor::Range::operator=
Range & operator=(const Range &rhs)
Assignment operator.
Definition: range.h:501
KTextEditor::Range::m_end
Cursor * m_end
This range's end cursor pointer.
Definition: range.h:661
ktexteditor_export.h
KTextEditor::Range::operator>
friend bool operator>(const Range &r1, const Range &r2)
Greater than operator.
Definition: range.h:602
KTextEditor::Range::operator-
friend Range operator-(const Range &r1, const Range &r2)
Subtraction operator.
Definition: range.h:535
KTextEditor::Range::operator-=
friend Range & operator-=(Range &r1, const Range &r2)
Subtraction assignment operator.
Definition: range.h:546
KTEXTEDITOR_EXPORT
#define KTEXTEDITOR_EXPORT
Definition: ktexteditor_export.h:35
KTextEditor::Range
An object representing a section of text, from one Cursor to another.
Definition: range.h:54
QDebug
KTextEditor::Range::operator!=
friend bool operator!=(const Range &r1, const Range &r2)
Inequality operator.
Definition: range.h:590
KTextEditor::Range::operator&
friend Range operator&(const Range &r1, const Range &r2)
Intersects r1 and r2.
Definition: range.h:557
KTextEditor::Range::end
Cursor & end()
Get the end position of this range.
Definition: range.cpp:306
KTextEditor::Range::intersect
Range intersect(const Range &range) const
Intersects this range with another, returning the shared area of the two ranges.
Definition: range.cpp:316
KTextEditor::Range::operator&=
friend Range & operator&=(Range &r1, const Range &r2)
Intersects r1 with r2 and assigns the result to r1.
Definition: range.h:568
KTextEditor::Range::operator+
friend Range operator+(const Range &r1, const Range &r2)
Addition operator.
Definition: range.h:512
KTextEditor::Range::operator<
friend bool operator<(const Range &r1, const Range &r2)
Less than operator.
Definition: range.h:614
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal