forked from qt-creator/qt-creator
Gotten rid of dulplicate files, and fixed includes.
This commit is contained in:
@@ -8,7 +8,7 @@ SUBDIRS = \
|
||||
utils \
|
||||
utils/process_stub.pro \
|
||||
cplusplus \
|
||||
qml
|
||||
qmljs
|
||||
|
||||
SUPPORT_QT_MAEMO = $$(QTCREATOR_WITH_MAEMO)
|
||||
!isEmpty(SUPPORT_QT_MAEMO) {
|
||||
|
@@ -1,5 +0,0 @@
|
||||
INCLUDEPATH += $$PWD/../../shared
|
||||
INCLUDEPATH += $$PWD/../../shared/qml $$PWD/../../shared/qml/parser
|
||||
|
||||
DEPENDPATH += $$PWD/../../shared
|
||||
LIBS *= -l$$qtLibraryTarget(Qml)
|
@@ -6,7 +6,7 @@ contains(CONFIG, dll) {
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
include($$PWD/../../shared/qml/qml.pri)
|
||||
include($$PWD/../../shared/qmljs/qmljs.pri)
|
||||
|
||||
##contains(QT, gui) {
|
||||
##HEADERS += \
|
5
src/libs/qmljs/qmljs.pri
Normal file
5
src/libs/qmljs/qmljs.pri
Normal file
@@ -0,0 +1,5 @@
|
||||
INCLUDEPATH += $$PWD/../../shared
|
||||
INCLUDEPATH += $$PWD/../../shared/qmljs $$PWD/../../shared/qmljs/parser
|
||||
|
||||
DEPENDPATH += $$PWD/../../shared/qmljs
|
||||
LIBS *= -l$$qtLibraryTarget(QmlJS)
|
@@ -1,9 +1,9 @@
|
||||
TEMPLATE = lib
|
||||
CONFIG += dll
|
||||
TARGET = Qml
|
||||
TARGET = QmlJS
|
||||
DEFINES += QML_BUILD_LIB QT_CREATOR
|
||||
|
||||
unix:QMAKE_CXXFLAGS_DEBUG += -O3
|
||||
|
||||
include(../../qtcreatorlibrary.pri)
|
||||
include(qml-lib.pri)
|
||||
include(qmljs-lib.pri)
|
@@ -27,11 +27,11 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
|
||||
#include "addarraymembervisitor.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlDesigner::Internal;
|
||||
using namespace QmlJS;
|
||||
|
@@ -27,11 +27,11 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
|
||||
#include "addobjectvisitor.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlDesigner::Internal;
|
||||
using namespace QmlJS;
|
||||
|
@@ -27,11 +27,11 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
|
||||
#include "addpropertyvisitor.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlDesigner::Internal;
|
||||
using namespace QmlJS;
|
||||
|
@@ -28,8 +28,10 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "astobjecttextextractor.h"
|
||||
#include "qmljsast_p.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
|
||||
using namespace Qml;
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlJS::AST;
|
||||
|
||||
|
@@ -30,10 +30,10 @@
|
||||
#ifndef ASTOBJECTTEXTEXTRACTOR_H
|
||||
#define ASTOBJECTTEXTEXTRACTOR_H
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
|
||||
#include "qmldocument.h"
|
||||
#include "qmljsastvisitor_p.h"
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -49,7 +49,7 @@ protected:
|
||||
virtual bool visit(QmlJS::AST::UiObjectDefinition *ast);
|
||||
|
||||
private:
|
||||
QmlDocument::Ptr m_document;
|
||||
Qml::QmlDocument::Ptr m_document;
|
||||
quint32 m_location;
|
||||
QString m_text;
|
||||
};
|
||||
|
@@ -28,8 +28,8 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "changeobjecttypevisitor.h"
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
||||
|
@@ -27,11 +27,11 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
|
||||
#include "changepropertyvisitor.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
||||
using namespace QmlDesigner;
|
||||
|
@@ -1,359 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtDeclarative module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** No Commercial Usage
|
||||
** This file contains pre-release code and may not be distributed.
|
||||
** You may use this file in accordance with the terms and conditions
|
||||
** contained in the Technology Preview License Agreement accompanying
|
||||
** this package.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "changeset.h"
|
||||
|
||||
namespace Utils {
|
||||
|
||||
ChangeSet::ChangeSet()
|
||||
: m_string(0), m_cursor(0), m_error(false)
|
||||
{
|
||||
}
|
||||
|
||||
static bool overlaps(int posA, int lengthA, int posB, int lengthB) {
|
||||
if (lengthB > 0) {
|
||||
return
|
||||
// right edge of B contained in A
|
||||
(posA < posB + lengthB && posA + lengthA >= posB + lengthB)
|
||||
// left edge of B contained in A
|
||||
|| (posA <= posB && posA + lengthA > posB)
|
||||
// A contained in B
|
||||
|| (posB < posA && posB + lengthB > posA + lengthA);
|
||||
} else {
|
||||
return (posB > posA && posB < posA + lengthA);
|
||||
}
|
||||
}
|
||||
|
||||
bool ChangeSet::hasOverlap(int pos, int length)
|
||||
{
|
||||
QListIterator<EditOp> i(m_operationList);
|
||||
while (i.hasNext()) {
|
||||
const EditOp &cmd = i.next();
|
||||
|
||||
switch (cmd.type) {
|
||||
case EditOp::Replace:
|
||||
if (overlaps(pos, length, cmd.pos1, cmd.length1))
|
||||
return true;
|
||||
break;
|
||||
|
||||
case EditOp::Move:
|
||||
if (overlaps(pos, length, cmd.pos1, cmd.length1))
|
||||
return true;
|
||||
if (cmd.pos2 > pos && cmd.pos2 < pos + length)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case EditOp::Insert:
|
||||
if (cmd.pos1 > pos && cmd.pos1 < pos + length)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case EditOp::Remove:
|
||||
if (overlaps(pos, length, cmd.pos1, cmd.length1))
|
||||
return true;
|
||||
break;
|
||||
|
||||
case EditOp::Flip:
|
||||
if (overlaps(pos, length, cmd.pos1, cmd.length1))
|
||||
return true;
|
||||
if (overlaps(pos, length, cmd.pos2, cmd.length2))
|
||||
return true;
|
||||
break;
|
||||
|
||||
case EditOp::Copy:
|
||||
if (overlaps(pos, length, cmd.pos1, cmd.length1))
|
||||
return true;
|
||||
if (cmd.pos2 > pos && cmd.pos2 < pos + length)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case EditOp::Unset:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChangeSet::isEmpty() const
|
||||
{
|
||||
return m_operationList.isEmpty();
|
||||
}
|
||||
|
||||
QList<ChangeSet::EditOp> ChangeSet::operationList() const
|
||||
{
|
||||
return m_operationList;
|
||||
}
|
||||
|
||||
void ChangeSet::clear()
|
||||
{
|
||||
m_string = 0;
|
||||
m_cursor = 0;
|
||||
m_operationList.clear();
|
||||
m_error = false;
|
||||
}
|
||||
|
||||
bool ChangeSet::replace(int pos, int length, const QString &replacement)
|
||||
{
|
||||
if (hasOverlap(pos, length))
|
||||
m_error = true;
|
||||
|
||||
EditOp cmd(EditOp::Replace);
|
||||
cmd.pos1 = pos;
|
||||
cmd.length1 = length;
|
||||
cmd.text = replacement;
|
||||
m_operationList += cmd;
|
||||
|
||||
return !m_error;
|
||||
}
|
||||
|
||||
bool ChangeSet::move(int pos, int length, int to)
|
||||
{
|
||||
if (hasOverlap(pos, length)
|
||||
|| hasOverlap(to, 0)
|
||||
|| overlaps(pos, length, to, 0))
|
||||
m_error = true;
|
||||
|
||||
EditOp cmd(EditOp::Move);
|
||||
cmd.pos1 = pos;
|
||||
cmd.length1 = length;
|
||||
cmd.pos2 = to;
|
||||
m_operationList += cmd;
|
||||
|
||||
return !m_error;
|
||||
}
|
||||
|
||||
bool ChangeSet::insert(int pos, const QString &text)
|
||||
{
|
||||
if (hasOverlap(pos, 0))
|
||||
m_error = true;
|
||||
|
||||
EditOp cmd(EditOp::Insert);
|
||||
cmd.pos1 = pos;
|
||||
cmd.text = text;
|
||||
m_operationList += cmd;
|
||||
|
||||
return !m_error;
|
||||
}
|
||||
|
||||
bool ChangeSet::remove(int pos, int length)
|
||||
{
|
||||
if (hasOverlap(pos, length))
|
||||
m_error = true;
|
||||
|
||||
EditOp cmd(EditOp::Remove);
|
||||
cmd.pos1 = pos;
|
||||
cmd.length1 = length;
|
||||
m_operationList += cmd;
|
||||
|
||||
return !m_error;
|
||||
}
|
||||
|
||||
bool ChangeSet::flip(int pos1, int length1, int pos2, int length2)
|
||||
{
|
||||
if (hasOverlap(pos1, length1)
|
||||
|| hasOverlap(pos2, length2)
|
||||
|| overlaps(pos1, length1, pos2, length2))
|
||||
m_error = true;
|
||||
|
||||
EditOp cmd(EditOp::Flip);
|
||||
cmd.pos1 = pos1;
|
||||
cmd.length1 = length1;
|
||||
cmd.pos2 = pos2;
|
||||
cmd.length2 = length2;
|
||||
m_operationList += cmd;
|
||||
|
||||
return !m_error;
|
||||
}
|
||||
|
||||
bool ChangeSet::copy(int pos, int length, int to)
|
||||
{
|
||||
if (hasOverlap(pos, length)
|
||||
|| hasOverlap(to, 0)
|
||||
|| overlaps(pos, length, to, 0))
|
||||
m_error = true;
|
||||
|
||||
EditOp cmd(EditOp::Copy);
|
||||
cmd.pos1 = pos;
|
||||
cmd.length1 = length;
|
||||
cmd.pos2 = to;
|
||||
m_operationList += cmd;
|
||||
|
||||
return !m_error;
|
||||
}
|
||||
|
||||
void ChangeSet::doReplace(const EditOp &replace, QList<EditOp> *replaceList)
|
||||
{
|
||||
Q_ASSERT(replace.type == EditOp::Replace);
|
||||
|
||||
{
|
||||
QMutableListIterator<EditOp> i(*replaceList);
|
||||
while (i.hasNext()) {
|
||||
EditOp &c = i.next();
|
||||
if (replace.pos1 <= c.pos1)
|
||||
c.pos1 += replace.text.size();
|
||||
if (replace.pos1 < c.pos1)
|
||||
c.pos1 -= replace.length1;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_string) {
|
||||
m_string->replace(replace.pos1, replace.length1, replace.text);
|
||||
} else if (m_cursor) {
|
||||
m_cursor->setPosition(replace.pos1);
|
||||
m_cursor->setPosition(replace.pos1 + replace.length1, QTextCursor::KeepAnchor);
|
||||
m_cursor->insertText(replace.text);
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeSet::convertToReplace(const EditOp &op, QList<EditOp> *replaceList)
|
||||
{
|
||||
EditOp replace1(EditOp::Replace);
|
||||
EditOp replace2(EditOp::Replace);
|
||||
|
||||
switch (op.type) {
|
||||
case EditOp::Replace:
|
||||
replaceList->append(op);
|
||||
break;
|
||||
|
||||
case EditOp::Move:
|
||||
replace1.pos1 = op.pos1;
|
||||
replace1.length1 = op.length1;
|
||||
replaceList->append(replace1);
|
||||
|
||||
replace2.pos1 = op.pos2;
|
||||
replace2.text = textAt(op.pos1, op.length1);
|
||||
replaceList->append(replace2);
|
||||
break;
|
||||
|
||||
case EditOp::Insert:
|
||||
replace1.pos1 = op.pos1;
|
||||
replace1.text = op.text;
|
||||
replaceList->append(replace1);
|
||||
break;
|
||||
|
||||
case EditOp::Remove:
|
||||
replace1.pos1 = op.pos1;
|
||||
replace1.length1 = op.length1;
|
||||
replaceList->append(replace1);
|
||||
break;
|
||||
|
||||
case EditOp::Flip:
|
||||
replace1.pos1 = op.pos1;
|
||||
replace1.length1 = op.length1;
|
||||
replace1.text = textAt(op.pos2, op.length2);
|
||||
replaceList->append(replace1);
|
||||
|
||||
replace2.pos1 = op.pos2;
|
||||
replace2.length1 = op.length2;
|
||||
replace2.text = textAt(op.pos1, op.length1);
|
||||
replaceList->append(replace2);
|
||||
break;
|
||||
|
||||
case EditOp::Copy:
|
||||
replace1.pos1 = op.pos2;
|
||||
replace1.text = textAt(op.pos1, op.length1);
|
||||
replaceList->append(replace1);
|
||||
break;
|
||||
|
||||
case EditOp::Unset:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool ChangeSet::hadErrors()
|
||||
{
|
||||
return m_error;
|
||||
}
|
||||
|
||||
void ChangeSet::apply(QString *s)
|
||||
{
|
||||
m_string = s;
|
||||
apply_helper();
|
||||
m_string = 0;
|
||||
}
|
||||
|
||||
void ChangeSet::apply(QTextCursor *textCursor)
|
||||
{
|
||||
m_cursor = textCursor;
|
||||
apply_helper();
|
||||
m_cursor = 0;
|
||||
}
|
||||
|
||||
QString ChangeSet::textAt(int pos, int length)
|
||||
{
|
||||
if (m_string) {
|
||||
return m_string->mid(pos, length);
|
||||
} else if (m_cursor) {
|
||||
m_cursor->setPosition(pos);
|
||||
m_cursor->setPosition(pos + length, QTextCursor::KeepAnchor);
|
||||
return m_cursor->selectedText();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void ChangeSet::apply_helper()
|
||||
{
|
||||
// convert all ops to replace
|
||||
QList<EditOp> replaceList;
|
||||
{
|
||||
while (!m_operationList.isEmpty()) {
|
||||
const EditOp cmd(m_operationList.first());
|
||||
m_operationList.removeFirst();
|
||||
convertToReplace(cmd, &replaceList);
|
||||
}
|
||||
}
|
||||
|
||||
// execute replaces
|
||||
if (m_cursor)
|
||||
m_cursor->beginEditBlock();
|
||||
|
||||
while (!replaceList.isEmpty()) {
|
||||
const EditOp cmd(replaceList.first());
|
||||
replaceList.removeFirst();
|
||||
doReplace(cmd, &replaceList);
|
||||
}
|
||||
|
||||
if (m_cursor)
|
||||
m_cursor->endEditBlock();
|
||||
}
|
||||
|
||||
} // end namespace Utils
|
@@ -1,120 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the QtDeclarative module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** No Commercial Usage
|
||||
** This file contains pre-release code and may not be distributed.
|
||||
** You may use this file in accordance with the terms and conditions
|
||||
** contained in the Technology Preview License Agreement accompanying
|
||||
** this package.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CHANGESET_H
|
||||
#define CHANGESET_H
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtGui/QTextCursor>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT ChangeSet
|
||||
{
|
||||
public:
|
||||
struct EditOp {
|
||||
enum Type
|
||||
{
|
||||
Unset,
|
||||
Replace,
|
||||
Move,
|
||||
Insert,
|
||||
Remove,
|
||||
Flip,
|
||||
Copy
|
||||
};
|
||||
|
||||
EditOp(): type(Unset), pos1(0), pos2(0), length1(0), length2(0) {}
|
||||
EditOp(Type t): type(t), pos1(0), pos2(0), length1(0), length2(0) {}
|
||||
|
||||
Type type;
|
||||
int pos1;
|
||||
int pos2;
|
||||
int length1;
|
||||
int length2;
|
||||
QString text;
|
||||
};
|
||||
|
||||
public:
|
||||
ChangeSet();
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
QList<EditOp> operationList() const;
|
||||
|
||||
void clear();
|
||||
|
||||
bool replace(int pos, int length, const QString &replacement);
|
||||
bool move(int pos, int length, int to);
|
||||
bool insert(int pos, const QString &text);
|
||||
bool remove(int pos, int length);
|
||||
bool flip(int pos1, int length1, int pos2, int length2);
|
||||
bool copy(int pos, int length, int to);
|
||||
|
||||
bool hadErrors();
|
||||
|
||||
void apply(QString *s);
|
||||
void apply(QTextCursor *textCursor);
|
||||
|
||||
private:
|
||||
bool hasOverlap(int pos, int length);
|
||||
QString textAt(int pos, int length);
|
||||
|
||||
void doReplace(const EditOp &replace, QList<EditOp> *replaceList);
|
||||
void convertToReplace(const EditOp &op, QList<EditOp> *replaceList);
|
||||
|
||||
void apply_helper();
|
||||
|
||||
private:
|
||||
QString *m_string;
|
||||
QTextCursor *m_cursor;
|
||||
|
||||
QList<EditOp> m_operationList;
|
||||
bool m_error;
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
#endif // CHANGESET_H
|
@@ -1,6 +1,4 @@
|
||||
SOURCES += $$PWD/qmldocument.cpp \
|
||||
$$PWD/idcollector.cpp \
|
||||
$$PWD/qmlsymbol.cpp \
|
||||
SOURCES += \
|
||||
$$PWD/qmlrewriter.cpp \
|
||||
$$PWD/qmlrefactoring.cpp \
|
||||
$$PWD/changeobjecttypevisitor.cpp \
|
||||
@@ -12,15 +10,11 @@ SOURCES += $$PWD/qmldocument.cpp \
|
||||
$$PWD/addobjectvisitor.cpp \
|
||||
$$PWD/addarraymembervisitor.cpp \
|
||||
$$PWD/astobjecttextextractor.cpp \
|
||||
$$PWD/indenter.cpp \
|
||||
$$PWD/changeset.cpp \
|
||||
$$PWD/objectlengthcalculator.cpp \
|
||||
$$PWD/firstdefinitionfinder.cpp \
|
||||
$$PWD/moveobjectbeforeobjectvisitor.cpp
|
||||
HEADERS += $$PWD/qmldocument.h \
|
||||
$$PWD/idcollector.h \
|
||||
HEADERS += \
|
||||
$$PWD/qmleditor_global.h \
|
||||
$$PWD/qmlsymbol.h \
|
||||
$$PWD/qmlrewriter.h \
|
||||
$$PWD/qmlrefactoring.h \
|
||||
$$PWD/changeobjecttypevisitor.h \
|
||||
@@ -32,9 +26,6 @@ HEADERS += $$PWD/qmldocument.h \
|
||||
$$PWD/addobjectvisitor.h \
|
||||
$$PWD/addarraymembervisitor.h \
|
||||
$$PWD/astobjecttextextractor.h \
|
||||
$$PWD/indenter.h \
|
||||
$$PWD/changeset.h \
|
||||
$$PWD/utils_global.h \
|
||||
$$PWD/objectlengthcalculator.h \
|
||||
$$PWD/firstdefinitionfinder.h \
|
||||
$$PWD/moveobjectbeforeobjectvisitor.h
|
||||
|
@@ -29,9 +29,9 @@
|
||||
|
||||
#include "firstdefinitionfinder.h"
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
|
||||
using namespace QmlDesigner;
|
||||
using namespace Qml;
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlJS::AST;
|
||||
|
||||
|
@@ -30,9 +30,8 @@
|
||||
#ifndef FIRSTDEFINITIONFINDER_H
|
||||
#define FIRSTDEFINITIONFINDER_H
|
||||
|
||||
#include "qmldocument.h"
|
||||
|
||||
#include <qmljsastvisitor_p.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -52,7 +51,7 @@ protected:
|
||||
void extractFirstObjectDefinition(QmlJS::AST::UiObjectInitializer* ast);
|
||||
|
||||
private:
|
||||
QmlDesigner::QmlDocument::Ptr m_doc;
|
||||
Qml::QmlDocument::Ptr m_doc;
|
||||
quint32 m_offset;
|
||||
QmlJS::AST::UiObjectDefinition *m_firstObjectDefinition;
|
||||
|
||||
|
@@ -1,93 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "idcollector.h"
|
||||
#include "qmljsast_p.h"
|
||||
#include "qmljsengine_p.h"
|
||||
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlDesigner::Internal;
|
||||
|
||||
QMap<QString, QmlIdSymbol*> IdCollector::operator()(const QString &fileName, QmlJS::AST::UiProgram *ast)
|
||||
{
|
||||
_fileName = fileName;
|
||||
_ids.clear();
|
||||
|
||||
Node::accept(ast, this);
|
||||
|
||||
return _ids;
|
||||
}
|
||||
|
||||
bool IdCollector::visit(QmlJS::AST::UiObjectBinding *ast)
|
||||
{
|
||||
_scopes.push(ast);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IdCollector::visit(QmlJS::AST::UiObjectDefinition *ast)
|
||||
{
|
||||
_scopes.push(ast);
|
||||
return true;
|
||||
}
|
||||
|
||||
void IdCollector::endVisit(QmlJS::AST::UiObjectBinding *)
|
||||
{
|
||||
_scopes.pop();
|
||||
}
|
||||
|
||||
void IdCollector::endVisit(QmlJS::AST::UiObjectDefinition *)
|
||||
{
|
||||
_scopes.pop();
|
||||
}
|
||||
|
||||
bool IdCollector::visit(QmlJS::AST::UiScriptBinding *ast)
|
||||
{
|
||||
if (!(ast->qualifiedId->next) && ast->qualifiedId->name->asString() == "id")
|
||||
if (ExpressionStatement *e = cast<ExpressionStatement*>(ast->statement))
|
||||
if (IdentifierExpression *i = cast<IdentifierExpression*>(e->expression))
|
||||
addId(i->name->asString(), ast);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void IdCollector::addId(const QString &id, QmlJS::AST::UiScriptBinding *ast)
|
||||
{
|
||||
if (!_ids.contains(id)) {
|
||||
Node *parent = _scopes.top();
|
||||
|
||||
if (UiObjectBinding *binding = cast<UiObjectBinding*>(parent))
|
||||
_ids[id] = new QmlIdSymbol(_fileName, ast, QmlSymbolFromFile(_fileName, binding));
|
||||
else if (UiObjectDefinition *definition = cast<UiObjectDefinition*>(parent))
|
||||
_ids[id] = new QmlIdSymbol(_fileName, ast, QmlSymbolFromFile(_fileName, definition));
|
||||
else
|
||||
Q_ASSERT(!"Unknown parent for id");
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef IDCOLLECTOR_H
|
||||
#define IDCOLLECTOR_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QPair>
|
||||
#include <QStack>
|
||||
#include <QString>
|
||||
|
||||
#include "qmljsastvisitor_p.h"
|
||||
#include "qmlsymbol.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
class IdCollector: protected QmlJS::AST::Visitor
|
||||
{
|
||||
public:
|
||||
QMap<QString, QmlIdSymbol*> operator()(const QString &fileName, QmlJS::AST::UiProgram *ast);
|
||||
|
||||
protected:
|
||||
virtual bool visit(QmlJS::AST::UiObjectBinding *ast);
|
||||
virtual bool visit(QmlJS::AST::UiObjectDefinition *ast);
|
||||
virtual bool visit(QmlJS::AST::UiScriptBinding *ast);
|
||||
|
||||
virtual void endVisit(QmlJS::AST::UiObjectBinding *);
|
||||
virtual void endVisit(QmlJS::AST::UiObjectDefinition *);
|
||||
|
||||
private:
|
||||
void addId(const QString &id, QmlJS::AST::UiScriptBinding *ast);
|
||||
|
||||
private:
|
||||
QString _fileName;
|
||||
QMap<QString, QmlIdSymbol*> _ids;
|
||||
QStack<QmlJS::AST::Node *> _scopes;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlDesigner
|
||||
|
||||
#endif // IDCOLLECTOR_H
|
@@ -1,90 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "indenter.h"
|
||||
|
||||
using namespace QmlDesigner;
|
||||
|
||||
Indenter::Indenter()
|
||||
{
|
||||
}
|
||||
|
||||
//static int blockStartState(const QTextBlock &block)
|
||||
//{
|
||||
// int state = block.userState();
|
||||
//
|
||||
// if (state == -1)
|
||||
// return 0;
|
||||
// else
|
||||
// return state & 0xff;
|
||||
//}
|
||||
//
|
||||
//void ScriptEditor::indentBlock(QTextDocument *, QTextBlock block, QChar typedChar)
|
||||
//{
|
||||
// TextEditor::TabSettings ts = tabSettings();
|
||||
//
|
||||
// QTextCursor tc(block);
|
||||
//
|
||||
// const QString blockText = block.text();
|
||||
// int startState = blockStartState(block.previous());
|
||||
//
|
||||
// QScriptIncrementalScanner scanner;
|
||||
// const QList<QScriptIncrementalScanner::Token> tokens = scanner(blockText, startState);
|
||||
//
|
||||
// if (! tokens.isEmpty()) {
|
||||
// const QScriptIncrementalScanner::Token tk = tokens.first();
|
||||
//
|
||||
// if (tk.is(QScriptIncrementalScanner::Token::RightBrace)
|
||||
// || tk.is(QScriptIncrementalScanner::Token::RightBracket)) {
|
||||
// if (TextEditor::TextBlockUserData::findPreviousBlockOpenParenthesis(&tc)) {
|
||||
// const QString text = tc.block().text();
|
||||
// int indent = ts.columnAt(text, ts.firstNonSpace(text));
|
||||
// ts.indentLine(block, indent);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// int initialIndent = 0;
|
||||
// for (QTextBlock it = block.previous(); it.isValid(); it = it.previous()) {
|
||||
// const QString text = it.text();
|
||||
//
|
||||
// if (! text.isEmpty()) {
|
||||
// initialIndent = ts.columnAt(text, ts.firstNonSpace(text));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// const int braceDepth = blockBraceDepth(block.previous());
|
||||
// const int previousBraceDepth = blockBraceDepth(block.previous().previous());
|
||||
// const int delta = qMax(0, braceDepth - previousBraceDepth);
|
||||
// int indent = initialIndent + (delta * ts.m_indentSize);
|
||||
// ts.indentLine(block, indent);
|
||||
//}
|
||||
//
|
@@ -1,43 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef INDENTER_H
|
||||
#define INDENTER_H
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class Indenter
|
||||
{
|
||||
public:
|
||||
Indenter();
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
#endif // INDENTER_H
|
@@ -27,14 +27,14 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
|
||||
#include "moveobjectbeforeobjectvisitor.h"
|
||||
#include "textmodifier.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
||||
using namespace QmlDesigner::Internal;
|
||||
|
@@ -27,14 +27,14 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
|
||||
#include "moveobjectvisitor.h"
|
||||
#include "textmodifier.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
||||
using namespace QmlDesigner::Internal;
|
||||
|
@@ -29,9 +29,9 @@
|
||||
|
||||
#include "objectlengthcalculator.h"
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
|
||||
using namespace QmlDesigner;
|
||||
using namespace Qml;
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlJS::AST;
|
||||
|
||||
|
@@ -30,9 +30,8 @@
|
||||
#ifndef OBJECTLENGTHCALCULATOR_H
|
||||
#define OBJECTLENGTHCALCULATOR_H
|
||||
|
||||
#include "qmldocument.h"
|
||||
|
||||
#include <qmljsastvisitor_p.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -50,7 +49,7 @@ protected:
|
||||
virtual bool visit(QmlJS::AST::UiObjectDefinition *ast);
|
||||
|
||||
private:
|
||||
QmlDocument::Ptr m_doc;
|
||||
Qml::QmlDocument::Ptr m_doc;
|
||||
quint32 m_offset;
|
||||
quint32 m_length;
|
||||
};
|
||||
|
@@ -1,165 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "idcollector.h"
|
||||
#include "qmldocument.h"
|
||||
#include "qmljsast_p.h"
|
||||
#include "qmljslexer_p.h"
|
||||
#include "qmljsparser_p.h"
|
||||
#include "qmljsengine_p.h"
|
||||
#include "qmljsnodepool_p.h"
|
||||
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlJS;
|
||||
|
||||
QmlDocument::QmlDocument(const QString &fileName)
|
||||
: _engine(0)
|
||||
, _pool(0)
|
||||
, _program(0)
|
||||
, _fileName(fileName)
|
||||
, _parsedCorrectly(false)
|
||||
{
|
||||
const int slashIdx = fileName.lastIndexOf('/');
|
||||
if (slashIdx != -1)
|
||||
_path = fileName.left(slashIdx);
|
||||
|
||||
if (fileName.toLower().endsWith(".qml"))
|
||||
_componentName = fileName.mid(slashIdx + 1, fileName.size() - (slashIdx + 1) - 4);
|
||||
}
|
||||
|
||||
QmlDocument::~QmlDocument()
|
||||
{
|
||||
if (_engine)
|
||||
delete _engine;
|
||||
|
||||
if (_pool)
|
||||
delete _pool;
|
||||
|
||||
qDeleteAll(_ids.values());
|
||||
}
|
||||
|
||||
QmlDocument::Ptr QmlDocument::create(const QString &fileName)
|
||||
{
|
||||
QmlDocument::Ptr doc(new QmlDocument(fileName));
|
||||
return doc;
|
||||
}
|
||||
|
||||
AST::UiProgram *QmlDocument::program() const
|
||||
{
|
||||
return _program;
|
||||
}
|
||||
|
||||
QList<DiagnosticMessage> QmlDocument::diagnosticMessages() const
|
||||
{
|
||||
return _diagnosticMessages;
|
||||
}
|
||||
|
||||
QString QmlDocument::source() const
|
||||
{
|
||||
return _source;
|
||||
}
|
||||
|
||||
void QmlDocument::setSource(const QString &source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
bool QmlDocument::parse()
|
||||
{
|
||||
Q_ASSERT(! _engine);
|
||||
Q_ASSERT(! _pool);
|
||||
Q_ASSERT(! _program);
|
||||
|
||||
_engine = new Engine();
|
||||
_pool = new NodePool(_fileName, _engine);
|
||||
_ids.clear();
|
||||
|
||||
Lexer lexer(_engine);
|
||||
Parser parser(_engine);
|
||||
|
||||
lexer.setCode(_source, /*line = */ 1);
|
||||
|
||||
_parsedCorrectly = parser.parse();
|
||||
_program = parser.ast();
|
||||
_diagnosticMessages = parser.diagnosticMessages();
|
||||
|
||||
if (_parsedCorrectly && _program) {
|
||||
Internal::IdCollector collect;
|
||||
_ids = collect(_fileName, _program);
|
||||
}
|
||||
|
||||
return _parsedCorrectly;
|
||||
}
|
||||
|
||||
Snapshot::Snapshot()
|
||||
{
|
||||
}
|
||||
|
||||
Snapshot::~Snapshot()
|
||||
{
|
||||
}
|
||||
|
||||
void Snapshot::insert(const QmlDocument::Ptr &document)
|
||||
{
|
||||
QMap<QString, QmlDocument::Ptr>::insert(document->fileName(), document);
|
||||
}
|
||||
|
||||
QmlDocument::PtrList Snapshot::importedDocuments(const QmlDocument::Ptr &doc, const QString &importPath) const
|
||||
{
|
||||
QmlDocument::PtrList result;
|
||||
|
||||
const QString docPath = doc->path() + '/' + importPath;
|
||||
|
||||
foreach (QmlDocument::Ptr candidate, *this) {
|
||||
if (candidate == doc)
|
||||
continue;
|
||||
|
||||
if (candidate->path() == doc->path() || candidate->path() == docPath)
|
||||
result.append(candidate);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QMap<QString, QmlDocument::Ptr> Snapshot::componentsDefinedByImportedDocuments(const QmlDocument::Ptr &doc, const QString &importPath) const
|
||||
{
|
||||
QMap<QString, QmlDocument::Ptr> result;
|
||||
|
||||
const QString docPath = doc->path() + '/' + importPath;
|
||||
|
||||
foreach (QmlDocument::Ptr candidate, *this) {
|
||||
if (candidate == doc)
|
||||
continue;
|
||||
|
||||
if (candidate->path() == doc->path() || candidate->path() == docPath)
|
||||
result.insert(candidate->componentName(), candidate);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@@ -1,109 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
#ifndef QMLDOCUMENT_H
|
||||
#define QMLDOCUMENT_H
|
||||
|
||||
#include <corelib_global.h>
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QPair>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include "qmleditor_global.h"
|
||||
#include "qmljsengine_p.h"
|
||||
#include "qmljsastfwd_p.h"
|
||||
#include "qmlsymbol.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class CORESHARED_EXPORT QmlDocument
|
||||
{
|
||||
public:
|
||||
typedef QSharedPointer<QmlDocument> Ptr;
|
||||
typedef QList<QmlDocument::Ptr> PtrList;
|
||||
typedef QMap<QString, QmlIdSymbol*> IdTable;
|
||||
|
||||
protected:
|
||||
QmlDocument(const QString &fileName);
|
||||
|
||||
public:
|
||||
~QmlDocument();
|
||||
|
||||
static QmlDocument::Ptr create(const QString &fileName);
|
||||
|
||||
QmlJS::AST::UiProgram *program() const;
|
||||
QList<QmlJS::DiagnosticMessage> diagnosticMessages() const;
|
||||
|
||||
QString source() const;
|
||||
void setSource(const QString &source);
|
||||
|
||||
bool parse();
|
||||
|
||||
bool isParsedCorrectly() const
|
||||
{ return _parsedCorrectly; }
|
||||
|
||||
IdTable ids() const { return _ids; }
|
||||
|
||||
QString fileName() const { return _fileName; }
|
||||
QString path() const { return _path; }
|
||||
QString componentName() const { return _componentName; }
|
||||
|
||||
private:
|
||||
QmlJS::Engine *_engine;
|
||||
QmlJS::NodePool *_pool;
|
||||
QmlJS::AST::UiProgram *_program;
|
||||
QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
|
||||
QString _fileName;
|
||||
QString _path;
|
||||
QString _componentName;
|
||||
QString _source;
|
||||
bool _parsedCorrectly;
|
||||
IdTable _ids;
|
||||
};
|
||||
|
||||
class CORESHARED_EXPORT Snapshot: public QMap<QString, QmlDocument::Ptr>
|
||||
{
|
||||
public:
|
||||
Snapshot();
|
||||
~Snapshot();
|
||||
|
||||
void insert(const QmlDocument::Ptr &document);
|
||||
|
||||
QmlDocument::Ptr document(const QString &fileName) const
|
||||
{ return value(fileName); }
|
||||
|
||||
QmlDocument::PtrList importedDocuments(const QmlDocument::Ptr &doc, const QString &importPath) const;
|
||||
QMap<QString, QmlDocument::Ptr> componentsDefinedByImportedDocuments(const QmlDocument::Ptr &doc, const QString &importPath) const;
|
||||
};
|
||||
|
||||
} // emd of namespace QmlDesigner
|
||||
|
||||
#endif // QMLDOCUMENT_H
|
@@ -40,10 +40,11 @@
|
||||
#include "removepropertyvisitor.h"
|
||||
#include "removeuiobjectmembervisitor.h"
|
||||
|
||||
using namespace Qml;
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlDesigner::Internal;
|
||||
|
||||
QmlRefactoring::QmlRefactoring(const QmlDocument::Ptr &doc, QmlDesigner::TextModifier &modifier, const QStringList &propertyOrder):
|
||||
QmlRefactoring::QmlRefactoring(const QmlDocument::Ptr &doc, TextModifier &modifier, const QStringList &propertyOrder):
|
||||
qmlDocument(doc),
|
||||
textModifier(&modifier),
|
||||
m_propertyOrder(propertyOrder)
|
||||
@@ -56,7 +57,7 @@ bool QmlRefactoring::reparseDocument()
|
||||
|
||||
// qDebug() << "QmlRefactoring::reparseDocument() new QML source:" << newSource;
|
||||
|
||||
QmlDesigner::QmlDocument::Ptr tmpDocument(QmlDesigner::QmlDocument::create("<ModelToTextMerger>"));
|
||||
QmlDocument::Ptr tmpDocument(QmlDocument::create("<ModelToTextMerger>"));
|
||||
tmpDocument->setSource(newSource);
|
||||
|
||||
if (tmpDocument->parse()) {
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
#include <import.h>
|
||||
#include <textmodifier.h>
|
||||
#include <filemanager/qmldocument.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
QmlRefactoring(const QmlDocument::Ptr &doc, QmlDesigner::TextModifier &modifier, const QStringList &propertyOrder);
|
||||
QmlRefactoring(const Qml::QmlDocument::Ptr &doc, QmlDesigner::TextModifier &modifier, const QStringList &propertyOrder);
|
||||
|
||||
bool reparseDocument();
|
||||
|
||||
@@ -70,8 +70,8 @@ public:
|
||||
bool removeProperty(int parentLocation, const QString &name);
|
||||
|
||||
private:
|
||||
QmlDocument::Ptr qmlDocument;
|
||||
QmlDesigner::TextModifier *textModifier;
|
||||
Qml::QmlDocument::Ptr qmlDocument;
|
||||
TextModifier *textModifier;
|
||||
QStringList m_propertyOrder;
|
||||
};
|
||||
|
||||
|
@@ -27,14 +27,14 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmlrewriter.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QTextBlock>
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
|
||||
#include "qmlrewriter.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
using namespace QmlJS;
|
||||
|
@@ -30,13 +30,13 @@
|
||||
#ifndef QMLREWRITER_H
|
||||
#define QMLREWRITER_H
|
||||
|
||||
#include "textmodifier.h"
|
||||
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
|
||||
#include <QtCore/QStack>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include <qmljsastvisitor_p.h>
|
||||
|
||||
#include "textmodifier.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
|
@@ -1,116 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljsast_p.h"
|
||||
#include "qmlsymbol.h"
|
||||
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
||||
|
||||
QmlSymbol::~QmlSymbol()
|
||||
{
|
||||
}
|
||||
|
||||
bool QmlSymbol::isBuildInSymbol() const
|
||||
{ return asBuildInSymbol() != 0; }
|
||||
|
||||
bool QmlSymbol::isSymbolFromFile() const
|
||||
{ return asSymbolFromFile() != 0; }
|
||||
|
||||
bool QmlSymbol::isIdSymbol() const
|
||||
{ return asIdSymbol() != 0; }
|
||||
|
||||
QmlBuildInSymbol const *QmlSymbol::asBuildInSymbol() const
|
||||
{ return 0; }
|
||||
|
||||
QmlSymbolFromFile const *QmlSymbol::asSymbolFromFile() const
|
||||
{ return 0; }
|
||||
|
||||
QmlIdSymbol const *QmlSymbol::asIdSymbol() const
|
||||
{ return 0; }
|
||||
|
||||
QmlBuildInSymbol::~QmlBuildInSymbol()
|
||||
{}
|
||||
|
||||
QmlBuildInSymbol const* QmlBuildInSymbol::asBuildInSymbol() const
|
||||
{ return this; }
|
||||
|
||||
QmlSymbolFromFile::QmlSymbolFromFile(const QString &fileName, QmlJS::AST::UiObjectMember *node):
|
||||
_fileName(fileName),
|
||||
_node(node)
|
||||
{}
|
||||
|
||||
QmlSymbolFromFile::~QmlSymbolFromFile()
|
||||
{}
|
||||
|
||||
const QmlSymbolFromFile *QmlSymbolFromFile::asSymbolFromFile() const
|
||||
{ return this; }
|
||||
|
||||
int QmlSymbolFromFile::line() const
|
||||
{ return _node->firstSourceLocation().startLine; }
|
||||
|
||||
int QmlSymbolFromFile::column() const
|
||||
{ return _node->firstSourceLocation().startColumn; }
|
||||
|
||||
QmlIdSymbol::QmlIdSymbol(const QString &fileName, QmlJS::AST::UiScriptBinding *idNode, const QmlSymbolFromFile &parentNode):
|
||||
QmlSymbolFromFile(fileName, idNode),
|
||||
_parentNode(parentNode)
|
||||
{}
|
||||
|
||||
QmlIdSymbol::~QmlIdSymbol()
|
||||
{}
|
||||
|
||||
QmlIdSymbol const *QmlIdSymbol::asIdSymbol() const
|
||||
{ return this; }
|
||||
|
||||
int QmlIdSymbol::line() const
|
||||
{ return idNode()->statement->firstSourceLocation().startLine; }
|
||||
|
||||
int QmlIdSymbol::column() const
|
||||
{ return idNode()->statement->firstSourceLocation().startColumn; }
|
||||
|
||||
QmlJS::AST::UiScriptBinding *QmlIdSymbol::idNode() const
|
||||
{ return cast<UiScriptBinding*>(node()); }
|
||||
|
||||
QmlPropertyDefinitionSymbol::QmlPropertyDefinitionSymbol(const QString &fileName, QmlJS::AST::UiPublicMember *propertyNode):
|
||||
QmlSymbolFromFile(fileName, propertyNode)
|
||||
{}
|
||||
|
||||
QmlPropertyDefinitionSymbol::~QmlPropertyDefinitionSymbol()
|
||||
{}
|
||||
|
||||
int QmlPropertyDefinitionSymbol::line() const
|
||||
{ return propertyNode()->identifierToken.startLine; }
|
||||
|
||||
int QmlPropertyDefinitionSymbol::column() const
|
||||
{ return propertyNode()->identifierToken.startColumn; }
|
||||
|
||||
QmlJS::AST::UiPublicMember *QmlPropertyDefinitionSymbol::propertyNode() const
|
||||
{ return cast<UiPublicMember*>(node()); }
|
@@ -1,121 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef QMLSYMBOL_H
|
||||
#define QMLSYMBOL_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "qmljsastfwd_p.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class QmlSymbol
|
||||
{
|
||||
public:
|
||||
virtual ~QmlSymbol() = 0;
|
||||
|
||||
bool isBuildInSymbol() const;
|
||||
bool isSymbolFromFile() const;
|
||||
bool isIdSymbol() const;
|
||||
|
||||
virtual class QmlBuildInSymbol const *asBuildInSymbol() const;
|
||||
virtual class QmlSymbolFromFile const *asSymbolFromFile() const;
|
||||
virtual class QmlIdSymbol const *asIdSymbol() const;
|
||||
};
|
||||
|
||||
class QmlBuildInSymbol: public QmlSymbol
|
||||
{
|
||||
public:
|
||||
virtual ~QmlBuildInSymbol();
|
||||
|
||||
virtual QmlBuildInSymbol const *asBuildInSymbol() const;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class QmlSymbolFromFile: public QmlSymbol
|
||||
{
|
||||
public:
|
||||
QmlSymbolFromFile(const QString &fileName, QmlJS::AST::UiObjectMember *node);
|
||||
virtual ~QmlSymbolFromFile();
|
||||
|
||||
virtual QmlSymbolFromFile const *asSymbolFromFile() const;
|
||||
|
||||
QString fileName() const
|
||||
{ return _fileName; }
|
||||
|
||||
virtual int line() const;
|
||||
virtual int column() const;
|
||||
|
||||
QmlJS::AST::UiObjectMember *node() const
|
||||
{ return _node; }
|
||||
|
||||
private:
|
||||
QString _fileName;
|
||||
QmlJS::AST::UiObjectMember *_node;
|
||||
};
|
||||
|
||||
class QmlIdSymbol: public QmlSymbolFromFile
|
||||
{
|
||||
public:
|
||||
QmlIdSymbol(const QString &fileName, QmlJS::AST::UiScriptBinding *idNode, const QmlSymbolFromFile &parentNode);
|
||||
virtual ~QmlIdSymbol();
|
||||
|
||||
QmlIdSymbol const *asIdSymbol() const;
|
||||
|
||||
virtual int line() const;
|
||||
virtual int column() const;
|
||||
|
||||
QmlSymbolFromFile const *parentNode() const
|
||||
{ return &_parentNode; }
|
||||
|
||||
private:
|
||||
QmlJS::AST::UiScriptBinding *idNode() const;
|
||||
|
||||
private:
|
||||
QmlSymbolFromFile _parentNode;
|
||||
};
|
||||
|
||||
class QmlPropertyDefinitionSymbol: public QmlSymbolFromFile
|
||||
{
|
||||
public:
|
||||
QmlPropertyDefinitionSymbol(const QString &fileName, QmlJS::AST::UiPublicMember *propertyNode);
|
||||
virtual ~QmlPropertyDefinitionSymbol();
|
||||
|
||||
virtual int line() const;
|
||||
virtual int column() const;
|
||||
|
||||
private:
|
||||
QmlJS::AST::UiPublicMember *propertyNode() const;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
#endif // QMLSYMBOL_H
|
@@ -27,11 +27,11 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
|
||||
#include "removepropertyvisitor.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
using namespace QmlDesigner::Internal;
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
||||
|
@@ -27,12 +27,13 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <QDebug>
|
||||
#include <qmljsast_p.h>
|
||||
#include <qmljsengine_p.h>
|
||||
|
||||
#include "removeuiobjectmembervisitor.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlDesigner::Internal;
|
||||
using namespace QmlJS;
|
||||
|
@@ -1,37 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef UTILS_GLOBAL_H
|
||||
#define UTILS_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#define QTCREATOR_UTILS_EXPORT
|
||||
|
||||
#endif // UTILS_GLOBAL_H
|
@@ -32,16 +32,19 @@
|
||||
#include "qmltextgenerator.h"
|
||||
#include "rewriteactioncompressor.h"
|
||||
#include "rewriterview.h"
|
||||
#include <filemanager/qmldocument.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include <qmljs/qmldocument.h>
|
||||
#include <variantproperty.h>
|
||||
#include <nodelistproperty.h>
|
||||
#include <nodeproperty.h>
|
||||
#include <textmodifier.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#define INDENT_DEPTH 4
|
||||
#undef DUMP_REWRITE_ACTIONS
|
||||
|
||||
using namespace Qml;
|
||||
using namespace QmlDesigner;
|
||||
using namespace QmlDesigner::Internal;
|
||||
|
||||
|
@@ -32,7 +32,7 @@
|
||||
#include <QtGui/QPlainTextEdit>
|
||||
#include <QtGui/QUndoStack>
|
||||
|
||||
#include <filemanager/changeset.h>
|
||||
#include <utils/changeset.h>
|
||||
|
||||
#include "plaintexteditmodifier.h"
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
include(../../libs/utils/utils.pri)
|
||||
include(../../libs/qml/qml.pri)
|
||||
include(../../libs/qmljs/qmljs.pri)
|
||||
include(../coreplugin/coreplugin.pri)
|
||||
include(../texteditor/texteditor.pri)
|
||||
|
@@ -34,7 +34,7 @@
|
||||
#include "qmllookupcontext.h"
|
||||
#include "qmlresolveexpression.h"
|
||||
|
||||
#include <qml/qmlsymbol.h>
|
||||
#include <qmljs/qmlsymbol.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
|
||||
#include <QtDebug>
|
||||
|
@@ -30,7 +30,7 @@
|
||||
#ifndef QMLCODECOMPLETION_H
|
||||
#define QMLCODECOMPLETION_H
|
||||
|
||||
#include <qml/metatype/qmltypesystem.h>
|
||||
#include <qmljs/qmltypesystem.h>
|
||||
#include <texteditor/icompletioncollector.h>
|
||||
|
||||
namespace TextEditor {
|
||||
|
@@ -39,12 +39,12 @@
|
||||
|
||||
#include <qscripthighlighter/qscriptindenter.h>
|
||||
|
||||
#include <qml/metatype/qmltypesystem.h>
|
||||
#include <qml/parser/qmljsastvisitor_p.h>
|
||||
#include <qml/parser/qmljsast_p.h>
|
||||
#include <qml/parser/qmljsengine_p.h>
|
||||
#include <qml/qmldocument.h>
|
||||
#include <qml/qmlidcollector.h>
|
||||
#include <qmljs/qmltypesystem.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
#include <qmljs/qmlidcollector.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
|
@@ -30,7 +30,7 @@
|
||||
#ifndef QMLEDITORW_H
|
||||
#define QMLEDITORW_H
|
||||
|
||||
#include <qml/qmldocument.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
#include <qscripthighlighter/qscriptincrementalscanner.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
|
||||
|
@@ -2,5 +2,5 @@ include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../plugins/texteditor/texteditor.pri)
|
||||
include(../../plugins/help/help.pri)
|
||||
include(../../shared/indenter/indenter.pri)
|
||||
include(../../libs/qml/qml.pri)
|
||||
include(../../libs/qmljs/qmljs.pri)
|
||||
include(../../libs/utils/utils.pri)
|
||||
|
@@ -29,12 +29,12 @@
|
||||
|
||||
#include "qmlexpressionundercursor.h"
|
||||
|
||||
#include <qml/parser/qmljsast_p.h>
|
||||
#include <qml/parser/qmljsastvisitor_p.h>
|
||||
#include <qml/parser/qmljsengine_p.h>
|
||||
#include <qml/parser/qmljslexer_p.h>
|
||||
#include <qml/parser/qmljsnodepool_p.h>
|
||||
#include <qml/parser/qmljsparser_p.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
#include <qmljs/parser/qmljslexer_p.h>
|
||||
#include <qmljs/parser/qmljsnodepool_p.h>
|
||||
#include <qmljs/parser/qmljsparser_p.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@@ -31,9 +31,9 @@
|
||||
#define QMLEXPRESSIONUNDERCURSOR_H
|
||||
|
||||
|
||||
#include <qml/parser/qmljsastfwd_p.h>
|
||||
#include <qml/qmldocument.h>
|
||||
#include <qml/qmlsymbol.h>
|
||||
#include <qmljs/parser/qmljsastfwd_p.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
#include <qmljs/qmlsymbol.h>
|
||||
|
||||
#include <QStack>
|
||||
#include <QTextBlock>
|
||||
|
@@ -38,7 +38,7 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <debugger/debuggerconstants.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <qml/qmlsymbol.h>
|
||||
#include <qmljs/qmlsymbol.h>
|
||||
#include <texteditor/itexteditor.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
|
||||
|
@@ -31,9 +31,9 @@
|
||||
#include "qmllookupcontext.h"
|
||||
#include "qmlresolveexpression.h"
|
||||
|
||||
#include <qml/metatype/qmltypesystem.h>
|
||||
#include <qml/parser/qmljsast_p.h>
|
||||
#include <qml/parser/qmljsengine_p.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
#include <qmljs/qmltypesystem.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@@ -30,10 +30,10 @@
|
||||
#ifndef QMLLOOKUPCONTEXT_H
|
||||
#define QMLLOOKUPCONTEXT_H
|
||||
|
||||
#include <qml/metatype/qmltypesystem.h>
|
||||
#include <qml/parser/qmljsastvisitor_p.h>
|
||||
#include <qml/qmldocument.h>
|
||||
#include <qml/qmlsymbol.h>
|
||||
#include <qmljs/qmltypesystem.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
#include <qmljs/qmlsymbol.h>
|
||||
|
||||
#include <QStack>
|
||||
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
#include "qmlmodelmanagerinterface.h"
|
||||
|
||||
#include <qml/qmldocument.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
|
||||
#include <QFuture>
|
||||
#include <QFutureSynchronizer>
|
||||
|
@@ -36,8 +36,8 @@
|
||||
#include <QStringList>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include <qml/qmldocument.h>
|
||||
#include <qml/metatype/qmltypesystem.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
#include <qmljs/qmltypesystem.h>
|
||||
|
||||
|
||||
namespace Qml {
|
||||
|
@@ -29,8 +29,8 @@
|
||||
|
||||
#include "qmlresolveexpression.h"
|
||||
|
||||
#include <qml/parser/qmljsast_p.h>
|
||||
#include <qml/parser/qmljsengine_p.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
using namespace Qml;
|
||||
using namespace QmlEditor;
|
||||
|
@@ -32,8 +32,8 @@
|
||||
|
||||
#include "qmllookupcontext.h"
|
||||
|
||||
#include <qml/parser/qmljsastvisitor_p.h>
|
||||
#include <qml/qmlsymbol.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/qmlsymbol.h>
|
||||
|
||||
namespace QmlEditor {
|
||||
namespace Internal {
|
||||
|
@@ -31,7 +31,7 @@
|
||||
#define QMLTASKMANAGER_H
|
||||
|
||||
#include <projectexplorer/taskwindow.h>
|
||||
#include <qml/qmldocument.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
|
@@ -1,191 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "exception.h"
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <execinfo.h>
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
#include <QRegExp>
|
||||
|
||||
/*!
|
||||
\defgroup CoreExceptions
|
||||
*/
|
||||
/*!
|
||||
\class Qml::Exception
|
||||
\ingroup CoreExceptions
|
||||
\brief This is the abstract base class for all excetions.
|
||||
Exceptions should be used in cases there is no other way to say something goes wrong. For example
|
||||
the result would be a inconsistent model or a crash.
|
||||
*/
|
||||
|
||||
using namespace Qml;
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
const char* demangle(const char* name)
|
||||
{
|
||||
char buf[1024];
|
||||
size_t size = 1024;
|
||||
int status;
|
||||
char* res;
|
||||
res = abi::__cxa_demangle(name,
|
||||
buf,
|
||||
&size,
|
||||
&status);
|
||||
return res;
|
||||
}
|
||||
#else
|
||||
const char* demangle(const char* name)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool Exception::s_shouldAssert = false;
|
||||
|
||||
void Exception::setShouldAssert(bool assert)
|
||||
{
|
||||
s_shouldAssert = assert;
|
||||
}
|
||||
|
||||
bool Exception::shouldAssert()
|
||||
{
|
||||
return s_shouldAssert;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Constructor
|
||||
|
||||
\param line use the __LINE__ macro
|
||||
\param function use the __FUNCTION__ or the Q_FUNC_INFO macro
|
||||
\param file use the __FILE__ macro
|
||||
*/
|
||||
Exception::Exception(int line,
|
||||
const QString &function,
|
||||
const QString &file)
|
||||
: m_line(line),
|
||||
m_function(function),
|
||||
m_file(file)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
void * array[50];
|
||||
int nSize = backtrace(array, 50);
|
||||
char ** symbols = backtrace_symbols(array, nSize);
|
||||
|
||||
for (int i = 0; i < nSize; i++)
|
||||
{
|
||||
m_backTrace.append(QString("%1\n").arg(symbols[i]));
|
||||
}
|
||||
|
||||
free(symbols);
|
||||
#endif
|
||||
|
||||
if (s_shouldAssert)
|
||||
Q_ASSERT_X(false, function.toLatin1(), QString("%1:%2 - %3").arg(file).arg(line).arg(function).toLatin1());
|
||||
}
|
||||
|
||||
Exception::~Exception()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the unmangled backtrace of this exception
|
||||
|
||||
\returns the backtrace as a string
|
||||
*/
|
||||
QString Exception::backTrace() const
|
||||
{
|
||||
return m_backTrace;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the optional description of this exception
|
||||
|
||||
\returns the description as string
|
||||
*/
|
||||
QString Exception::description() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the line number where this exception was thrown
|
||||
|
||||
\returns the line number as integer
|
||||
*/
|
||||
int Exception::line() const
|
||||
{
|
||||
return m_line;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the function name where this exception was thrown
|
||||
|
||||
\returns the function name as string
|
||||
*/
|
||||
QString Exception::function() const
|
||||
{
|
||||
return m_function;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the file name where this exception was thrown
|
||||
|
||||
\returns the file name as string
|
||||
*/
|
||||
QString Exception::file() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const Exception &exception)
|
||||
{
|
||||
debug.nospace() << "Exception: " << exception.type() << "\n"
|
||||
"Function: " << exception.function() << "\n"
|
||||
"File: " << exception.file() << "\n"
|
||||
"Line: " << exception.line() << "\n";
|
||||
if (!exception.description().isEmpty())
|
||||
debug.nospace() << exception.description();
|
||||
|
||||
if (!exception.backTrace().isEmpty())
|
||||
debug.nospace() << exception.backTrace();
|
||||
|
||||
return debug.space();
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QString Exception::type() const
|
||||
\brief Returns the type of this exception
|
||||
|
||||
\returns the type as a string
|
||||
*/
|
@@ -1,70 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef EXCEPTION_H
|
||||
#define EXCEPTION_H
|
||||
|
||||
#include <qml/qml_global.h>
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace Qml {
|
||||
|
||||
class QML_EXPORT Exception
|
||||
{
|
||||
public:
|
||||
Exception(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
virtual ~Exception();
|
||||
|
||||
virtual QString type() const=0;
|
||||
virtual QString description() const;
|
||||
|
||||
int line() const;
|
||||
QString function() const;
|
||||
QString file() const;
|
||||
QString backTrace() const;
|
||||
|
||||
static void setShouldAssert(bool assert);
|
||||
static bool shouldAssert();
|
||||
|
||||
private:
|
||||
int m_line;
|
||||
QString m_function;
|
||||
QString m_file;
|
||||
QString m_backTrace;
|
||||
static bool s_shouldAssert;
|
||||
};
|
||||
|
||||
QML_EXPORT QDebug operator<<(QDebug debug, const Exception &exception);
|
||||
|
||||
} // namespace Qml
|
||||
|
||||
#endif // EXCEPTION_H
|
@@ -1,62 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "invalidmetainfoexception.h"
|
||||
|
||||
/*!
|
||||
\class Qml::InvalidMetaInfoException
|
||||
\ingroup CoreExceptions
|
||||
\brief Exception for a invalid meta info
|
||||
|
||||
\see NodeMetaInfo PropertyMetaInfo MetaInfo
|
||||
*/
|
||||
using namespace Qml;
|
||||
/*!
|
||||
\brief Constructor
|
||||
|
||||
\param line use the __LINE__ macro
|
||||
\param function use the __FUNCTION__ or the Q_FUNC_INFO macro
|
||||
\param file use the __FILE__ macro
|
||||
*/
|
||||
InvalidMetaInfoException::InvalidMetaInfoException(int line,
|
||||
const QString &function,
|
||||
const QString &file)
|
||||
: Exception(line, function, file)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the type of this exception
|
||||
|
||||
\returns the type as a string
|
||||
*/
|
||||
QString InvalidMetaInfoException::type() const
|
||||
{
|
||||
return "InvalidMetaInfoException";
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef INVALIDMETAINFOEXCEPTION_H
|
||||
#define INVALIDMETAINFOEXCEPTION_H
|
||||
|
||||
#include "exception.h"
|
||||
|
||||
namespace Qml {
|
||||
|
||||
class QML_EXPORT InvalidMetaInfoException : public Exception
|
||||
{
|
||||
public:
|
||||
InvalidMetaInfoException(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
|
||||
QString type() const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // INVALIDMETAINFOEXCEPTION_H
|
@@ -1,489 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "invalidmetainfoexception.h"
|
||||
#include "metainfo.h"
|
||||
#include "propertymetainfo.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPair>
|
||||
#include <QtAlgorithms>
|
||||
#include <QMetaProperty>
|
||||
#include <QmlMetaType>
|
||||
|
||||
enum {
|
||||
debug = false
|
||||
};
|
||||
|
||||
namespace Qml {
|
||||
namespace Internal {
|
||||
|
||||
class MetaInfoPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(MetaInfoPrivate)
|
||||
public:
|
||||
typedef QSharedPointer<MetaInfoPrivate> Pointer;
|
||||
typedef QWeakPointer<MetaInfoPrivate> WeakPointer;
|
||||
|
||||
|
||||
MetaInfoPrivate(MetaInfo *q);
|
||||
void clear();
|
||||
|
||||
void initialize();
|
||||
void parseQmlTypes();
|
||||
void parseNonQmlTypes();
|
||||
void parseValueTypes();
|
||||
void parseNonQmlClassRecursively(const QMetaObject *qMetaObject);
|
||||
void parseProperties(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const;
|
||||
void parseClassInfo(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const;
|
||||
|
||||
QString typeName(const QMetaObject *qMetaObject) const;
|
||||
|
||||
void parseXmlFiles();
|
||||
|
||||
QMultiHash<QString, QString> m_superClassHash; // the list of direct superclasses
|
||||
QHash<QString, NodeMetaInfo> m_nodeMetaInfoHash;
|
||||
QHash<QString, QString> m_QtTypesToQmlTypes;
|
||||
|
||||
MetaInfo *m_q;
|
||||
bool m_isInitialized;
|
||||
};
|
||||
|
||||
MetaInfoPrivate::MetaInfoPrivate(MetaInfo *q) :
|
||||
m_q(q),
|
||||
m_isInitialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
void MetaInfoPrivate::clear()
|
||||
{
|
||||
m_superClassHash.clear();
|
||||
m_nodeMetaInfoHash.clear();
|
||||
m_isInitialized = false;
|
||||
}
|
||||
|
||||
void MetaInfoPrivate::initialize()
|
||||
{
|
||||
parseQmlTypes();
|
||||
parseNonQmlTypes();
|
||||
// parseValueTypes();
|
||||
// parseXmlFiles();
|
||||
|
||||
m_isInitialized = true;
|
||||
}
|
||||
|
||||
void MetaInfoPrivate::parseProperties(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const
|
||||
{
|
||||
Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject");
|
||||
Q_ASSERT_X(nodeMetaInfo.isValid(), Q_FUNC_INFO, "invalid NodeMetaInfo");
|
||||
|
||||
for (int i = qMetaObject->propertyOffset(); i < qMetaObject->propertyCount(); ++i) {
|
||||
QMetaProperty qProperty = qMetaObject->property(i);
|
||||
|
||||
PropertyMetaInfo propertyInfo;
|
||||
|
||||
propertyInfo.setName(QLatin1String(qProperty.name()));
|
||||
|
||||
QString typeName(qProperty.typeName());
|
||||
QString noStar = typeName;
|
||||
bool star = false;
|
||||
while (noStar.contains('*')) {//strip star
|
||||
noStar.chop(1);
|
||||
star = true;
|
||||
}
|
||||
if (m_QtTypesToQmlTypes.contains(noStar)) {
|
||||
typeName = star ? m_QtTypesToQmlTypes.value(noStar) + '*' : m_QtTypesToQmlTypes.value(noStar);
|
||||
//### versions
|
||||
}
|
||||
int majorVersion = -1, minorVersion = -1;
|
||||
if (QmlType *propertyType = QmlMetaType::qmlType(qMetaObject)) {
|
||||
majorVersion = propertyType->majorVersion();
|
||||
minorVersion = propertyType->minorVersion();
|
||||
}
|
||||
|
||||
propertyInfo.setType(typeName, majorVersion, minorVersion);
|
||||
propertyInfo.setValid(true);
|
||||
propertyInfo.setReadable(qProperty.isReadable());
|
||||
propertyInfo.setWritable(qProperty.isWritable());
|
||||
propertyInfo.setResettable(qProperty.isResettable());
|
||||
propertyInfo.setEnumType(qProperty.isEnumType());
|
||||
propertyInfo.setFlagType(qProperty.isFlagType());
|
||||
|
||||
// if (propertyInfo.isEnumType()) {
|
||||
// EnumeratorMetaInfo enumerator;
|
||||
//
|
||||
// QMetaEnum qEnumerator = qProperty.enumerator();
|
||||
// enumerator.setValid(qEnumerator.isValid());
|
||||
// enumerator.setIsFlagType(qEnumerator.isFlag());
|
||||
// enumerator.setScope(qEnumerator.scope());
|
||||
// enumerator.setName(qEnumerator.name());
|
||||
// for (int i = 0 ;i < qEnumerator.keyCount(); i++)
|
||||
// {
|
||||
// enumerator.addElement(qEnumerator.valueToKey(i), i);
|
||||
// }
|
||||
//
|
||||
// propertyInfo.setEnumerator(enumerator);
|
||||
// }
|
||||
|
||||
nodeMetaInfo.addProperty(propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void MetaInfoPrivate::parseClassInfo(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const
|
||||
{
|
||||
Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject");
|
||||
Q_ASSERT_X(nodeMetaInfo.isValid(), Q_FUNC_INFO, "invalid NodeMetaInfo");
|
||||
for (int index = qMetaObject->classInfoCount() - 1 ; index >= 0 ; --index) {
|
||||
QMetaClassInfo classInfo = qMetaObject->classInfo(index);
|
||||
if (QLatin1String(classInfo.name()) == QLatin1String("DefaultProperty")) {
|
||||
nodeMetaInfo.setDefaultProperty(classInfo.value());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MetaInfoPrivate::parseNonQmlClassRecursively(const QMetaObject *qMetaObject)
|
||||
{
|
||||
Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject");
|
||||
const QString className = qMetaObject->className();
|
||||
if ( !m_q->hasNodeMetaInfo(className)
|
||||
&& !QmlMetaType::qmlTypeNames().contains(typeName(qMetaObject).toAscii()) ) {
|
||||
NodeMetaInfo nodeMetaInfo(*m_q);
|
||||
nodeMetaInfo.setTypeName(typeName(qMetaObject));
|
||||
parseProperties(nodeMetaInfo, qMetaObject);
|
||||
parseClassInfo(nodeMetaInfo, qMetaObject);
|
||||
|
||||
if (debug)
|
||||
qDebug() << "adding non qml type" << className << typeName(qMetaObject) << ", parent type" << typeName(qMetaObject->superClass());
|
||||
m_q->addNodeInfo(nodeMetaInfo, typeName(qMetaObject->superClass()));
|
||||
}
|
||||
|
||||
if (const QMetaObject *superClass = qMetaObject->superClass()) {
|
||||
parseNonQmlClassRecursively(superClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString MetaInfoPrivate::typeName(const QMetaObject *qMetaObject) const
|
||||
{
|
||||
if (!qMetaObject)
|
||||
return QString();
|
||||
QString className = qMetaObject->className();
|
||||
if (QmlType *qmlType = QmlMetaType::qmlType(qMetaObject)) {
|
||||
QString qmlClassName(qmlType->qmlTypeName());
|
||||
if (!qmlClassName.isEmpty())
|
||||
className = qmlType->qmlTypeName(); // Ensure that we always use the qml name,
|
||||
// if available.
|
||||
}
|
||||
return className;
|
||||
}
|
||||
|
||||
void MetaInfoPrivate::parseQmlTypes()
|
||||
{
|
||||
foreach (QmlType *qmlType, QmlMetaType::qmlTypes()) {
|
||||
const QString qtTypeName(qmlType->typeName());
|
||||
const QString qmlTypeName(qmlType->qmlTypeName());
|
||||
m_QtTypesToQmlTypes.insert(qtTypeName, qmlTypeName);
|
||||
}
|
||||
foreach (QmlType *qmlType, QmlMetaType::qmlTypes()) {
|
||||
const QMetaObject *qMetaObject = qmlType->metaObject();
|
||||
|
||||
// parseQmlTypes is called iteratively e.g. when plugins are loaded
|
||||
if (m_q->hasNodeMetaInfo(qmlType->qmlTypeName(), qmlType->majorVersion(), qmlType->minorVersion()))
|
||||
continue;
|
||||
|
||||
NodeMetaInfo nodeMetaInfo(*m_q);
|
||||
nodeMetaInfo.setTypeName(qmlType->qmlTypeName());
|
||||
nodeMetaInfo.setMajorVersion(qmlType->majorVersion());
|
||||
nodeMetaInfo.setMinorVersion(qmlType->minorVersion());
|
||||
|
||||
parseProperties(nodeMetaInfo, qMetaObject);
|
||||
parseClassInfo(nodeMetaInfo, qMetaObject);
|
||||
|
||||
QString superTypeName = typeName(qMetaObject->superClass());
|
||||
if (qmlType->baseMetaObject() != qMetaObject) {
|
||||
// type is declared with Q_DECLARE_EXTENDED_TYPE
|
||||
// also parse properties of original type
|
||||
parseProperties(nodeMetaInfo, qmlType->baseMetaObject());
|
||||
superTypeName = typeName(qmlType->baseMetaObject()->superClass());
|
||||
}
|
||||
|
||||
m_q->addNodeInfo(nodeMetaInfo, superTypeName);
|
||||
}
|
||||
}
|
||||
|
||||
void MetaInfoPrivate::parseNonQmlTypes()
|
||||
{
|
||||
foreach (QmlType *qmlType, QmlMetaType::qmlTypes()) {
|
||||
parseNonQmlClassRecursively(qmlType->metaObject());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
using Qml::Internal::MetaInfoPrivate;
|
||||
|
||||
MetaInfo MetaInfo::s_global;
|
||||
QStringList MetaInfo::s_pluginDirs;
|
||||
|
||||
|
||||
/*!
|
||||
\class Qml::MetaInfo
|
||||
\ingroup CoreModel
|
||||
\brief The MetaInfo class provides meta information about qml types and properties.
|
||||
|
||||
The MetaInfo, NodeMetaInfo, PropertyMetaInfo and EnumeratorMetaInfo
|
||||
classes provide information about the (static and dynamic) qml types available in
|
||||
a specific model. Just like their Model, ModelNode and AbstractProperty counterparts,
|
||||
objects of these classes are handles - that means, they are implicitly shared, and
|
||||
should be created on the stack.
|
||||
|
||||
The MetaInfo object should always be accessed via the model (see Model::metaInfo()).
|
||||
Otherwise types specific to a model (like sub components) might
|
||||
be missed.
|
||||
|
||||
\see Model::metaInfo(), Qml::NodeMetaInfo, Qml::PropertyMetaInfo, Qml::EnumeratorMetaInfo
|
||||
*/
|
||||
|
||||
/*!
|
||||
\brief Constructs a copy of the given meta info.
|
||||
*/
|
||||
MetaInfo::MetaInfo(const MetaInfo &metaInfo) :
|
||||
m_p(metaInfo.m_p)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Creates a meta information object with just the qml types registered statically.
|
||||
You almost always want to use Model::metaInfo() instead!
|
||||
|
||||
You almost certainly want to access the meta information for the model.
|
||||
|
||||
\see Model::metaInfo()
|
||||
*/
|
||||
MetaInfo::MetaInfo() :
|
||||
m_p(new MetaInfoPrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
MetaInfo::~MetaInfo()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Assigns other to this meta information and returns a reference to this meta information.
|
||||
*/
|
||||
MetaInfo& MetaInfo::operator=(const MetaInfo &other)
|
||||
{
|
||||
m_p = other.m_p;
|
||||
return *this;
|
||||
}
|
||||
|
||||
QList<NodeMetaInfo> MetaInfo::allTypes() const
|
||||
{
|
||||
return m_p->m_nodeMetaInfoHash.values();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether a type with the given name is registered in the meta system.
|
||||
*/
|
||||
bool MetaInfo::hasNodeMetaInfo(const QString &typeName, int /*majorVersion*/, int /*minorVersion*/) const
|
||||
{
|
||||
if (m_p->m_nodeMetaInfoHash.contains(typeName))
|
||||
return true;
|
||||
if (!isGlobal())
|
||||
return global().hasNodeMetaInfo(typeName);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns meta information for a qml type. An invalid NodeMetaInfo object if the type is unknown.
|
||||
*/
|
||||
NodeMetaInfo MetaInfo::nodeMetaInfo(const QString &typeName, int /*majorVersion*/, int /*minorVersion*/) const
|
||||
{
|
||||
if (m_p->m_nodeMetaInfoHash.contains(typeName))
|
||||
return m_p->m_nodeMetaInfoHash.value(typeName, NodeMetaInfo());
|
||||
if (!isGlobal())
|
||||
return global().nodeMetaInfo(typeName);
|
||||
|
||||
return NodeMetaInfo();
|
||||
}
|
||||
|
||||
QStringList MetaInfo::superClasses(const QString &className) const
|
||||
{
|
||||
QStringList ancestorList = m_p->m_superClassHash.values(className);
|
||||
foreach (const QString &ancestor, ancestorList) {
|
||||
QStringList superClassList = superClasses(ancestor);
|
||||
if (!superClassList.isEmpty())
|
||||
ancestorList += superClassList;
|
||||
}
|
||||
if (!isGlobal())
|
||||
ancestorList += global().superClasses(className);
|
||||
return ancestorList;
|
||||
}
|
||||
|
||||
QStringList MetaInfo::directSuperClasses(const QString &className) const
|
||||
{
|
||||
QStringList directAncestorList = m_p->m_superClassHash.values(className);
|
||||
if (!isGlobal())
|
||||
directAncestorList += global().directSuperClasses(className);
|
||||
return directAncestorList;
|
||||
}
|
||||
|
||||
QList<NodeMetaInfo> MetaInfo::superClasses(const NodeMetaInfo &nodeInfo) const
|
||||
{
|
||||
if (!nodeInfo.isValid()) {
|
||||
Q_ASSERT_X(nodeInfo.isValid(), Q_FUNC_INFO, "Invalid nodeInfo argument");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
QList<NodeMetaInfo> superClassList;
|
||||
|
||||
foreach (const QString &typeName, superClasses(nodeInfo.typeName())) {
|
||||
if (!hasNodeMetaInfo(typeName))
|
||||
continue;
|
||||
const NodeMetaInfo superClass = nodeMetaInfo(typeName);
|
||||
if (!superClassList.contains(superClass))
|
||||
superClassList.append(superClass);
|
||||
}
|
||||
return superClassList;
|
||||
}
|
||||
|
||||
QList<NodeMetaInfo> MetaInfo::directSuperClasses(const NodeMetaInfo &nodeInfo) const
|
||||
{
|
||||
if (!nodeInfo.isValid()) {
|
||||
Q_ASSERT_X(nodeInfo.isValid(), Q_FUNC_INFO, "Invalid nodeInfo argument");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
QList<NodeMetaInfo> superClassList;
|
||||
|
||||
foreach (const QString &typeName, directSuperClasses(nodeInfo.typeName())) {
|
||||
if (!hasNodeMetaInfo(typeName))
|
||||
continue;
|
||||
const NodeMetaInfo superClass = nodeMetaInfo(typeName);
|
||||
if (!superClassList.contains(superClass))
|
||||
superClassList.append(superClass);
|
||||
}
|
||||
return superClassList;
|
||||
}
|
||||
|
||||
QStringList MetaInfo::itemLibraryItems() const
|
||||
{
|
||||
QStringList completeList = m_p->m_nodeMetaInfoHash.keys();
|
||||
QStringList finalList;
|
||||
foreach (const QString &name, completeList) {
|
||||
if (nodeMetaInfo(name).isVisibleToItemLibrary())
|
||||
finalList.append(name);
|
||||
}
|
||||
|
||||
if (!isGlobal())
|
||||
finalList += global().itemLibraryItems();
|
||||
|
||||
return finalList;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether className is the same type or a type derived from superClassName.
|
||||
*/
|
||||
bool MetaInfo::isSubclassOf(const QString &className, const QString &superClassName) const
|
||||
{
|
||||
return (className == superClassName) || superClasses(className).contains(superClassName);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Access to the global meta information object.
|
||||
You almost always want to use Model::metaInfo() instead.
|
||||
|
||||
Internally all meta information objects share this "global" object
|
||||
where static qml type information is stored.
|
||||
*/
|
||||
MetaInfo MetaInfo::global()
|
||||
{
|
||||
if (!s_global.m_p->m_isInitialized) {
|
||||
s_global.m_p = QSharedPointer<MetaInfoPrivate>(new MetaInfoPrivate(&s_global));
|
||||
s_global.m_p->initialize();
|
||||
}
|
||||
return s_global;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Clears the global meta information object.
|
||||
|
||||
This method should be called once on application shutdown to free static data structures.
|
||||
*/
|
||||
void MetaInfo::clearGlobal()
|
||||
{
|
||||
MetaInfo::global().m_p->clear();
|
||||
}
|
||||
|
||||
void MetaInfo::setPluginPaths(const QStringList &paths)
|
||||
{
|
||||
s_pluginDirs = paths;
|
||||
}
|
||||
|
||||
/*!
|
||||
This bypasses the notifications to the model that the metatype has changed.
|
||||
Use MetaInfo::addNodeInfo() instead
|
||||
*/
|
||||
void MetaInfo::addSuperClassRelationship(const QString &superClassName, const QString &className)
|
||||
{
|
||||
m_p->m_superClassHash.insert(className, superClassName);
|
||||
}
|
||||
|
||||
void MetaInfo::addNodeInfo(NodeMetaInfo &nodeInfo, const QString &baseType)
|
||||
{
|
||||
if (nodeInfo.typeName().isEmpty() || nodeInfo.metaInfo() != *this)
|
||||
throw new InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
if (nodeInfo.typeName() == baseType) // prevent simple recursion
|
||||
throw new InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
m_p->m_nodeMetaInfoHash.insert(nodeInfo.typeName(), nodeInfo);
|
||||
|
||||
if (!baseType.isEmpty()) {
|
||||
m_p->m_superClassHash.insert(nodeInfo.typeName(), baseType);
|
||||
}
|
||||
}
|
||||
|
||||
bool MetaInfo::isGlobal() const
|
||||
{
|
||||
return (this->m_p == s_global.m_p);
|
||||
}
|
||||
|
||||
bool operator==(const MetaInfo &first, const MetaInfo &second)
|
||||
{
|
||||
return first.m_p == second.m_p;
|
||||
}
|
||||
|
||||
bool operator!=(const MetaInfo &first, const MetaInfo &second)
|
||||
{
|
||||
return !(first == second);
|
||||
}
|
||||
} //namespace Qml
|
@@ -1,112 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef METAINFO_H
|
||||
#define METAINFO_H
|
||||
|
||||
#include <qml/qml_global.h>
|
||||
#include <qml/metatype/nodemetainfo.h>
|
||||
#include <qml/metatype/propertymetainfo.h>
|
||||
|
||||
#include <QMultiHash>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QtCore/QSharedPointer>
|
||||
|
||||
namespace Qml {
|
||||
|
||||
class ModelNode;
|
||||
class AbstractProperty;
|
||||
|
||||
namespace Internal {
|
||||
class MetaInfoPrivate;
|
||||
class ModelPrivate;
|
||||
class SubComponentManagerPrivate;
|
||||
typedef QSharedPointer<MetaInfoPrivate> MetaInfoPrivatePointer;
|
||||
}
|
||||
|
||||
QML_EXPORT bool operator==(const MetaInfo &first, const MetaInfo &second);
|
||||
QML_EXPORT bool operator!=(const MetaInfo &first, const MetaInfo &second);
|
||||
|
||||
class QML_EXPORT MetaInfo
|
||||
{
|
||||
friend class Qml::Internal::MetaInfoPrivate;
|
||||
friend class Qml::Internal::MetaInfoParser;
|
||||
friend class Qml::NodeMetaInfo;
|
||||
friend bool Qml::operator==(const MetaInfo &, const MetaInfo &);
|
||||
|
||||
public:
|
||||
MetaInfo(const MetaInfo &metaInfo);
|
||||
~MetaInfo();
|
||||
MetaInfo& operator=(const MetaInfo &other);
|
||||
|
||||
QList<NodeMetaInfo> allTypes() const;
|
||||
|
||||
bool hasNodeMetaInfo(const QString &typeName, int majorVersion = 4, int minorVersion = 6) const;
|
||||
// ### makes no sense since ModelNode has minor/major version
|
||||
NodeMetaInfo nodeMetaInfo(const ModelNode &node) const;
|
||||
NodeMetaInfo nodeMetaInfo(const QString &typeName, int majorVersion = 4, int minorVersion = 6) const;
|
||||
|
||||
// TODO: Move these to private
|
||||
bool isSubclassOf(const QString &className, const QString &superClassName) const;
|
||||
bool isSubclassOf(const ModelNode &modelNode, const QString &superClassName) const;
|
||||
|
||||
bool hasEnumerator(const QString &enumeratorName) const;
|
||||
|
||||
QStringList itemLibraryItems() const;
|
||||
|
||||
public:
|
||||
static MetaInfo global();
|
||||
static void clearGlobal();
|
||||
|
||||
static void setPluginPaths(const QStringList &paths);
|
||||
|
||||
private:
|
||||
QStringList superClasses(const QString &className) const;
|
||||
QStringList directSuperClasses(const QString &className) const;
|
||||
QList<NodeMetaInfo> superClasses(const NodeMetaInfo &nodeMetaInfo) const;
|
||||
QList<NodeMetaInfo> directSuperClasses(const NodeMetaInfo &nodeMetaInfo) const;
|
||||
|
||||
void addSuperClassRelationship(const QString &superClassName, const QString &className);
|
||||
|
||||
void addNodeInfo(NodeMetaInfo &info, const QString &baseType);
|
||||
|
||||
bool isGlobal() const;
|
||||
|
||||
private:
|
||||
MetaInfo();
|
||||
|
||||
Internal::MetaInfoPrivatePointer m_p;
|
||||
static MetaInfo s_global;
|
||||
static QStringList s_pluginDirs;
|
||||
};
|
||||
|
||||
} // namespace Qml
|
||||
|
||||
#endif // METAINFO_H
|
@@ -1,699 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "invalidmetainfoexception.h"
|
||||
#include "metainfo.h"
|
||||
#include "nodemetainfo.h"
|
||||
#include "propertymetainfo.h"
|
||||
|
||||
#include <QtCore/QSharedData>
|
||||
#include <QtCore/QtDebug>
|
||||
#include <QtGui/QIcon>
|
||||
#include <QtDeclarative/QmlMetaType>
|
||||
#include <QtDeclarative/QmlContext>
|
||||
#include <QtDeclarative/QmlEngine>
|
||||
#include <QtDeclarative/QmlComponent>
|
||||
#include <private/qmlvaluetype_p.h>
|
||||
|
||||
namespace Qml {
|
||||
namespace Internal {
|
||||
|
||||
class NodeMetaInfoData : public QSharedData
|
||||
{
|
||||
public:
|
||||
typedef enum {
|
||||
No = -1,
|
||||
Unknown = 0,
|
||||
Yes = 1,
|
||||
} TristateBoolean;
|
||||
|
||||
public:
|
||||
NodeMetaInfoData(const MetaInfo &metaInfo) :
|
||||
metaInfo(metaInfo),
|
||||
isContainer(false),
|
||||
isVisibleToItemLibrary(false),
|
||||
isFXItem(Unknown),
|
||||
icon(),
|
||||
category("misc")
|
||||
{ }
|
||||
|
||||
MetaInfo metaInfo;
|
||||
QString typeName;
|
||||
bool isContainer;
|
||||
bool isVisibleToItemLibrary;
|
||||
TristateBoolean isFXItem;
|
||||
QHash<QString, PropertyMetaInfo> propertyMetaInfoHash;
|
||||
QIcon icon;
|
||||
QString category;
|
||||
QString qmlFile;
|
||||
QString defaultProperty;
|
||||
int majorVersion;
|
||||
int minorVersion;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
/*!
|
||||
\class Qml::NodeMetaInfo
|
||||
\ingroup CoreModel
|
||||
\brief The NodeMetaInfo class provides meta information about a qml type.
|
||||
|
||||
A NodeMetaInfo object can be created via ModelNode::metaInfo, or MetaInfo::nodeMetaInfo.
|
||||
|
||||
The object can be invalid - you can check this by calling isValid().
|
||||
The object is invalid if you ask for meta information for
|
||||
an non-existing qml property. Also the node meta info can become invalid
|
||||
if the enclosing type is deregistered from the meta type system (e.g.
|
||||
a sub component qml file is deleted). Trying to call any accessor methods on an invalid
|
||||
NodeMetaInfo object will result in an InvalidMetaInfoException being thrown.
|
||||
|
||||
\see Qml::MetaInfo, Qml::PropertyMetaInfo, Qml::EnumeratorMetaInfo
|
||||
*/
|
||||
|
||||
NodeMetaInfo::NodeMetaInfo()
|
||||
: m_data(0)
|
||||
{
|
||||
// create invalid node
|
||||
}
|
||||
|
||||
NodeMetaInfo::NodeMetaInfo(const MetaInfo &metaInfo)
|
||||
: m_data(new Internal::NodeMetaInfoData(metaInfo))
|
||||
{
|
||||
}
|
||||
|
||||
NodeMetaInfo::~NodeMetaInfo()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Creates a copy of the handle.
|
||||
*/
|
||||
NodeMetaInfo::NodeMetaInfo(const NodeMetaInfo &other)
|
||||
: m_data(other.m_data)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Copies the handle.
|
||||
*/
|
||||
NodeMetaInfo &NodeMetaInfo::operator=(const NodeMetaInfo &other)
|
||||
{
|
||||
if (this != &other)
|
||||
this->m_data = other.m_data;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the meta information system knows about this type.
|
||||
*/
|
||||
bool NodeMetaInfo::isValid() const
|
||||
{
|
||||
return (m_data.data() != 0);
|
||||
}
|
||||
|
||||
MetaInfo NodeMetaInfo::metaInfo() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
return m_data->metaInfo;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Creates an instance of the qml type in the given qml context.
|
||||
|
||||
\throws InvalidArgumentException when the context argument is a null pointer
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
QObject *NodeMetaInfo::createInstance(QmlContext *parentContext) const
|
||||
{
|
||||
if (!parentContext) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Context cannot be null");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
QObject *object = 0;
|
||||
if (isComponent()) {
|
||||
// qml component
|
||||
// TODO: This is maybe expensive ...
|
||||
QmlComponent component(parentContext->engine(), QUrl::fromLocalFile(m_data->qmlFile));
|
||||
object = component.create(parentContext);
|
||||
} else {
|
||||
// primitive
|
||||
object = QmlMetaType::qmlType(typeName().toAscii(), 4, 6)->create();
|
||||
if (object && parentContext)
|
||||
QmlEngine::setContextForObject(object, new QmlContext(parentContext, object));
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns all (direct and indirect) ancestor types.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
QList<NodeMetaInfo> NodeMetaInfo::superClasses() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
return m_data->metaInfo.superClasses(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns direct ancestor types.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
QList<NodeMetaInfo> NodeMetaInfo::directSuperClasses() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
return m_data->metaInfo.directSuperClasses(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns meta information for all properties, including properties inherited from base types.
|
||||
|
||||
Returns a Hash with the name of the property as key and property meta information as value. Node
|
||||
In case there are multiple properties with the same name in the hierarchy the property defined
|
||||
in the more concrete subclass is chosen.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
QHash<QString,PropertyMetaInfo> NodeMetaInfo::properties(bool resolveDotSyntax ) const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
QHash<QString,PropertyMetaInfo> propertiesInfo;
|
||||
propertiesInfo = m_data->propertyMetaInfoHash;
|
||||
foreach (const NodeMetaInfo &nodeInfo, directSuperClasses()) {
|
||||
QHash<QString,PropertyMetaInfo> superClassProperties = nodeInfo.properties();
|
||||
QHashIterator<QString,PropertyMetaInfo> iter(superClassProperties);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
if (!propertiesInfo.contains(iter.key()))
|
||||
propertiesInfo.insert(iter.key(), iter.value());
|
||||
}
|
||||
}
|
||||
if (resolveDotSyntax) {
|
||||
QHashIterator<QString,PropertyMetaInfo> iter(dotProperties());
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
if (!propertiesInfo.contains(iter.key()))
|
||||
propertiesInfo.insert(iter.key(), iter.value());
|
||||
}
|
||||
}
|
||||
return propertiesInfo;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns meta information for all dot properties, including properties inherited from base types.
|
||||
|
||||
*/
|
||||
QHash<QString,PropertyMetaInfo> NodeMetaInfo::dotProperties() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
QHash<QString,PropertyMetaInfo> propertiesInfo;
|
||||
|
||||
foreach (const QString &propertyName, properties().keys()) {
|
||||
if (property(propertyName).hasDotSubProperties()) {
|
||||
QString propertyType = property(propertyName).type();
|
||||
if (propertyType.right(1) == "*")
|
||||
propertyType = propertyType.left(propertyType.size() - 1).trimmed();
|
||||
NodeMetaInfo nodeInfo(m_data->metaInfo.nodeMetaInfo(propertyType, majorVersion(), minorVersion()));
|
||||
if (nodeInfo.isValid()) {
|
||||
QHashIterator<QString,PropertyMetaInfo> iter(nodeInfo.properties());
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
if (!propertiesInfo.contains(iter.key()) && iter.key() != "objectName")
|
||||
propertiesInfo.insert(propertyName + "." + iter.key(), iter.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return propertiesInfo;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns meta information for a property. An invalid PropertyMetaInfo object if the given property name is unknown.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
PropertyMetaInfo NodeMetaInfo::property(const QString &propertyName, bool resolveDotSyntax) const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
if (resolveDotSyntax && propertyName.contains('.')) {
|
||||
const QStringList nameParts = propertyName.split('.');
|
||||
NodeMetaInfo nodeInfo = *this;
|
||||
const int partCount = nameParts.size();
|
||||
for (int i = 0; i < partCount; ++i) {
|
||||
const QString namePart(nameParts.at(i));
|
||||
const PropertyMetaInfo propInfo = nodeInfo.property(namePart, false);
|
||||
|
||||
if (!propInfo.isValid())
|
||||
break;
|
||||
|
||||
if (i + 1 == partCount)
|
||||
return propInfo;
|
||||
|
||||
QString propertyType = propInfo.type();
|
||||
if (propertyType.right(1) == "*")
|
||||
propertyType = propertyType.left(propertyType.size() - 1).trimmed();
|
||||
nodeInfo = m_data->metaInfo.nodeMetaInfo(propertyType, majorVersion(), minorVersion());
|
||||
if (!nodeInfo.isValid()) {
|
||||
qDebug() << "no type info available for" << propertyType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return PropertyMetaInfo();
|
||||
} else {
|
||||
PropertyMetaInfo propertyMetaInfo;
|
||||
|
||||
if (hasLocalProperty(propertyName)) {
|
||||
propertyMetaInfo = m_data->propertyMetaInfoHash.value(propertyName, PropertyMetaInfo());
|
||||
} else {
|
||||
foreach (const NodeMetaInfo &superTypeMetaInfo, directSuperClasses()) {
|
||||
Q_ASSERT(superTypeMetaInfo.isValid());
|
||||
propertyMetaInfo = superTypeMetaInfo.property(propertyName);
|
||||
if (propertyMetaInfo.isValid())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return propertyMetaInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the type has a (not inherited) property.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
bool NodeMetaInfo::hasLocalProperty(const QString &propertyName, bool resolveDotSyntax) const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
if (resolveDotSyntax && propertyName.contains('.')) {
|
||||
const QStringList nameParts = propertyName.split('.');
|
||||
NodeMetaInfo nodeInfo = *this;
|
||||
const int partCount = nameParts.size();
|
||||
for (int i = 0; i < partCount; ++i) {
|
||||
QString namePart(nameParts.at(i));
|
||||
const PropertyMetaInfo propInfo = nodeInfo.property(namePart, false);
|
||||
|
||||
if (!propInfo.isValid())
|
||||
break;
|
||||
|
||||
if (i + 1 == partCount)
|
||||
return true;
|
||||
|
||||
QString propertyType = propInfo.type();
|
||||
if (propertyType.right(1) == "*")
|
||||
propertyType = propertyType.left(propertyType.size() - 1).trimmed();
|
||||
nodeInfo = m_data->metaInfo.nodeMetaInfo(propertyType, majorVersion(), minorVersion());
|
||||
if (!nodeInfo.isValid()) {
|
||||
qDebug() << "no type info available for" << propertyType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return m_data->propertyMetaInfoHash.contains(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the type has a (inherited or not inherited) property.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
bool NodeMetaInfo::hasProperty(const QString &propertyName, bool resolveDotSyntax) const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
if (hasLocalProperty(propertyName, resolveDotSyntax))
|
||||
return true;
|
||||
|
||||
foreach (const NodeMetaInfo &nodeMetaInfo, directSuperClasses()) {
|
||||
if (nodeMetaInfo.hasProperty(propertyName, resolveDotSyntax))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::addProperty(const PropertyMetaInfo &property)
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
m_data->propertyMetaInfoHash.insert(property.name(), property);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the name of the qml type.
|
||||
|
||||
This is not necessarily the class name: E.g. the class defining "Item" is QmlGraphicsItem.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
QString NodeMetaInfo::typeName() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
return m_data->typeName;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the name of the major number of the qml type.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
int NodeMetaInfo::majorVersion() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\brief Returns the name of the minor number of the qml type to which the type is used.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
int NodeMetaInfo::minorVersion() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
return m_data->minorVersion;
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::hasDefaultProperty() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
return m_data->defaultProperty.isNull();
|
||||
}
|
||||
|
||||
QString NodeMetaInfo::defaultProperty() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
return m_data->defaultProperty;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setDefaultProperty(const QString &defaultProperty)
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
m_data->defaultProperty = defaultProperty;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setMajorVersion(int version)
|
||||
{
|
||||
m_data->majorVersion = version;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setMinorVersion(int version)
|
||||
{
|
||||
m_data->minorVersion = version;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setInvalid()
|
||||
{
|
||||
if (!isValid())
|
||||
return;
|
||||
|
||||
m_data = 0;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setTypeName(const QString &typeName)
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
m_data->typeName = typeName;
|
||||
}
|
||||
|
||||
uint qHash(const NodeMetaInfo &nodeMetaInfo)
|
||||
{
|
||||
if (!nodeMetaInfo.isValid())
|
||||
return 0;
|
||||
return qHash(nodeMetaInfo.m_data->typeName);
|
||||
}
|
||||
|
||||
bool operator==(const NodeMetaInfo &firstNodeInfo,
|
||||
const NodeMetaInfo &secondNodeInfo)
|
||||
{
|
||||
if (!firstNodeInfo.isValid() || !secondNodeInfo.isValid())
|
||||
return false;
|
||||
return firstNodeInfo.m_data->typeName == secondNodeInfo.m_data->typeName;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether objects of these type can have children.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
bool NodeMetaInfo::isContainer() const
|
||||
{
|
||||
// TODO KAI: Is this too generic?
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
return m_data->isContainer;
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isVisibleToItemLibrary() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
return m_data->isVisibleToItemLibrary;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setIsContainer(bool isContainer)
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
m_data->isContainer = isContainer;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setIsVisibleToItemLibrary(bool isVisibleToItemLibrary)
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
m_data->isVisibleToItemLibrary = isVisibleToItemLibrary;
|
||||
}
|
||||
|
||||
QIcon NodeMetaInfo::icon() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
return m_data->icon;
|
||||
}
|
||||
|
||||
QString NodeMetaInfo::category() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
return m_data->category;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setIcon(const QIcon &icon)
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
m_data->icon = icon;
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setCategory(const QString &category)
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
m_data->category = category;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the type inherits from "QWidget".
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
bool NodeMetaInfo::isWidget() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
return m_data->metaInfo.isSubclassOf(m_data->typeName, "Qt/QWidget");
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the type inherits from "QGraphicsWidget".
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
bool NodeMetaInfo::isGraphicsWidget() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
return m_data->metaInfo.isSubclassOf(m_data->typeName, "Qt/QGraphicsWidget");
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the type inherits from "QGraphicsObject".
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
bool NodeMetaInfo::isGraphicsObject() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
return m_data->metaInfo.isSubclassOf(m_data->typeName, "QGraphicsObject");
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the type inherits from "Item/QmlGraphicsItem".
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
bool NodeMetaInfo::isQmlGraphicsItem() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
|
||||
if (m_data->isFXItem == Internal::NodeMetaInfoData::Unknown) {
|
||||
m_data->isFXItem = m_data->metaInfo.isSubclassOf(m_data->typeName, "Qt/Item") ? Internal::NodeMetaInfoData::Yes : Internal::NodeMetaInfoData::No;
|
||||
}
|
||||
|
||||
return m_data->isFXItem == Internal::NodeMetaInfoData::Yes;
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isComponent() const
|
||||
{
|
||||
return !m_data->qmlFile.isEmpty();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the type inherits from a type.
|
||||
|
||||
\throws InvalidMetaInfoException if the object is not valid
|
||||
*/
|
||||
bool NodeMetaInfo::isSubclassOf(const QString &type, int /*majorVersion*/, int /*minorVersion*/) const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
return m_data->metaInfo.isSubclassOf(m_data->typeName, type);
|
||||
}
|
||||
|
||||
void NodeMetaInfo::setQmlFile(const QString &filePath)
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(0, Q_FUNC_INFO, "Invalid NodeMetaInfo object");
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
}
|
||||
m_data->qmlFile = filePath;
|
||||
}
|
||||
|
||||
} // namespace Qml
|
@@ -1,132 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef NODEMETAINFO_H
|
||||
#define NODEMETAINFO_H
|
||||
|
||||
#include <qml/qml_global.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QExplicitlySharedDataPointer>
|
||||
#include <QIcon>
|
||||
|
||||
class QmlContext;
|
||||
|
||||
namespace Qml {
|
||||
|
||||
class MetaInfo;
|
||||
|
||||
namespace Internal {
|
||||
class MetaInfoPrivate;
|
||||
class MetaInfoParser;
|
||||
class NodeMetaInfoData;
|
||||
class SubComponentManagerPrivate;
|
||||
class ItemLibraryInfoData;
|
||||
}
|
||||
|
||||
class PropertyMetaInfo;
|
||||
|
||||
class QML_EXPORT NodeMetaInfo
|
||||
{
|
||||
friend class Qml::MetaInfo;
|
||||
friend class Qml::Internal::ItemLibraryInfoData;
|
||||
friend class Qml::Internal::MetaInfoPrivate;
|
||||
friend class Qml::Internal::MetaInfoParser;
|
||||
friend QML_EXPORT uint qHash(const NodeMetaInfo &nodeMetaInfo);
|
||||
friend QML_EXPORT bool operator ==(const NodeMetaInfo &firstNodeInfo, const NodeMetaInfo &secondNodeInfo);
|
||||
|
||||
public:
|
||||
~NodeMetaInfo();
|
||||
|
||||
NodeMetaInfo(const NodeMetaInfo &other);
|
||||
NodeMetaInfo &operator=(const NodeMetaInfo &other);
|
||||
|
||||
bool isValid() const;
|
||||
MetaInfo metaInfo() const;
|
||||
|
||||
QObject *createInstance(QmlContext *parentContext) const;
|
||||
|
||||
PropertyMetaInfo property(const QString &propertyName, bool resolveDotSyntax = false) const;
|
||||
|
||||
QList<NodeMetaInfo> superClasses() const;
|
||||
QList<NodeMetaInfo> directSuperClasses() const;
|
||||
QHash<QString,PropertyMetaInfo> properties(bool resolveDotSyntax = false) const;
|
||||
|
||||
|
||||
QString typeName() const;
|
||||
int majorVersion() const;
|
||||
int minorVersion() const;
|
||||
|
||||
bool hasDefaultProperty() const;
|
||||
QString defaultProperty() const;
|
||||
|
||||
bool hasProperty(const QString &propertyName, bool resolveDotSyntax = false) const;
|
||||
bool isContainer() const;
|
||||
bool isVisibleToItemLibrary() const;
|
||||
|
||||
bool isWidget() const;
|
||||
bool isGraphicsWidget() const;
|
||||
bool isGraphicsObject() const;
|
||||
bool isQmlGraphicsItem() const;
|
||||
bool isComponent() const;
|
||||
bool isSubclassOf(const QString& type, int majorVersion = 4, int minorVersion = 6) const;
|
||||
|
||||
QIcon icon() const;
|
||||
QString category() const;
|
||||
|
||||
private:
|
||||
NodeMetaInfo();
|
||||
NodeMetaInfo(const MetaInfo &metaInfo);
|
||||
|
||||
void setInvalid();
|
||||
void setTypeName(const QString &typeName);
|
||||
void addProperty(const PropertyMetaInfo &property);
|
||||
void setIsContainer(bool isContainer);
|
||||
void setIsVisibleToItemLibrary(bool isVisibleToItemLibrary);
|
||||
void setIcon(const QIcon &icon);
|
||||
void setCategory(const QString &category);
|
||||
void setQmlFile(const QString &filePath);
|
||||
void setDefaultProperty(const QString &defaultProperty);
|
||||
void setMajorVersion(int version);
|
||||
void setMinorVersion(int version);
|
||||
|
||||
bool hasLocalProperty(const QString &propertyName, bool resolveDotSyntax = false) const;
|
||||
QHash<QString,PropertyMetaInfo> dotProperties() const;
|
||||
|
||||
private:
|
||||
QExplicitlySharedDataPointer<Internal::NodeMetaInfoData> m_data;
|
||||
};
|
||||
|
||||
QML_EXPORT uint qHash(const NodeMetaInfo &nodeMetaInfo);
|
||||
QML_EXPORT bool operator ==(const NodeMetaInfo &firstNodeInfo,
|
||||
const NodeMetaInfo &secondNodeInfo);
|
||||
} // namespace Qml
|
||||
|
||||
#endif // NODEMETAINFO_H
|
@@ -1,405 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "propertymetainfo.h"
|
||||
|
||||
#include <QSharedData>
|
||||
|
||||
#include "invalidmetainfoexception.h"
|
||||
#include "metainfo.h"
|
||||
#include <private/qmlvaluetype_p.h>
|
||||
|
||||
namespace Qml {
|
||||
namespace Internal {
|
||||
|
||||
class PropertyMetaInfoData : public QSharedData
|
||||
{
|
||||
public:
|
||||
PropertyMetaInfoData()
|
||||
: QSharedData(),
|
||||
isValid(false),
|
||||
readable(false),
|
||||
writeable(false),
|
||||
resettable(false),
|
||||
enumType(false),
|
||||
flagType(false),
|
||||
isVisible(false)
|
||||
{}
|
||||
|
||||
QString name;
|
||||
QString type;
|
||||
int majorVersion;
|
||||
int minorVersion;
|
||||
bool isValid;
|
||||
|
||||
bool readable;
|
||||
bool writeable;
|
||||
bool resettable;
|
||||
|
||||
bool enumType;
|
||||
bool flagType;
|
||||
bool isVisible;
|
||||
|
||||
QHash<QString, QVariant> defaultValueHash;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
/*!
|
||||
\class Qml::PropertyMetaInfo
|
||||
\ingroup CoreModel
|
||||
\brief The PropertyMetaInfo class provides meta information about a qml type property.
|
||||
|
||||
A PropertyMetaInfo object can be NodeMetaInfo, or AbstractProperty::metaInfo.
|
||||
|
||||
The object can be invalid - you can check this by calling isValid().
|
||||
The object is invalid if you ask for meta information for
|
||||
an non-existing qml type. Also the node meta info can become invalid
|
||||
if the type is deregistered from the meta type system (e.g.
|
||||
a sub component qml file is deleted). Trying to call any accessor methods on an invalid
|
||||
PropertyMetaInfo object will result in an InvalidMetaInfoException being thrown.
|
||||
|
||||
|
||||
\see Qml::MetaInfo, Qml::NodeMetaInfo, Qml::EnumeratorMetaInfo
|
||||
*/
|
||||
|
||||
PropertyMetaInfo::PropertyMetaInfo()
|
||||
: m_data(new Internal::PropertyMetaInfoData)
|
||||
{
|
||||
}
|
||||
|
||||
PropertyMetaInfo::~PropertyMetaInfo()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Creates a copy of the handle.
|
||||
*/
|
||||
PropertyMetaInfo::PropertyMetaInfo(const PropertyMetaInfo &other)
|
||||
: m_data(other.m_data)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Copies the handle.
|
||||
*/
|
||||
PropertyMetaInfo &PropertyMetaInfo::operator=(const PropertyMetaInfo &other)
|
||||
{
|
||||
if (this != &other)
|
||||
m_data = other.m_data;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the meta information system knows about this property.
|
||||
*/
|
||||
bool PropertyMetaInfo::isValid() const
|
||||
{
|
||||
return m_data->isValid;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the name of the property.
|
||||
*/
|
||||
QString PropertyMetaInfo::name() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->name;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the type name of the property.
|
||||
*/
|
||||
QString PropertyMetaInfo::type() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->type;
|
||||
}
|
||||
|
||||
int PropertyMetaInfo::typeMajorVersion() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->majorVersion;
|
||||
}
|
||||
|
||||
int PropertyMetaInfo::typeMinorVersion() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->minorVersion;
|
||||
}
|
||||
|
||||
bool PropertyMetaInfo::isVisibleToPropertyEditor() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->isVisible;
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setIsVisibleToPropertyEditor(bool isVisible)
|
||||
{
|
||||
m_data->isVisible = isVisible;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the QVariant type of the property.
|
||||
*/
|
||||
QVariant::Type PropertyMetaInfo::variantTypeId() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
Q_ASSERT(!m_data->type.isEmpty());
|
||||
return QVariant::nameToType(m_data->type.toLatin1().data());
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the propery is readable.
|
||||
*/
|
||||
bool PropertyMetaInfo::isReadable() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->readable;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the propery is writeable.
|
||||
*/
|
||||
bool PropertyMetaInfo::isWriteable() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->writeable;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the propery is resettable.
|
||||
*/
|
||||
bool PropertyMetaInfo::isResettable() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->resettable;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the propery is complex value type.
|
||||
*/
|
||||
bool PropertyMetaInfo::isValueType() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
|
||||
QmlValueType *valueType(QmlValueTypeFactory::valueType(variantTypeId()));
|
||||
return valueType;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the propery is a QmlList.
|
||||
*/
|
||||
bool PropertyMetaInfo::isListProperty() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
|
||||
return type().contains("QmlList");
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the propery has sub properties with "." syntax e.g. font
|
||||
*/
|
||||
bool PropertyMetaInfo::hasDotSubProperties() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
|
||||
return isValueType() || !isWriteable();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the propery stores an enum value.
|
||||
*/
|
||||
bool PropertyMetaInfo::isEnumType() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->enumType;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns whether the propery stores a flag value.
|
||||
*/
|
||||
bool PropertyMetaInfo::isFlagType() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
return m_data->flagType;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns a default value if there is one specified, an invalid QVariant otherwise.
|
||||
*/
|
||||
QVariant PropertyMetaInfo::defaultValue(const NodeMetaInfo &nodeMetaInfoArg) const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
|
||||
QList<NodeMetaInfo> nodeMetaInfoList(nodeMetaInfoArg.superClasses());
|
||||
nodeMetaInfoList.prepend(nodeMetaInfoArg);
|
||||
foreach (const NodeMetaInfo &nodeMetaInfo, nodeMetaInfoList) {
|
||||
if (m_data->defaultValueHash.contains(nodeMetaInfo.typeName()))
|
||||
return m_data->defaultValueHash.value(nodeMetaInfo.typeName());
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setName(const QString &name)
|
||||
{
|
||||
m_data->name = name;
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setType(const QString &type, int majorVersion, int minorVersion)
|
||||
{
|
||||
m_data->type = type;
|
||||
m_data->majorVersion = majorVersion;
|
||||
m_data->minorVersion = minorVersion;
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setValid(bool isValid)
|
||||
{
|
||||
m_data->isValid = isValid;
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setReadable(bool isReadable)
|
||||
{
|
||||
m_data->readable = isReadable;
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setWritable(bool isWritable)
|
||||
{
|
||||
m_data->writeable = isWritable;
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setResettable(bool isRessetable)
|
||||
{
|
||||
m_data->resettable = isRessetable;
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setEnumType(bool isEnumType)
|
||||
{
|
||||
m_data->enumType = isEnumType;
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setFlagType(bool isFlagType)
|
||||
{
|
||||
m_data->flagType = isFlagType;
|
||||
}
|
||||
|
||||
void PropertyMetaInfo::setDefaultValue(const NodeMetaInfo &nodeMetaInfo, const QVariant &value)
|
||||
{
|
||||
m_data->defaultValueHash.insert(nodeMetaInfo.typeName(), value);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief cast value type of QVariant parameter
|
||||
|
||||
If the type of the passed variant does not correspond to type(), the method tries to convert
|
||||
the value according to QVariant::convert(). Returns a new QVariant with casted value type
|
||||
if successful, an invalid QVariant otherwise.
|
||||
|
||||
\param variant the QVariant to take the value from
|
||||
\returns QVariant with aligned value type, or invalid QVariant
|
||||
*/
|
||||
QVariant PropertyMetaInfo::castedValue(const QVariant &originalVariant) const
|
||||
{
|
||||
if (!isValid()) {
|
||||
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "");
|
||||
throw InvalidMetaInfoException(__LINE__, Q_FUNC_INFO, __FILE__);
|
||||
}
|
||||
|
||||
QVariant variant = originalVariant;
|
||||
if (m_data->enumType) {
|
||||
return variant;
|
||||
}
|
||||
|
||||
QVariant::Type typeId = variantTypeId();
|
||||
|
||||
if (typeId == QVariant::UserType && m_data->type == QLatin1String("QVariant")) {
|
||||
return variant;
|
||||
} else if (variant.type() == QVariant::List && variant.type() == QVariant::List) {
|
||||
// TODO: check the contents of the list
|
||||
return variant;
|
||||
} else if (type() == "var" || type() == "variant") {
|
||||
return variant;
|
||||
} else if (type() == "alias") {
|
||||
// TODO: The Qml compiler resolves the alias type. We probably should do the same.
|
||||
return variant;
|
||||
} else if (variant.convert(typeId)) {
|
||||
return variant;
|
||||
} else {
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Qml
|
@@ -1,113 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef PROPERTYMETAINFO_H
|
||||
#define PROPERTYMETAINFO_H
|
||||
|
||||
#include <qml/qml_global.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QExplicitlySharedDataPointer>
|
||||
#include <QVariant>
|
||||
|
||||
namespace Qml {
|
||||
|
||||
class MetaInfo;
|
||||
class NodeMetaInfo;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class MetaInfoPrivate;
|
||||
class MetaInfoParser;
|
||||
class PropertyMetaInfoData;
|
||||
|
||||
}
|
||||
|
||||
class QML_EXPORT PropertyMetaInfo
|
||||
{
|
||||
friend class Qml::Internal::MetaInfoPrivate;
|
||||
friend class Qml::Internal::MetaInfoParser;
|
||||
friend class Qml::MetaInfo;
|
||||
friend class Qml::NodeMetaInfo;
|
||||
public:
|
||||
PropertyMetaInfo();
|
||||
~PropertyMetaInfo();
|
||||
|
||||
PropertyMetaInfo(const PropertyMetaInfo &other);
|
||||
PropertyMetaInfo& operator=(const PropertyMetaInfo &other);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
QString name() const;
|
||||
QString type() const;
|
||||
int typeMajorVersion() const;
|
||||
int typeMinorVersion() const;
|
||||
|
||||
QVariant::Type variantTypeId() const;
|
||||
|
||||
bool isReadable() const;
|
||||
bool isWriteable() const;
|
||||
bool isResettable() const;
|
||||
bool isValueType() const;
|
||||
bool isListProperty() const;
|
||||
|
||||
bool isEnumType() const;
|
||||
bool isFlagType() const;
|
||||
|
||||
QVariant defaultValue(const NodeMetaInfo &nodeMetaInfo) const;
|
||||
bool isVisibleToPropertyEditor() const;
|
||||
|
||||
QVariant castedValue(const QVariant &variant) const;
|
||||
|
||||
private:
|
||||
void setName(const QString &name);
|
||||
void setType(const QString &type, int majorVersion, int minorVersion);
|
||||
void setValid(bool isValid);
|
||||
|
||||
void setReadable(bool isReadable);
|
||||
void setWritable(bool isWritable);
|
||||
void setResettable(bool isRessetable);
|
||||
|
||||
void setEnumType(bool isEnumType);
|
||||
void setFlagType(bool isFlagType);
|
||||
|
||||
void setDefaultValue(const NodeMetaInfo &nodeMetaInfo, const QVariant &value);
|
||||
void setIsVisibleToPropertyEditor(bool isVisible);
|
||||
|
||||
bool hasDotSubProperties() const;
|
||||
|
||||
|
||||
private:
|
||||
QExplicitlySharedDataPointer<Internal::PropertyMetaInfoData> m_data;
|
||||
};
|
||||
|
||||
} // namespace Qml
|
||||
|
||||
|
||||
#endif // PROPERTYMETAINFO_H
|
@@ -1,43 +0,0 @@
|
||||
include(parser/parser.pri)
|
||||
|
||||
DEPENDPATH += $$PWD $$PWD/metatype
|
||||
INCLUDEPATH *= $$PWD/..
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/qml_global.h \
|
||||
$$PWD/qmlidcollector.h \
|
||||
$$PWD/qmldocument.h \
|
||||
$$PWD/qmlpackageinfo.h \
|
||||
$$PWD/qmlsymbol.h \
|
||||
$$PWD/metatype/exception.h \
|
||||
$$PWD/metatype/QmlMetaTypeBackend.h \
|
||||
$$PWD/metatype/qmltypesystem.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/qmlidcollector.cpp \
|
||||
$$PWD/qmldocument.cpp \
|
||||
$$PWD/qmlsymbol.cpp \
|
||||
$$PWD/qmlpackageinfo.cpp \
|
||||
$$PWD/metatype/exception.cpp \
|
||||
$$PWD/metatype/QmlMetaTypeBackend.cpp \
|
||||
$$PWD/metatype/qmltypesystem.cpp
|
||||
|
||||
contains(QT_CONFIG, declarative) {
|
||||
QT += declarative
|
||||
|
||||
DEFINES += BUILD_DECLARATIVE_BACKEND
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/metatype/metainfo.h \
|
||||
$$PWD/metatype/nodemetainfo.h \
|
||||
$$PWD/metatype/propertymetainfo.h \
|
||||
$$PWD/metatype/QtDeclarativeMetaTypeBackend.h \
|
||||
$$PWD/metatype/invalidmetainfoexception.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/metatype/metainfo.cpp \
|
||||
$$PWD/metatype/nodemetainfo.cpp \
|
||||
$$PWD/metatype/propertymetainfo.cpp \
|
||||
$$PWD/metatype/QtDeclarativeMetaTypeBackend.cpp \
|
||||
$$PWD/metatype/invalidmetainfoexception.cpp
|
||||
}
|
@@ -30,9 +30,9 @@
|
||||
#ifndef QMLMETATYPEBACKEND_H
|
||||
#define QMLMETATYPEBACKEND_H
|
||||
|
||||
#include <qml/qml_global.h>
|
||||
#include <qml/qmlpackageinfo.h>
|
||||
#include <qml/qmlsymbol.h>
|
||||
#include <qmljs/qml_global.h>
|
||||
#include <qmljs/qmlpackageinfo.h>
|
||||
#include <qmljs/qmlsymbol.h>
|
||||
|
||||
namespace Qml {
|
||||
|
@@ -27,7 +27,6 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "metainfo.h"
|
||||
#include "QtDeclarativeMetaTypeBackend.h"
|
||||
|
||||
#include <QDebug>
|
||||
@@ -59,17 +58,9 @@ class QmlDeclarativeObjectSymbol: public QmlDeclarativeSymbol
|
||||
QmlDeclarativeObjectSymbol &operator=(const QmlDeclarativeObjectSymbol &);
|
||||
|
||||
public:
|
||||
QmlDeclarativeObjectSymbol(const NodeMetaInfo &metaInfo, QtDeclarativeMetaTypeBackend* backend):
|
||||
QmlDeclarativeSymbol(backend),
|
||||
m_metaInfo(metaInfo),
|
||||
m_membersToBeDone(true)
|
||||
QmlDeclarativeObjectSymbol(QtDeclarativeMetaTypeBackend* backend):
|
||||
QmlDeclarativeSymbol(backend)
|
||||
{
|
||||
Q_ASSERT(metaInfo.isValid());
|
||||
|
||||
m_name = m_metaInfo.typeName();
|
||||
const int slashIdx = m_name.indexOf('/');
|
||||
if (slashIdx != -1)
|
||||
m_name = m_name.mid(slashIdx + 1);
|
||||
}
|
||||
|
||||
virtual ~QmlDeclarativeObjectSymbol()
|
||||
@@ -83,19 +74,12 @@ public:
|
||||
|
||||
virtual const List members()
|
||||
{
|
||||
if (m_membersToBeDone)
|
||||
initMembers();
|
||||
|
||||
return m_members;
|
||||
}
|
||||
|
||||
virtual List members(bool includeBaseClassMembers)
|
||||
{
|
||||
List result = members();
|
||||
|
||||
if (includeBaseClassMembers)
|
||||
result.append(backend()->inheritedMembers(m_metaInfo));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -103,11 +87,6 @@ public:
|
||||
{ return false; }
|
||||
|
||||
public:
|
||||
static QString key(const NodeMetaInfo &metaInfo)
|
||||
{
|
||||
return key(metaInfo.typeName(), metaInfo.majorVersion(), metaInfo.minorVersion());
|
||||
}
|
||||
|
||||
static QString key(const QString &typeNameWithPackage, int majorVersion, int minorVersion)
|
||||
{
|
||||
return QString(typeNameWithPackage)
|
||||
@@ -129,17 +108,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void initMembers()
|
||||
{
|
||||
if (!m_membersToBeDone)
|
||||
return;
|
||||
m_membersToBeDone = false;
|
||||
|
||||
m_members = backend()->members(m_metaInfo);
|
||||
}
|
||||
|
||||
private:
|
||||
NodeMetaInfo m_metaInfo;
|
||||
QString m_name;
|
||||
|
||||
bool m_membersToBeDone;
|
||||
@@ -152,9 +120,8 @@ class QmlDeclarativePropertySymbol: public QmlDeclarativeSymbol
|
||||
QmlDeclarativePropertySymbol &operator=(const QmlDeclarativePropertySymbol &);
|
||||
|
||||
public:
|
||||
QmlDeclarativePropertySymbol(const PropertyMetaInfo &metaInfo, QtDeclarativeMetaTypeBackend* backend):
|
||||
QmlDeclarativeSymbol(backend),
|
||||
m_metaInfo(metaInfo)
|
||||
QmlDeclarativePropertySymbol(QtDeclarativeMetaTypeBackend* backend):
|
||||
QmlDeclarativeSymbol(backend)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -162,10 +129,10 @@ public:
|
||||
{}
|
||||
|
||||
virtual const QString name() const
|
||||
{ return m_metaInfo.name(); }
|
||||
{ return QString(); }
|
||||
|
||||
virtual QmlBuildInSymbol *type() const
|
||||
{ return backend()->typeOf(m_metaInfo); }
|
||||
{ return 0; }
|
||||
|
||||
virtual const List members()
|
||||
{
|
||||
@@ -181,7 +148,6 @@ public:
|
||||
{ return true; }
|
||||
|
||||
private:
|
||||
PropertyMetaInfo m_metaInfo;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
@@ -193,25 +159,15 @@ using namespace Qml::Internal;
|
||||
QtDeclarativeMetaTypeBackend::QtDeclarativeMetaTypeBackend(QmlTypeSystem *typeSystem):
|
||||
QmlMetaTypeBackend(typeSystem)
|
||||
{
|
||||
foreach (const NodeMetaInfo &metaInfo, MetaInfo::global().allTypes()) {
|
||||
m_symbols.insert(QmlDeclarativeObjectSymbol::key(metaInfo), new QmlDeclarativeObjectSymbol(metaInfo, this));
|
||||
}
|
||||
}
|
||||
|
||||
QtDeclarativeMetaTypeBackend::~QtDeclarativeMetaTypeBackend()
|
||||
{
|
||||
qDeleteAll(m_symbols.values());
|
||||
}
|
||||
|
||||
QList<QmlSymbol *> QtDeclarativeMetaTypeBackend::availableTypes(const QString &package, int majorVersion, int minorVersion)
|
||||
{
|
||||
QList<QmlSymbol *> result;
|
||||
const QString prefix = package + QLatin1Char('/');
|
||||
|
||||
foreach (const NodeMetaInfo &metaInfo, MetaInfo::global().allTypes()) {
|
||||
if (metaInfo.typeName().startsWith(prefix) && metaInfo.majorVersion() == majorVersion && metaInfo.minorVersion() == minorVersion)
|
||||
result.append(getSymbol(metaInfo));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -220,46 +176,6 @@ QmlSymbol *QtDeclarativeMetaTypeBackend::resolve(const QString &typeName, const
|
||||
{
|
||||
QList<QmlSymbol *> result;
|
||||
|
||||
foreach (const PackageInfo &package, packages) {
|
||||
if (QmlSymbol *symbol = m_symbols.value(QmlDeclarativeObjectSymbol::key(package.name(), typeName, package.majorVersion(), package.minorVersion()), 0))
|
||||
return symbol;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QList<QmlSymbol *> QtDeclarativeMetaTypeBackend::members(const NodeMetaInfo &metaInfo)
|
||||
{
|
||||
QList<QmlSymbol *> result;
|
||||
|
||||
foreach (const PropertyMetaInfo &propertyInfo, metaInfo.properties(false).values()) {
|
||||
result.append(new QmlDeclarativePropertySymbol(propertyInfo, this));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<QmlSymbol *> QtDeclarativeMetaTypeBackend::inheritedMembers(const NodeMetaInfo &metaInfo)
|
||||
{
|
||||
QList<QmlSymbol *> result;
|
||||
|
||||
foreach (const NodeMetaInfo &superNode, metaInfo.directSuperClasses()) {
|
||||
result.append(getSymbol(superNode)->members(true));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QmlDeclarativeSymbol *QtDeclarativeMetaTypeBackend::typeOf(const PropertyMetaInfo &metaInfo)
|
||||
{
|
||||
const QString key = QmlDeclarativeObjectSymbol::key(metaInfo.type(), metaInfo.typeMajorVersion(), metaInfo.typeMinorVersion());
|
||||
|
||||
return m_symbols.value(key, 0);
|
||||
}
|
||||
|
||||
QmlDeclarativeSymbol *QtDeclarativeMetaTypeBackend::getSymbol(const NodeMetaInfo &metaInfo)
|
||||
{
|
||||
const QString key = QmlDeclarativeObjectSymbol::key(metaInfo);
|
||||
|
||||
return m_symbols.value(key, 0);
|
||||
}
|
@@ -30,9 +30,7 @@
|
||||
#ifndef QTDECLARATIVEMETATYPEBACKEND_H
|
||||
#define QTDECLARATIVEMETATYPEBACKEND_H
|
||||
|
||||
#include <qml/metatype/QmlMetaTypeBackend.h>
|
||||
#include <qml/metatype/nodemetainfo.h>
|
||||
#include <qml/metatype/propertymetainfo.h>
|
||||
#include <qmljs/QmlMetaTypeBackend.h>
|
||||
|
||||
#include <QtCore/QList>
|
||||
|
||||
@@ -57,15 +55,15 @@ public:
|
||||
virtual QmlSymbol *resolve(const QString &typeName, const QList<PackageInfo> &packages);
|
||||
|
||||
protected:
|
||||
QList<QmlSymbol *> members(const Qml::NodeMetaInfo &metaInfo);
|
||||
QList<QmlSymbol *> inheritedMembers(const Qml::NodeMetaInfo &metaInfo);
|
||||
QmlDeclarativeSymbol *typeOf(const Qml::PropertyMetaInfo &metaInfo);
|
||||
// QList<QmlSymbol *> members(const Qml::NodeMetaInfo &metaInfo);
|
||||
// QList<QmlSymbol *> inheritedMembers(const Qml::NodeMetaInfo &metaInfo);
|
||||
// QmlDeclarativeSymbol *typeOf(const Qml::PropertyMetaInfo &metaInfo);
|
||||
|
||||
private:
|
||||
QmlDeclarativeSymbol *getSymbol(const Qml::NodeMetaInfo &metaInfo);
|
||||
// QmlDeclarativeSymbol *getSymbol(const Qml::NodeMetaInfo &metaInfo);
|
||||
|
||||
private:
|
||||
QMap<QString, QmlDeclarativeSymbol*> m_symbols;
|
||||
// QMap<QString, QmlDeclarativeSymbol*> m_symbols;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
@@ -1,5 +1,5 @@
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
##INCLUDEPATH += $$PWD
|
||||
DEPENDPATH += $$PWD
|
||||
|
||||
HEADERS += $$PWD/qmljsast_p.h \
|
@@ -29,11 +29,11 @@
|
||||
|
||||
#include "qmlidcollector.h"
|
||||
#include "qmldocument.h"
|
||||
#include "qmljsast_p.h"
|
||||
#include "qmljslexer_p.h"
|
||||
#include "qmljsparser_p.h"
|
||||
#include "qmljsnodepool_p.h"
|
||||
#include "qmljsastfwd_p.h"
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljslexer_p.h>
|
||||
#include <qmljs/parser/qmljsparser_p.h>
|
||||
#include <qmljs/parser/qmljsnodepool_p.h>
|
||||
#include <qmljs/parser/qmljsastfwd_p.h>
|
||||
|
||||
using namespace Qml;
|
||||
using namespace QmlJS;
|
@@ -29,8 +29,9 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
|
||||
#include "qmlidcollector.h"
|
||||
#include "qmljsast_p.h"
|
||||
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
@@ -30,10 +30,10 @@
|
||||
#ifndef QMLIDCOLLECTOR_H
|
||||
#define QMLIDCOLLECTOR_H
|
||||
|
||||
#include <qml/parser/qmljsastvisitor_p.h>
|
||||
#include <qml/parser/qmljsengine_p.h>
|
||||
#include <qml/qmldocument.h>
|
||||
#include <qml/qmlsymbol.h>
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
#include <qmljs/qmldocument.h>
|
||||
#include <qmljs/qmlsymbol.h>
|
||||
|
||||
#include <QMap>
|
||||
#include <QPair>
|
33
src/shared/qmljs/qmljs.pri
Normal file
33
src/shared/qmljs/qmljs.pri
Normal file
@@ -0,0 +1,33 @@
|
||||
include(parser/parser.pri)
|
||||
|
||||
DEPENDPATH += $$PWD $$PWD/metatype
|
||||
INCLUDEPATH += $$PWD/..
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/qml_global.h \
|
||||
$$PWD/qmlidcollector.h \
|
||||
$$PWD/qmldocument.h \
|
||||
$$PWD/qmlpackageinfo.h \
|
||||
$$PWD/qmlsymbol.h \
|
||||
$$PWD/QmlMetaTypeBackend.h \
|
||||
$$PWD/qmltypesystem.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/qmlidcollector.cpp \
|
||||
$$PWD/qmldocument.cpp \
|
||||
$$PWD/qmlsymbol.cpp \
|
||||
$$PWD/qmlpackageinfo.cpp \
|
||||
$$PWD/QmlMetaTypeBackend.cpp \
|
||||
$$PWD/qmltypesystem.cpp
|
||||
|
||||
contains(QT_CONFIG, declarative) {
|
||||
QT += declarative
|
||||
|
||||
DEFINES += BUILD_DECLARATIVE_BACKEND
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/QtDeclarativeMetaTypeBackend.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/QtDeclarativeMetaTypeBackend.cpp
|
||||
}
|
@@ -30,7 +30,7 @@
|
||||
#ifndef PACKAGEINFO_H
|
||||
#define PACKAGEINFO_H
|
||||
|
||||
#include <qml/qml_global.h>
|
||||
#include <qmljs/qml_global.h>
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
@@ -27,10 +27,11 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljsast_p.h"
|
||||
#include "qmljsengine_p.h"
|
||||
#include "qmlsymbol.h"
|
||||
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
#include <qmljs/parser/qmljsengine_p.h>
|
||||
|
||||
using namespace Qml;
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
@@ -30,8 +30,8 @@
|
||||
#ifndef QMLSYMBOL_H
|
||||
#define QMLSYMBOL_H
|
||||
|
||||
#include <qml/parser/qmljsastfwd_p.h>
|
||||
#include <qml/qml_global.h>
|
||||
#include <qmljs/parser/qmljsastfwd_p.h>
|
||||
#include <qmljs/qml_global.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
@@ -30,9 +30,9 @@
|
||||
#ifndef QMLTYPESYSTEM_H
|
||||
#define QMLTYPESYSTEM_H
|
||||
|
||||
#include <qml/qml_global.h>
|
||||
#include <qml/qmlpackageinfo.h>
|
||||
#include <qml/qmlsymbol.h>
|
||||
#include <qmljs/qml_global.h>
|
||||
#include <qmljs/qmlpackageinfo.h>
|
||||
#include <qmljs/qmlsymbol.h>
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QObject>
|
@@ -23,6 +23,12 @@ SOURCES += \
|
||||
application.cpp \
|
||||
welcomescreen.cpp
|
||||
|
||||
include(../../../shared/qmljs/qmljs.pri)
|
||||
HEADERS+=../../../libs/utils/changeset.h
|
||||
SOURCES+=../../../libs/utils/changeset.cpp
|
||||
INCLUDEPATH+=../../../libs
|
||||
DEFINES+=QTCREATOR_UTILS_STATIC_LIB QML_BUILD_STATIC_LIB
|
||||
|
||||
include(../../../plugins/qmldesigner/config.pri)
|
||||
include(../../../plugins/qmldesigner/components/integration/integration.pri)
|
||||
include(../../../plugins/qmldesigner/components/propertyeditor/propertyeditor.pri)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user