forked from qt-creator/qt-creator
QmlDesigner: Add option in navigator to show only visible items
At the moment we show everything in default properties including non visible items. This is a bad default. Instead we provide an option if only visible items or all objects are shown in the navigator. Change-Id: I65b58d949136bcce4b06f1f47f56fb0f210fed5c Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -43,6 +43,8 @@ public:
|
|||||||
virtual void notifyModelNodesRemoved(const QList<ModelNode> &modelNodes) = 0;
|
virtual void notifyModelNodesRemoved(const QList<ModelNode> &modelNodes) = 0;
|
||||||
virtual void notifyModelNodesInserted(const QList<ModelNode> &modelNodes) = 0;
|
virtual void notifyModelNodesInserted(const QList<ModelNode> &modelNodes) = 0;
|
||||||
virtual void notifyModelNodesMoved(const QList<ModelNode> &modelNodes) = 0;
|
virtual void notifyModelNodesMoved(const QList<ModelNode> &modelNodes) = 0;
|
||||||
|
virtual void setFilter(bool showObjects) = 0;
|
||||||
|
virtual void resetModel() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //QmlDesigner
|
} //QmlDesigner
|
||||||
|
@@ -246,6 +246,16 @@ Qt::ItemFlags NavigatorTreeModel::flags(const QModelIndex &index) const
|
|||||||
| Qt::ItemNeverHasChildren;
|
| Qt::ItemNeverHasChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ModelNode> filteredList(const NodeListProperty &property, bool filter)
|
||||||
|
{
|
||||||
|
if (!filter)
|
||||||
|
return property.toModelNodeList();
|
||||||
|
|
||||||
|
return Utils::filtered(property.toModelNodeList(), [] (const ModelNode &arg) {
|
||||||
|
return QmlItemNode::isValidQmlItemNode(arg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex NavigatorTreeModel::index(int row, int column,
|
QModelIndex NavigatorTreeModel::index(int row, int column,
|
||||||
const QModelIndex &parent) const
|
const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
@@ -262,7 +272,7 @@ QModelIndex NavigatorTreeModel::index(int row, int column,
|
|||||||
|
|
||||||
ModelNode modelNode;
|
ModelNode modelNode;
|
||||||
if (parentModelNode.defaultNodeListProperty().isValid())
|
if (parentModelNode.defaultNodeListProperty().isValid())
|
||||||
modelNode = parentModelNode.defaultNodeListProperty().at(row);
|
modelNode = filteredList(parentModelNode.defaultNodeListProperty(), m_showOnlyVisibleItems).at(row);
|
||||||
|
|
||||||
if (!modelNode.isValid())
|
if (!modelNode.isValid())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
@@ -293,7 +303,7 @@ QModelIndex NavigatorTreeModel::parent(const QModelIndex &index) const
|
|||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
||||||
if (!parentModelNode.isRootNode() && parentModelNode.parentProperty().isNodeListProperty())
|
if (!parentModelNode.isRootNode() && parentModelNode.parentProperty().isNodeListProperty())
|
||||||
row = parentModelNode.parentProperty().toNodeListProperty().indexOf(parentModelNode);
|
row = filteredList(parentModelNode.parentProperty().toNodeListProperty(), m_showOnlyVisibleItems).indexOf(parentModelNode);
|
||||||
|
|
||||||
return createIndexFromModelNode(row, 0, parentModelNode);
|
return createIndexFromModelNode(row, 0, parentModelNode);
|
||||||
}
|
}
|
||||||
@@ -313,7 +323,7 @@ int NavigatorTreeModel::rowCount(const QModelIndex &parent) const
|
|||||||
int rows = 0;
|
int rows = 0;
|
||||||
|
|
||||||
if (modelNode.defaultNodeListProperty().isValid())
|
if (modelNode.defaultNodeListProperty().isValid())
|
||||||
rows = modelNode.defaultNodeListProperty().count();
|
rows = filteredList(modelNode.defaultNodeListProperty(), m_showOnlyVisibleItems).count();
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
@@ -628,4 +638,17 @@ void NavigatorTreeModel::notifyModelNodesMoved(const QList<ModelNode> &modelNode
|
|||||||
layoutChanged(indexes);
|
layoutChanged(indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NavigatorTreeModel::setFilter(bool showOnlyVisibleItems)
|
||||||
|
{
|
||||||
|
m_showOnlyVisibleItems = showOnlyVisibleItems;
|
||||||
|
resetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigatorTreeModel::resetModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
m_nodeIndexHash.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
} // QmlDesigner
|
} // QmlDesigner
|
||||||
|
@@ -87,6 +87,8 @@ public:
|
|||||||
void notifyModelNodesRemoved(const QList<ModelNode> &modelNodes) override;
|
void notifyModelNodesRemoved(const QList<ModelNode> &modelNodes) override;
|
||||||
void notifyModelNodesInserted(const QList<ModelNode> &modelNodes) override;
|
void notifyModelNodesInserted(const QList<ModelNode> &modelNodes) override;
|
||||||
void notifyModelNodesMoved(const QList<ModelNode> &modelNodes) override;
|
void notifyModelNodesMoved(const QList<ModelNode> &modelNodes) override;
|
||||||
|
void setFilter(bool showOnlyVisibleItems) override;
|
||||||
|
void resetModel() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void moveNodesInteractive(NodeAbstractProperty &parentProperty, const QList<ModelNode> &modelNodes, int targetIndex);
|
void moveNodesInteractive(NodeAbstractProperty &parentProperty, const QList<ModelNode> &modelNodes, int targetIndex);
|
||||||
@@ -97,6 +99,7 @@ private:
|
|||||||
|
|
||||||
QPointer<NavigatorView> m_view;
|
QPointer<NavigatorView> m_view;
|
||||||
mutable QHash<ModelNode, QModelIndex> m_nodeIndexHash;
|
mutable QHash<ModelNode, QModelIndex> m_nodeIndexHash;
|
||||||
|
bool m_showOnlyVisibleItems = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <bindingproperty.h>
|
#include <bindingproperty.h>
|
||||||
#include <designmodecontext.h>
|
#include <designmodecontext.h>
|
||||||
|
#include <designersettings.h>
|
||||||
#include <nodeproperty.h>
|
#include <nodeproperty.h>
|
||||||
#include <nodelistproperty.h>
|
#include <nodelistproperty.h>
|
||||||
#include <variantproperty.h>
|
#include <variantproperty.h>
|
||||||
@@ -88,6 +89,7 @@ NavigatorView::NavigatorView(QObject* parent) :
|
|||||||
connect(m_widget.data(), &NavigatorWidget::rightButtonClicked, this, &NavigatorView::rightButtonClicked);
|
connect(m_widget.data(), &NavigatorWidget::rightButtonClicked, this, &NavigatorView::rightButtonClicked);
|
||||||
connect(m_widget.data(), &NavigatorWidget::downButtonClicked, this, &NavigatorView::downButtonClicked);
|
connect(m_widget.data(), &NavigatorWidget::downButtonClicked, this, &NavigatorView::downButtonClicked);
|
||||||
connect(m_widget.data(), &NavigatorWidget::upButtonClicked, this, &NavigatorView::upButtonClicked);
|
connect(m_widget.data(), &NavigatorWidget::upButtonClicked, this, &NavigatorView::upButtonClicked);
|
||||||
|
connect(m_widget.data(), &NavigatorWidget::filterToggled, this, &NavigatorView::filterToggled);
|
||||||
|
|
||||||
#ifndef QMLDESIGNER_TEST
|
#ifndef QMLDESIGNER_TEST
|
||||||
NameItemDelegate *idDelegate = new NameItemDelegate(this);
|
NameItemDelegate *idDelegate = new NameItemDelegate(this);
|
||||||
@@ -145,6 +147,9 @@ void NavigatorView::modelAttached(Model *model)
|
|||||||
{
|
{
|
||||||
AbstractView::modelAttached(model);
|
AbstractView::modelAttached(model);
|
||||||
|
|
||||||
|
m_currentModelInterface->setFilter(
|
||||||
|
DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS).toBool());
|
||||||
|
|
||||||
QTreeView *treeView = treeWidget();
|
QTreeView *treeView = treeWidget();
|
||||||
treeView->expandAll();
|
treeView->expandAll();
|
||||||
|
|
||||||
@@ -400,6 +405,13 @@ void NavigatorView::downButtonClicked()
|
|||||||
blockSelectionChangedSignal(blocked);
|
blockSelectionChangedSignal(blocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NavigatorView::filterToggled(bool flag)
|
||||||
|
{
|
||||||
|
m_currentModelInterface->setFilter(flag);
|
||||||
|
treeWidget()->expandAll();
|
||||||
|
DesignerSettings::setValue(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS, flag);
|
||||||
|
}
|
||||||
|
|
||||||
void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, const QItemSelection &/*deselected*/)
|
void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, const QItemSelection &/*deselected*/)
|
||||||
{
|
{
|
||||||
if (m_blockSelectionChangedSignal)
|
if (m_blockSelectionChangedSignal)
|
||||||
|
@@ -99,6 +99,7 @@ private:
|
|||||||
void rightButtonClicked();
|
void rightButtonClicked();
|
||||||
void upButtonClicked();
|
void upButtonClicked();
|
||||||
void downButtonClicked();
|
void downButtonClicked();
|
||||||
|
void filterToggled(bool);
|
||||||
|
|
||||||
protected: //functions
|
protected: //functions
|
||||||
QTreeView *treeWidget() const;
|
QTreeView *treeWidget() const;
|
||||||
|
@@ -27,14 +27,17 @@
|
|||||||
#include "navigatorview.h"
|
#include "navigatorview.h"
|
||||||
#include "qmldesignerconstants.h"
|
#include "qmldesignerconstants.h"
|
||||||
#include "qmldesignericons.h"
|
#include "qmldesignericons.h"
|
||||||
|
#include <designersettings.h>
|
||||||
#include <theme.h>
|
#include <theme.h>
|
||||||
|
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QMenu>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -80,29 +83,49 @@ QList<QToolButton *> NavigatorWidget::createToolBarWidgets()
|
|||||||
{
|
{
|
||||||
QList<QToolButton *> buttons;
|
QList<QToolButton *> buttons;
|
||||||
|
|
||||||
buttons.append(new QToolButton());
|
|
||||||
buttons.last()->setIcon(Icons::ARROW_LEFT.icon());
|
|
||||||
buttons.last()->setToolTip(tr("Become last sibling of parent (CTRL + Left)."));
|
|
||||||
buttons.last()->setShortcut(QKeySequence(Qt::Key_Left | Qt::CTRL));
|
|
||||||
connect(buttons.last(), &QAbstractButton::clicked, this, &NavigatorWidget::leftButtonClicked);
|
|
||||||
|
|
||||||
buttons.append(new QToolButton());
|
auto button = new QToolButton();
|
||||||
buttons.last()->setIcon(Icons::ARROW_RIGHT.icon());
|
button->setIcon(Icons::ARROW_LEFT.icon());
|
||||||
buttons.last()->setToolTip(tr("Become child of last sibling (CTRL + Right)."));
|
button->setToolTip(tr("Become last sibling of parent (CTRL + Left)."));
|
||||||
buttons.last()->setShortcut(QKeySequence(Qt::Key_Right | Qt::CTRL));
|
button->setShortcut(QKeySequence(Qt::Key_Left | Qt::CTRL));
|
||||||
connect(buttons.last(), &QAbstractButton::clicked, this, &NavigatorWidget::rightButtonClicked);
|
connect(button, &QAbstractButton::clicked, this, &NavigatorWidget::leftButtonClicked);
|
||||||
|
buttons.append(button);
|
||||||
|
|
||||||
buttons.append(new QToolButton());
|
button = new QToolButton();
|
||||||
buttons.last()->setIcon(Icons::ARROW_DOWN.icon());
|
button->setIcon(Icons::ARROW_RIGHT.icon());
|
||||||
buttons.last()->setToolTip(tr("Move down (CTRL + Down)."));
|
button->setToolTip(tr("Become child of last sibling (CTRL + Right)."));
|
||||||
buttons.last()->setShortcut(QKeySequence(Qt::Key_Down | Qt::CTRL));
|
button->setShortcut(QKeySequence(Qt::Key_Right | Qt::CTRL));
|
||||||
connect(buttons.last(), &QAbstractButton::clicked, this, &NavigatorWidget::downButtonClicked);
|
connect(button, &QAbstractButton::clicked, this, &NavigatorWidget::rightButtonClicked);
|
||||||
|
buttons.append(button);
|
||||||
|
|
||||||
buttons.append(new QToolButton());
|
button = new QToolButton();
|
||||||
buttons.last()->setIcon(Icons::ARROW_UP.icon());
|
button->setIcon(Icons::ARROW_DOWN.icon());
|
||||||
buttons.last()->setToolTip(tr("Move up (CTRL + Up)."));
|
button->setToolTip(tr("Move down (CTRL + Down)."));
|
||||||
buttons.last()->setShortcut(QKeySequence(Qt::Key_Up | Qt::CTRL));
|
button->setShortcut(QKeySequence(Qt::Key_Down | Qt::CTRL));
|
||||||
connect(buttons.last(), &QAbstractButton::clicked, this, &NavigatorWidget::upButtonClicked);
|
connect(button, &QAbstractButton::clicked, this, &NavigatorWidget::downButtonClicked);
|
||||||
|
buttons.append(button);
|
||||||
|
|
||||||
|
button = new QToolButton();
|
||||||
|
button->setIcon(Icons::ARROW_UP.icon());
|
||||||
|
button->setToolTip(tr("Move up (CTRL + Up)."));
|
||||||
|
button->setShortcut(QKeySequence(Qt::Key_Up | Qt::CTRL));
|
||||||
|
connect(button, &QAbstractButton::clicked, this, &NavigatorWidget::upButtonClicked);
|
||||||
|
buttons.append(button);
|
||||||
|
|
||||||
|
auto filter = new QToolButton;
|
||||||
|
filter->setIcon(Utils::Icons::FILTER.icon());
|
||||||
|
filter->setToolTip(tr("Filter Tree"));
|
||||||
|
filter->setPopupMode(QToolButton::InstantPopup);
|
||||||
|
filter->setProperty("noArrow", true);
|
||||||
|
auto filterMenu = new QMenu(filter);
|
||||||
|
auto objectAction = new QAction(tr("Show only visible itmes."));
|
||||||
|
objectAction->setCheckable(true);
|
||||||
|
objectAction->setChecked(
|
||||||
|
DesignerSettings::getValue(DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS).toBool());
|
||||||
|
connect(objectAction, &QAction::toggled, this, &NavigatorWidget::filterToggled);
|
||||||
|
filterMenu->addAction(objectAction);
|
||||||
|
filter->setMenu(filterMenu);
|
||||||
|
buttons.append(filter);
|
||||||
|
|
||||||
return buttons;
|
return buttons;
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,7 @@ signals:
|
|||||||
void rightButtonClicked();
|
void rightButtonClicked();
|
||||||
void upButtonClicked();
|
void upButtonClicked();
|
||||||
void downButtonClicked();
|
void downButtonClicked();
|
||||||
|
void filterToggled(bool);
|
||||||
|
|
||||||
private: // functions
|
private: // functions
|
||||||
NavigatorView *navigatorView() const;
|
NavigatorView *navigatorView() const;
|
||||||
|
@@ -74,6 +74,7 @@ void DesignerSettings::fromSettings(QSettings *settings)
|
|||||||
restoreValue(settings, DesignerSettingsKey::FORWARD_PUPPET_OUTPUT, QString());
|
restoreValue(settings, DesignerSettingsKey::FORWARD_PUPPET_OUTPUT, QString());
|
||||||
restoreValue(settings, DesignerSettingsKey::REFORMAT_UI_QML_FILES, true);
|
restoreValue(settings, DesignerSettingsKey::REFORMAT_UI_QML_FILES, true);
|
||||||
restoreValue(settings, DesignerSettingsKey::IGNORE_DEVICE_PIXEL_RATIO, false);
|
restoreValue(settings, DesignerSettingsKey::IGNORE_DEVICE_PIXEL_RATIO, false);
|
||||||
|
restoreValue(settings, DesignerSettingsKey::NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS, true);
|
||||||
|
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
|
@@ -60,6 +60,7 @@ const char PUPPET_KILL_TIMEOUT[] = "PuppetKillTimeout";
|
|||||||
const char DEBUG_PUPPET[] = "DebugPuppet";
|
const char DEBUG_PUPPET[] = "DebugPuppet";
|
||||||
const char FORWARD_PUPPET_OUTPUT[] = "ForwardPuppetOutput";
|
const char FORWARD_PUPPET_OUTPUT[] = "ForwardPuppetOutput";
|
||||||
const char STATESEDITOR_EXPANDED[] = "StatesEditorExpanded";
|
const char STATESEDITOR_EXPANDED[] = "StatesEditorExpanded";
|
||||||
|
const char NAVIGATOR_SHOW_ONLY_VISIBLE_ITEMS[] = "NavigatorShowOnlyVisibleItems";
|
||||||
const char REFORMAT_UI_QML_FILES[] = "ReformatUiQmlFiles"; /* These settings are not exposed in ui. */
|
const char REFORMAT_UI_QML_FILES[] = "ReformatUiQmlFiles"; /* These settings are not exposed in ui. */
|
||||||
const char IGNORE_DEVICE_PIXEL_RATIO[] = "IgnoreDevicePixelRaio"; /* The settings can be used to turn off the feature, if there are serious issues */
|
const char IGNORE_DEVICE_PIXEL_RATIO[] = "IgnoreDevicePixelRaio"; /* The settings can be used to turn off the feature, if there are serious issues */
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user