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

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • kte5
documentcursor.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org>
4  * Copyright (C) 2012 Dominik Haumann <dhaumann@kde.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef KTEXTEDITOR_DOCUMENT_CURSOR_H
23 #define KTEXTEDITOR_DOCUMENT_CURSOR_H
24 
25 #include <ktexteditor/cursor.h>
26 #include <ktexteditor/document.h>
27 
28 #include "katepartprivate_export.h"
29 
30 namespace KTextEditor {
31 
69 class KATEPART_TESTS_EXPORT DocumentCursor
70 {
71  //
72  // sub types
73  //
74  public:
78  enum WrapBehavior {
79  Wrap = 0x0,
80  NoWrap = 0x1
81  };
82 
83  //
84  // Constructor
85  //
86  public:
92  DocumentCursor(KTextEditor::Document* document);
93 
97  DocumentCursor(KTextEditor::Document* document, const KTextEditor::Cursor& position);
98 
102  DocumentCursor(KTextEditor::Document* document, int line, int column);
103 
108  DocumentCursor (const DocumentCursor &other);
109 
110  //
111  // stuff that needs to be implemented by editor part cusors
112  //
113  public:
114 
119  Document *document () const;
120 
128  void setPosition (const KTextEditor::Cursor& position);
129 
134  int line() const;
135 
140  int column() const;
141 
145  ~DocumentCursor ();
146 
147  //
148  // forbidden stuff
149  //
150  private:
154  DocumentCursor ();
155 
156  //
157  // convenience API
158  //
159  public:
160 
166  inline bool isValid() const {
167  return line() >= 0 && column() >= 0;
168  }
169 
175  // TODO KDE5: use KTE::Document::isValidTextPosition()
176  inline bool isValidTextPosition() const {
177  return isValid() && line() < document()->lines() && column() <= document()->lineLength(line());
178  }
179 
196  void makeValid();
197 
206  void setPosition (int line, int column);
207 
212  void setLine(int line);
213 
218  void setColumn(int column);
219 
225  bool atStartOfLine() const;
226 
232  bool atEndOfLine() const;
233 
239  bool atStartOfDocument() const;
240 
247  bool atEndOfDocument() const;
248 
256  bool gotoNextLine();
257 
265  bool gotoPreviousLine();
266 
278  bool move(int chars, WrapBehavior wrapBehavior = Wrap);
279 
284  const Cursor& toCursor () const;
285 
290  operator const Cursor& () const;
291 
292  //
293  // operators for: DocumentCursor <-> DocumentCursor
294  //
299  DocumentCursor &operator= (const DocumentCursor &other);
300 
311  inline friend bool operator==(const DocumentCursor& c1, const DocumentCursor& c2)
312  { return c1.document() == c2.document() && c1.line() == c2.line() && c1.column() == c2.column(); }
313 
320  inline friend bool operator!=(const DocumentCursor& c1, const DocumentCursor& c2)
321  { return !(c1 == c2); }
322 
330  inline friend bool operator>(const DocumentCursor& c1, const DocumentCursor& c2)
331  { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() > c2.column()); }
332 
340  inline friend bool operator>=(const DocumentCursor& c1, const DocumentCursor& c2)
341  { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() >= c2.column()); }
342 
350  inline friend bool operator<(const DocumentCursor& c1, const DocumentCursor& c2)
351  { return !(c1 >= c2); }
352 
360  inline friend bool operator<=(const DocumentCursor& c1, const DocumentCursor& c2)
361  { return !(c1 > c2); }
362 
369  inline friend QDebug operator<< (QDebug s, const DocumentCursor *cursor) {
370  if (cursor)
371  s.nospace() << "(" << cursor->document() << ": " << cursor->line() << ", " << cursor->column() << ")";
372  else
373  s.nospace() << "(null document cursor)";
374  return s.space();
375  }
376 
383  inline friend QDebug operator<< (QDebug s, const DocumentCursor &cursor) {
384  return s << &cursor;
385  }
386 
387  private:
388  KTextEditor::Document* m_document;
389  KTextEditor::Cursor m_cursor;
390 };
391 
392 }
393 
394 #endif
395 
396 // kate: space-indent on; indent-width 2; replace-tabs on;
KTextEditor::DocumentCursor::operator>=
friend bool operator>=(const DocumentCursor &c1, const DocumentCursor &c2)
Greater than or equal to operator.
Definition: documentcursor.h:340
KTextEditor::DocumentCursor::operator!=
friend bool operator!=(const DocumentCursor &c1, const DocumentCursor &c2)
Inequality operator.
Definition: documentcursor.h:320
KTextEditor::DocumentCursor::isValidTextPosition
bool isValidTextPosition() const
Check whether the current position of this cursor is a valid text position.
Definition: documentcursor.h:176
KTextEditor::DocumentCursor
A Cursor which is bound to a specific Document.
Definition: documentcursor.h:69
QDebug::nospace
QDebug & nospace()
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
KTextEditor::DocumentCursor::operator<=
friend bool operator<=(const DocumentCursor &c1, const DocumentCursor &c2)
Less than or equal to operator.
Definition: documentcursor.h:360
KTextEditor::DocumentCursor::operator==
friend bool operator==(const DocumentCursor &c1, const DocumentCursor &c2)
Equality operator.
Definition: documentcursor.h:311
KTextEditor::DocumentCursor::isValid
bool isValid() const
Returns whether the current position of this cursor is a valid position, i.e.
Definition: documentcursor.h:166
KTextEditor::DocumentCursor::line
int line() const
Retrieve the line on which this cursor is situated.
Definition: documentcursor.cpp:77
katepartprivate_export.h
QDebug::space
QDebug & space()
QDebug
KTextEditor::DocumentCursor::operator>
friend bool operator>(const DocumentCursor &c1, const DocumentCursor &c2)
Greater than operator.
Definition: documentcursor.h:330
KTextEditor::DocumentCursor::operator<
friend bool operator<(const DocumentCursor &c1, const DocumentCursor &c2)
Less than operator.
Definition: documentcursor.h:350
KTextEditor::DocumentCursor::column
int column() const
Retrieve the column on which this cursor is situated.
Definition: documentcursor.cpp:82
KTextEditor::DocumentCursor::WrapBehavior
WrapBehavior
Wrap behavior for end of line treatement used in move().
Definition: documentcursor.h:78
KTextEditor::DocumentCursor::document
Document * document() const
Gets the document to which this cursor is bound.
Definition: documentcursor.cpp:63
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • 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