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

Kate

  • sources
  • kde-4.12
  • 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  inline bool isValidTextPosition() const {
176  return isValid() && line() < document()->lines() && column() <= document()->lineLength(line());
177  }
178 
187  void setPosition (int line, int column);
188 
193  void setLine(int line);
194 
199  void setColumn(int column);
200 
206  bool atStartOfLine() const;
207 
213  bool atEndOfLine() const;
214 
220  bool atStartOfDocument() const;
221 
228  bool atEndOfDocument() const;
229 
237  bool gotoNextLine();
238 
246  bool gotoPreviousLine();
247 
259  bool move(int chars, WrapBehavior wrapBehavior = Wrap);
260 
265  const Cursor& toCursor () const;
266 
271  operator const Cursor& () const;
272 
273  //
274  // operators for: DocumentCursor <-> DocumentCursor
275  //
280  DocumentCursor &operator= (const DocumentCursor &other);
281 
292  inline friend bool operator==(const DocumentCursor& c1, const DocumentCursor& c2)
293  { return c1.document() == c2.document() && c1.line() == c2.line() && c1.column() == c2.column(); }
294 
301  inline friend bool operator!=(const DocumentCursor& c1, const DocumentCursor& c2)
302  { return !(c1 == c2); }
303 
311  inline friend bool operator>(const DocumentCursor& c1, const DocumentCursor& c2)
312  { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() > c2.column()); }
313 
321  inline friend bool operator>=(const DocumentCursor& c1, const DocumentCursor& c2)
322  { return c1.line() > c2.line() || (c1.line() == c2.line() && c1.column() >= c2.column()); }
323 
331  inline friend bool operator<(const DocumentCursor& c1, const DocumentCursor& c2)
332  { return !(c1 >= c2); }
333 
341  inline friend bool operator<=(const DocumentCursor& c1, const DocumentCursor& c2)
342  { return !(c1 > c2); }
343 
350  inline friend QDebug operator<< (QDebug s, const DocumentCursor *cursor) {
351  if (cursor)
352  s.nospace() << "(" << cursor->document() << ": " << cursor->line() << ", " << cursor->column() << ")";
353  else
354  s.nospace() << "(null document cursor)";
355  return s.space();
356  }
357 
364  inline friend QDebug operator<< (QDebug s, const DocumentCursor &cursor) {
365  return s << &cursor;
366  }
367 
368  private:
369  KTextEditor::Document* m_document;
370  KTextEditor::Cursor m_cursor;
371 };
372 
373 }
374 
375 #endif
376 
377 // 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:321
KTextEditor::DocumentCursor::operator!=
friend bool operator!=(const DocumentCursor &c1, const DocumentCursor &c2)
Inequality operator.
Definition: documentcursor.h:301
KTextEditor::DocumentCursor::isValidTextPosition
bool isValidTextPosition() const
Check whether the current position of this cursor is a valid text position.
Definition: documentcursor.h:175
cursor.h
KTextEditor::DocumentCursor
A Cursor which is bound to a specific Document.
Definition: documentcursor.h:69
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
KTextEditor::Cursor
KTextEditor::DocumentCursor::operator<=
friend bool operator<=(const DocumentCursor &c1, const DocumentCursor &c2)
Less than or equal to operator.
Definition: documentcursor.h:341
KTextEditor::DocumentCursor::operator==
friend bool operator==(const DocumentCursor &c1, const DocumentCursor &c2)
Equality operator.
Definition: documentcursor.h:292
operator<<
QDebug operator<<(QDebug s, KDebugStreamFunction f)
KTextEditor::Document
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
document.h
move
CopyJob * move(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
KTextEditor::DocumentCursor::operator>
friend bool operator>(const DocumentCursor &c1, const DocumentCursor &c2)
Greater than operator.
Definition: documentcursor.h:311
KTextEditor::DocumentCursor::operator<
friend bool operator<(const DocumentCursor &c1, const DocumentCursor &c2)
Less than operator.
Definition: documentcursor.h:331
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-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:51 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
  • 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