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

QmlDesigner.itemlibrary: filter item library by imports

Only show items that are available and use requiredImport for filtering
parent 8cdb63ea
...@@ -355,7 +355,6 @@ void DesignDocumentController::loadCurrentModel() ...@@ -355,7 +355,6 @@ void DesignDocumentController::loadCurrentModel()
m_d->model->attachView(m_d->nodeInstanceView.data()); m_d->model->attachView(m_d->nodeInstanceView.data());
m_d->model->attachView(m_d->navigator.data()); m_d->model->attachView(m_d->navigator.data());
m_d->itemLibraryView->widget()->setItemLibraryInfo(m_d->model->metaInfo().itemLibraryInfo());
m_d->itemLibraryView->widget()->setResourcePath(QFileInfo(m_d->fileName).absolutePath()); m_d->itemLibraryView->widget()->setResourcePath(QFileInfo(m_d->fileName).absolutePath());
if (!m_d->componentAction) { if (!m_d->componentAction) {
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "itemlibrarymodel.h" #include "itemlibrarymodel.h"
#include "itemlibraryinfo.h" #include "itemlibraryinfo.h"
#include <model.h>
#include <nodemetainfo.h>
#include <QVariant> #include <QVariant>
#include <QMimeData> #include <QMimeData>
...@@ -378,7 +380,12 @@ bool ItemLibraryModel::isItemVisible(int itemLibId) ...@@ -378,7 +380,12 @@ bool ItemLibraryModel::isItemVisible(int itemLibId)
return elementModel(sectionLibId)->isItemVisible(itemLibId); return elementModel(sectionLibId)->isItemVisible(itemLibId);
} }
void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo) QString entryToImport(const ItemLibraryEntry &entry)
{
return entry.requiredImport() + " " + QString::number(entry.majorVersion()) + "." + QString::number(entry.minorVersion());
}
void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
{ {
QMap<QString, int> sections; QMap<QString, int> sections;
...@@ -387,36 +394,46 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo) ...@@ -387,36 +394,46 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo)
m_sections.clear(); m_sections.clear();
m_nextLibId = 0; m_nextLibId = 0;
foreach (ItemLibraryEntry entry, itemLibraryInfo->entries()) { QStringList imports;
QString itemSectionName = entry.category(); foreach (const Import &import, model->imports())
ItemLibrarySectionModel *sectionModel; if (import.isLibraryImport())
ItemLibraryItemModel *itemModel; imports << import.url() + " " + import.version();
int itemId = m_nextLibId++, sectionId;
if (sections.contains(itemSectionName)) {
sectionId = sections.value(itemSectionName);
sectionModel = elementModel(sectionId);
} else {
sectionId = m_nextLibId++;
sectionModel = new ItemLibrarySectionModel(m_scriptEngine.data(), sectionId, itemSectionName, this);
addElement(sectionModel, sectionId);
sections.insert(itemSectionName, sectionId);
}
m_itemInfos.insert(itemId, entry); foreach (ItemLibraryEntry entry, itemLibraryInfo->entries()) {
itemModel = new ItemLibraryItemModel(m_scriptEngine.data(), itemId, entry.name());
// delayed creation of (default) icons
if (entry.iconPath().isEmpty())
entry.setIconPath(QLatin1String(":/ItemLibrary/images/item-default-icon.png"));
if (entry.dragIcon().isNull())
entry.setDragIcon(createDragPixmap(getWidth(entry), getHeight(entry)));
itemModel->setItemIconPath(entry.iconPath()); bool valid = model->metaInfo(entry.typeName(), entry.majorVersion(), entry.minorVersion()).isValid();
itemModel->setItemIconSize(m_itemIconSize);
sectionModel->addSectionEntry(itemModel); if (valid && entry.requiredImport().isEmpty() || imports.contains(entryToImport(entry))) {
m_sections.insert(itemId, sectionId); QString itemSectionName = entry.category();
ItemLibrarySectionModel *sectionModel;
ItemLibraryItemModel *itemModel;
int itemId = m_nextLibId++, sectionId;
if (sections.contains(itemSectionName)) {
sectionId = sections.value(itemSectionName);
sectionModel = elementModel(sectionId);
} else {
sectionId = m_nextLibId++;
sectionModel = new ItemLibrarySectionModel(m_scriptEngine.data(), sectionId, itemSectionName, this);
addElement(sectionModel, sectionId);
sections.insert(itemSectionName, sectionId);
}
m_itemInfos.insert(itemId, entry);
itemModel = new ItemLibraryItemModel(m_scriptEngine.data(), itemId, entry.name());
// delayed creation of (default) icons
if (entry.iconPath().isEmpty())
entry.setIconPath(QLatin1String(":/ItemLibrary/images/item-default-icon.png"));
if (entry.dragIcon().isNull())
entry.setDragIcon(createDragPixmap(getWidth(entry), getHeight(entry)));
itemModel->setItemIconPath(entry.iconPath());
itemModel->setItemIconSize(m_itemIconSize);
sectionModel->addSectionEntry(itemModel);
m_sections.insert(itemId, sectionId);
}
} }
updateVisibility(); updateVisibility();
......
...@@ -42,6 +42,7 @@ namespace QmlDesigner { ...@@ -42,6 +42,7 @@ namespace QmlDesigner {
class ItemLibraryInfo; class ItemLibraryInfo;
class ItemLibraryEntry; class ItemLibraryEntry;
class Model;
namespace Internal { namespace Internal {
...@@ -131,7 +132,7 @@ public: ...@@ -131,7 +132,7 @@ public:
QString searchText() const; QString searchText() const;
void update(ItemLibraryInfo *itemLibraryInfo); void update(ItemLibraryInfo *itemLibraryInfo, Model *model);
QString getTypeName(int libId); QString getTypeName(int libId);
QMimeData *getMimeData(int libId); QMimeData *getMimeData(int libId);
......
#include "itemlibraryview.h" #include "itemlibraryview.h"
#include "itemlibrarywidget.h" #include "itemlibrarywidget.h"
#include <import.h>
namespace QmlDesigner { namespace QmlDesigner {
...@@ -21,19 +22,24 @@ ItemLibraryWidget *ItemLibraryView::widget() ...@@ -21,19 +22,24 @@ ItemLibraryWidget *ItemLibraryView::widget()
void ItemLibraryView::modelAttached(Model *model) void ItemLibraryView::modelAttached(Model *model)
{ {
AbstractView::modelAttached(model); AbstractView::modelAttached(model);
m_widget->setModel(model);
updateImports();
} }
void ItemLibraryView::modelAboutToBeDetached(Model *model) void ItemLibraryView::modelAboutToBeDetached(Model *model)
{ {
AbstractView::modelAboutToBeDetached(model); AbstractView::modelAboutToBeDetached(model);
m_widget->setModel(0);
} }
void ItemLibraryView::importAdded(const Import &import) void ItemLibraryView::importAdded(const Import &)
{ {
updateImports();
} }
void ItemLibraryView::importRemoved(const Import &import) void ItemLibraryView::importRemoved(const Import &)
{ {
updateImports();
} }
void ItemLibraryView::nodeCreated(const ModelNode &) void ItemLibraryView::nodeCreated(const ModelNode &)
...@@ -122,4 +128,9 @@ void ItemLibraryView::instancesCompleted(const QVector<ModelNode> &) ...@@ -122,4 +128,9 @@ void ItemLibraryView::instancesCompleted(const QVector<ModelNode> &)
} }
void ItemLibraryView::updateImports()
{
m_widget->updateModel();
}
} //QmlDesigner } //QmlDesigner
...@@ -79,6 +79,9 @@ public: ...@@ -79,6 +79,9 @@ public:
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList); void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList); void instancesCompleted(const QVector<ModelNode> &completedNodeList);
protected:
void updateImports();
private: private:
QWeakPointer<ItemLibraryWidget> m_widget; QWeakPointer<ItemLibraryWidget> m_widget;
}; };
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include "itemlibrarymodel.h" #include "itemlibrarymodel.h"
#include "itemlibraryimageprovider.h" #include "itemlibraryimageprovider.h"
#include "customdraganddrop.h" #include "customdraganddrop.h"
#include <model.h>
#include <metainfo.h>
#include <QFileInfo> #include <QFileInfo>
#include <QFileIconProvider> #include <QFileIconProvider>
...@@ -107,6 +109,7 @@ public: ...@@ -107,6 +109,7 @@ public:
QSize m_itemIconSize, m_resIconSize; QSize m_itemIconSize, m_resIconSize;
MyFileIconProvider m_iconProvider; MyFileIconProvider m_iconProvider;
Model *model;
}; };
ItemLibraryWidgetPrivate::ItemLibraryWidgetPrivate(QObject *object) : ItemLibraryWidgetPrivate::ItemLibraryWidgetPrivate(QObject *object) :
...@@ -279,9 +282,16 @@ void ItemLibraryWidget::setSearchFilter(const QString &searchFilter) ...@@ -279,9 +282,16 @@ void ItemLibraryWidget::setSearchFilter(const QString &searchFilter)
} }
} }
void ItemLibraryWidget::setModel(Model *model)
{
m_d->model = model;
setItemLibraryInfo(model->metaInfo().itemLibraryInfo());
updateModel();
}
void ItemLibraryWidget::updateModel() void ItemLibraryWidget::updateModel()
{ {
m_d->m_itemLibraryModel->update(m_d->m_itemLibraryInfo.data()); m_d->m_itemLibraryModel->update(m_d->m_itemLibraryInfo.data(), m_d->model);
updateSearch(); updateSearch();
} }
......
...@@ -38,6 +38,7 @@ namespace QmlDesigner { ...@@ -38,6 +38,7 @@ namespace QmlDesigner {
class ItemLibraryWidgetPrivate; class ItemLibraryWidgetPrivate;
class MetaInfo; class MetaInfo;
class ItemLibraryEntry; class ItemLibraryEntry;
class Model;
class ItemLibraryWidget : public QFrame class ItemLibraryWidget : public QFrame
{ {
...@@ -60,6 +61,8 @@ public Q_SLOTS: ...@@ -60,6 +61,8 @@ public Q_SLOTS:
void startDragAndDrop(int itemLibId); void startDragAndDrop(int itemLibId);
void showItemInfo(int itemLibId); void showItemInfo(int itemLibId);
void setModel(Model *model);
protected: protected:
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
......
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