forked from qt-creator/qt-creator
Add components library expand/collapse all context menu options
also change import name from "library" to "module" and relevant tweaks. Task-number: QDS-3589 Change-Id: Ib467dda61b6720cebe843e34cb807aee6221f5cb Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -33,9 +33,11 @@ import StudioTheme 1.0 as StudioTheme
|
|||||||
/* The view displaying the item grid.
|
/* The view displaying the item grid.
|
||||||
|
|
||||||
The following Qml context properties have to be set:
|
The following Qml context properties have to be set:
|
||||||
- ItemLibraryModel listmodel
|
- ItemLibraryModel itemLibraryModel
|
||||||
- int itemLibraryIconWidth
|
- int itemLibraryIconWidth
|
||||||
- int itemLibraryIconHeight
|
- int itemLibraryIconHeight
|
||||||
|
- ItemLibraryWidget rootView
|
||||||
|
- QColor highlightColor
|
||||||
|
|
||||||
itemLibraryModel structure:
|
itemLibraryModel structure:
|
||||||
|
|
||||||
@@ -100,11 +102,22 @@ ScrollView {
|
|||||||
id: contextMenu
|
id: contextMenu
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("Remove Library")
|
text: qsTr("Remove Module")
|
||||||
enabled: importToRemove !== ""
|
enabled: importToRemove !== "" && importToRemove !== "QtQuick"
|
||||||
&& importToRemove !== "QtQuick"
|
|
||||||
onTriggered: rootView.removeImport(importToRemove)
|
onTriggered: rootView.removeImport(importToRemove)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StudioControls.MenuSeparator {}
|
||||||
|
|
||||||
|
StudioControls.MenuItem {
|
||||||
|
text: qsTr("Expand All")
|
||||||
|
onTriggered: itemLibraryModel.expandAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
StudioControls.MenuItem {
|
||||||
|
text: qsTr("Collapse All")
|
||||||
|
onTriggered: itemLibraryModel.collapseAll()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +138,7 @@ ScrollView {
|
|||||||
topPadding: 0
|
topPadding: 0
|
||||||
bottomPadding: 0
|
bottomPadding: 0
|
||||||
expanded: importExpanded
|
expanded: importExpanded
|
||||||
onExpandedChanged: itemLibraryModel.setExpanded(expanded, importUrl);
|
onToggleExpand: importExpanded = !importExpanded
|
||||||
onShowContextMenu: {
|
onShowContextMenu: {
|
||||||
importToRemove = importUsed ? "" : importUrl
|
importToRemove = importUsed ? "" : importUrl
|
||||||
contextMenu.popup()
|
contextMenu.popup()
|
||||||
@@ -148,7 +161,7 @@ ScrollView {
|
|||||||
caption: categoryName + " (" + itemModel.rowCount() + ")"
|
caption: categoryName + " (" + itemModel.rowCount() + ")"
|
||||||
visible: categoryVisible
|
visible: categoryVisible
|
||||||
expanded: categoryExpanded
|
expanded: categoryExpanded
|
||||||
onExpandedChanged: itemLibraryModel.setExpanded(expanded, categoryName);
|
onToggleExpand: categoryExpanded = !categoryExpanded
|
||||||
|
|
||||||
Grid {
|
Grid {
|
||||||
id: itemGrid
|
id: itemGrid
|
||||||
@@ -171,5 +184,4 @@ ScrollView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -43,8 +43,6 @@ Item {
|
|||||||
property int rightPadding: 0
|
property int rightPadding: 0
|
||||||
property int bottomPadding: 4
|
property int bottomPadding: 4
|
||||||
|
|
||||||
property int animationDuration: 0
|
|
||||||
|
|
||||||
property bool expanded: true
|
property bool expanded: true
|
||||||
property int level: 0
|
property int level: 0
|
||||||
property int levelShift: 10
|
property int levelShift: 10
|
||||||
@@ -59,6 +57,7 @@ Item {
|
|||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
signal showContextMenu()
|
signal showContextMenu()
|
||||||
|
signal toggleExpand()
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: header
|
id: header
|
||||||
@@ -75,12 +74,6 @@ Item {
|
|||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: 4 + (level * levelShift)
|
anchors.leftMargin: 4 + (level * levelShift)
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
Behavior on rotation {
|
|
||||||
NumberAnimation {
|
|
||||||
easing.type: Easing.OutCubic
|
|
||||||
duration: section.animationDuration
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Controls.Label {
|
Controls.Label {
|
||||||
@@ -98,8 +91,8 @@ Item {
|
|||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (mouse.button === Qt.LeftButton) {
|
if (mouse.button === Qt.LeftButton) {
|
||||||
section.animationDuration = 120
|
trans.enabled = true
|
||||||
section.expanded = !section.expanded
|
section.toggleExpand()
|
||||||
} else {
|
} else {
|
||||||
section.showContextMenu()
|
section.showContextMenu()
|
||||||
}
|
}
|
||||||
@@ -135,13 +128,6 @@ Item {
|
|||||||
anchors.topMargin: section.topPadding
|
anchors.topMargin: section.topPadding
|
||||||
}
|
}
|
||||||
|
|
||||||
Behavior on implicitHeight {
|
|
||||||
NumberAnimation {
|
|
||||||
easing.type: Easing.OutCubic
|
|
||||||
duration: section.animationDuration
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "Collapsed"
|
name: "Collapsed"
|
||||||
@@ -156,4 +142,14 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
transitions: Transition {
|
||||||
|
id: trans
|
||||||
|
enabled: false
|
||||||
|
NumberAnimation {
|
||||||
|
properties: "implicitHeight,rotation";
|
||||||
|
duration: 120;
|
||||||
|
easing.type: Easing.OutCubic
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "itemlibrarycategoriesmodel.h"
|
#include "itemlibrarycategoriesmodel.h"
|
||||||
#include "itemlibrarycategory.h"
|
#include "itemlibrarycategory.h"
|
||||||
|
#include "itemlibrarymodel.h"
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -72,6 +73,24 @@ QVariant ItemLibraryCategoriesModel::data(const QModelIndex &index, int role) co
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ItemLibraryCategoriesModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
// currently only categoryExpanded property is updatable
|
||||||
|
if (index.isValid() && m_roleNames.contains(role)) {
|
||||||
|
QVariant currValue = m_categoryList.at(index.row())->property(m_roleNames.value(role));
|
||||||
|
if (currValue != value) {
|
||||||
|
m_categoryList[index.row()]->setProperty(m_roleNames.value(role), value);
|
||||||
|
if (m_roleNames.value(role) == "categoryExpanded") {
|
||||||
|
ItemLibraryModel::saveExpandedState(value.toBool(),
|
||||||
|
m_categoryList[index.row()]->categoryName());
|
||||||
|
}
|
||||||
|
emit dataChanged(index, index, {role});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> ItemLibraryCategoriesModel::roleNames() const
|
QHash<int, QByteArray> ItemLibraryCategoriesModel::roleNames() const
|
||||||
{
|
{
|
||||||
return m_roleNames;
|
return m_roleNames;
|
||||||
|
@@ -44,6 +44,7 @@ public:
|
|||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
void addCategory(ItemLibraryCategory *category);
|
void addCategory(ItemLibraryCategory *category);
|
||||||
|
@@ -37,7 +37,7 @@ class ItemLibraryCategory : public QObject
|
|||||||
|
|
||||||
Q_PROPERTY(QString categoryName READ categoryName FINAL)
|
Q_PROPERTY(QString categoryName READ categoryName FINAL)
|
||||||
Q_PROPERTY(bool categoryVisible READ isVisible NOTIFY visibilityChanged FINAL)
|
Q_PROPERTY(bool categoryVisible READ isVisible NOTIFY visibilityChanged FINAL)
|
||||||
Q_PROPERTY(bool categoryExpanded READ categoryExpanded FINAL)
|
Q_PROPERTY(bool categoryExpanded READ categoryExpanded WRITE setExpanded NOTIFY expandedChanged FINAL)
|
||||||
Q_PROPERTY(QObject *itemModel READ itemModel NOTIFY itemModelChanged FINAL)
|
Q_PROPERTY(QObject *itemModel READ itemModel NOTIFY itemModelChanged FINAL)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -62,6 +62,7 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void itemModelChanged();
|
void itemModelChanged();
|
||||||
void visibilityChanged();
|
void visibilityChanged();
|
||||||
|
void expandedChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ItemLibraryItemsModel m_itemModel;
|
ItemLibraryItemsModel m_itemModel;
|
||||||
|
@@ -28,15 +28,16 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
ItemLibraryImport::ItemLibraryImport(const Import &import, QObject *parent)
|
ItemLibraryImport::ItemLibraryImport(const Import &import, QObject *parent, bool isUserSection)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_import(import)
|
m_import(import),
|
||||||
|
m_isUserSection(isUserSection)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ItemLibraryImport::importName() const
|
QString ItemLibraryImport::importName() const
|
||||||
{
|
{
|
||||||
if (importUrl().isEmpty())
|
if (m_isUserSection)
|
||||||
return userComponentsTitle();
|
return userComponentsTitle();
|
||||||
|
|
||||||
if (importUrl() == "QtQuick")
|
if (importUrl() == "QtQuick")
|
||||||
@@ -47,6 +48,9 @@ QString ItemLibraryImport::importName() const
|
|||||||
|
|
||||||
QString ItemLibraryImport::importUrl() const
|
QString ItemLibraryImport::importUrl() const
|
||||||
{
|
{
|
||||||
|
if (m_isUserSection)
|
||||||
|
return userComponentsTitle();
|
||||||
|
|
||||||
return m_import.url();
|
return m_import.url();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +61,7 @@ bool ItemLibraryImport::importExpanded() const
|
|||||||
|
|
||||||
QString ItemLibraryImport::sortingName() const
|
QString ItemLibraryImport::sortingName() const
|
||||||
{
|
{
|
||||||
if (importName() == userComponentsTitle()) // user components always come first
|
if (m_isUserSection) // user components always come first
|
||||||
return "_";
|
return "_";
|
||||||
|
|
||||||
return importName();
|
return importName();
|
||||||
@@ -109,7 +113,7 @@ bool ItemLibraryImport::setVisible(bool isVisible)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemLibraryImport::isVisible() const
|
bool ItemLibraryImport::importVisible() const
|
||||||
{
|
{
|
||||||
return m_isVisible;
|
return m_isVisible;
|
||||||
}
|
}
|
||||||
@@ -119,17 +123,22 @@ void ItemLibraryImport::setImportUsed(bool importUsed)
|
|||||||
m_importUsed = importUsed;
|
m_importUsed = importUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemLibraryImport::isImportUsed() const
|
bool ItemLibraryImport::importUsed() const
|
||||||
{
|
{
|
||||||
return m_importUsed;
|
return m_importUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ItemLibraryImport::hasCategories() const
|
||||||
|
{
|
||||||
|
return m_categoryModel.rowCount() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ItemLibraryImport::sortCategorySections()
|
void ItemLibraryImport::sortCategorySections()
|
||||||
{
|
{
|
||||||
m_categoryModel.sortCategorySections();
|
m_categoryModel.sortCategorySections();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLibraryImport::setExpanded(bool expanded)
|
void ItemLibraryImport::setImportExpanded(bool expanded)
|
||||||
{
|
{
|
||||||
m_importExpanded = expanded;
|
m_importExpanded = expanded;
|
||||||
}
|
}
|
||||||
@@ -144,6 +153,11 @@ ItemLibraryCategory *ItemLibraryImport::getCategorySection(const QString &catego
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ItemLibraryImport::isUserSection() const
|
||||||
|
{
|
||||||
|
return m_isUserSection;
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
QString ItemLibraryImport::userComponentsTitle()
|
QString ItemLibraryImport::userComponentsTitle()
|
||||||
{
|
{
|
||||||
|
@@ -38,21 +38,22 @@ class ItemLibraryImport : public QObject
|
|||||||
|
|
||||||
Q_PROPERTY(QString importName READ importName FINAL)
|
Q_PROPERTY(QString importName READ importName FINAL)
|
||||||
Q_PROPERTY(QString importUrl READ importUrl FINAL)
|
Q_PROPERTY(QString importUrl READ importUrl FINAL)
|
||||||
Q_PROPERTY(bool importVisible READ isVisible NOTIFY visibilityChanged FINAL)
|
Q_PROPERTY(bool importVisible READ importVisible NOTIFY importVisibleChanged FINAL)
|
||||||
Q_PROPERTY(bool importUsed READ isImportUsed NOTIFY importUsedChanged FINAL)
|
Q_PROPERTY(bool importUsed READ importUsed NOTIFY importUsedChanged FINAL)
|
||||||
Q_PROPERTY(bool importExpanded READ importExpanded FINAL)
|
Q_PROPERTY(bool importExpanded READ importExpanded WRITE setImportExpanded NOTIFY importExpandChanged FINAL)
|
||||||
Q_PROPERTY(QObject *categoryModel READ categoryModel NOTIFY categoryModelChanged FINAL)
|
Q_PROPERTY(QObject *categoryModel READ categoryModel NOTIFY categoryModelChanged FINAL)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ItemLibraryImport(const Import &import, QObject *parent = nullptr);
|
ItemLibraryImport(const Import &import, QObject *parent = nullptr, bool isUserSection = false);
|
||||||
|
|
||||||
QString importName() const;
|
QString importName() const;
|
||||||
QString importUrl() const;
|
QString importUrl() const;
|
||||||
bool importExpanded() const;
|
bool importExpanded() const;
|
||||||
QString sortingName() const;
|
QString sortingName() const;
|
||||||
Import importEntry() const;
|
Import importEntry() const;
|
||||||
bool isVisible() const;
|
bool importVisible() const;
|
||||||
bool isImportUsed() const;
|
bool importUsed() const;
|
||||||
|
bool hasCategories() const;
|
||||||
ItemLibraryCategory *getCategorySection(const QString &categoryName) const;
|
ItemLibraryCategory *getCategorySection(const QString &categoryName) const;
|
||||||
|
|
||||||
void addCategory(ItemLibraryCategory *category);
|
void addCategory(ItemLibraryCategory *category);
|
||||||
@@ -61,20 +62,24 @@ public:
|
|||||||
bool setVisible(bool isVisible);
|
bool setVisible(bool isVisible);
|
||||||
void setImportUsed(bool importUsed);
|
void setImportUsed(bool importUsed);
|
||||||
void sortCategorySections();
|
void sortCategorySections();
|
||||||
void setExpanded(bool expanded);
|
void setImportExpanded(bool expanded = true);
|
||||||
|
|
||||||
static QString userComponentsTitle();
|
static QString userComponentsTitle();
|
||||||
|
|
||||||
|
bool isUserSection() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void categoryModelChanged();
|
void categoryModelChanged();
|
||||||
void visibilityChanged();
|
void importVisibleChanged();
|
||||||
void importUsedChanged();
|
void importUsedChanged();
|
||||||
|
void importExpandChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Import m_import;
|
Import m_import;
|
||||||
bool m_importExpanded = true;
|
bool m_importExpanded = true;
|
||||||
bool m_isVisible = true;
|
bool m_isVisible = true;
|
||||||
bool m_importUsed = false;
|
bool m_importUsed = false;
|
||||||
|
bool m_isUserSection = false; // user components import section
|
||||||
ItemLibraryCategoriesModel m_categoryModel;
|
ItemLibraryCategoriesModel m_categoryModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -47,15 +47,48 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
// sectionName can be an import or category section
|
// sectionName can be an import url or a category name
|
||||||
void ItemLibraryModel::setExpanded(bool expanded, const QString §ionName)
|
void ItemLibraryModel::saveExpandedState(bool expanded, const QString §ionName)
|
||||||
{
|
{
|
||||||
collapsedStateHash.insert(sectionName, expanded);
|
expandedStateHash.insert(sectionName, expanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemLibraryModel::sectionExpanded(const QString §ionName) const
|
bool ItemLibraryModel::loadExpandedState(const QString §ionName)
|
||||||
{
|
{
|
||||||
return collapsedStateHash.value(sectionName, true);
|
return expandedStateHash.value(sectionName, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemLibraryModel::expandAll()
|
||||||
|
{
|
||||||
|
bool changed = false;
|
||||||
|
for (const QPointer<ItemLibraryImport> &import : std::as_const(m_importList)) {
|
||||||
|
if (import->hasCategories() && !import->importExpanded()) {
|
||||||
|
changed = true;
|
||||||
|
import->setImportExpanded();
|
||||||
|
saveExpandedState(true, import->importUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
beginResetModel();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemLibraryModel::collapseAll()
|
||||||
|
{
|
||||||
|
bool changed = false;
|
||||||
|
for (const QPointer<ItemLibraryImport> &import : std::as_const(m_importList)) {
|
||||||
|
if (import->hasCategories() && import->importExpanded()) {
|
||||||
|
changed = true;
|
||||||
|
import->setImportExpanded(false);
|
||||||
|
saveExpandedState(false, import->importUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
beginResetModel();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLibraryModel::setFlowMode(bool b)
|
void ItemLibraryModel::setFlowMode(bool b)
|
||||||
@@ -83,7 +116,7 @@ int ItemLibraryModel::rowCount(const QModelIndex & /*parent*/) const
|
|||||||
|
|
||||||
QVariant ItemLibraryModel::data(const QModelIndex &index, int role) const
|
QVariant ItemLibraryModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() +1 > m_importList.count())
|
if (!index.isValid() || index.row() >= m_importList.count())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (m_roleNames.contains(role)) {
|
if (m_roleNames.contains(role)) {
|
||||||
@@ -101,6 +134,22 @@ QVariant ItemLibraryModel::data(const QModelIndex &index, int role) const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ItemLibraryModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
// currently only importExpanded property is updatable
|
||||||
|
if (index.isValid() && m_roleNames.contains(role)) {
|
||||||
|
QVariant currValue = m_importList.at(index.row())->property(m_roleNames.value(role));
|
||||||
|
if (currValue != value) {
|
||||||
|
m_importList[index.row()]->setProperty(m_roleNames.value(role), value);
|
||||||
|
if (m_roleNames.value(role) == "importExpanded")
|
||||||
|
saveExpandedState(value.toBool(), m_importList[index.row()]->importUrl());
|
||||||
|
emit dataChanged(index, index, {role});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> ItemLibraryModel::roleNames() const
|
QHash<int, QByteArray> ItemLibraryModel::roleNames() const
|
||||||
{
|
{
|
||||||
return m_roleNames;
|
return m_roleNames;
|
||||||
@@ -146,7 +195,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
|||||||
if (import.isLibraryImport()) {
|
if (import.isLibraryImport()) {
|
||||||
ItemLibraryImport *itemLibImport = new ItemLibraryImport(import, this);
|
ItemLibraryImport *itemLibImport = new ItemLibraryImport(import, this);
|
||||||
m_importList.append(itemLibImport);
|
m_importList.append(itemLibImport);
|
||||||
itemLibImport->setExpanded(sectionExpanded(import.url()));
|
itemLibImport->setImportExpanded(loadExpandedState(import.url()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,9 +233,9 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
|||||||
// create an import section for user components
|
// create an import section for user components
|
||||||
importSection = importByUrl(ItemLibraryImport::userComponentsTitle());
|
importSection = importByUrl(ItemLibraryImport::userComponentsTitle());
|
||||||
if (!importSection) {
|
if (!importSection) {
|
||||||
importSection = new ItemLibraryImport({}, this);
|
importSection = new ItemLibraryImport({}, this, true);
|
||||||
m_importList.append(importSection);
|
m_importList.append(importSection);
|
||||||
importSection->setExpanded(sectionExpanded(catName));
|
importSection->setImportExpanded(loadExpandedState(catName));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (catName.startsWith("Qt Quick - "))
|
if (catName.startsWith("Qt Quick - "))
|
||||||
@@ -205,7 +254,8 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
|||||||
if (!categorySection) {
|
if (!categorySection) {
|
||||||
categorySection = new ItemLibraryCategory(catName, importSection);
|
categorySection = new ItemLibraryCategory(catName, importSection);
|
||||||
importSection->addCategory(categorySection);
|
importSection->addCategory(categorySection);
|
||||||
categorySection->setExpanded(sectionExpanded(categorySection->categoryName()));
|
if (!importSection->isUserSection())
|
||||||
|
categorySection->setExpanded(loadExpandedState(categorySection->categoryName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// create item
|
// create item
|
||||||
@@ -251,7 +301,7 @@ ItemLibraryImport *ItemLibraryModel::importByUrl(const QString &importUrl) const
|
|||||||
if (itemLibraryImport->importUrl() == importUrl
|
if (itemLibraryImport->importUrl() == importUrl
|
||||||
|| (importUrl.isEmpty() && itemLibraryImport->importUrl() == "QtQuick")
|
|| (importUrl.isEmpty() && itemLibraryImport->importUrl() == "QtQuick")
|
||||||
|| (importUrl == ItemLibraryImport::userComponentsTitle()
|
|| (importUrl == ItemLibraryImport::userComponentsTitle()
|
||||||
&& itemLibraryImport->importName() == ItemLibraryImport::userComponentsTitle())) {
|
&& itemLibraryImport->isUserSection())) {
|
||||||
return itemLibraryImport;
|
return itemLibraryImport;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -48,6 +48,7 @@ public:
|
|||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
QString searchText() const;
|
QString searchText() const;
|
||||||
@@ -62,15 +63,17 @@ public:
|
|||||||
void setFlowMode(bool);
|
void setFlowMode(bool);
|
||||||
|
|
||||||
static void registerQmlTypes();
|
static void registerQmlTypes();
|
||||||
|
static void saveExpandedState(bool expanded, const QString §ionName);
|
||||||
|
static bool loadExpandedState(const QString §ionName);
|
||||||
|
|
||||||
Q_INVOKABLE void setExpanded(bool, const QString §ion);
|
Q_INVOKABLE void expandAll();
|
||||||
|
Q_INVOKABLE void collapseAll();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateVisibility(bool *changed);
|
void updateVisibility(bool *changed);
|
||||||
void addRoleNames();
|
void addRoleNames();
|
||||||
void sortSections();
|
void sortSections();
|
||||||
void clearSections();
|
void clearSections();
|
||||||
bool sectionExpanded(const QString §ionName) const;
|
|
||||||
|
|
||||||
QList<QPointer<ItemLibraryImport>> m_importList;
|
QList<QPointer<ItemLibraryImport>> m_importList;
|
||||||
QHash<int, QByteArray> m_roleNames;
|
QHash<int, QByteArray> m_roleNames;
|
||||||
@@ -78,7 +81,7 @@ private:
|
|||||||
QString m_searchText;
|
QString m_searchText;
|
||||||
bool m_flowMode = false;
|
bool m_flowMode = false;
|
||||||
|
|
||||||
QHash<QString, bool> collapsedStateHash;
|
inline static QHash<QString, bool> expandedStateHash;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -117,8 +117,8 @@ ItemLibraryWidget::ItemLibraryWidget(AsynchronousImageCache &imageCache,
|
|||||||
SLOT(handleTabChanged(int)));
|
SLOT(handleTabChanged(int)));
|
||||||
QObject::connect(m_headerWidget->rootObject(), SIGNAL(filterChanged(QString)), this,
|
QObject::connect(m_headerWidget->rootObject(), SIGNAL(filterChanged(QString)), this,
|
||||||
SLOT(handleFilterChanged(QString)));
|
SLOT(handleFilterChanged(QString)));
|
||||||
QObject::connect(m_headerWidget->rootObject(), SIGNAL(addLibraryClicked()), this,
|
QObject::connect(m_headerWidget->rootObject(), SIGNAL(addModuleClicked()), this,
|
||||||
SLOT(handleAddLibrary()));
|
SLOT(handleAddModule()));
|
||||||
QObject::connect(m_headerWidget->rootObject(), SIGNAL(addAssetClicked()), this,
|
QObject::connect(m_headerWidget->rootObject(), SIGNAL(addAssetClicked()), this,
|
||||||
SLOT(handleAddAsset()));
|
SLOT(handleAddAsset()));
|
||||||
|
|
||||||
@@ -245,7 +245,7 @@ void ItemLibraryWidget::handleFilterChanged(const QString &filterText)
|
|||||||
updateSearch();
|
updateSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLibraryWidget::handleAddLibrary()
|
void ItemLibraryWidget::handleAddModule()
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(m_headerWidget->rootObject(), "setTab", Q_ARG(QVariant, 0));
|
QMetaObject::invokeMethod(m_headerWidget->rootObject(), "setTab", Q_ARG(QVariant, 0));
|
||||||
handleTabChanged(2);
|
handleTabChanged(2);
|
||||||
@@ -267,7 +267,7 @@ void ItemLibraryWidget::handleAddImport(int index)
|
|||||||
|
|
||||||
m_model->changeImports({import}, {});
|
m_model->changeImports({import}, {});
|
||||||
QmlDesignerPlugin::instance()->currentDesignDocument()->updateSubcomponentManager();
|
QmlDesignerPlugin::instance()->currentDesignDocument()->updateSubcomponentManager();
|
||||||
m_stackedWidget->setCurrentIndex(0); // switch to the Components Library after import is added
|
m_stackedWidget->setCurrentIndex(0); // switch to the Components view after import is added
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLibraryWidget::delayedUpdateModel()
|
void ItemLibraryWidget::delayedUpdateModel()
|
||||||
|
@@ -130,7 +130,7 @@ private:
|
|||||||
private slots:
|
private slots:
|
||||||
void handleTabChanged(int index);
|
void handleTabChanged(int index);
|
||||||
void handleFilterChanged(const QString &filterText);
|
void handleFilterChanged(const QString &filterText);
|
||||||
void handleAddLibrary();
|
void handleAddModule();
|
||||||
void handleAddAsset();
|
void handleAddAsset();
|
||||||
void handleAddImport(int index);
|
void handleAddImport(int index);
|
||||||
};
|
};
|
||||||
|
@@ -34,7 +34,7 @@ Column {
|
|||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: header
|
id: header
|
||||||
text: qsTr("Select a Library to add")
|
text: qsTr("Select a Module to Add")
|
||||||
color: "#ffffff"
|
color: "#ffffff"
|
||||||
font.pixelSize: 16
|
font.pixelSize: 16
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
@@ -34,7 +34,7 @@ Item {
|
|||||||
|
|
||||||
signal tabChanged(int index)
|
signal tabChanged(int index)
|
||||||
signal filterChanged(string filterText)
|
signal filterChanged(string filterText)
|
||||||
signal addLibraryClicked()
|
signal addModuleClicked()
|
||||||
signal addAssetClicked()
|
signal addAssetClicked()
|
||||||
|
|
||||||
function setTab(index)
|
function setTab(index)
|
||||||
@@ -65,7 +65,7 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: [{title: qsTr("Components"), addToolTip: qsTr("Add Library")},
|
model: [{title: qsTr("Components"), addToolTip: qsTr("Add Module")},
|
||||||
{title: qsTr("Assets"), addToolTip: qsTr("Add new assets to project.")}]
|
{title: qsTr("Assets"), addToolTip: qsTr("Add new assets to project.")}]
|
||||||
|
|
||||||
TabButton {
|
TabButton {
|
||||||
@@ -105,7 +105,7 @@ Item {
|
|||||||
id: mouseArea
|
id: mouseArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onClicked: index == 0 ? addLibraryClicked() : addAssetClicked()
|
onClicked: index == 0 ? addModuleClicked() : addAssetClicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user