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:
Thomas Hartmann
2020-07-01 14:46:15 +02:00
parent c05755a2e1
commit 94f9544df5
9 changed files with 73 additions and 34 deletions

View File

@@ -51,11 +51,11 @@ AddNewBackendDialog::~AddNewBackendDialog()
delete m_ui;
}
void AddNewBackendDialog::setupPossibleTypes(const QList<CppTypeData> &types)
void AddNewBackendDialog::setupPossibleTypes(const QList<QmlTypeData> &types)
{
QSignalBlocker blocker(this);
m_typeData = types;
for (const CppTypeData &typeData : types)
for (const QmlTypeData &typeData : types)
m_ui->comboBox->addItem(typeData.typeName);
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)
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;
}
@@ -100,7 +100,7 @@ void AddNewBackendDialog::invalidate()
if (m_ui->comboBox->currentIndex() < 0)
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->checkBox->setChecked(false);

View File

@@ -42,7 +42,7 @@ class AddNewBackendDialog : public QDialog
public:
explicit AddNewBackendDialog(QWidget *parent = nullptr);
~AddNewBackendDialog() override;
void setupPossibleTypes(const QList<CppTypeData> &types);
void setupPossibleTypes(const QList<QmlTypeData> &types);
QString importString() const;
QString type() const;
bool applied() const;
@@ -53,7 +53,7 @@ private:
void invalidate();
Ui::AddNewBackendDialog *m_ui;
QList<CppTypeData> m_typeData;
QList<QmlTypeData> m_typeData;
bool m_applied = false;
bool m_isSingleton = false;

View File

@@ -75,7 +75,7 @@ void BackendModel::resetModel()
static const PropertyTypeList simpleTypes = {"int", "real", "color", "string"};
if (rewriterView)
for (const CppTypeData &cppTypeData : rewriterView->getCppTypes())
for (const QmlTypeData &cppTypeData : rewriterView->getQMLTypes())
if (cppTypeData.isSingleton) {
NodeMetaInfo metaInfo = m_connectionView->model()->metaInfo(cppTypeData.typeName.toUtf8());
if (metaInfo.isValid() && !metaInfo.isSubclassOf("QtQuick.Item")) {
@@ -146,20 +146,20 @@ QStringList BackendModel::possibleCppTypes() const
QStringList list;
if (rewriterView)
foreach (const CppTypeData &cppTypeData, rewriterView->getCppTypes())
foreach (const QmlTypeData &cppTypeData, rewriterView->getQMLTypes())
list.append(cppTypeData.typeName);
return list;
}
CppTypeData BackendModel::cppTypeDataForType(const QString &typeName) const
QmlTypeData BackendModel::cppTypeDataForType(const QString &typeName) const
{
RewriterView *rewriterView = m_connectionView->model()->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;
});
}
@@ -173,7 +173,7 @@ void BackendModel::deletePropertyByRow(int rowNumber)
/* singleton case remove the import */
if (data(index(rowNumber, 0), Qt::UserRole + 1).toBool()) {
const QString typeName = data(index(rowNumber, 0), Qt::UserRole + 1).toString();
CppTypeData cppTypeData = cppTypeDataForType(typeName);
QmlTypeData cppTypeData = cppTypeDataForType(typeName);
if (cppTypeData.isSingleton) {
@@ -214,7 +214,7 @@ void BackendModel::addNewBackend()
QStringList availableTypes;
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();
/* Only show singletons if the import is missing */
}));

View File

@@ -52,7 +52,7 @@ public:
void resetModel();
QStringList possibleCppTypes() const;
CppTypeData cppTypeDataForType(const QString &typeName) const;
QmlTypeData cppTypeDataForType(const QString &typeName) const;
void deletePropertyByRow(int rowNumber);

View File

@@ -53,7 +53,7 @@ class ModelNodePositionStorage;
} //Internal
struct CppTypeData
struct QmlTypeData
{
QString superClassName;
QString importUrl;
@@ -61,6 +61,7 @@ struct CppTypeData
QString cppClassName;
QString typeName;
bool isSingleton = false;
bool isCppType = false;
};
class QMLDESIGNERCORE_EXPORT RewriterView : public AbstractView
@@ -158,7 +159,7 @@ public:
QStringList autoComplete(const QString &text, int pos, bool explicitComplete = true);
QList<CppTypeData> getCppTypes();
QList<QmlTypeData> getQMLTypes() const;
void setWidgetStatusCallback(std::function<void(bool)> setWidgetStatusCallback);

View File

@@ -958,7 +958,7 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
QVector<MockupTypeContainer> mockupTypesVector;
for (const CppTypeData &cppTypeData : model()->rewriterView()->getCppTypes()) {
for (const QmlTypeData &cppTypeData : model()->rewriterView()->getQMLTypes()) {
const QString versionString = cppTypeData.versionString;
int majorVersion = -1;
int minorVersion = -1;

View File

@@ -960,27 +960,31 @@ QStringList RewriterView::autoComplete(const QString &text, int pos, bool explic
return list;
}
QList<CppTypeData> RewriterView::getCppTypes()
QList<QmlTypeData> RewriterView::getQMLTypes() const
{
QList<CppTypeData> cppDataList;
for (const QmlJS::ModelManagerInterface::CppData &cppData : QmlJS::ModelManagerInterface::instance()->cppData().values())
QList<QmlTypeData> qmlDataList;
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::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;
cppData.cppClassName = fakeMetaObject->className();
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);
if (qmlData.importUrl != "<cpp>") //ignore pure unregistered cpp types
qmlDataList.append(qmlData);
}
}
return cppDataList;
return qmlDataList;
}
void RewriterView::setWidgetStatusCallback(std::function<void (bool)> setWidgetStatusCallback)
@@ -990,7 +994,6 @@ void RewriterView::setWidgetStatusCallback(std::function<void (bool)> setWidgetS
void RewriterView::qmlTextChanged()
{
getCppTypes();
if (inErrorState())
return;

View File

@@ -2176,6 +2176,37 @@ QSet<QPair<QString, QString> > TextToModelMerger::qrcMapping() const
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,
const SourceLocation &location)
{

View File

@@ -41,6 +41,8 @@ namespace QmlDesigner {
class RewriterView;
class DocumentMessage;
struct QmlTypeData;
namespace Internal {
class DifferenceHandler;
@@ -133,6 +135,8 @@ public:
QSet<QPair<QString, QString>> qrcMapping() const;
QList<QmlTypeData> getQMLSingletons() const;
private:
void setupCustomParserNode(const ModelNode &node);
void setupComponent(const ModelNode &node);