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
00020 #ifndef KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00021 #define KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00022
00023 #include <ktexteditor/ktexteditor_export.h>
00024 #include <ktexteditor/range.h>
00025 #include <ktexteditor/smartcursor.h>
00026 #include <ktexteditor/attribute.h>
00027
00028 #include <QtCore/QList>
00029
00030 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00031 template <class T> class QStack;
00032 #endif
00033
00034 class KAction;
00035
00036 namespace KTextEditor
00037 {
00038 class SmartRangeNotifier;
00039 class SmartRangeWatcher;
00040
00094 class KTEXTEDITOR_EXPORT SmartRange : public Range
00095 {
00096 friend class SmartCursor;
00097
00098 public:
00100 enum InsertBehavior {
00102 DoNotExpand = 0,
00104 ExpandLeft = 0x1,
00106 ExpandRight = 0x2
00107 };
00108 Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior)
00109
00110 virtual ~SmartRange();
00111
00115 virtual bool isSmartRange() const;
00116
00120 virtual SmartRange* toSmartRange() const;
00121
00134 virtual void setRange(const Range& range);
00135
00143 inline SmartCursor& smartStart()
00144 { return *static_cast<SmartCursor*>(m_start); }
00145
00153 inline const SmartCursor& smartStart() const
00154 { return *static_cast<const SmartCursor*>(m_start); }
00155
00163 inline SmartCursor& smartEnd()
00164 { return *static_cast<SmartCursor*>(m_end); }
00165
00173 inline const SmartCursor& smartEnd() const
00174 { return *static_cast<const SmartCursor*>(m_end); }
00175
00180 virtual bool confineToRange(const Range& range);
00181
00186 virtual bool expandToRange(const Range& range);
00187
00188
00203 Document* document() const;
00204
00211 virtual QStringList text(bool block = false) const;
00212
00220 virtual bool replaceText(const QStringList &text, bool block = false);
00221
00229 virtual bool removeText(bool block = false);
00230
00231
00232
00246 InsertBehaviors insertBehavior() const;
00247
00258 void setInsertBehavior(InsertBehaviors behavior);
00259
00260
00261
00277 inline SmartRange* parentRange() const
00278 { return m_parentRange; }
00279
00294 virtual void setParentRange(SmartRange* r);
00295
00303 bool hasParent(SmartRange* parent) const;
00304
00310 inline int depth() const
00311 { return m_parentRange ? m_parentRange->depth() + 1 : 0; }
00312
00318 inline SmartRange* topParentRange() const
00319 { return parentRange() ? parentRange()->topParentRange() : const_cast<SmartRange*>(this); }
00320
00328 const QList<SmartRange*>& childRanges() const;
00329
00336 void clearChildRanges();
00337
00342 void deleteChildRanges();
00343
00348 void clearAndDeleteChildRanges();
00349
00358 SmartRange* childBefore( const SmartRange * range ) const;
00359
00368 SmartRange* childAfter( const SmartRange * range ) const;
00369
00381 SmartRange* mostSpecificRange(const Range& input) const;
00382
00391 SmartRange* firstRangeContaining(const Cursor& pos) const;
00392
00412 SmartRange* deepestRangeContaining(const Cursor& pos,
00413 QStack<SmartRange*>* rangesEntered = 0L,
00414 QStack<SmartRange*>* rangesExited = 0L) const;
00415
00416 QList<SmartRange*> deepestRangesContaining(const Cursor& pos) const;
00417
00422 int overlapCount() const;
00423
00424
00425
00439 Attribute::Ptr attribute() const;
00440
00450 void setAttribute(Attribute::Ptr attribute);
00451
00452
00453
00472 void associateAction(KAction* action);
00473
00480 void dissociateAction(KAction* action);
00481
00487 const QList<KAction*>& associatedActions() const
00488 { return m_associatedActions; }
00489
00493 void clearAssociatedActions();
00494
00495
00496
00514 SmartRangeNotifier* primaryNotifier();
00515
00520 const QList<SmartRangeNotifier*> notifiers() const;
00521
00527 void addNotifier(SmartRangeNotifier* notifier);
00528
00534 void removeNotifier(SmartRangeNotifier* notifier);
00535
00545 void deletePrimaryNotifier();
00546
00554 const QList<SmartRangeWatcher*>& watchers() const;
00555
00563 void addWatcher(SmartRangeWatcher* watcher);
00564
00570 void removeWatcher(SmartRangeWatcher* watcher);
00572
00573
00587 inline SmartRange& operator=(const SmartRange& rhs)
00588 { setRange(rhs); return *this; }
00589
00599 inline SmartRange& operator=(const Range& rhs)
00600 { setRange(rhs); return *this; }
00601
00602 protected:
00618 SmartRange(SmartCursor* start, SmartCursor* end, SmartRange* parent = 0L, InsertBehaviors insertBehavior = DoNotExpand);
00619
00628 virtual void rangeChanged(Cursor* cursor, const Range& from);
00629
00635 virtual void checkFeedback();
00636
00642 virtual SmartRangeNotifier* createNotifier() = 0;
00643
00648 void rebuildChildStructure();
00649
00650 private:
00655 SmartRange(const SmartRange&);
00656
00661 SmartRange* deepestRangeContainingInternal(const Cursor& pos,
00662 QStack<SmartRange*>* rangesEntered,
00663 QStack<SmartRange*>* rangesExited,
00664 bool first = false) const;
00665
00671 void insertChildRange(SmartRange* newChild);
00672
00678 void removeChildRange(SmartRange* newChild);
00679
00685 Attribute::Ptr m_attribute;
00686
00687 SmartRange* m_parentRange;
00688
00694 QList<SmartRange*> m_childRanges;
00695
00701 QList<KAction*> m_associatedActions;
00702
00708 QList<SmartRangeNotifier*> m_notifiers;
00709
00715 QList<SmartRangeWatcher*> m_watchers;
00716
00722 bool m_ownsAttribute :1;
00729 uchar m_overlapCount:6;
00730 };
00731
00732 Q_DECLARE_OPERATORS_FOR_FLAGS(SmartRange::InsertBehaviors)
00733
00734 }
00735
00736 #endif
00737
00738