Commit e2ef1d82 authored by Christian Kamm's avatar Christian Kamm
Browse files

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: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent fd17d2f9
......@@ -128,60 +128,36 @@ QTextCursor QuickFixOperation::textCursor() const
void QuickFixOperation::setTextCursor(const QTextCursor &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
{ return _doc->translationUnit()->tokenAt(index); }
void QuickFixOperation::getTokenStartPosition(unsigned index, unsigned *line, unsigned *column) 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
int QuickFixOperation::tokenStartPosition(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;
getTokenStartPosition(index, &line, &col);
QTextCursor tc = _textCursor;
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col - 1);
tc.setPosition(tc.position() + tk.f.length, QTextCursor::KeepAnchor);
return tc;
int QuickFixOperation::tokenEndPosition(unsigned index) const
{
unsigned line, column;
_doc->translationUnit()->getPosition(tokenAt(index).end(), &line, &column);
return _textCursor.document()->findBlockByNumber(line - 1).position() + column - 1;
}
QTextCursor QuickFixOperation::moveAtStartOfToken(unsigned index) const
QTextCursor QuickFixOperation::selectToken(unsigned index) const
{
unsigned line, col;
getTokenStartPosition(index, &line, &col);
QTextCursor tc = _textCursor;
tc.setPosition(tc.document()->findBlockByNumber(line - 1).position() + col - 1);
tc.setPosition(tokenStartPosition(index));
tc.setPosition(tokenEndPosition(index), QTextCursor::KeepAnchor);
return tc;
}
QTextCursor QuickFixOperation::moveAtEndOfToken(unsigned index) const
QTextCursor QuickFixOperation::selectNode(AST *ast) 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);
tc.setPosition(tokenStartPosition(ast->firstToken()));
tc.setPosition(tokenEndPosition(ast->lastToken() - 1), QTextCursor::KeepAnchor);
return tc;
}
......
......@@ -70,16 +70,11 @@ public:
protected:
const CPlusPlus::Token &tokenAt(unsigned index) const;
void getTokenStartPosition(unsigned index, unsigned *line,
unsigned *column) const;
void getTokenEndPosition(unsigned index, unsigned *line,
unsigned *column) const;
int tokenStartPosition(unsigned index) const;
int tokenEndPosition(unsigned index) const;
QTextCursor cursor(unsigned index) const;
QTextCursor cursor(CPlusPlus::AST *ast) const;
QTextCursor moveAtStartOfToken(unsigned index) const;
QTextCursor moveAtEndOfToken(unsigned index) const;
QTextCursor selectToken(unsigned index) const;
QTextCursor selectNode(CPlusPlus::AST *ast) const;
private:
CPlusPlus::Document::Ptr _doc;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment