forked from qt-creator/qt-creator
QmlDesigner.itemlibrary: filter item library by imports
Only show items that are available and use requiredImport for filtering
This commit is contained in:
@@ -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,7 +394,16 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo)
|
||||
m_sections.clear();
|
||||
m_nextLibId = 0;
|
||||
|
||||
QStringList imports;
|
||||
foreach (const Import &import, model->imports())
|
||||
if (import.isLibraryImport())
|
||||
imports << import.url() + " " + import.version();
|
||||
|
||||
foreach (ItemLibraryEntry entry, itemLibraryInfo->entries()) {
|
||||
|
||||
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;
|
||||
@@ -418,6 +434,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo)
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user