Merge remote branch 'origin/2.1'

Conflicts:
	share/qtcreator/templates/mobileapp/app.pro
	share/qtcreator/templates/qmlapp/app.pro
	src/plugins/cpptools/cpptools.pro
This commit is contained in:
dt
2010-10-04 16:07:46 +02:00
386 changed files with 12674 additions and 4573 deletions

View File

@@ -149,20 +149,20 @@ public:
QList<QmlJSQuickFixOperation::Ptr> ComponentFromObjectDef::match(const QmlJSQuickFixState &state)
{
QList<QmlJSQuickFixOperation::Ptr> result;
const int pos = state.currentFile().cursor().position();
QList<Node *> path = state.semanticInfo().astPath(pos);
for (int i = path.size() - 1; i >= 0; --i) {
Node *node = path.at(i);
if (UiObjectDefinition *objDef = cast<UiObjectDefinition *>(node)) {
if (!state.currentFile().isCursorOn(objDef->qualifiedTypeNameId))
return noResult();
// check that the node is not the root node
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
result.append(QmlJSQuickFixOperation::Ptr(new Operation(state, objDef)));
return result;
return singleResult(new Operation(state, objDef));
}
}
}
return result;
return noResult();
}

View File

@@ -63,6 +63,7 @@
#include <texteditor/texteditorsettings.h>
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/refactoroverlay.h>
#include <texteditor/tooltip/tooltip.h>
#include <qmldesigner/qmldesignerconstants.h>
#include <utils/changeset.h>
#include <utils/uncommentselection.h>
@@ -82,7 +83,8 @@
enum {
UPDATE_DOCUMENT_DEFAULT_INTERVAL = 100,
UPDATE_USES_DEFAULT_INTERVAL = 150,
UPDATE_OUTLINE_INTERVAL = 500 // msecs after new semantic info has been arrived / cursor has moved
UPDATE_OUTLINE_INTERVAL = 500, // msecs after new semantic info has been arrived / cursor has moved
TOOLTIP_TIMER_INTERVAL = 1000 // delay after we show the Quick ToolBar after a tooltip
};
using namespace QmlJS;
@@ -678,6 +680,7 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
m_modelManager(0),
m_contextPane(0),
m_updateSelectedElements(false),
m_toolTipPosition(0),
m_findReferences(new FindReferences(this))
{
qRegisterMetaType<QmlJSEditor::Internal::SemanticInfo>("QmlJSEditor::Internal::SemanticInfo");
@@ -725,6 +728,11 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
m_cursorPositionTimer->setSingleShot(true);
connect(m_cursorPositionTimer, SIGNAL(timeout()), this, SLOT(updateCursorPositionNow()));
m_toolTipTimer = new QTimer(this);
m_toolTipTimer->setInterval(TOOLTIP_TIMER_INTERVAL);
m_toolTipTimer->setSingleShot(true);
connect(m_toolTipTimer, SIGNAL(timeout()), this, SLOT(updateToolTipNow()));
baseTextDocument()->setSyntaxHighlighter(new Highlighter(document()));
m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<ModelManagerInterface>();
@@ -750,6 +758,9 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
connect(this, SIGNAL(refactorMarkerClicked(TextEditor::Internal::RefactorMarker)),
SLOT(onRefactorMarkerClicked(TextEditor::Internal::RefactorMarker)));
connect(editableInterface(), SIGNAL(tooltipRequested(TextEditor::ITextEditor*, QPoint, int)),
SLOT(onTooltipRequested(TextEditor::ITextEditor*, QPoint, int)));
setRequestMarkEnabled(true);
}
@@ -973,8 +984,8 @@ static UiQualifiedId *qualifiedTypeNameId(UiObjectMember *m)
void QmlJSTextEditor::updateCursorPositionNow()
{
if (m_contextPane && document() && !semanticInfo().document.isNull() &&
document()->revision() == semanticInfo().document->editorRevision())
if (m_contextPane && document() && semanticInfo().isValid()
&& document()->revision() == semanticInfo().document->editorRevision())
{
Node *oldNode = m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition);
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
@@ -1034,6 +1045,18 @@ void QmlJSTextEditor::setUpdateSelectedElements(bool value)
m_updateSelectedElements = value;
}
void QmlJSTextEditor::renameId(const QString &oldId, const QString &newId)
{
Utils::ChangeSet changeSet;
foreach (const AST::SourceLocation &loc, m_semanticInfo.idLocations.value(oldId)) {
changeSet.replace(loc.begin(), loc.end(), newId);
}
QTextCursor tc = textCursor();
changeSet.apply(&tc);
}
void QmlJSTextEditor::updateUsesNow()
{
if (document()->revision() != m_semanticInfo.revision()) {
@@ -1202,7 +1225,7 @@ void QmlJSTextEditor::setSelectedElements()
endPos = textCursor().position();
}
if (m_semanticInfo.document) {
if (m_semanticInfo.isValid()) {
SelectedElement selectedMembers;
QList<UiObjectMember *> members = selectedMembers(m_semanticInfo.lookupContext(),
startPos, endPos);
@@ -1231,14 +1254,7 @@ void QmlJSTextEditor::renameIdUnderCursor()
QLineEdit::Normal,
id, &ok);
if (ok) {
Utils::ChangeSet changeSet;
foreach (const AST::SourceLocation &loc, m_semanticInfo.idLocations.value(id)) {
changeSet.replace(loc.begin(), loc.end(), newId);
}
QTextCursor tc = textCursor();
changeSet.apply(&tc);
renameId(id, newId);
}
}
@@ -1443,7 +1459,7 @@ void QmlJSTextEditor::findUsages()
void QmlJSTextEditor::showContextPane()
{
if (m_contextPane) {
if (m_contextPane && m_semanticInfo.isValid()) {
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
m_contextPane->apply(editableInterface(), m_semanticInfo.lookupContext(), newNode, false, true);
m_oldCursorPosition = position();
@@ -1458,6 +1474,28 @@ void QmlJSTextEditor::performQuickFix(int index)
op->perform();
}
void QmlJSTextEditor::onTooltipRequested(TextEditor::ITextEditor* /* editor */, QPoint /* point */, int position)
{
m_toolTipPosition = position;
if (m_contextPane) {
m_toolTipTimer->start();
}
}
void QmlJSTextEditor::updateToolTipNow()
{
if (!TextEditor::ToolTip::instance()->isVisible())
return;
if (m_contextPane && m_semanticInfo.isValid()) {
Node *newNode = m_semanticInfo.declaringMemberNoProperties(m_toolTipPosition);
m_contextPane->apply(editableInterface(), m_semanticInfo.lookupContext(), newNode, false, true);
m_oldCursorPosition = m_toolTipPosition;
QList<TextEditor::Internal::RefactorMarker> markers;
setRefactorMarkers(markers);
}
}
void QmlJSTextEditor::contextMenuEvent(QContextMenuEvent *e)
{
QMenu *menu = new QMenu();
@@ -1536,8 +1574,12 @@ void QmlJSTextEditor::wheelEvent(QWheelEvent *event)
BaseTextEditor::wheelEvent(event);
if (visible)
m_contextPane->apply(editableInterface(), m_semanticInfo.lookupContext(), m_semanticInfo.declaringMemberNoProperties(position()), false, true);
if (visible) {
LookupContext::Ptr lookupContext;
if (m_semanticInfo.isValid())
lookupContext = m_semanticInfo.lookupContext();
m_contextPane->apply(editableInterface(), lookupContext, m_semanticInfo.declaringMemberNoProperties(position()), false, true);
}
}
void QmlJSTextEditor::resizeEvent(QResizeEvent *event)
@@ -1838,8 +1880,12 @@ QModelIndex QmlJSTextEditor::indexForPosition(unsigned cursorPosition, const QMo
bool QmlJSTextEditor::hideContextPane()
{
bool b = (m_contextPane) && m_contextPane->widget()->isVisible();
if (b)
m_contextPane->apply(editableInterface(), m_semanticInfo.lookupContext(), 0, false);
if (b) {
LookupContext::Ptr lookupContext;
if (m_semanticInfo.isValid())
lookupContext = m_semanticInfo.lookupContext();
m_contextPane->apply(editableInterface(), lookupContext, 0, false);
}
return b;
}

View File

@@ -243,6 +243,8 @@ public:
bool updateSelectedElements() const;
void setUpdateSelectedElements(bool value);
void renameId(const QString &oldId, const QString &newId);
public slots:
void followSymbolUnderCursor();
void findUsages();
@@ -279,6 +281,8 @@ private slots:
void onRefactorMarkerClicked(const TextEditor::Internal::RefactorMarker &marker);
void performQuickFix(int index);
void onTooltipRequested(TextEditor::ITextEditor* editor, QPoint point, int position);
void updateToolTipNow();
protected:
void contextMenuEvent(QContextMenuEvent *e);
@@ -316,6 +320,7 @@ private:
QTimer *m_semanticRehighlightTimer;
QTimer *m_updateOutlineTimer;
QTimer *m_updateOutlineIndexTimer;
QTimer *m_toolTipTimer;
QTimer *m_cursorPositionTimer;
QComboBox *m_outlineCombo;
QmlOutlineModel *m_outlineModel;
@@ -333,6 +338,7 @@ private:
QmlJS::IContextPane *m_contextPane;
int m_oldCursorPosition;
bool m_updateSelectedElements;
int m_toolTipPosition;
FindReferences *m_findReferences;
};

View File

@@ -58,6 +58,10 @@ const char * const JS_MIMETYPE = "application/javascript";
const char *const TASK_CATEGORY_QML = "Task.Category.Qml";
const char * const WIZARD_CATEGORY_QML = "S.Qml";
const char * const WIZARD_TR_CATEGORY_QML = QT_TRANSLATE_NOOP("QmlJsEditor", "QML");
} // namespace Constants
} // namespace QmlJSEditor

View File

@@ -134,10 +134,10 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
addObject(m_editor);
Core::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
wizardParameters.setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
wizardParameters.setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
wizardParameters.setDescription(tr("Creates a Qt QML file."));
wizardParameters.setDisplayName(tr("Qt QML File"));
wizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_QML));
wizardParameters.setDisplayCategory(QCoreApplication::translate("QmlJsEditor", Constants::WIZARD_TR_CATEGORY_QML));
wizardParameters.setDescription(tr("Creates a QML file."));
wizardParameters.setDisplayName(tr("QML File"));
wizardParameters.setId(QLatin1String("Q.Qml"));
addAutoReleasedObject(new QmlFileWizard(wizardParameters, core));

View File

@@ -117,6 +117,17 @@ QList<QuickFixOperation::Ptr> QmlJSQuickFixFactory::matchingOperations(QuickFixS
return QList<TextEditor::QuickFixOperation::Ptr>();
}
QList<QmlJSQuickFixOperation::Ptr> QmlJSQuickFixFactory::noResult()
{
return QList<QmlJSQuickFixOperation::Ptr>();
}
QList<QmlJSQuickFixOperation::Ptr> QmlJSQuickFixFactory::singleResult(QmlJSQuickFixOperation *operation)
{
QList<QmlJSQuickFixOperation::Ptr> result;
result.append(QmlJSQuickFixOperation::Ptr(operation));
return result;
}
QmlJSQuickFixCollector::QmlJSQuickFixCollector()
{

View File

@@ -132,6 +132,9 @@ public:
QmlJSQuickFixOperation objects.
*/
virtual QList<QmlJSQuickFixOperation::Ptr> match(const QmlJSQuickFixState &state) = 0;
static QList<QmlJSQuickFixOperation::Ptr> noResult();
static QList<QmlJSQuickFixOperation::Ptr> singleResult(QmlJSQuickFixOperation *operation);
};
namespace Internal {

View File

@@ -52,8 +52,6 @@ class SplitInitializerOp: public QmlJSQuickFixFactory
public:
virtual QList<QmlJSQuickFixOperation::Ptr> match(const QmlJSQuickFixState &state)
{
QList<QmlJSQuickFixOperation::Ptr> result;
UiObjectInitializer *objectInitializer = 0;
const int pos = state.currentFile().cursor().position();
@@ -70,8 +68,9 @@ public:
}
if (objectInitializer)
result.append(QSharedPointer<QmlJSQuickFixOperation>(new Operation(state, objectInitializer)));
return result;
return singleResult(new Operation(state, objectInitializer));
else
return noResult();
}
private:

View File

@@ -30,6 +30,7 @@
#include "qmljsrefactoringchanges.h"
#include "qmljseditorcodeformatter.h"
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabsettings.h>
@@ -109,11 +110,33 @@ Document::Ptr QmlJSRefactoringFile::qmljsDocument() const
return m_qmljsDocument;
}
unsigned QmlJSRefactoringFile::startOf(const QmlJS::AST::SourceLocation &loc) const
unsigned QmlJSRefactoringFile::startOf(const AST::SourceLocation &loc) const
{
return position(loc.startLine, loc.startColumn);
}
bool QmlJSRefactoringFile::isCursorOn(AST::UiObjectMember *ast) const
{
const unsigned pos = cursor().position();
return ast->firstSourceLocation().begin() <= pos
&& pos <= ast->lastSourceLocation().end();
}
bool QmlJSRefactoringFile::isCursorOn(AST::UiQualifiedId *ast) const
{
const unsigned pos = cursor().position();
if (ast->identifierToken.begin() > pos)
return false;
AST::UiQualifiedId *last = ast;
while (last->next)
last = last->next;
return pos <= ast->identifierToken.end();
}
QmlJSRefactoringChanges *QmlJSRefactoringFile::refactoringChanges() const
{
return static_cast<QmlJSRefactoringChanges *>(m_refactoringChanges);

View File

@@ -57,6 +57,9 @@ public:
*/
unsigned startOf(const QmlJS::AST::SourceLocation &loc) const;
bool isCursorOn(QmlJS::AST::UiObjectMember *ast) const;
bool isCursorOn(QmlJS::AST::UiQualifiedId *ast) const;
private:
QmlJSRefactoringChanges *refactoringChanges() const;

View File

@@ -38,7 +38,7 @@ QVariant QmlOutlineItem::data(int role) const
if (role == Qt::ToolTipRole) {
AST::SourceLocation location = m_outlineModel->sourceLocation(index());
AST::UiQualifiedId *uiQualifiedId = m_outlineModel->idNode(index());
if (!uiQualifiedId || !location.isValid())
if (!uiQualifiedId || !location.isValid() || !m_outlineModel->m_semanticInfo.isValid())
return QVariant();
QList<AST::Node *> astPath = m_outlineModel->m_semanticInfo.astPath(location.begin());