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()
m_d->model->attachView(m_d->nodeInstanceView.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());
if (!m_d->componentAction) {
......
......@@ -29,6 +29,8 @@
#include "itemlibrarymodel.h"
#include "itemlibraryinfo.h"
#include <model.h>
#include <nodemetainfo.h>
#include <QVariant>
#include <QMimeData>
......@@ -378,7 +380,12 @@ bool ItemLibraryModel::isItemVisible(int 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;
......@@ -387,36 +394,46 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo)
m_sections.clear();
m_nextLibId = 0;
foreach (ItemLibraryEntry entry, itemLibraryInfo->entries()) {
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);
}
QStringList imports;
foreach (const Import &import, model->imports())
if (import.isLibraryImport())
imports << import.url() + " " + import.version();
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)));
foreach (ItemLibraryEntry entry, itemLibraryInfo->entries()) {
itemModel->setItemIconPath(entry.iconPath());
itemModel->setItemIconSize(m_itemIconSize);
sectionModel->addSectionEntry(itemModel);
m_sections.insert(itemId, sectionId);
bool valid = model->metaInfo(entry.typeName(), entry.majorVersion(), entry.minorVersion()).isValid();
if (valid && entry.requiredImport().isEmpty() || imports.contains(entryToImport(entry))) {
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();
......
......@@ -42,6 +42,7 @@ namespace QmlDesigner {
class ItemLibraryInfo;
class ItemLibraryEntry;
class Model;
namespace Internal {
......@@ -131,7 +132,7 @@ public:
QString searchText() const;
void update(ItemLibraryInfo *itemLibraryInfo);
void update(ItemLibraryInfo *itemLibraryInfo, Model *model);
QString getTypeName(int libId);
QMimeData *getMimeData(int libId);
......
#include "itemlibraryview.h"
#include "itemlibrarywidget.h"
#include <import.h>
namespace QmlDesigner {
......@@ -21,19 +22,24 @@ ItemLibraryWidget *ItemLibraryView::widget()
void ItemLibraryView::modelAttached(Model *model)
{
AbstractView::modelAttached(model);
m_widget->setModel(model);
updateImports();
}
void ItemLibraryView::modelAboutToBeDetached(Model *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 &)
......@@ -122,4 +128,9 @@ void ItemLibraryView::instancesCompleted(const QVector<ModelNode> &)
}
void ItemLibraryView::updateImports()
{
m_widget->updateModel();
}
} //QmlDesigner
......@@ -79,6 +79,9 @@ public:
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
protected:
void updateImports();
private:
QWeakPointer<ItemLibraryWidget> m_widget;
};
......
......@@ -34,6 +34,8 @@
#include "itemlibrarymodel.h"
#include "itemlibraryimageprovider.h"
#include "customdraganddrop.h"
#include <model.h>
#include <metainfo.h>
#include <QFileInfo>
#include <QFileIconProvider>
......@@ -107,6 +109,7 @@ public:
QSize m_itemIconSize, m_resIconSize;
MyFileIconProvider m_iconProvider;
Model *model;
};
ItemLibraryWidgetPrivate::ItemLibraryWidgetPrivate(QObject *object) :
......@@ -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()
{
m_d->m_itemLibraryModel->update(m_d->m_itemLibraryInfo.data());
m_d->m_itemLibraryModel->update(m_d->m_itemLibraryInfo.data(), m_d->model);
updateSearch();
}
......
......@@ -38,6 +38,7 @@ namespace QmlDesigner {
class ItemLibraryWidgetPrivate;
class MetaInfo;
class ItemLibraryEntry;
class Model;
class ItemLibraryWidget : public QFrame
{
......@@ -60,6 +61,8 @@ public Q_SLOTS:
void startDragAndDrop(int itemLibId);
void showItemInfo(int itemLibId);
void setModel(Model *model);
protected:
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