Commit bda50da7 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.itemlibrary: do not show non-visual content items

Task-number: QTCREATORBUG-4770
parent df6f8099
......@@ -327,7 +327,7 @@ QList<RewriterView::Error> DesignDocumentController::loadMaster(QPlainTextEdit *
m_d->masterModel->attachView(m_d->rewriterView.data());
m_d->model = m_d->masterModel;
m_d->subComponentManager = new SubComponentManager(m_d->masterModel->metaInfo(), this);
m_d->subComponentManager = new SubComponentManager(m_d->masterModel.data(), this);
m_d->subComponentManager->update(m_d->searchPath, m_d->model->imports());
loadCurrentModel();
......
......@@ -35,8 +35,6 @@
#include "corelib_global.h"
#include <metainfo.h>
#include <QObject>
#include <QString>
#include <QUrl>
......@@ -44,12 +42,17 @@
namespace QmlDesigner {
class Import;
class Model;
namespace Internal {
class SubComponentManagerPrivate;
}
class CORESHARED_EXPORT SubComponentManager : public QObject
{
Q_OBJECT
public:
explicit SubComponentManager(MetaInfo metaInfo, QObject *parent = 0);
explicit SubComponentManager(Model *model, QObject *parent = 0);
~SubComponentManager();
void update(const QUrl &fileUrl, const QList<Import> &imports);
......@@ -60,7 +63,7 @@ public:
private:
friend class Internal::SubComponentManagerPrivate;
class Internal::SubComponentManagerPrivate *m_d;
Internal::SubComponentManagerPrivate *m_d;
};
} // namespace QmlDesigner
......
......@@ -31,6 +31,7 @@
**************************************************************************/
#include "subcomponentmanager.h"
#include "model.h"
#include "metainfo.h"
#include <QDir>
......@@ -81,7 +82,7 @@ static const QString QMLFILEPATTERN = QString(QLatin1String("*.qml"));
class SubComponentManagerPrivate : QObject {
Q_OBJECT
public:
SubComponentManagerPrivate(MetaInfo metaInfo, SubComponentManager *q);
SubComponentManagerPrivate(Model *model, SubComponentManager *q);
void addImport(int pos, const Import &import);
void removeImport(int pos);
......@@ -96,10 +97,11 @@ public:
QList<QFileInfo> watchedFiles(const QString &canonicalDirPath);
void unregisterQmlFile(const QFileInfo &fileInfo, const QString &qualifier);
void registerQmlFile(const QFileInfo &fileInfo, const QString &qualifier, bool addToLibrary);
Model *model() const;
SubComponentManager *m_q;
MetaInfo m_metaInfo;
QWeakPointer<Model> m_model;
QFileSystemWatcher m_watcher;
......@@ -111,9 +113,9 @@ public:
QList<Import> m_imports;
};
SubComponentManagerPrivate::SubComponentManagerPrivate(MetaInfo metaInfo, SubComponentManager *q) :
SubComponentManagerPrivate::SubComponentManagerPrivate(Model *model, SubComponentManager *q) :
m_q(q),
m_metaInfo(metaInfo)
m_model(model)
{
connect(&m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(parseDirectory(QString)));
}
......@@ -323,6 +325,9 @@ static inline bool isDepricatedQtType(const QString &typeName)
void SubComponentManagerPrivate::registerQmlFile(const QFileInfo &fileInfo, const QString &qualifier,
bool addToLibrary)
{
if (!model())
return;
QString componentName = fileInfo.baseName();
if (!qualifier.isEmpty()) {
......@@ -342,11 +347,20 @@ void SubComponentManagerPrivate::registerQmlFile(const QFileInfo &fileInfo, cons
itemLibraryEntry.setName(componentName);
itemLibraryEntry.setCategory("QML Components");
if (!m_metaInfo.itemLibraryInfo()->containsEntry(itemLibraryEntry))
m_metaInfo.itemLibraryInfo()->addEntry(itemLibraryEntry);
if (model()->metaInfo(componentName).isValid() && model()->metaInfo(componentName).isSubclassOf("QtQuick.Item", -1, -1) &&
!model()->metaInfo().itemLibraryInfo()->containsEntry(itemLibraryEntry)) {
model()->metaInfo().itemLibraryInfo()->addEntry(itemLibraryEntry);
}
}
}
Model *SubComponentManagerPrivate::model() const
{
return m_model.data();
}
} // namespace Internal
/*!
......@@ -356,9 +370,9 @@ void SubComponentManagerPrivate::registerQmlFile(const QFileInfo &fileInfo, cons
these in the metatype system.
*/
SubComponentManager::SubComponentManager(MetaInfo metaInfo, QObject *parent) :
SubComponentManager::SubComponentManager(Model *model, QObject *parent) :
QObject(parent),
m_d(new Internal::SubComponentManagerPrivate(metaInfo, this))
m_d(new Internal::SubComponentManagerPrivate(model, this))
{
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment