QmlDesigner: Add flow mode to ItemLibrary

If in flow mode we only show FlowItems.

Change-Id: I7d41155eac8bc180c7ac1d0092b35d7fc3f9be91
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2020-01-29 12:28:30 +01:00
parent bff9d65729
commit 868e3133c0
5 changed files with 29 additions and 0 deletions

View File

@@ -64,6 +64,13 @@ void ItemLibraryModel::setExpanded(bool expanded, const QString &section)
collapsedStateHash.insert(section, expanded);
}
void ItemLibraryModel::setFlowMode(bool b)
{
m_flowMode = b;
bool changed;
updateVisibility(&changed);
}
ItemLibraryModel::ItemLibraryModel(QObject *parent)
: QAbstractListModel(parent)
{
@@ -187,6 +194,12 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
bool forceVisiblity = valid && NodeHints::fromItemLibraryEntry(entry).visibleInLibrary();
if (m_flowMode) {
forceVisiblity = false;
isItem = metaInfo.isSubclassOf("FlowView.FlowItem");
}
if (valid
&& (isItem || forceVisiblity) //We can change if the navigator does support pure QObjects
&& (entry.requiredImport().isEmpty()
@@ -262,6 +275,10 @@ void ItemLibraryModel::updateVisibility(bool *changed)
bool sectionChanged = false;
bool sectionVisibility = itemLibrarySection->updateSectionVisibility(sectionSearchText,
&sectionChanged);
if (m_flowMode && itemLibrarySection->sectionName() != "My QML Components")
sectionVisibility= false;
*changed |= sectionChanged;
*changed |= itemLibrarySection->setVisible(sectionVisibility);
}

View File

@@ -73,6 +73,8 @@ public:
void setExpanded(bool, const QString &section);
void setFlowMode(bool);
signals:
void qmlModelChanged();
void searchTextChanged();
@@ -88,6 +90,7 @@ private: // variables
QHash<int, QByteArray> m_roleNames;
QString m_searchText;
bool m_flowMode = false;
};
} // namespace QmlDesigner

View File

@@ -27,6 +27,7 @@
#include "itemlibrarywidget.h"
#include <import.h>
#include <importmanagerview.h>
#include <qmlitemnode.h>
#include <rewriterview.h>
namespace QmlDesigner {
@@ -68,6 +69,7 @@ void ItemLibraryView::modelAttached(Model *model)
updateImports();
model->attachView(m_importManagerView);
m_hasErrors = !rewriterView()->errors().isEmpty();
m_widget->setFlowMode(QmlItemNode(rootModelNode()).isFlowView());
}
void ItemLibraryView::modelAboutToBeDetached(Model *model)

View File

@@ -416,6 +416,11 @@ void ItemLibraryWidget::startDragAndDrop(QQuickItem *mouseArea, QVariant itemLib
});
}
void ItemLibraryWidget::setFlowMode(bool b)
{
m_itemLibraryModel->setFlowMode(b);
}
void ItemLibraryWidget::removeImport(const QString &name)
{
QTC_ASSERT(m_model, return);

View File

@@ -86,6 +86,8 @@ public:
Q_INVOKABLE void startDragAndDrop(QQuickItem *mouseArea, QVariant itemLibId);
void setFlowMode(bool b);
signals:
void itemActivated(const QString& itemName);