2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-02-18 11:47:15 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-02-18 11:47:15 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-02-18 11:47:15 +01:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
#include "qmloutlinemodel.h"
|
2010-07-19 11:39:41 +02:00
|
|
|
#include "qmljseditor.h"
|
2010-07-19 14:28:53 +02:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
#include <qmljs/parser/qmljsastvisitor_p.h>
|
2011-07-01 13:51:53 +02:00
|
|
|
#include <qmljs/qmljscontext.h>
|
2011-08-08 12:26:22 +02:00
|
|
|
#include <qmljs/qmljsscopechain.h>
|
2010-07-19 14:28:53 +02:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
|
|
|
|
#include <qmljs/qmljsrewriter.h>
|
2015-03-04 16:46:23 +01:00
|
|
|
#include <qmljs/qmljsvalueowner.h>
|
2010-11-11 10:05:05 +01:00
|
|
|
#include <qmljstools/qmljsrefactoringchanges.h>
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2015-06-04 12:35:59 +02:00
|
|
|
#include <utils/dropsupport.h>
|
2010-08-25 13:21:38 +02:00
|
|
|
|
2010-07-13 17:05:47 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QTime>
|
|
|
|
|
#include <QMimeData>
|
2010-07-12 09:44:42 +02:00
|
|
|
#include <typeinfo>
|
|
|
|
|
|
|
|
|
|
using namespace QmlJS;
|
|
|
|
|
using namespace QmlJSEditor::Internal;
|
2010-11-11 10:05:05 +01:00
|
|
|
using namespace QmlJSTools;
|
2010-07-12 09:44:42 +02:00
|
|
|
|
|
|
|
|
enum {
|
2010-07-14 13:36:18 +02:00
|
|
|
debug = false
|
2010-07-12 09:44:42 +02:00
|
|
|
};
|
|
|
|
|
|
2014-09-29 14:41:42 +02:00
|
|
|
static const char INTERNAL_MIMETYPE[] = "application/x-qtcreator-qmloutlinemodel";
|
|
|
|
|
|
2010-07-13 17:05:47 +02:00
|
|
|
namespace QmlJSEditor {
|
|
|
|
|
namespace Internal {
|
2010-07-12 09:44:42 +02:00
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QmlOutlineItem::QmlOutlineItem(QmlOutlineModel *model) :
|
2010-08-25 13:21:38 +02:00
|
|
|
m_outlineModel(model)
|
2010-07-19 11:39:41 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant QmlOutlineItem::data(int role) const
|
|
|
|
|
{
|
|
|
|
|
if (role == Qt::ToolTipRole) {
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::SourceLocation location = m_outlineModel->sourceLocation(index());
|
|
|
|
|
AST::UiQualifiedId *uiQualifiedId = m_outlineModel->idNode(index());
|
2010-10-04 14:32:50 +02:00
|
|
|
if (!uiQualifiedId || !location.isValid() || !m_outlineModel->m_semanticInfo.isValid())
|
2010-07-19 11:39:41 +02:00
|
|
|
return QVariant();
|
|
|
|
|
|
2011-07-04 09:46:10 +02:00
|
|
|
QList<AST::Node *> astPath = m_outlineModel->m_semanticInfo.rangePath(location.begin());
|
2011-08-08 12:47:49 +02:00
|
|
|
ScopeChain scopeChain = m_outlineModel->m_semanticInfo.scopeChain(astPath);
|
|
|
|
|
const Value *value = scopeChain.evaluate(uiQualifiedId);
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2011-08-08 12:26:22 +02:00
|
|
|
return prettyPrint(value, scopeChain.context());
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (role == Qt::DecorationRole)
|
2010-08-25 13:21:38 +02:00
|
|
|
return m_outlineModel->icon(index());
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
return QStandardItem::data(role);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 14:28:53 +02:00
|
|
|
int QmlOutlineItem::type() const
|
|
|
|
|
{
|
|
|
|
|
return UserType;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
void QmlOutlineItem::setItemData(const QMap<int, QVariant> &roles)
|
|
|
|
|
{
|
|
|
|
|
QMap<int,QVariant>::const_iterator iter(roles.constBegin());
|
|
|
|
|
while (iter != roles.constEnd()) {
|
|
|
|
|
setData(iter.value(), iter.key());
|
2014-05-21 20:25:42 +03:00
|
|
|
++iter;
|
2010-08-31 10:57:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
QString QmlOutlineItem::prettyPrint(const Value *value, const ContextPtr &context) const
|
2010-07-19 11:39:41 +02:00
|
|
|
{
|
|
|
|
|
if (! value)
|
|
|
|
|
return QString();
|
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
if (const ObjectValue *objectValue = value->asObjectValue()) {
|
2010-07-19 11:39:41 +02:00
|
|
|
const QString className = objectValue->className();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!className.isEmpty())
|
2010-07-19 11:39:41 +02:00
|
|
|
return className;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-01 12:11:02 +02:00
|
|
|
const QString typeId = context->valueOwner()->typeId(value);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (typeId == QLatin1String("undefined"))
|
2010-07-19 11:39:41 +02:00
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
return typeId;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 14:28:53 +02:00
|
|
|
/**
|
|
|
|
|
Returns mapping of every UiObjectMember object to it's direct UiObjectMember parent object.
|
|
|
|
|
*/
|
|
|
|
|
class ObjectMemberParentVisitor : public AST::Visitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QHash<AST::UiObjectMember*,AST::UiObjectMember*> operator()(Document::Ptr doc) {
|
|
|
|
|
parent.clear();
|
|
|
|
|
if (doc && doc->ast())
|
|
|
|
|
doc->ast()->accept(this);
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QHash<AST::UiObjectMember*,AST::UiObjectMember*> parent;
|
|
|
|
|
QList<AST::UiObjectMember *> stack;
|
|
|
|
|
|
|
|
|
|
bool preVisit(AST::Node *node)
|
|
|
|
|
{
|
|
|
|
|
if (AST::UiObjectMember *objMember = node->uiObjectMemberCast())
|
|
|
|
|
stack.append(objMember);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void postVisit(AST::Node *node)
|
|
|
|
|
{
|
|
|
|
|
if (AST::UiObjectMember *objMember = node->uiObjectMemberCast()) {
|
|
|
|
|
stack.removeLast();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!stack.isEmpty())
|
2010-07-19 14:28:53 +02:00
|
|
|
parent.insert(objMember, stack.last());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
class QmlOutlineModelSync : protected AST::Visitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QmlOutlineModelSync(QmlOutlineModel *model) :
|
|
|
|
|
m_model(model),
|
|
|
|
|
indent(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
void operator()(Document::Ptr doc)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
|
|
|
|
m_nodeToIndex.clear();
|
|
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "QmlOutlineModel ------";
|
|
|
|
|
if (doc && doc->ast())
|
|
|
|
|
doc->ast()->accept(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool preVisit(AST::Node *node)
|
|
|
|
|
{
|
|
|
|
|
if (!node)
|
|
|
|
|
return false;
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "QmlOutlineModel -" << QByteArray(indent++, '-').constData() << node << typeid(*node).name();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void postVisit(AST::Node *)
|
|
|
|
|
{
|
|
|
|
|
indent--;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-13 17:05:47 +02:00
|
|
|
typedef QPair<QString,QString> ElementType;
|
2010-07-12 09:44:42 +02:00
|
|
|
bool visit(AST::UiObjectDefinition *objDef)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex index = m_model->enterObjectDefinition(objDef);
|
2010-07-12 09:44:42 +02:00
|
|
|
m_nodeToIndex.insert(objDef, index);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 13:34:49 +02:00
|
|
|
void endVisit(AST::UiObjectDefinition * /*objDef*/)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
m_model->leaveObjectDefiniton();
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
bool visit(AST::UiObjectBinding *objBinding)
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index = m_model->enterObjectBinding(objBinding);
|
|
|
|
|
m_nodeToIndex.insert(objBinding, index);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endVisit(AST::UiObjectBinding * /*objBinding*/)
|
|
|
|
|
{
|
|
|
|
|
m_model->leaveObjectBinding();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool visit(AST::UiArrayBinding *arrayBinding)
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index = m_model->enterArrayBinding(arrayBinding);
|
|
|
|
|
m_nodeToIndex.insert(arrayBinding, index);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endVisit(AST::UiArrayBinding * /*arrayBinding*/)
|
|
|
|
|
{
|
|
|
|
|
m_model->leaveArrayBinding();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
bool visit(AST::UiScriptBinding *scriptBinding)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex index = m_model->enterScriptBinding(scriptBinding);
|
2010-07-12 09:44:42 +02:00
|
|
|
m_nodeToIndex.insert(scriptBinding, index);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endVisit(AST::UiScriptBinding * /*scriptBinding*/)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
m_model->leaveScriptBinding();
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-14 13:32:42 +02:00
|
|
|
bool visit(AST::UiPublicMember *publicMember)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex index = m_model->enterPublicMember(publicMember);
|
2010-07-14 13:32:42 +02:00
|
|
|
m_nodeToIndex.insert(publicMember, index);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endVisit(AST::UiPublicMember * /*publicMember*/)
|
|
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
m_model->leavePublicMember();
|
2010-07-14 13:32:42 +02:00
|
|
|
}
|
2010-07-12 15:51:26 +02:00
|
|
|
|
2010-09-27 15:36:50 +02:00
|
|
|
bool visit(AST::FunctionDeclaration *functionDeclaration)
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index = m_model->enterFunctionDeclaration(functionDeclaration);
|
|
|
|
|
m_nodeToIndex.insert(functionDeclaration, index);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void endVisit(AST::FunctionDeclaration * /*functionDeclaration*/)
|
|
|
|
|
{
|
|
|
|
|
m_model->leaveFunctionDeclaration();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-27 18:10:00 +10:00
|
|
|
bool visit(AST::BinaryExpression *binExp)
|
|
|
|
|
{
|
|
|
|
|
AST::IdentifierExpression *lhsIdent = AST::cast<AST::IdentifierExpression *>(binExp->left);
|
|
|
|
|
AST::ObjectLiteral *rhsObjLit = AST::cast<AST::ObjectLiteral *>(binExp->right);
|
|
|
|
|
|
2012-12-03 15:36:45 +01:00
|
|
|
if (lhsIdent && rhsObjLit && (lhsIdent->name == QLatin1String("testcase"))
|
2011-07-27 18:10:00 +10:00
|
|
|
&& (binExp->op == QSOperator::Assign)) {
|
|
|
|
|
QModelIndex index = m_model->enterTestCase(rhsObjLit);
|
|
|
|
|
m_nodeToIndex.insert(rhsObjLit, index);
|
|
|
|
|
|
2013-11-06 14:17:23 +01:00
|
|
|
if (AST::PropertyAssignmentList *properties = rhsObjLit->properties)
|
2011-07-27 18:10:00 +10:00
|
|
|
visitProperties(properties);
|
|
|
|
|
|
|
|
|
|
m_model->leaveTestCase();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 14:17:23 +01:00
|
|
|
void visitProperties(AST::PropertyAssignmentList *properties)
|
2011-07-27 18:10:00 +10:00
|
|
|
{
|
|
|
|
|
while (properties) {
|
|
|
|
|
QModelIndex index = m_model->enterTestCaseProperties(properties);
|
|
|
|
|
m_nodeToIndex.insert(properties, index);
|
2013-11-06 14:17:23 +01:00
|
|
|
if (AST::PropertyNameAndValue *assignment = AST::cast<AST::PropertyNameAndValue *>(properties->assignment))
|
|
|
|
|
if (AST::ObjectLiteral *objLiteral = AST::cast<AST::ObjectLiteral *>(assignment->value))
|
|
|
|
|
visitProperties(objLiteral->properties);
|
2011-07-27 18:10:00 +10:00
|
|
|
|
|
|
|
|
m_model->leaveTestCaseProperties();
|
|
|
|
|
properties = properties->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
QmlOutlineModel *m_model;
|
2010-07-13 17:05:47 +02:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
QHash<AST::Node*, QModelIndex> m_nodeToIndex;
|
|
|
|
|
int indent;
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-29 17:34:09 +03:00
|
|
|
QmlOutlineModel::QmlOutlineModel(QmlJSEditorDocument *document) :
|
|
|
|
|
QStandardItemModel(document),
|
|
|
|
|
m_editorDocument(document)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-07-13 17:05:47 +02:00
|
|
|
m_icons = Icons::instance();
|
2012-01-24 15:36:40 +01:00
|
|
|
const QString resourcePath = Core::ICore::resourcePath();
|
2012-11-26 21:17:34 +02:00
|
|
|
Icons::instance()->setIconFilesPath(resourcePath + QLatin1String("/qmlicons"));
|
2010-07-19 14:28:53 +02:00
|
|
|
|
|
|
|
|
setItemPrototype(new QmlOutlineItem(this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList QmlOutlineModel::mimeTypes() const
|
|
|
|
|
{
|
|
|
|
|
QStringList types;
|
2014-09-29 14:41:42 +02:00
|
|
|
types << QLatin1String(INTERNAL_MIMETYPE);
|
2015-06-04 12:35:59 +02:00
|
|
|
types << Utils::DropSupport::mimeTypesForFilePaths();
|
2010-07-19 14:28:53 +02:00
|
|
|
return types;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const
|
|
|
|
|
{
|
|
|
|
|
if (indexes.count() <= 0)
|
|
|
|
|
return 0;
|
2015-06-04 12:35:59 +02:00
|
|
|
auto data = new Utils::DropMimeData;
|
2014-09-29 14:41:42 +02:00
|
|
|
data->setOverrideFileDropAction(Qt::CopyAction);
|
2010-07-19 14:28:53 +02:00
|
|
|
QByteArray encoded;
|
|
|
|
|
QDataStream stream(&encoded, QIODevice::WriteOnly);
|
|
|
|
|
stream << indexes.size();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < indexes.size(); ++i) {
|
2010-08-09 17:41:22 +02:00
|
|
|
QModelIndex index = indexes.at(i);
|
|
|
|
|
|
2014-09-29 14:41:42 +02:00
|
|
|
AST::SourceLocation location = sourceLocation(index);
|
2014-12-21 21:54:30 +02:00
|
|
|
data->addFile(m_editorDocument->filePath().toString(), location.startLine,
|
2014-09-29 14:41:42 +02:00
|
|
|
location.startColumn - 1 /*editors have 0-based column*/);
|
|
|
|
|
|
2010-08-09 17:41:22 +02:00
|
|
|
QList<int> rowPath;
|
|
|
|
|
for (QModelIndex i = index; i.isValid(); i = i.parent()) {
|
|
|
|
|
rowPath.prepend(i.row());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stream << rowPath;
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
2014-09-29 14:41:42 +02:00
|
|
|
data->setData(QLatin1String(INTERNAL_MIMETYPE), encoded);
|
2010-07-19 14:28:53 +02:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlOutlineModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int /*column*/, const QModelIndex &parent)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << __FUNCTION__ << row << parent;
|
|
|
|
|
|
|
|
|
|
// check if the action is supported
|
|
|
|
|
if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// We cannot reparent outside of the root item
|
|
|
|
|
if (!parent.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// check if the format is supported
|
|
|
|
|
QStringList types = mimeTypes();
|
|
|
|
|
if (types.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
QString format = types.at(0);
|
|
|
|
|
if (!data->hasFormat(format))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// decode and insert
|
|
|
|
|
QByteArray encoded = data->data(format);
|
|
|
|
|
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
|
|
|
|
int indexSize;
|
|
|
|
|
stream >> indexSize;
|
|
|
|
|
QList<QmlOutlineItem*> itemsToMove;
|
|
|
|
|
for (int i = 0; i < indexSize; ++i) {
|
2010-08-09 17:41:22 +02:00
|
|
|
QList<int> rowPath;
|
|
|
|
|
stream >> rowPath;
|
|
|
|
|
|
|
|
|
|
QModelIndex index;
|
|
|
|
|
foreach (int row, rowPath) {
|
|
|
|
|
index = this->index(row, 0, index);
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itemsToMove << static_cast<QmlOutlineItem*>(itemFromIndex(index));
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlOutlineItem *targetItem = static_cast<QmlOutlineItem*>(itemFromIndex(parent));
|
|
|
|
|
reparentNodes(targetItem, row, itemsToMove);
|
2010-08-09 17:41:22 +02:00
|
|
|
|
|
|
|
|
// Prevent view from calling removeRow() on it's own
|
2010-07-19 14:28:53 +02:00
|
|
|
return false;
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-07 15:25:05 +02:00
|
|
|
Qt::ItemFlags QmlOutlineModel::flags(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return QStandardItemModel::flags(index);
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags flags = Qt::ItemIsSelectable|Qt::ItemIsEnabled;
|
|
|
|
|
|
|
|
|
|
// only allow drag&drop if we're in sync
|
|
|
|
|
if (m_semanticInfo.isValid()
|
2014-01-30 16:10:23 +01:00
|
|
|
&& !m_editorDocument->isSemanticInfoOutdated()) {
|
2010-10-07 15:25:05 +02:00
|
|
|
if (index.parent().isValid())
|
|
|
|
|
flags |= Qt::ItemIsDragEnabled;
|
|
|
|
|
if (index.data(ItemTypeRole) != NonElementBindingType)
|
|
|
|
|
flags |= Qt::ItemIsDropEnabled;
|
|
|
|
|
}
|
|
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-28 17:33:47 +02:00
|
|
|
Qt::DropActions QmlOutlineModel::supportedDragActions() const
|
|
|
|
|
{
|
2014-09-29 14:41:42 +02:00
|
|
|
// copy action used for dragging onto editor splits
|
|
|
|
|
return Qt::MoveAction | Qt::CopyAction;
|
2014-08-28 17:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-07 15:25:05 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
Document::Ptr QmlOutlineModel::document() const
|
2010-07-13 11:18:42 +02:00
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
return m_semanticInfo.document;
|
2010-07-13 11:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
void QmlOutlineModel::update(const SemanticInfo &semanticInfo)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
m_semanticInfo = semanticInfo;
|
2010-09-08 10:11:44 +02:00
|
|
|
if (! m_semanticInfo.isValid())
|
|
|
|
|
return;
|
2010-07-13 11:18:42 +02:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
m_treePos.clear();
|
|
|
|
|
m_treePos.append(0);
|
|
|
|
|
m_currentItem = invisibleRootItem();
|
|
|
|
|
|
2010-10-20 11:52:54 +02:00
|
|
|
// resetModel() actually gives better average performance
|
|
|
|
|
// then the incremental updates.
|
|
|
|
|
beginResetModel();
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
m_typeToIcon.clear();
|
2010-08-25 13:21:38 +02:00
|
|
|
m_itemToNode.clear();
|
|
|
|
|
m_itemToIdNode.clear();
|
|
|
|
|
m_itemToIcon.clear();
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2010-08-25 12:24:47 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QmlOutlineModelSync syncModel(this);
|
2010-07-19 11:39:41 +02:00
|
|
|
syncModel(m_semanticInfo.document);
|
|
|
|
|
|
2010-10-20 11:52:54 +02:00
|
|
|
endResetModel();
|
|
|
|
|
|
2010-07-12 14:45:22 +02:00
|
|
|
emit updated();
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterObjectDefinition(AST::UiObjectDefinition *objDef)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-07-19 11:39:41 +02:00
|
|
|
const QString typeName = asString(objDef->qualifiedTypeNameId);
|
2010-07-22 10:12:04 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> data;
|
2010-08-31 10:57:03 +02:00
|
|
|
AST::UiQualifiedId *idNode = 0;
|
|
|
|
|
QIcon icon;
|
2010-08-25 13:21:38 +02:00
|
|
|
|
2010-09-14 10:09:43 +02:00
|
|
|
data.insert(Qt::DisplayRole, typeName);
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
if (typeName.at(0).isUpper()) {
|
|
|
|
|
data.insert(ItemTypeRole, ElementType);
|
2010-09-03 15:26:02 +02:00
|
|
|
data.insert(AnnotationRole, getAnnotation(objDef->initializer));
|
2010-09-14 10:09:43 +02:00
|
|
|
idNode = objDef->qualifiedTypeNameId;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!m_typeToIcon.contains(typeName))
|
2010-08-31 10:57:03 +02:00
|
|
|
m_typeToIcon.insert(typeName, getIcon(objDef->qualifiedTypeNameId));
|
|
|
|
|
icon = m_typeToIcon.value(typeName);
|
2010-08-25 13:21:38 +02:00
|
|
|
} else {
|
|
|
|
|
// it's a grouped propery like 'anchors'
|
|
|
|
|
data.insert(ItemTypeRole, NonElementBindingType);
|
2010-08-31 10:57:03 +02:00
|
|
|
icon = m_icons->scriptBindingIcon();
|
2010-08-25 13:21:38 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = enterNode(data, objDef, idNode, icon);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
return item->index();
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
void QmlOutlineModel::leaveObjectDefiniton()
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterObjectBinding(AST::UiObjectBinding *objBinding)
|
|
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> bindingData;
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
bindingData.insert(Qt::DisplayRole, asString(objBinding->qualifiedId));
|
|
|
|
|
bindingData.insert(ItemTypeRole, ElementBindingType);
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *bindingItem = enterNode(bindingData, objBinding, objBinding->qualifiedId, m_icons->scriptBindingIcon());
|
2010-08-10 16:33:23 +02:00
|
|
|
|
|
|
|
|
const QString typeName = asString(objBinding->qualifiedTypeNameId);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!m_typeToIcon.contains(typeName))
|
2010-08-10 16:33:23 +02:00
|
|
|
m_typeToIcon.insert(typeName, getIcon(objBinding->qualifiedTypeNameId));
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> objectData;
|
|
|
|
|
objectData.insert(Qt::DisplayRole, typeName);
|
|
|
|
|
objectData.insert(AnnotationRole, getAnnotation(objBinding->initializer));
|
|
|
|
|
objectData.insert(ItemTypeRole, ElementType);
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
enterNode(objectData, objBinding, objBinding->qualifiedTypeNameId, m_typeToIcon.value(typeName));
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
return bindingItem->index();
|
2010-08-10 16:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leaveObjectBinding()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex QmlOutlineModel::enterArrayBinding(AST::UiArrayBinding *arrayBinding)
|
|
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> bindingData;
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
bindingData.insert(Qt::DisplayRole, asString(arrayBinding->qualifiedId));
|
|
|
|
|
bindingData.insert(ItemTypeRole, ElementBindingType);
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = enterNode(bindingData, arrayBinding, arrayBinding->qualifiedId, m_icons->scriptBindingIcon());
|
2010-08-10 16:33:23 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
return item->index();
|
2010-08-10 16:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leaveArrayBinding()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterScriptBinding(AST::UiScriptBinding *scriptBinding)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> objectData;
|
|
|
|
|
|
|
|
|
|
objectData.insert(Qt::DisplayRole, asString(scriptBinding->qualifiedId));
|
|
|
|
|
objectData.insert(AnnotationRole, getAnnotation(scriptBinding->statement));
|
|
|
|
|
objectData.insert(ItemTypeRole, NonElementBindingType);
|
2010-07-16 11:03:42 +02:00
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = enterNode(objectData, scriptBinding, scriptBinding->qualifiedId, m_icons->scriptBindingIcon());
|
2010-07-16 11:03:42 +02:00
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
return item->index();
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
void QmlOutlineModel::leaveScriptBinding()
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterPublicMember(AST::UiPublicMember *publicMember)
|
|
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QMap<int, QVariant> objectData;
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2011-09-13 09:57:24 +02:00
|
|
|
if (!publicMember->name.isEmpty())
|
|
|
|
|
objectData.insert(Qt::DisplayRole, publicMember->name.toString());
|
2011-05-12 13:25:35 +02:00
|
|
|
objectData.insert(AnnotationRole, getAnnotation(publicMember->statement));
|
2010-08-25 13:21:38 +02:00
|
|
|
objectData.insert(ItemTypeRole, NonElementBindingType);
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *item = enterNode(objectData, publicMember, 0, m_icons->publicMemberIcon());
|
2010-08-25 13:21:38 +02:00
|
|
|
|
|
|
|
|
return item->index();
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leavePublicMember()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-27 15:36:50 +02:00
|
|
|
QModelIndex QmlOutlineModel::enterFunctionDeclaration(AST::FunctionDeclaration *functionDeclaration)
|
|
|
|
|
{
|
|
|
|
|
QMap<int, QVariant> objectData;
|
|
|
|
|
|
2011-09-13 09:57:24 +02:00
|
|
|
if (!functionDeclaration->name.isEmpty())
|
|
|
|
|
objectData.insert(Qt::DisplayRole, functionDeclaration->name.toString());
|
2010-09-27 15:36:50 +02:00
|
|
|
objectData.insert(ItemTypeRole, ElementBindingType);
|
|
|
|
|
|
|
|
|
|
QmlOutlineItem *item = enterNode(objectData, functionDeclaration, 0, m_icons->functionDeclarationIcon());
|
|
|
|
|
|
|
|
|
|
return item->index();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leaveFunctionDeclaration()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-27 18:10:00 +10:00
|
|
|
QModelIndex QmlOutlineModel::enterTestCase(AST::ObjectLiteral *objectLiteral)
|
|
|
|
|
{
|
|
|
|
|
QMap<int, QVariant> objectData;
|
|
|
|
|
|
2012-11-26 21:17:34 +02:00
|
|
|
objectData.insert(Qt::DisplayRole, QLatin1String("testcase"));
|
2011-07-27 18:10:00 +10:00
|
|
|
objectData.insert(ItemTypeRole, ElementBindingType);
|
|
|
|
|
|
|
|
|
|
QmlOutlineItem *item = enterNode(objectData, objectLiteral, 0, m_icons->objectDefinitionIcon());
|
|
|
|
|
|
|
|
|
|
return item->index();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leaveTestCase()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 14:17:23 +01:00
|
|
|
QModelIndex QmlOutlineModel::enterTestCaseProperties(AST::PropertyAssignmentList *propertyAssignmentList)
|
2011-07-27 18:10:00 +10:00
|
|
|
{
|
|
|
|
|
QMap<int, QVariant> objectData;
|
2013-11-06 14:17:23 +01:00
|
|
|
if (AST::PropertyNameAndValue *assignment = AST::cast<AST::PropertyNameAndValue *>(
|
|
|
|
|
propertyAssignmentList->assignment)) {
|
|
|
|
|
if (AST::IdentifierPropertyName *propertyName = AST::cast<AST::IdentifierPropertyName *>(assignment->name)) {
|
|
|
|
|
objectData.insert(Qt::DisplayRole, propertyName->id.toString());
|
|
|
|
|
objectData.insert(ItemTypeRole, ElementBindingType);
|
|
|
|
|
QmlOutlineItem *item;
|
|
|
|
|
if (assignment->value->kind == AST::Node::Kind_FunctionExpression)
|
|
|
|
|
item = enterNode(objectData, assignment, 0, m_icons->functionDeclarationIcon());
|
|
|
|
|
else if (assignment->value->kind == AST::Node::Kind_ObjectLiteral)
|
|
|
|
|
item = enterNode(objectData, assignment, 0, m_icons->objectDefinitionIcon());
|
|
|
|
|
else
|
|
|
|
|
item = enterNode(objectData, assignment, 0, m_icons->scriptBindingIcon());
|
2011-07-27 18:10:00 +10:00
|
|
|
|
2013-11-06 14:17:23 +01:00
|
|
|
return item->index();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (AST::PropertyGetterSetter *getterSetter = AST::cast<AST::PropertyGetterSetter *>(
|
|
|
|
|
propertyAssignmentList->assignment)) {
|
|
|
|
|
if (AST::IdentifierPropertyName *propertyName = AST::cast<AST::IdentifierPropertyName *>(getterSetter->name)) {
|
|
|
|
|
objectData.insert(Qt::DisplayRole, propertyName->id.toString());
|
|
|
|
|
objectData.insert(ItemTypeRole, ElementBindingType);
|
|
|
|
|
QmlOutlineItem *item;
|
|
|
|
|
item = enterNode(objectData, getterSetter, 0, m_icons->functionDeclarationIcon());
|
|
|
|
|
|
|
|
|
|
return item->index();
|
|
|
|
|
|
|
|
|
|
}
|
2011-07-27 18:10:00 +10:00
|
|
|
}
|
2013-11-06 14:17:23 +01:00
|
|
|
return QModelIndex();
|
2011-07-27 18:10:00 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leaveTestCaseProperties()
|
|
|
|
|
{
|
|
|
|
|
leaveNode();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::Node *QmlOutlineModel::nodeForIndex(const QModelIndex &index) const
|
2010-07-19 11:39:41 +02:00
|
|
|
{
|
2010-08-25 13:21:38 +02:00
|
|
|
QTC_ASSERT(index.isValid() && (index.model() == this), return 0);
|
2010-07-19 11:39:41 +02:00
|
|
|
if (index.isValid()) {
|
2010-07-19 14:28:53 +02:00
|
|
|
QmlOutlineItem *item = static_cast<QmlOutlineItem*>(itemFromIndex(index));
|
2010-12-16 13:20:58 +01:00
|
|
|
QTC_ASSERT(item, return 0);
|
2010-08-25 13:21:38 +02:00
|
|
|
QTC_ASSERT(m_itemToNode.contains(item), return 0);
|
|
|
|
|
return m_itemToNode.value(item);
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::SourceLocation QmlOutlineModel::sourceLocation(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
AST::SourceLocation location;
|
2010-08-26 18:35:30 +02:00
|
|
|
QTC_ASSERT(index.isValid() && (index.model() == this), return location);
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::Node *node = nodeForIndex(index);
|
|
|
|
|
if (node) {
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (AST::UiObjectMember *member = node->uiObjectMemberCast())
|
2010-08-25 13:21:38 +02:00
|
|
|
location = getLocation(member);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (AST::ExpressionNode *expression = node->expressionCast())
|
2010-09-27 15:36:50 +02:00
|
|
|
location = getLocation(expression);
|
2013-11-06 14:17:23 +01:00
|
|
|
else if (AST::PropertyAssignmentList *propertyAssignmentList = AST::cast<AST::PropertyAssignmentList *>(node))
|
|
|
|
|
location = getLocation(propertyAssignmentList);
|
2010-08-25 13:21:38 +02:00
|
|
|
}
|
|
|
|
|
return location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST::UiQualifiedId *QmlOutlineModel::idNode(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(index.isValid() && (index.model() == this), return 0);
|
|
|
|
|
QmlOutlineItem *item = static_cast<QmlOutlineItem*>(itemFromIndex(index));
|
|
|
|
|
return m_itemToIdNode.value(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QIcon QmlOutlineModel::icon(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(index.isValid() && (index.model() == this), return QIcon());
|
|
|
|
|
QmlOutlineItem *item = static_cast<QmlOutlineItem*>(itemFromIndex(index));
|
|
|
|
|
return m_itemToIcon.value(item);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-31 10:57:03 +02:00
|
|
|
QmlOutlineItem *QmlOutlineModel::enterNode(QMap<int, QVariant> data, AST::Node *node, AST::UiQualifiedId *idNode, const QIcon &icon)
|
2010-07-12 09:44:42 +02:00
|
|
|
{
|
|
|
|
|
int siblingIndex = m_treePos.last();
|
2010-09-14 10:09:43 +02:00
|
|
|
QmlOutlineItem *newItem = 0;
|
2010-07-12 09:44:42 +02:00
|
|
|
if (siblingIndex == 0) {
|
|
|
|
|
// first child
|
|
|
|
|
if (!m_currentItem->hasChildren()) {
|
|
|
|
|
if (debug)
|
2010-07-16 11:03:42 +02:00
|
|
|
qDebug() << "QmlOutlineModel - Adding" << "element to" << m_currentItem->text();
|
|
|
|
|
|
2010-09-14 10:09:43 +02:00
|
|
|
newItem = new QmlOutlineItem(this);
|
2010-07-12 09:44:42 +02:00
|
|
|
} else {
|
|
|
|
|
m_currentItem = m_currentItem->child(0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// sibling
|
|
|
|
|
if (m_currentItem->rowCount() <= siblingIndex) {
|
|
|
|
|
if (debug)
|
2010-07-16 11:03:42 +02:00
|
|
|
qDebug() << "QmlOutlineModel - Adding" << "element to" << m_currentItem->text();
|
|
|
|
|
|
2010-09-14 10:09:43 +02:00
|
|
|
newItem = new QmlOutlineItem(this);
|
2010-07-12 09:44:42 +02:00
|
|
|
} else {
|
|
|
|
|
m_currentItem = m_currentItem->child(siblingIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-14 10:09:43 +02:00
|
|
|
QmlOutlineItem *item = newItem ? newItem : static_cast<QmlOutlineItem*>(m_currentItem);
|
|
|
|
|
m_itemToNode.insert(item, node);
|
|
|
|
|
m_itemToIdNode.insert(item, idNode);
|
|
|
|
|
m_itemToIcon.insert(item, icon);
|
|
|
|
|
|
|
|
|
|
if (newItem) {
|
|
|
|
|
m_currentItem->appendRow(newItem);
|
|
|
|
|
m_currentItem = newItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setItemData(m_currentItem->index(), data);
|
2010-08-31 10:57:03 +02:00
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
m_treePos.append(0);
|
|
|
|
|
|
2010-09-14 10:09:43 +02:00
|
|
|
return item;
|
2010-07-12 09:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::leaveNode()
|
|
|
|
|
{
|
|
|
|
|
int lastIndex = m_treePos.takeLast();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lastIndex > 0) {
|
|
|
|
|
// element has children
|
|
|
|
|
if (lastIndex < m_currentItem->rowCount()) {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "QmlOutlineModel - removeRows from " << m_currentItem->text() << lastIndex << m_currentItem->rowCount() - lastIndex;
|
|
|
|
|
m_currentItem->removeRows(lastIndex, m_currentItem->rowCount() - lastIndex);
|
|
|
|
|
}
|
|
|
|
|
m_currentItem = parentItem();
|
|
|
|
|
} else {
|
|
|
|
|
if (m_currentItem->hasChildren()) {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "QmlOutlineModel - removeRows from " << m_currentItem->text() << 0 << m_currentItem->rowCount();
|
|
|
|
|
m_currentItem->removeRows(0, m_currentItem->rowCount());
|
|
|
|
|
}
|
|
|
|
|
m_currentItem = parentItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_treePos.last()++;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 14:28:53 +02:00
|
|
|
void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<QmlOutlineItem*> itemsToMove)
|
|
|
|
|
{
|
|
|
|
|
Utils::ChangeSet changeSet;
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::UiObjectMember *targetObjectMember = m_itemToNode.value(targetItem)->uiObjectMemberCast();
|
2010-07-19 14:28:53 +02:00
|
|
|
if (!targetObjectMember)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<Utils::ChangeSet::Range> changedRanges;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < itemsToMove.size(); ++i) {
|
|
|
|
|
QmlOutlineItem *outlineItem = itemsToMove.at(i);
|
2010-08-25 13:21:38 +02:00
|
|
|
AST::UiObjectMember *sourceObjectMember = m_itemToNode.value(outlineItem)->uiObjectMemberCast();
|
2010-07-19 14:28:53 +02:00
|
|
|
if (!sourceObjectMember)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool insertionOrderSpecified = true;
|
|
|
|
|
AST::UiObjectMember *memberToInsertAfter = 0;
|
|
|
|
|
{
|
|
|
|
|
if (row == -1) {
|
|
|
|
|
insertionOrderSpecified = false;
|
|
|
|
|
} else if (row > 0) {
|
|
|
|
|
QmlOutlineItem *outlineItem = static_cast<QmlOutlineItem*>(targetItem->child(row - 1));
|
2010-08-25 13:21:38 +02:00
|
|
|
memberToInsertAfter = m_itemToNode.value(outlineItem)->uiObjectMemberCast();
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::ChangeSet::Range range;
|
|
|
|
|
if (sourceObjectMember)
|
|
|
|
|
moveObjectMember(sourceObjectMember, targetObjectMember, insertionOrderSpecified,
|
|
|
|
|
memberToInsertAfter, &changeSet, &range);
|
|
|
|
|
changedRanges << range;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QmlJSRefactoringChanges refactoring(ModelManagerInterface::instance(), m_semanticInfo.snapshot);
|
2011-08-17 11:35:57 +02:00
|
|
|
TextEditor::RefactoringFilePtr file = refactoring.file(m_semanticInfo.document->fileName());
|
|
|
|
|
file->setChangeSet(changeSet);
|
2010-07-19 14:28:53 +02:00
|
|
|
foreach (const Utils::ChangeSet::Range &range, changedRanges) {
|
2011-08-17 11:35:57 +02:00
|
|
|
file->appendIndentRange(range);
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
2011-08-17 11:35:57 +02:00
|
|
|
file->apply();
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlOutlineModel::moveObjectMember(AST::UiObjectMember *toMove,
|
|
|
|
|
AST::UiObjectMember *newParent,
|
|
|
|
|
bool insertionOrderSpecified,
|
|
|
|
|
AST::UiObjectMember *insertAfter,
|
|
|
|
|
Utils::ChangeSet *changeSet,
|
|
|
|
|
Utils::ChangeSet::Range *addedRange)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(toMove);
|
|
|
|
|
Q_ASSERT(newParent);
|
|
|
|
|
Q_ASSERT(changeSet);
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QHash<AST::UiObjectMember*, AST::UiObjectMember*> parentMembers;
|
2010-07-19 14:28:53 +02:00
|
|
|
{
|
|
|
|
|
ObjectMemberParentVisitor visitor;
|
|
|
|
|
parentMembers = visitor(m_semanticInfo.document);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST::UiObjectMember *oldParent = parentMembers.value(toMove);
|
|
|
|
|
Q_ASSERT(oldParent);
|
|
|
|
|
|
|
|
|
|
// make sure that target parent is actually a direct ancestor of target sibling
|
|
|
|
|
if (insertAfter)
|
|
|
|
|
newParent = parentMembers.value(insertAfter);
|
|
|
|
|
|
|
|
|
|
const QString documentText = m_semanticInfo.document->source();
|
|
|
|
|
|
2010-08-12 18:05:50 +02:00
|
|
|
Rewriter rewriter(documentText, changeSet, QStringList());
|
2010-07-19 14:28:53 +02:00
|
|
|
|
2010-08-12 18:05:50 +02:00
|
|
|
if (AST::UiObjectDefinition *objDefinition = AST::cast<AST::UiObjectDefinition*>(newParent)) {
|
2010-07-19 14:28:53 +02:00
|
|
|
AST::UiObjectMemberList *listInsertAfter = 0;
|
|
|
|
|
if (insertionOrderSpecified) {
|
|
|
|
|
if (insertAfter) {
|
|
|
|
|
listInsertAfter = objDefinition->initializer->members;
|
|
|
|
|
while (listInsertAfter && (listInsertAfter->member != insertAfter))
|
|
|
|
|
listInsertAfter = listInsertAfter->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 09:51:07 +02:00
|
|
|
if (AST::UiScriptBinding *moveScriptBinding = AST::cast<AST::UiScriptBinding*>(toMove)) {
|
2010-07-19 14:28:53 +02:00
|
|
|
const QString propertyName = asString(moveScriptBinding->qualifiedId);
|
|
|
|
|
QString propertyValue;
|
|
|
|
|
{
|
|
|
|
|
const int offset = moveScriptBinding->statement->firstSourceLocation().begin();
|
|
|
|
|
const int length = moveScriptBinding->statement->lastSourceLocation().end() - offset;
|
|
|
|
|
propertyValue = documentText.mid(offset, length);
|
|
|
|
|
}
|
|
|
|
|
Rewriter::BindingType bindingType = Rewriter::ScriptBinding;
|
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (insertionOrderSpecified)
|
2010-07-19 14:28:53 +02:00
|
|
|
*addedRange = rewriter.addBinding(objDefinition->initializer, propertyName, propertyValue, bindingType, listInsertAfter);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2010-07-19 14:28:53 +02:00
|
|
|
*addedRange = rewriter.addBinding(objDefinition->initializer, propertyName, propertyValue, bindingType);
|
|
|
|
|
} else {
|
|
|
|
|
QString strToMove;
|
|
|
|
|
{
|
|
|
|
|
const int offset = toMove->firstSourceLocation().begin();
|
|
|
|
|
const int length = toMove->lastSourceLocation().end() - offset;
|
|
|
|
|
strToMove = documentText.mid(offset, length);
|
|
|
|
|
}
|
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (insertionOrderSpecified)
|
2010-07-19 14:28:53 +02:00
|
|
|
*addedRange = rewriter.addObject(objDefinition->initializer, strToMove, listInsertAfter);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2010-07-19 14:28:53 +02:00
|
|
|
*addedRange = rewriter.addObject(objDefinition->initializer, strToMove);
|
|
|
|
|
}
|
2010-08-12 18:05:50 +02:00
|
|
|
} else if (AST::UiArrayBinding *arrayBinding = AST::cast<AST::UiArrayBinding*>(newParent)) {
|
|
|
|
|
AST::UiArrayMemberList *listInsertAfter = 0;
|
|
|
|
|
if (insertionOrderSpecified) {
|
|
|
|
|
if (insertAfter) {
|
|
|
|
|
listInsertAfter = arrayBinding->members;
|
|
|
|
|
while (listInsertAfter && (listInsertAfter->member != insertAfter))
|
|
|
|
|
listInsertAfter = listInsertAfter->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QString strToMove;
|
|
|
|
|
{
|
|
|
|
|
const int offset = toMove->firstSourceLocation().begin();
|
|
|
|
|
const int length = toMove->lastSourceLocation().end() - offset;
|
|
|
|
|
strToMove = documentText.mid(offset, length);
|
|
|
|
|
}
|
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (insertionOrderSpecified)
|
2010-08-12 18:05:50 +02:00
|
|
|
*addedRange = rewriter.addObject(arrayBinding, strToMove, listInsertAfter);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2010-08-12 18:05:50 +02:00
|
|
|
*addedRange = rewriter.addObject(arrayBinding, strToMove);
|
2010-09-07 14:34:38 +02:00
|
|
|
} else if (AST::cast<AST::UiObjectBinding*>(newParent)) {
|
2010-08-12 18:05:50 +02:00
|
|
|
qDebug() << "TODO: Reparent to UiObjectBinding";
|
|
|
|
|
return;
|
2010-07-19 14:28:53 +02:00
|
|
|
// target is a property
|
2010-08-12 18:05:50 +02:00
|
|
|
} else {
|
|
|
|
|
return;
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
2010-08-12 18:05:50 +02:00
|
|
|
|
|
|
|
|
rewriter.removeObjectMember(toMove, oldParent);
|
2010-07-19 14:28:53 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
QStandardItem *QmlOutlineModel::parentItem()
|
|
|
|
|
{
|
|
|
|
|
QStandardItem *parent = m_currentItem->parent();
|
|
|
|
|
if (!parent)
|
|
|
|
|
parent = invisibleRootItem();
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 11:39:41 +02:00
|
|
|
|
|
|
|
|
QString QmlOutlineModel::asString(AST::UiQualifiedId *id)
|
|
|
|
|
{
|
|
|
|
|
QString text;
|
|
|
|
|
for (; id; id = id->next) {
|
2011-09-13 09:57:24 +02:00
|
|
|
if (!id->name.isEmpty())
|
|
|
|
|
text += id->name;
|
2010-07-19 11:39:41 +02:00
|
|
|
else
|
|
|
|
|
text += QLatin1Char('?');
|
|
|
|
|
|
|
|
|
|
if (id->next)
|
|
|
|
|
text += QLatin1Char('.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST::SourceLocation QmlOutlineModel::getLocation(AST::UiObjectMember *objMember) {
|
|
|
|
|
AST::SourceLocation location;
|
2014-09-29 14:41:42 +02:00
|
|
|
location = objMember->firstSourceLocation();
|
2010-07-19 11:39:41 +02:00
|
|
|
location.length = objMember->lastSourceLocation().offset
|
|
|
|
|
- objMember->firstSourceLocation().offset
|
|
|
|
|
+ objMember->lastSourceLocation().length;
|
|
|
|
|
return location;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-27 15:36:50 +02:00
|
|
|
AST::SourceLocation QmlOutlineModel::getLocation(AST::ExpressionNode *exprNode) {
|
|
|
|
|
AST::SourceLocation location;
|
2014-09-29 14:41:42 +02:00
|
|
|
location = exprNode->firstSourceLocation();
|
2010-09-27 15:36:50 +02:00
|
|
|
location.length = exprNode->lastSourceLocation().offset
|
|
|
|
|
- exprNode->firstSourceLocation().offset
|
|
|
|
|
+ exprNode->lastSourceLocation().length;
|
|
|
|
|
return location;
|
2011-07-27 18:10:00 +10:00
|
|
|
}
|
|
|
|
|
|
2013-11-06 14:17:23 +01:00
|
|
|
AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyAssignmentList *propertyNode) {
|
|
|
|
|
if (AST::PropertyNameAndValue *assignment = AST::cast<AST::PropertyNameAndValue *>(propertyNode->assignment))
|
|
|
|
|
return getLocation(assignment);
|
|
|
|
|
if (AST::PropertyGetterSetter *getterSetter = AST::cast<AST::PropertyGetterSetter *>(propertyNode->assignment))
|
|
|
|
|
return getLocation(getterSetter);
|
|
|
|
|
return propertyNode->commaToken; // should never happen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyNameAndValue *propertyNode) {
|
2011-07-27 18:10:00 +10:00
|
|
|
AST::SourceLocation location;
|
2014-09-29 14:41:42 +02:00
|
|
|
location = propertyNode->name->propertyNameToken;
|
2011-07-27 18:10:00 +10:00
|
|
|
location.length = propertyNode->value->lastSourceLocation().end() - location.offset;
|
|
|
|
|
|
|
|
|
|
return location;
|
2010-09-27 15:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-06 14:17:23 +01:00
|
|
|
AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyGetterSetter *propertyNode) {
|
|
|
|
|
AST::SourceLocation location;
|
2014-09-29 14:41:42 +02:00
|
|
|
location = propertyNode->name->propertyNameToken;
|
2013-11-06 14:17:23 +01:00
|
|
|
location.length = propertyNode->rbraceToken.end() - location.offset;
|
|
|
|
|
|
|
|
|
|
return location;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
QIcon QmlOutlineModel::getIcon(AST::UiQualifiedId *qualifiedId) {
|
2010-10-22 13:38:20 +02:00
|
|
|
QIcon icon;
|
|
|
|
|
if (qualifiedId) {
|
|
|
|
|
QString name = asString(qualifiedId);
|
|
|
|
|
if (name.contains(QLatin1Char('.')))
|
|
|
|
|
name = name.split(QLatin1Char('.')).last();
|
2010-07-19 11:39:41 +02:00
|
|
|
|
2010-10-22 13:38:20 +02:00
|
|
|
// TODO: get rid of namespace prefixes.
|
2012-11-26 21:17:34 +02:00
|
|
|
icon = m_icons->icon(QLatin1String("Qt"), name);
|
2010-10-22 13:38:20 +02:00
|
|
|
if (icon.isNull())
|
2012-11-26 21:17:34 +02:00
|
|
|
icon = m_icons->icon(QLatin1String("QtWebkit"), name);
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
2010-10-22 13:38:20 +02:00
|
|
|
return icon;
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
QString QmlOutlineModel::getAnnotation(AST::UiObjectInitializer *objectInitializer) {
|
|
|
|
|
const QHash<QString,QString> bindings = getScriptBindings(objectInitializer);
|
2010-08-10 15:11:14 +02:00
|
|
|
|
2012-11-26 21:17:34 +02:00
|
|
|
if (bindings.contains(QLatin1String("id")))
|
|
|
|
|
return bindings.value(QLatin1String("id"));
|
2010-08-10 15:11:14 +02:00
|
|
|
|
2012-11-26 21:17:34 +02:00
|
|
|
if (bindings.contains(QLatin1String("name")))
|
|
|
|
|
return bindings.value(QLatin1String("name"));
|
2010-08-10 15:11:14 +02:00
|
|
|
|
2012-11-26 21:17:34 +02:00
|
|
|
if (bindings.contains(QLatin1String("target")))
|
|
|
|
|
return bindings.value(QLatin1String("target"));
|
2010-08-10 15:11:14 +02:00
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QString QmlOutlineModel::getAnnotation(AST::Statement *statement)
|
2010-08-12 15:10:19 +02:00
|
|
|
{
|
|
|
|
|
if (AST::ExpressionStatement *expr = AST::cast<AST::ExpressionStatement*>(statement))
|
|
|
|
|
return getAnnotation(expr->expression);
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 13:21:38 +02:00
|
|
|
QString QmlOutlineModel::getAnnotation(AST::ExpressionNode *expression)
|
2010-08-12 15:10:19 +02:00
|
|
|
{
|
|
|
|
|
if (!expression)
|
|
|
|
|
return QString();
|
|
|
|
|
QString source = m_semanticInfo.document->source();
|
2013-05-03 16:50:12 +02:00
|
|
|
QString str = source.mid(expression->firstSourceLocation().begin(),
|
|
|
|
|
expression->lastSourceLocation().end()
|
|
|
|
|
- expression->firstSourceLocation().begin());
|
|
|
|
|
// only show first line
|
|
|
|
|
return str.left(str.indexOf(QLatin1Char('\n')));
|
2010-08-12 15:10:19 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:33:23 +02:00
|
|
|
QHash<QString,QString> QmlOutlineModel::getScriptBindings(AST::UiObjectInitializer *objectInitializer) {
|
2010-08-10 15:11:14 +02:00
|
|
|
QHash <QString,QString> scriptBindings;
|
2010-08-10 16:33:23 +02:00
|
|
|
for (AST::UiObjectMemberList *it = objectInitializer->members; it; it = it->next) {
|
2010-07-22 09:51:07 +02:00
|
|
|
if (AST::UiScriptBinding *binding = AST::cast<AST::UiScriptBinding*>(it->member)) {
|
2010-08-10 15:11:14 +02:00
|
|
|
const QString bindingName = asString(binding->qualifiedId);
|
2010-08-12 15:10:19 +02:00
|
|
|
scriptBindings.insert(bindingName, getAnnotation(binding->statement));
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-08-10 15:11:14 +02:00
|
|
|
return scriptBindings;
|
2010-07-19 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:44:42 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlJSEditor
|