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

KTextEditor

  • sources
  • kde-4.12
  • 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  //BEGIN comparison functions
296  bool contains(const Range& range) const;
297 
305  bool contains(const Cursor& cursor) const;
306 
314  bool containsLine(int line) const;
315 
323  bool containsColumn(int column) const;
324 
332  bool overlaps(const Range& range) const;
333 
341  bool overlapsLine(int line) const;
342 
353  bool overlapsColumn(int column) const;
354 
368  int positionRelativeToCursor(const Cursor& cursor) const;
369 
382  int positionRelativeToLine(int line) const;
383 
393  bool boundaryAtCursor(const Cursor& cursor) const;
394 
404  bool boundaryOnLine(int line) const;
405 
415  bool boundaryOnColumn(int column) const;
417  //END
418 
427  Range intersect(const Range& range) const;
428 
437  Range encompass(const Range& range) const;
438 
448  inline Range& operator=(const Range& rhs)
449  { setRange(rhs); return *this; }
450 
459  inline friend Range operator+(const Range& r1, const Range& r2)
460  { return Range(r1.start() + r2.start(), r1.end() + r2.end()); }
461 
470  inline friend Range& operator+=(Range& r1, const Range& r2)
471  { r1.setRange(r1.start() + r2.start(), r1.end() + r2.end()); return r1; }
472 
482  inline friend Range operator-(const Range& r1, const Range& r2)
483  { return Range(r1.start() - r2.start(), r1.end() - r2.end()); }
484 
493  inline friend Range& operator-=(Range& r1, const Range& r2)
494  { r1.setRange(r1.start() - r2.start(), r1.end() - r2.end()); return r1; }
495 
504  inline friend Range operator&(const Range& r1, const Range& r2)
505  { return r1.intersect(r2); }
506 
515  inline friend Range& operator&=(Range& r1, const Range& r2)
516  { r1.setRange(r1.intersect(r2)); return r1; }
517 
526  inline friend bool operator==(const Range& r1, const Range& r2)
527  { return r1.start() == r2.start() && r1.end() == r2.end(); }
528 
537  inline friend bool operator!=(const Range& r1, const Range& r2)
538  { return r1.start() != r2.start() || r1.end() != r2.end(); }
539 
549  inline friend bool operator>(const Range& r1, const Range& r2)
550  { return r1.start() > r2.end(); }
551 
561  inline friend bool operator<(const Range& r1, const Range& r2)
562  { return r1.end() < r2.start(); }
563 
567  inline friend QDebug operator<< (QDebug s, const Range& range) {
568  if (&range)
569  s << "[" << range.start() << " -> " << range.end() << "]";
570  else
571  s << "(null range)";
572  return s;
573  }
574 
575  protected:
584  Range(Cursor* start, Cursor* end);
585 
594  virtual void rangeChanged(Cursor* cursor, const Range& from);
595 
601  Cursor* m_start;
602 
608  Cursor* m_end;
609 };
610 
611 }
612 
613 #endif
614 
615 // 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:601
cursor.h
KTextEditor::Range::operator==
friend bool operator==(const Range &r1, const Range &r2)
Equality operator.
Definition: range.h:526
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:470
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:448
KTextEditor::Range::m_end
Cursor * m_end
This range's end cursor pointer.
Definition: range.h:608
ktexteditor_export.h
operator<<
QDebug operator<<(QDebug s, KDebugStreamFunction f)
KTextEditor::Range::operator>
friend bool operator>(const Range &r1, const Range &r2)
Greater than operator.
Definition: range.h:549
KTextEditor::Range::operator-
friend Range operator-(const Range &r1, const Range &r2)
Subtraction operator.
Definition: range.h:482
KTextEditor::Range::operator-=
friend Range & operator-=(Range &r1, const Range &r2)
Subtraction assignment operator.
Definition: range.h:493
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
KTextEditor::Range::operator!=
friend bool operator!=(const Range &r1, const Range &r2)
Inequality operator.
Definition: range.h:537
KTextEditor::Range::operator&
friend Range operator&(const Range &r1, const Range &r2)
Intersects r1 and r2.
Definition: range.h:504
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:515
end
const KShortcut & end()
KTextEditor::Range::operator+
friend Range operator+(const Range &r1, const Range &r2)
Addition operator.
Definition: range.h:459
KTextEditor::Range::operator<
friend bool operator<(const Range &r1, const Range &r2)
Less than operator.
Definition: range.h:561
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:41 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
  • Applications
  •   Libraries
  •     libkonq
  • 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