• 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
smartrange.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) 2008 David Nolden <david.nolden.kdevelop@art-master.de>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KDELIBS_KTEXTEDITOR_SMARTRANGE_H
21 #define KDELIBS_KTEXTEDITOR_SMARTRANGE_H
22 
23 #include <ktexteditor/ktexteditor_export.h>
24 #include <ktexteditor/range.h>
25 #include <ktexteditor/smartcursor.h>
26 #include <ktexteditor/attribute.h>
27 
28 #include <QtCore/QList>
29 
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 template <class T> class QStack;
32 #endif
33 
34 class KAction;
35 
36 namespace KTextEditor
37 {
38 class SmartRangeNotifier;
39 class SmartRangeWatcher;
40 
94 class KTEXTEDITOR_EXPORT SmartRange : public Range
95 {
96  friend class SmartCursor;
97 
98  public:
100  enum InsertBehavior {
102  DoNotExpand = 0,
104  ExpandLeft = 0x1,
106  ExpandRight = 0x2
107  };
108  Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior)
109 
110  virtual ~SmartRange();
111 
115  virtual bool isSmartRange() const;
116 
120  virtual SmartRange* toSmartRange() const;
121 
134  virtual void setRange(const Range& range);
135 
143  inline SmartCursor& smartStart()
144  { return *static_cast<SmartCursor*>(m_start); }
145 
153  inline const SmartCursor& smartStart() const
154  { return *static_cast<const SmartCursor*>(m_start); }
155 
163  inline SmartCursor& smartEnd()
164  { return *static_cast<SmartCursor*>(m_end); }
165 
173  inline const SmartCursor& smartEnd() const
174  { return *static_cast<const SmartCursor*>(m_end); }
175 
180  virtual bool confineToRange(const Range& range);
181 
186  virtual bool expandToRange(const Range& range);
187 
188  //BEGIN Functionality present from having this range associated with a Document
203  Document* document() const;
204 
211  virtual QStringList text(bool block = false) const;
212 
220  virtual bool replaceText(const QStringList &text, bool block = false);
221 
229  virtual bool removeText(bool block = false);
230  //END
231 
232  //BEGIN Behavior
246  InsertBehaviors insertBehavior() const;
247 
258  void setInsertBehavior(InsertBehaviors behavior);
259  //END
260 
261  //BEGIN Relationships to other ranges
277  inline SmartRange* parentRange() const
278  { return m_parentRange; }
279 
294  virtual void setParentRange(SmartRange* r);
295 
303  bool hasParent(SmartRange* parent) const;
304 
310  inline int depth() const
311  { return m_parentRange ? m_parentRange->depth() + 1 : 0; }
312 
318  inline SmartRange* topParentRange() const
319  { return parentRange() ? parentRange()->topParentRange() : const_cast<SmartRange*>(this); }
320 
328  const QList<SmartRange*>& childRanges() const;
329 
336  void clearChildRanges();
337 
342  void deleteChildRanges();
343 
348  void clearAndDeleteChildRanges();
349 
358  SmartRange* childBefore( const SmartRange * range ) const;
359 
368  SmartRange* childAfter( const SmartRange * range ) const;
369 
381  SmartRange* mostSpecificRange(const Range& input) const;
382 
391  SmartRange* firstRangeContaining(const Cursor& pos) const;
392 
412  SmartRange* deepestRangeContaining(const Cursor& pos,
413  QStack<SmartRange*>* rangesEntered = 0L,
414  QStack<SmartRange*>* rangesExited = 0L) const;
415 
416  QList<SmartRange*> deepestRangesContaining(const Cursor& pos) const;
417 
422  int overlapCount() const;
423  //END
424 
425  //BEGIN Arbitrary highlighting
439  Attribute::Ptr attribute() const;
440 
450  void setAttribute(Attribute::Ptr attribute);
451  //END
452 
453  //BEGIN Action binding
472  void associateAction(KAction* action);
473 
480  void dissociateAction(KAction* action);
481 
487  const QList<KAction*>& associatedActions() const
488  { return m_associatedActions; }
489 
493  void clearAssociatedActions();
494  //END
495 
496  //BEGIN Notification methods
514  SmartRangeNotifier* primaryNotifier();
515 
520  const QList<SmartRangeNotifier*> notifiers() const;
521 
529  void addNotifier(SmartRangeNotifier* notifier);
530 
536  void removeNotifier(SmartRangeNotifier* notifier);
537 
547  void deletePrimaryNotifier();
548 
556  const QList<SmartRangeWatcher*>& watchers() const;
557 
567  void addWatcher(SmartRangeWatcher* watcher);
568 
574  void removeWatcher(SmartRangeWatcher* watcher);
576  //END
577 
591  inline SmartRange& operator=(const SmartRange& rhs)
592  { setRange(rhs); return *this; }
593 
603  inline SmartRange& operator=(const Range& rhs)
604  { setRange(rhs); return *this; }
605 
606  protected:
622  SmartRange(SmartCursor* start, SmartCursor* end, SmartRange* parent = 0L, InsertBehaviors insertBehavior = DoNotExpand);
623 
632  virtual void rangeChanged(Cursor* cursor, const Range& from);
633 
639  virtual void checkFeedback();
640 
646  virtual SmartRangeNotifier* createNotifier() = 0;
647 
652  void rebuildChildStructure();
653 
654  private:
659  SmartRange(const SmartRange&);
660 
665  SmartRange* deepestRangeContainingInternal(const Cursor& pos,
666  QStack<SmartRange*>* rangesEntered,
667  QStack<SmartRange*>* rangesExited,
668  bool first = false) const;
669 
675  void insertChildRange(SmartRange* newChild);
676 
682  void removeChildRange(SmartRange* newChild);
683 
689  Attribute::Ptr m_attribute;
690 
691  SmartRange* m_parentRange;
692 
698  QList<SmartRange*> m_childRanges;
699 
705  QList<KAction*> m_associatedActions;
706 
712  QList<SmartRangeNotifier*> m_notifiers;
713 
719  QList<SmartRangeWatcher*> m_watchers;
720 
726  bool m_ownsAttribute :1;
733  uchar m_overlapCount:6;
734 };
735 
736 Q_DECLARE_OPERATORS_FOR_FLAGS(SmartRange::InsertBehaviors)
737 
738 }
739 
740 #endif
741 
742 // kate: space-indent on; indent-width 2; replace-tabs on;
KTextEditor::SmartRange::InsertBehavior
InsertBehavior
Determine how the range reacts to characters inserted immediately outside the range.
Definition: smartrange.h:100
KTextEditor::SmartRange::operator=
SmartRange & operator=(const SmartRange &rhs)
Assignment operator.
Definition: smartrange.h:591
KTextEditor::SmartRange
A Range which is bound to a specific Document, and maintains its position.
Definition: smartrange.h:94
KTextEditor::SmartRange::operator=
SmartRange & operator=(const Range &rhs)
Assignment operator.
Definition: smartrange.h:603
KTextEditor::Cursor
An object which represents a position in a Document.
Definition: cursor.h:55
KTextEditor::SmartRange::depth
int depth() const
Calculate the current depth of this range.
Definition: smartrange.h:310
range.h
attribute.h
ktexteditor_export.h
KTextEditor::Document
A KParts derived class representing a text document.
Definition: document.h:111
KTextEditor::Attribute::Ptr
KSharedPtr< Attribute > Ptr
Definition: attribute.h:61
KTextEditor::SmartCursor
A Cursor which is bound to a specific Document, and maintains its position.
Definition: smartcursor.h:65
KTextEditor::SmartRange::smartEnd
SmartCursor & smartEnd()
Get the end point of this range.
Definition: smartrange.h:163
KTEXTEDITOR_EXPORT
#define KTEXTEDITOR_EXPORT
Definition: ktexteditor_export.h:35
QList
KTextEditor::SmartRange::topParentRange
SmartRange * topParentRange() const
Returns the range's top parent range, or this range if there are no parents.
Definition: smartrange.h:318
KTextEditor::SmartRange::smartEnd
const SmartCursor & smartEnd() const
Get the end point of this range.
Definition: smartrange.h:173
QStringList
KTextEditor::Range
An object representing a section of text, from one Cursor to another.
Definition: range.h:54
KTextEditor::SmartRange::associatedActions
const QList< KAction * > & associatedActions() const
Access the list of currently associated KActions.
Definition: smartrange.h:487
smartcursor.h
KTextEditor::SmartRangeWatcher
A class which provides notifications of state changes to a SmartRange via virtual inheritance...
Definition: smartrangewatcher.h:50
KTextEditor::SmartRangeNotifier
A class which provides notifications of state changes to a SmartRange via QObject signals...
Definition: smartrangenotifier.h:48
KTextEditor::SmartRange::smartStart
const SmartCursor & smartStart() const
Get the start point of this range.
Definition: smartrange.h:153
KTextEditor::SmartRange::parentRange
SmartRange * parentRange() const
Returns this range's parent range, if one exists.
Definition: smartrange.h:277
QStack
Definition: smartrange.h:31
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