summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcodecompletion.cpp
diff options
context:
space:
mode:
authorcon <qtc-committer@nokia.com>2009-11-03 18:08:01 +0100
committercon <qtc-committer@nokia.com>2009-11-03 18:08:01 +0100
commitfa3484757122bc75925df38638eae32cb28e711e (patch)
tree6e312bd324364796e66fe37f6d2e41ea6d23c78b /src/plugins/cpptools/cppcodecompletion.cpp
parente77e8e9a287da0d20176402050a04f4fdc14f187 (diff)
parent2c115e934fb5700e42f64491af92b3facfb2cbf0 (diff)
downloadqt-creator-fa3484757122bc75925df38638eae32cb28e711e.tar.gz
Merge commit 'origin/1.3'
Conflicts: src/plugins/debugger/gdb/gdbengine.cpp src/plugins/qt4projectmanager/qt4project.cpp
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
-rw-r--r--src/plugins/cpptools/cppcodecompletion.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index 5cea0c14c9..3e8e1df882 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -214,12 +214,21 @@ protected:
{ _item = newCompletionItem(name->unqualifiedNameId()); }
};
+struct CompleteFunctionDeclaration
+{
+ explicit CompleteFunctionDeclaration(Function *f = 0)
+ : function(f)
+ {}
+
+ Function *function;
+};
} // namespace Internal
} // namespace CppTools
using namespace CppTools::Internal;
+Q_DECLARE_METATYPE(CompleteFunctionDeclaration)
void FakeToolTipFrame::paintEvent(QPaintEvent *)
{
@@ -1074,18 +1083,13 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
Overview overview;
overview.setShowArgumentNames(true);
- // get rid of parentheses and cv-qualifiers
- QString completion = overview(f->type());
- if (f->isVolatile() || f->isConst())
- completion = completion.mid(1, completion.lastIndexOf(')') - 1);
- else
- completion = completion.mid(1, completion.size() - 2);
-
- if (completion.size()) {
- TextEditor::CompletionItem item(this);
- item.text = completion;
- m_completions.append(item);
- }
+ // gets: "parameter list) cv-spec",
+ QString completion = overview(f->type()).mid(1);
+
+ TextEditor::CompletionItem item(this);
+ item.text = completion;
+ item.data = QVariant::fromValue(CompleteFunctionDeclaration(f));
+ m_completions.append(item);
}
return true;
}
@@ -1567,6 +1571,14 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
}
}
}
+
+ if (m_autoInsertBrackets && item.data.canConvert<CompleteFunctionDeclaration>()) {
+ // everything from the closing parenthesis on are extra chars, to
+ // make sure an auto-inserted ")" gets replaced by ") const" if necessary
+ int closingParen = toInsert.lastIndexOf(QLatin1Char(')'));
+ extraChars = toInsert.mid(closingParen);
+ toInsert.truncate(closingParen);
+ }
}
// Avoid inserting characters that are already there