Changeset View
Changeset View
Standalone View
Standalone View
src/include/ktexteditor/range.h
Context not available. | |||||
54 | */ | 54 | */ | ||
---|---|---|---|---|---|
55 | class KTEXTEDITOR_EXPORT Range | 55 | class KTEXTEDITOR_EXPORT Range | ||
56 | { | 56 | { | ||
57 | Q_GADGET | ||||
58 | Q_PROPERTY(Cursor start READ start WRITE setStart) | ||||
59 | Q_PROPERTY(Cursor end READ end WRITE setEnd) | ||||
60 | | ||||
57 | public: | 61 | public: | ||
58 | /** | 62 | /** | ||
59 | * Default constructor. Creates a valid range from position (0, 0) to | 63 | * Default constructor. Creates a valid range from position (0, 0) to | ||
60 | * position (0, 0). | 64 | * position (0, 0). | ||
61 | */ | 65 | */ | ||
62 | Q_DECL_CONSTEXPR Range() Q_DECL_NOEXCEPT { | 66 | Q_INVOKABLE Q_DECL_CONSTEXPR Range() Q_DECL_NOEXCEPT { | ||
63 | } | 67 | } | ||
64 | 68 | | |||
65 | /** | 69 | /** | ||
Context not available. | |||||
69 | * \param start start position | 73 | * \param start start position | ||
70 | * \param end end position | 74 | * \param end end position | ||
71 | */ | 75 | */ | ||
72 | Q_DECL_CONSTEXPR Range(const Cursor &start, const Cursor &end) Q_DECL_NOEXCEPT | 76 | Q_INVOKABLE Q_DECL_CONSTEXPR Range(const Cursor &start, const Cursor &end) Q_DECL_NOEXCEPT | ||
73 | : m_start(qMin(start, end)) | 77 | : m_start(qMin(start, end)) | ||
74 | , m_end(qMax(start, end)) | 78 | , m_end(qMax(start, end)) | ||
75 | { | 79 | { | ||
Context not available. | |||||
118 | /** | 122 | /** | ||
119 | * Validity check. In the base class, returns true unless the range starts before (0,0). | 123 | * Validity check. In the base class, returns true unless the range starts before (0,0). | ||
120 | */ | 124 | */ | ||
121 | Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOEXCEPT { | 125 | Q_INVOKABLE Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOEXCEPT { | ||
122 | return start().isValid() && end().isValid(); | 126 | return start().isValid() && end().isValid(); | ||
123 | } | 127 | } | ||
124 | 128 | | |||
Context not available. | |||||
619 | KTEXTEDITOR_EXPORT char *toString(const KTextEditor::Range &range); | 623 | KTEXTEDITOR_EXPORT char *toString(const KTextEditor::Range &range); | ||
620 | } | 624 | } | ||
621 | 625 | | |||
626 | inline QJSValue rangeToScriptValue(QJSEngine *engine, const KTextEditor::Range &range) | ||||
627 | { | ||||
628 | QString code = QStringLiteral("new Range(%1, %2, %3, %4);").arg(range.start().line()) | ||||
629 | .arg(range.start().column()) | ||||
630 | .arg(range.end().line()) | ||||
631 | .arg(range.end().column()); | ||||
632 | QJSValue result = engine->evaluate(code); | ||||
633 | Q_ASSERT(!result.isError()); | ||||
634 | return result; | ||||
635 | } | ||||
636 | | ||||
637 | inline void rangeFromScriptValue(const QJSValue &obj, KTextEditor::Range &range) | ||||
638 | { | ||||
639 | range.setRange(KTextEditor::Cursor(obj.property(QStringLiteral("start")).property(QStringLiteral("line")).toInt(), | ||||
640 | obj.property(QStringLiteral("start")).property(QStringLiteral("column")).toInt()), | ||||
641 | KTextEditor::Cursor(obj.property(QStringLiteral("end")).property(QStringLiteral("line")).toInt(), | ||||
642 | obj.property(QStringLiteral("end")).property(QStringLiteral("column")).toInt())); | ||||
643 | } | ||||
644 | | ||||
622 | #endif | 645 | #endif | ||
Context not available. |