forked from qt-creator/qt-creator
QmlDesigner: Rename CppTypeData to QmlTypeData
Also adding getQMLSingletons(). The Backendmodel now also knows about QML singletons. Change-Id: I96e130678ef956e569960c431f45bd362d026f5f Reviewed-by: Aleksei German <aleksei.german@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -51,11 +51,11 @@ AddNewBackendDialog::~AddNewBackendDialog()
|
|||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddNewBackendDialog::setupPossibleTypes(const QList<CppTypeData> &types)
|
void AddNewBackendDialog::setupPossibleTypes(const QList<QmlTypeData> &types)
|
||||||
{
|
{
|
||||||
QSignalBlocker blocker(this);
|
QSignalBlocker blocker(this);
|
||||||
m_typeData = types;
|
m_typeData = types;
|
||||||
for (const CppTypeData &typeData : types)
|
for (const QmlTypeData &typeData : types)
|
||||||
m_ui->comboBox->addItem(typeData.typeName);
|
m_ui->comboBox->addItem(typeData.typeName);
|
||||||
|
|
||||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_ui->comboBox->count() > 0);
|
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_ui->comboBox->count() > 0);
|
||||||
@@ -67,7 +67,7 @@ QString AddNewBackendDialog::importString() const
|
|||||||
if (m_ui->comboBox->currentIndex() < 0)
|
if (m_ui->comboBox->currentIndex() < 0)
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
CppTypeData typeData = m_typeData.at(m_ui->comboBox->currentIndex());
|
QmlTypeData typeData = m_typeData.at(m_ui->comboBox->currentIndex());
|
||||||
|
|
||||||
return typeData.importUrl + " " + typeData.versionString;
|
return typeData.importUrl + " " + typeData.versionString;
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ void AddNewBackendDialog::invalidate()
|
|||||||
if (m_ui->comboBox->currentIndex() < 0)
|
if (m_ui->comboBox->currentIndex() < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CppTypeData typeData = m_typeData.at(m_ui->comboBox->currentIndex());
|
QmlTypeData typeData = m_typeData.at(m_ui->comboBox->currentIndex());
|
||||||
m_ui->importLabel->setText(importString());
|
m_ui->importLabel->setText(importString());
|
||||||
|
|
||||||
m_ui->checkBox->setChecked(false);
|
m_ui->checkBox->setChecked(false);
|
||||||
|
@@ -42,7 +42,7 @@ class AddNewBackendDialog : public QDialog
|
|||||||
public:
|
public:
|
||||||
explicit AddNewBackendDialog(QWidget *parent = nullptr);
|
explicit AddNewBackendDialog(QWidget *parent = nullptr);
|
||||||
~AddNewBackendDialog() override;
|
~AddNewBackendDialog() override;
|
||||||
void setupPossibleTypes(const QList<CppTypeData> &types);
|
void setupPossibleTypes(const QList<QmlTypeData> &types);
|
||||||
QString importString() const;
|
QString importString() const;
|
||||||
QString type() const;
|
QString type() const;
|
||||||
bool applied() const;
|
bool applied() const;
|
||||||
@@ -53,7 +53,7 @@ private:
|
|||||||
void invalidate();
|
void invalidate();
|
||||||
|
|
||||||
Ui::AddNewBackendDialog *m_ui;
|
Ui::AddNewBackendDialog *m_ui;
|
||||||
QList<CppTypeData> m_typeData;
|
QList<QmlTypeData> m_typeData;
|
||||||
|
|
||||||
bool m_applied = false;
|
bool m_applied = false;
|
||||||
bool m_isSingleton = false;
|
bool m_isSingleton = false;
|
||||||
|
@@ -75,7 +75,7 @@ void BackendModel::resetModel()
|
|||||||
static const PropertyTypeList simpleTypes = {"int", "real", "color", "string"};
|
static const PropertyTypeList simpleTypes = {"int", "real", "color", "string"};
|
||||||
|
|
||||||
if (rewriterView)
|
if (rewriterView)
|
||||||
for (const CppTypeData &cppTypeData : rewriterView->getCppTypes())
|
for (const QmlTypeData &cppTypeData : rewriterView->getQMLTypes())
|
||||||
if (cppTypeData.isSingleton) {
|
if (cppTypeData.isSingleton) {
|
||||||
NodeMetaInfo metaInfo = m_connectionView->model()->metaInfo(cppTypeData.typeName.toUtf8());
|
NodeMetaInfo metaInfo = m_connectionView->model()->metaInfo(cppTypeData.typeName.toUtf8());
|
||||||
if (metaInfo.isValid() && !metaInfo.isSubclassOf("QtQuick.Item")) {
|
if (metaInfo.isValid() && !metaInfo.isSubclassOf("QtQuick.Item")) {
|
||||||
@@ -146,20 +146,20 @@ QStringList BackendModel::possibleCppTypes() const
|
|||||||
QStringList list;
|
QStringList list;
|
||||||
|
|
||||||
if (rewriterView)
|
if (rewriterView)
|
||||||
foreach (const CppTypeData &cppTypeData, rewriterView->getCppTypes())
|
foreach (const QmlTypeData &cppTypeData, rewriterView->getQMLTypes())
|
||||||
list.append(cppTypeData.typeName);
|
list.append(cppTypeData.typeName);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
CppTypeData BackendModel::cppTypeDataForType(const QString &typeName) const
|
QmlTypeData BackendModel::cppTypeDataForType(const QString &typeName) const
|
||||||
{
|
{
|
||||||
RewriterView *rewriterView = m_connectionView->model()->rewriterView();
|
RewriterView *rewriterView = m_connectionView->model()->rewriterView();
|
||||||
|
|
||||||
if (!rewriterView)
|
if (!rewriterView)
|
||||||
return CppTypeData();
|
return QmlTypeData();
|
||||||
|
|
||||||
return Utils::findOr(rewriterView->getCppTypes(), CppTypeData(), [&typeName](const CppTypeData &data) {
|
return Utils::findOr(rewriterView->getQMLTypes(), QmlTypeData(), [&typeName](const QmlTypeData &data) {
|
||||||
return typeName == data.typeName;
|
return typeName == data.typeName;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ void BackendModel::deletePropertyByRow(int rowNumber)
|
|||||||
/* singleton case remove the import */
|
/* singleton case remove the import */
|
||||||
if (data(index(rowNumber, 0), Qt::UserRole + 1).toBool()) {
|
if (data(index(rowNumber, 0), Qt::UserRole + 1).toBool()) {
|
||||||
const QString typeName = data(index(rowNumber, 0), Qt::UserRole + 1).toString();
|
const QString typeName = data(index(rowNumber, 0), Qt::UserRole + 1).toString();
|
||||||
CppTypeData cppTypeData = cppTypeDataForType(typeName);
|
QmlTypeData cppTypeData = cppTypeDataForType(typeName);
|
||||||
|
|
||||||
if (cppTypeData.isSingleton) {
|
if (cppTypeData.isSingleton) {
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ void BackendModel::addNewBackend()
|
|||||||
QStringList availableTypes;
|
QStringList availableTypes;
|
||||||
|
|
||||||
if (rewriterView)
|
if (rewriterView)
|
||||||
dialog.setupPossibleTypes(Utils::filtered(rewriterView->getCppTypes(), [model](const CppTypeData &cppTypeData) {
|
dialog.setupPossibleTypes(Utils::filtered(rewriterView->getQMLTypes(), [model](const QmlTypeData &cppTypeData) {
|
||||||
return !cppTypeData.isSingleton || !model->metaInfo(cppTypeData.typeName.toUtf8()).isValid();
|
return !cppTypeData.isSingleton || !model->metaInfo(cppTypeData.typeName.toUtf8()).isValid();
|
||||||
/* Only show singletons if the import is missing */
|
/* Only show singletons if the import is missing */
|
||||||
}));
|
}));
|
||||||
|
@@ -52,7 +52,7 @@ public:
|
|||||||
void resetModel();
|
void resetModel();
|
||||||
|
|
||||||
QStringList possibleCppTypes() const;
|
QStringList possibleCppTypes() const;
|
||||||
CppTypeData cppTypeDataForType(const QString &typeName) const;
|
QmlTypeData cppTypeDataForType(const QString &typeName) const;
|
||||||
|
|
||||||
void deletePropertyByRow(int rowNumber);
|
void deletePropertyByRow(int rowNumber);
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ class ModelNodePositionStorage;
|
|||||||
|
|
||||||
} //Internal
|
} //Internal
|
||||||
|
|
||||||
struct CppTypeData
|
struct QmlTypeData
|
||||||
{
|
{
|
||||||
QString superClassName;
|
QString superClassName;
|
||||||
QString importUrl;
|
QString importUrl;
|
||||||
@@ -61,6 +61,7 @@ struct CppTypeData
|
|||||||
QString cppClassName;
|
QString cppClassName;
|
||||||
QString typeName;
|
QString typeName;
|
||||||
bool isSingleton = false;
|
bool isSingleton = false;
|
||||||
|
bool isCppType = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QMLDESIGNERCORE_EXPORT RewriterView : public AbstractView
|
class QMLDESIGNERCORE_EXPORT RewriterView : public AbstractView
|
||||||
@@ -158,7 +159,7 @@ public:
|
|||||||
|
|
||||||
QStringList autoComplete(const QString &text, int pos, bool explicitComplete = true);
|
QStringList autoComplete(const QString &text, int pos, bool explicitComplete = true);
|
||||||
|
|
||||||
QList<CppTypeData> getCppTypes();
|
QList<QmlTypeData> getQMLTypes() const;
|
||||||
|
|
||||||
void setWidgetStatusCallback(std::function<void(bool)> setWidgetStatusCallback);
|
void setWidgetStatusCallback(std::function<void(bool)> setWidgetStatusCallback);
|
||||||
|
|
||||||
|
@@ -958,7 +958,7 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
|
|||||||
|
|
||||||
QVector<MockupTypeContainer> mockupTypesVector;
|
QVector<MockupTypeContainer> mockupTypesVector;
|
||||||
|
|
||||||
for (const CppTypeData &cppTypeData : model()->rewriterView()->getCppTypes()) {
|
for (const QmlTypeData &cppTypeData : model()->rewriterView()->getQMLTypes()) {
|
||||||
const QString versionString = cppTypeData.versionString;
|
const QString versionString = cppTypeData.versionString;
|
||||||
int majorVersion = -1;
|
int majorVersion = -1;
|
||||||
int minorVersion = -1;
|
int minorVersion = -1;
|
||||||
|
@@ -960,27 +960,31 @@ QStringList RewriterView::autoComplete(const QString &text, int pos, bool explic
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CppTypeData> RewriterView::getCppTypes()
|
QList<QmlTypeData> RewriterView::getQMLTypes() const
|
||||||
{
|
{
|
||||||
QList<CppTypeData> cppDataList;
|
QList<QmlTypeData> qmlDataList;
|
||||||
for (const QmlJS::ModelManagerInterface::CppData &cppData : QmlJS::ModelManagerInterface::instance()->cppData().values())
|
|
||||||
|
qmlDataList.append(m_textToModelMerger->getQMLSingletons());
|
||||||
|
|
||||||
|
for (const QmlJS::ModelManagerInterface::CppData &cppData :
|
||||||
|
QmlJS::ModelManagerInterface::instance()->cppData().values())
|
||||||
for (const LanguageUtils::FakeMetaObject::ConstPtr &fakeMetaObject : cppData.exportedTypes) {
|
for (const LanguageUtils::FakeMetaObject::ConstPtr &fakeMetaObject : cppData.exportedTypes) {
|
||||||
for (const LanguageUtils::FakeMetaObject::Export &exportItem : fakeMetaObject->exports()) {
|
for (const LanguageUtils::FakeMetaObject::Export &exportItem :
|
||||||
|
fakeMetaObject->exports()) {
|
||||||
|
QmlTypeData qmlData;
|
||||||
|
qmlData.cppClassName = fakeMetaObject->className();
|
||||||
|
qmlData.typeName = exportItem.type;
|
||||||
|
qmlData.importUrl = exportItem.package;
|
||||||
|
qmlData.versionString = exportItem.version.toString();
|
||||||
|
qmlData.superClassName = fakeMetaObject->superclassName();
|
||||||
|
qmlData.isSingleton = fakeMetaObject->isSingleton();
|
||||||
|
|
||||||
CppTypeData cppData;
|
if (qmlData.importUrl != "<cpp>") //ignore pure unregistered cpp types
|
||||||
cppData.cppClassName = fakeMetaObject->className();
|
qmlDataList.append(qmlData);
|
||||||
cppData.typeName = exportItem.type;
|
|
||||||
cppData.importUrl = exportItem.package;
|
|
||||||
cppData.versionString = exportItem.version.toString();
|
|
||||||
cppData.superClassName = fakeMetaObject->superclassName();
|
|
||||||
cppData.isSingleton = fakeMetaObject->isSingleton();
|
|
||||||
|
|
||||||
if (cppData.importUrl != "<cpp>") //ignore pure unregistered cpp types
|
|
||||||
cppDataList.append(cppData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cppDataList;
|
return qmlDataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RewriterView::setWidgetStatusCallback(std::function<void (bool)> setWidgetStatusCallback)
|
void RewriterView::setWidgetStatusCallback(std::function<void (bool)> setWidgetStatusCallback)
|
||||||
@@ -990,7 +994,6 @@ void RewriterView::setWidgetStatusCallback(std::function<void (bool)> setWidgetS
|
|||||||
|
|
||||||
void RewriterView::qmlTextChanged()
|
void RewriterView::qmlTextChanged()
|
||||||
{
|
{
|
||||||
getCppTypes();
|
|
||||||
if (inErrorState())
|
if (inErrorState())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -2176,6 +2176,37 @@ QSet<QPair<QString, QString> > TextToModelMerger::qrcMapping() const
|
|||||||
return m_qrcMapping;
|
return m_qrcMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QmlTypeData> TextToModelMerger::getQMLSingletons() const
|
||||||
|
{
|
||||||
|
QList<QmlTypeData> list;
|
||||||
|
const QmlJS::Imports *imports = m_scopeChain->context()->imports(
|
||||||
|
m_scopeChain->document().data());
|
||||||
|
|
||||||
|
if (!imports)
|
||||||
|
return list;
|
||||||
|
|
||||||
|
for (const QmlJS::Import &import : imports->all()) {
|
||||||
|
if (import.info.type() == ImportType::Library && !import.libraryPath.isEmpty()) {
|
||||||
|
const LibraryInfo &libraryInfo = m_scopeChain->context()->snapshot().libraryInfo(
|
||||||
|
import.libraryPath);
|
||||||
|
|
||||||
|
for (const QmlDirParser::Component &component : libraryInfo.components()) {
|
||||||
|
if (component.singleton) {
|
||||||
|
QmlTypeData qmlData;
|
||||||
|
|
||||||
|
qmlData.typeName = component.typeName;
|
||||||
|
qmlData.importUrl = import.info.name();
|
||||||
|
qmlData.versionString = import.info.version().toString();
|
||||||
|
qmlData.isSingleton = component.singleton;
|
||||||
|
|
||||||
|
list.append(qmlData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
QString TextToModelMerger::textAt(const Document::Ptr &doc,
|
QString TextToModelMerger::textAt(const Document::Ptr &doc,
|
||||||
const SourceLocation &location)
|
const SourceLocation &location)
|
||||||
{
|
{
|
||||||
|
@@ -41,6 +41,8 @@ namespace QmlDesigner {
|
|||||||
class RewriterView;
|
class RewriterView;
|
||||||
class DocumentMessage;
|
class DocumentMessage;
|
||||||
|
|
||||||
|
struct QmlTypeData;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class DifferenceHandler;
|
class DifferenceHandler;
|
||||||
@@ -131,7 +133,9 @@ public:
|
|||||||
|
|
||||||
void delayedSetup();
|
void delayedSetup();
|
||||||
|
|
||||||
QSet<QPair<QString, QString> > qrcMapping() const;
|
QSet<QPair<QString, QString>> qrcMapping() const;
|
||||||
|
|
||||||
|
QList<QmlTypeData> getQMLSingletons() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupCustomParserNode(const ModelNode &node);
|
void setupCustomParserNode(const ModelNode &node);
|
||||||
|
Reference in New Issue
Block a user