• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • interfaces
  • 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
31namespace KTextEditor
32{
33class SmartRange;
34
54class 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
128 virtual bool isSmartRange() const;
129
133 virtual SmartRange* toSmartRange() const;
134
158 Cursor& start();
159
167 const Cursor& start() const;
168
188 Cursor& end();
189
197 const Cursor& end() const;
198
204 void setBothLines(int line);
205
211 void setBothColumns(int column);
212
218 virtual void setRange(const Range& range);
219
230 void setRange(const Cursor& start, const Cursor& end);
231
239 virtual bool expandToRange(const Range& range);
240
248 virtual bool confineToRange(const Range& range);
249
257 bool onSingleLine() const;
258
265 int numberOfLines() const;
266
273 int columnWidth() const;
274
281 bool isEmpty() const;
282
283 //BEGIN comparison functions
300 bool contains(const Range& range) const;
301
309 bool contains(const Cursor& cursor) const;
310
318 bool containsLine(int line) const;
319
327 bool containsColumn(int column) const;
328
336 bool overlaps(const Range& range) const;
337
345 bool overlapsLine(int line) const;
346
357 bool overlapsColumn(int column) const;
358
372 int positionRelativeToCursor(const Cursor& cursor) const;
373
386 int positionRelativeToLine(int line) const;
387
397 bool boundaryAtCursor(const Cursor& cursor) const;
398
408 bool boundaryOnLine(int line) const;
409
419 bool boundaryOnColumn(int column) const;
421 //END
422
431 Range intersect(const Range& range) const;
432
441 Range encompass(const Range& range) const;
442
452 inline Range& operator=(const Range& rhs)
453 { setRange(rhs); return *this; }
454
463 inline friend Range operator+(const Range& r1, const Range& r2)
464 { return Range(r1.start() + r2.start(), r1.end() + r2.end()); }
465
474 inline friend Range& operator+=(Range& r1, const Range& r2)
475 { r1.setRange(r1.start() + r2.start(), r1.end() + r2.end()); return r1; }
476
486 inline friend Range operator-(const Range& r1, const Range& r2)
487 { return Range(r1.start() - r2.start(), r1.end() - r2.end()); }
488
497 inline friend Range& operator-=(Range& r1, const Range& r2)
498 { r1.setRange(r1.start() - r2.start(), r1.end() - r2.end()); return r1; }
499
508 inline friend Range operator&(const Range& r1, const Range& r2)
509 { return r1.intersect(r2); }
510
519 inline friend Range& operator&=(Range& r1, const Range& r2)
520 { r1.setRange(r1.intersect(r2)); return r1; }
521
530 inline friend bool operator==(const Range& r1, const Range& r2)
531 { return r1.start() == r2.start() && r1.end() == r2.end(); }
532
541 inline friend bool operator!=(const Range& r1, const Range& r2)
542 { return r1.start() != r2.start() || r1.end() != r2.end(); }
543
553 inline friend bool operator>(const Range& r1, const Range& r2)
554 { return r1.start() > r2.end(); }
555
565 inline friend bool operator<(const Range& r1, const Range& r2)
566 { return r1.end() < r2.start(); }
567
571 inline friend QDebug operator<< (QDebug s, const Range& range) {
572 if (&range)
573 s << "[" << range.start() << " -> " << range.end() << "]";
574 else
575 s << "(null range)";
576 return s;
577 }
578
579 protected:
588 Range(Cursor* start, Cursor* end);
589
598 virtual void rangeChanged(Cursor* cursor, const Range& from);
599
605 Cursor* m_start;
606
612 Cursor* m_end;
613};
614
615}
616
617#endif
618
619// kate: space-indent on; indent-width 2; replace-tabs on;
KTextEditor::Cursor
An object which represents a position in a Document.
Definition: cursor.h:62
KTextEditor::Range
An object representing a section of text, from one Cursor to another.
Definition: range.h:55
KTextEditor::Range::operator-=
friend Range & operator-=(Range &r1, const Range &r2)
Subtraction assignment operator.
Definition: range.h:497
KTextEditor::Range::m_start
Cursor * m_start
This range's start cursor pointer.
Definition: range.h:605
KTextEditor::Range::operator&=
friend Range & operator&=(Range &r1, const Range &r2)
Intersects r1 with r2 and assigns the result to r1.
Definition: range.h:519
KTextEditor::Range::operator<
friend bool operator<(const Range &r1, const Range &r2)
Less than operator.
Definition: range.h:565
KTextEditor::Range::operator=
Range & operator=(const Range &rhs)
Assignment operator.
Definition: range.h:452
KTextEditor::Range::operator!=
friend bool operator!=(const Range &r1, const Range &r2)
Inequality operator.
Definition: range.h:541
KTextEditor::Range::operator+=
friend Range & operator+=(Range &r1, const Range &r2)
Addition assignment operator.
Definition: range.h:474
KTextEditor::Range::m_end
Cursor * m_end
This range's end cursor pointer.
Definition: range.h:612
KTextEditor::Range::operator==
friend bool operator==(const Range &r1, const Range &r2)
Equality operator.
Definition: range.h:530
KTextEditor::Range::boundaryOnColumn
bool boundaryOnColumn(int column) const
Check whether column is on the same column as either of the start() or end() boundaries.
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+(const Range &r1, const Range &r2)
Addition operator.
Definition: range.h:463
KTextEditor::Range::start
Cursor & start()
Get the start position of this range.
Definition: range.cpp:296
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::Range::operator>
friend bool operator>(const Range &r1, const Range &r2)
Greater than operator.
Definition: range.h:553
KTextEditor::Range::operator&
friend Range operator&(const Range &r1, const Range &r2)
Intersects r1 and r2.
Definition: range.h:508
KTextEditor::Range::operator-
friend Range operator-(const Range &r1, const Range &r2)
Subtraction operator.
Definition: range.h:486
KTextEditor::Range::end
Cursor & end()
Get the end position of this range.
Definition: range.cpp:306
KTextEditor::SmartRange
A Range which is bound to a specific Document, and maintains its position.
Definition: smartrange.h:95
cursor.h
ktexteditor_export.h
end
const KShortcut & end()
KTextEditor
Namespace for the KDE Text Editor Interfaces.
Definition: annotationinterface.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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