forked from qt-creator/qt-creator
Make the QuickFixOperation interface more useful.
* Rename cursor(unsigned/AST*) to selectToken and selectNode. These return a cursor that has the given token or AST node selected. * Rename getTokenStart/EndPosition to tokenStart/EndPosition. Instead of returning line and column numbers, return a position usable with text cursors. * Remove moveAtStart/EndOfToken. Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
@@ -128,60 +128,36 @@ QTextCursor QuickFixOperation::textCursor() const
|
|||||||
void QuickFixOperation::setTextCursor(const QTextCursor &cursor)
|
void QuickFixOperation::setTextCursor(const QTextCursor &cursor)
|
||||||
{ _textCursor = cursor; }
|
{ _textCursor = cursor; }
|
||||||
|
|
||||||
QTextCursor QuickFixOperation::cursor(AST *ast) const
|
|
||||||
{
|
|
||||||
TranslationUnit *unit = document()->translationUnit();
|
|
||||||
unsigned startLine, startColumn, endLine, endColumn;
|
|
||||||
unit->getTokenStartPosition(ast->firstToken(), &startLine, &startColumn);
|
|
||||||
unit->getTokenEndPosition(ast->lastToken() - 1, &endLine, &endColumn);
|
|
||||||
|
|
||||||
QTextDocument *textDocument = _textCursor.document();
|
|
||||||
QTextCursor tc(textDocument);
|
|
||||||
tc.setPosition(textDocument->findBlockByNumber(startLine - 1).position() + startColumn - 1);
|
|
||||||
tc.setPosition(textDocument->findBlockByNumber(endLine - 1).position() + endColumn - 1,
|
|
||||||
QTextCursor::KeepAnchor);
|
|
||||||
|
|
||||||
return tc;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CPlusPlus::Token &QuickFixOperation::tokenAt(unsigned index) const
|
const CPlusPlus::Token &QuickFixOperation::tokenAt(unsigned index) const
|
||||||
{ return _doc->translationUnit()->tokenAt(index); }
|
{ return _doc->translationUnit()->tokenAt(index); }
|
||||||
|
|
||||||
void QuickFixOperation::getTokenStartPosition(unsigned index, unsigned *line, unsigned *column) const
|
int QuickFixOperation::tokenStartPosition(unsigned index) const
|
||||||
{ _doc->translationUnit()->getPosition(tokenAt(index).begin(), line, column); }
|
|
||||||
|
|
||||||
void QuickFixOperation::getTokenEndPosition(unsigned index, unsigned *line, unsigned *column) const
|
|
||||||
{ _doc->translationUnit()->getPosition(tokenAt(index).end(), line, column); }
|
|
||||||
|
|
||||||
QTextCursor QuickFixOperation::cursor(unsigned index) const
|
|
||||||
{
|
{
|
||||||
const Token &tk = tokenAt(index);
|
unsigned line, column;
|
||||||
|
_doc->translationUnit()->getPosition(tokenAt(index).begin(), &line, &column);
|
||||||
|
return _textCursor.document()->findBlockByNumber(line - 1).position() + column - 1;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned line, col;
|
int QuickFixOperation::tokenEndPosition(unsigned index) const
|
||||||
getTokenStartPosition(index, &line, &col);
|
{
|
||||||
|
unsigned line, column;
|
||||||
|
_doc->translationUnit()->getPosition(tokenAt(index).end(), &line, &column);
|
||||||
|
return _textCursor.document()->findBlockByNumber(line - 1).position() + column - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextCursor QuickFixOperation::selectToken(unsigned index) const
|
||||||
|
{
|
||||||
QTextCursor tc = _textCursor;
|
QTextCursor tc = _textCursor;
|
||||||
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col - 1);
|
tc.setPosition(tokenStartPosition(index));
|
||||||
tc.setPosition(tc.position() + tk.f.length, QTextCursor::KeepAnchor);
|
tc.setPosition(tokenEndPosition(index), QTextCursor::KeepAnchor);
|
||||||
return tc;
|
return tc;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCursor QuickFixOperation::moveAtStartOfToken(unsigned index) const
|
QTextCursor QuickFixOperation::selectNode(AST *ast) const
|
||||||
{
|
{
|
||||||
unsigned line, col;
|
|
||||||
getTokenStartPosition(index, &line, &col);
|
|
||||||
QTextCursor tc = _textCursor;
|
QTextCursor tc = _textCursor;
|
||||||
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col - 1);
|
tc.setPosition(tokenStartPosition(ast->firstToken()));
|
||||||
return tc;
|
tc.setPosition(tokenEndPosition(ast->lastToken() - 1), QTextCursor::KeepAnchor);
|
||||||
}
|
|
||||||
|
|
||||||
QTextCursor QuickFixOperation::moveAtEndOfToken(unsigned index) const
|
|
||||||
{
|
|
||||||
const Token &tk = tokenAt(index);
|
|
||||||
|
|
||||||
unsigned line, col;
|
|
||||||
getTokenStartPosition(index, &line, &col);
|
|
||||||
QTextCursor tc = _textCursor;
|
|
||||||
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col + tk.f.length - 1);
|
|
||||||
return tc;
|
return tc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,16 +70,11 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
const CPlusPlus::Token &tokenAt(unsigned index) const;
|
const CPlusPlus::Token &tokenAt(unsigned index) const;
|
||||||
void getTokenStartPosition(unsigned index, unsigned *line,
|
int tokenStartPosition(unsigned index) const;
|
||||||
unsigned *column) const;
|
int tokenEndPosition(unsigned index) const;
|
||||||
void getTokenEndPosition(unsigned index, unsigned *line,
|
|
||||||
unsigned *column) const;
|
|
||||||
|
|
||||||
QTextCursor cursor(unsigned index) const;
|
QTextCursor selectToken(unsigned index) const;
|
||||||
QTextCursor cursor(CPlusPlus::AST *ast) const;
|
QTextCursor selectNode(CPlusPlus::AST *ast) const;
|
||||||
|
|
||||||
QTextCursor moveAtStartOfToken(unsigned index) const;
|
|
||||||
QTextCursor moveAtEndOfToken(unsigned index) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CPlusPlus::Document::Ptr _doc;
|
CPlusPlus::Document::Ptr _doc;
|
||||||
|
|||||||
Reference in New Issue
Block a user