summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper K. Pedersen <jesper.pedersen@kdab.com>2013-05-23 12:55:26 +0000
committerJesper K. Pedersen <jesper.pedersen@kdab.com>2013-05-29 07:25:18 +0200
commit0b7e56aed100c5e0a70b0cadc11a44dcfd2abd5d (patch)
treee6739043377eb2e7880a2433f2a46768d4a896cd
parent5c4418a2be7d0c441a40c9dee7f2ca10d84cc8aa (diff)
make it possible to get text from selection
Change-Id: Iafbba49f5a0ca2c75034e64eaf856d3afa41c718 Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
-rw-r--r--objects/basetexteditor.cpp34
-rw-r--r--objects/basetexteditor.h2
2 files changed, 26 insertions, 10 deletions
diff --git a/objects/basetexteditor.cpp b/objects/basetexteditor.cpp
index 58a427c..8f62091 100644
--- a/objects/basetexteditor.cpp
+++ b/objects/basetexteditor.cpp
@@ -486,16 +486,7 @@ bool BaseTextEditor::findRegexp(const QString &regexp, bool backward, bool caseS
void BaseTextEditor::deleteRegion(const Position &from, const Position &to)
{
- QPointer<Mark> start = createMark();
- gotoPosition(from);
- int fromPos = nativePosition();
- gotoPosition(to);
- int toPos = nativePosition();
- QTextCursor cursor( textEditorWidget()->document());
- cursor.setPosition(fromPos);
- cursor.setPosition(toPos, QTextCursor::KeepAnchor);
- cursor.removeSelectedText();
- gotoMark(start);
+ fetchSelectionAndDelete(from, to, true);
}
void BaseTextEditor::gotoDocumentStart()
@@ -516,6 +507,23 @@ int BaseTextEditor::lineCount()
return 0;
}
+QString BaseTextEditor::fetchSelectionAndDelete(const Position &from, const Position &to, bool del)
+{
+ QPointer<Mark> start = createMark();
+ gotoPosition(from);
+ int fromPos = nativePosition();
+ gotoPosition(to);
+ int toPos = nativePosition();
+ QTextCursor cursor( textEditorWidget()->document());
+ cursor.setPosition(fromPos);
+ cursor.setPosition(toPos, QTextCursor::KeepAnchor);
+ QString text = cursor.selectedText();
+ if (del)
+ cursor.removeSelectedText();
+ gotoMark(start);
+ return text;
+}
+
void BaseTextEditor::indent()
{
if (textEditorWidget())
@@ -543,3 +551,9 @@ QTextDocument::FindFlags BaseTextEditor::flags(bool backward, bool caseSensitive
return textEditor->editorWidget();
return 0;
}
+
+
+QString Scripting::Internal::BaseTextEditor::text(const Scripting::Internal::Position &from, const Scripting::Internal::Position &to)
+{
+ return fetchSelectionAndDelete(from, to, false);
+}
diff --git a/objects/basetexteditor.h b/objects/basetexteditor.h
index 31b9866..10c77ce 100644
--- a/objects/basetexteditor.h
+++ b/objects/basetexteditor.h
@@ -124,11 +124,13 @@ public slots:
bool findRegexp(const QString& regexp, bool backward = false, bool caseSensitively = false, bool wholeWords = false);
void indent();
void deleteRegion( const Position& from, const Position& to);
+ QString text( const Position& from, const Position& to);
void gotoDocumentStart();
void gotoDocumentEnd();
int lineCount();
private:
+ QString fetchSelectionAndDelete( const Position& from, const Position& to, bool del);
QTextDocument::FindFlags flags(bool backward, bool caseSensitively, bool wholeWords) const;
};