KTextEditor
smartrange.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00020 #define KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00021
00022 #include <ktexteditor/ktexteditor_export.h>
00023 #include <ktexteditor/range.h>
00024 #include <ktexteditor/smartcursor.h>
00025 #include <ktexteditor/attribute.h>
00026
00027 #include <QtCore/QList>
00028
00029 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00030 template <class T> class QStack;
00031 #endif
00032
00033 class KAction;
00034
00035 namespace KTextEditor
00036 {
00037 class SmartRangeNotifier;
00038 class SmartRangeWatcher;
00039
00081 class KTEXTEDITOR_EXPORT SmartRange : public Range
00082 {
00083 friend class SmartCursor;
00084
00085 public:
00087 enum InsertBehavior {
00089 DoNotExpand = 0,
00091 ExpandLeft = 0x1,
00093 ExpandRight = 0x2
00094 };
00095 Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior)
00096
00097 virtual ~SmartRange();
00098
00102 virtual bool isSmartRange() const;
00103
00107 virtual SmartRange* toSmartRange() const;
00108
00121 virtual void setRange(const Range& range);
00122
00130 inline SmartCursor& smartStart()
00131 { return *static_cast<SmartCursor*>(m_start); }
00132
00140 inline const SmartCursor& smartStart() const
00141 { return *static_cast<const SmartCursor*>(m_start); }
00142
00150 inline SmartCursor& smartEnd()
00151 { return *static_cast<SmartCursor*>(m_end); }
00152
00160 inline const SmartCursor& smartEnd() const
00161 { return *static_cast<const SmartCursor*>(m_end); }
00162
00167 virtual bool confineToRange(const Range& range);
00168
00173 virtual bool expandToRange(const Range& range);
00174
00175
00190 Document* document() const;
00191
00198 virtual QStringList text(bool block = false) const;
00199
00207 virtual bool replaceText(const QStringList &text, bool block = false);
00208
00216 virtual bool removeText(bool block = false);
00217
00218
00219
00233 InsertBehaviors insertBehavior() const;
00234
00245 void setInsertBehavior(InsertBehaviors behavior);
00246
00247
00248
00264 inline SmartRange* parentRange() const
00265 { return m_parentRange; }
00266
00281 virtual void setParentRange(SmartRange* r);
00282
00290 bool hasParent(SmartRange* parent) const;
00291
00297 inline int depth() const
00298 { return m_parentRange ? m_parentRange->depth() + 1 : 0; }
00299
00305 inline SmartRange* topParentRange() const
00306 { return parentRange() ? parentRange()->topParentRange() : const_cast<SmartRange*>(this); }
00307
00315 const QList<SmartRange*>& childRanges() const;
00316
00323 void clearChildRanges();
00324
00329 void deleteChildRanges();
00330
00335 void clearAndDeleteChildRanges();
00336
00344 SmartRange* childBefore( const SmartRange * range ) const;
00345
00353 SmartRange* childAfter( const SmartRange * range ) const;
00354
00363 SmartRange* mostSpecificRange(const Range& input) const;
00364
00373 SmartRange* firstRangeContaining(const Cursor& pos) const;
00374
00391 SmartRange* deepestRangeContaining(const Cursor& pos,
00392 QStack<SmartRange*>* rangesEntered = 0L,
00393 QStack<SmartRange*>* rangesExited = 0L) const;
00394
00395
00396
00410 Attribute::Ptr attribute() const;
00411
00421 void setAttribute(Attribute::Ptr attribute);
00422
00423
00424
00443 void associateAction(KAction* action);
00444
00451 void dissociateAction(KAction* action);
00452
00458 const QList<KAction*>& associatedActions() const
00459 { return m_associatedActions; }
00460
00464 void clearAssociatedActions();
00465
00466
00467
00485 SmartRangeNotifier* primaryNotifier();
00486
00491 const QList<SmartRangeNotifier*> notifiers() const;
00492
00498 void addNotifier(SmartRangeNotifier* notifier);
00499
00505 void removeNotifier(SmartRangeNotifier* notifier);
00506
00516 void deletePrimaryNotifier();
00517
00525 const QList<SmartRangeWatcher*>& watchers() const;
00526
00534 void addWatcher(SmartRangeWatcher* watcher);
00535
00541 void removeWatcher(SmartRangeWatcher* watcher);
00543
00544
00558 inline SmartRange& operator=(const SmartRange& rhs)
00559 { setRange(rhs); return *this; }
00560
00570 inline SmartRange& operator=(const Range& rhs)
00571 { setRange(rhs); return *this; }
00572
00573 protected:
00588 SmartRange(SmartCursor* start, SmartCursor* end, SmartRange* parent = 0L, InsertBehaviors insertBehavior = DoNotExpand);
00589
00598 virtual void rangeChanged(Cursor* cursor, const Range& from);
00599
00605 virtual void checkFeedback();
00606
00612 virtual SmartRangeNotifier* createNotifier() = 0;
00613
00614 private:
00619 SmartRange(const SmartRange&);
00620
00625 SmartRange* deepestRangeContainingInternal(const Cursor& pos,
00626 QStack<SmartRange*>* rangesEntered,
00627 QStack<SmartRange*>* rangesExited,
00628 bool first = false) const;
00629
00635 void insertChildRange(SmartRange* newChild);
00636
00642 void removeChildRange(SmartRange* newChild);
00643
00649 Attribute::Ptr m_attribute;
00650
00656 SmartRange* m_parentRange;
00657
00663 QList<SmartRange*> m_childRanges;
00664
00670 QList<KAction*> m_associatedActions;
00671
00677 QList<SmartRangeNotifier*> m_notifiers;
00678
00684 QList<SmartRangeWatcher*> m_watchers;
00685
00691 bool m_ownsAttribute :1;
00692 };
00693
00694 Q_DECLARE_OPERATORS_FOR_FLAGS(SmartRange::InsertBehaviors)
00695
00696 }
00697
00698 #endif
00699
00700