forked from qt-creator/qt-creator
QmlDesigner: Fix crumble bar for infile components
CrumbleBarInfo contains the ModelNode to properly identify the node. We cannot use the id, because no every component has an id. If the crumble bar only contains one item it is hidden. Change-Id: I4d421eaad8962aa9043567e1f27957b1aa089766 Reviewed-by: Marco Bubke <marco.bubke@digia.com>
This commit is contained in:
@@ -31,11 +31,43 @@
|
||||
|
||||
#include "qmldesignerplugin.h"
|
||||
|
||||
#include <nodeabstractproperty.h>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QtDebug>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
static DesignDocument *currentDesignDocument()
|
||||
{
|
||||
return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument();
|
||||
}
|
||||
|
||||
static inline QString componentIdForModelNode(const ModelNode &modelNode)
|
||||
{
|
||||
if (modelNode.id().isEmpty()) {
|
||||
if (modelNode.hasParentProperty()
|
||||
&& modelNode.parentProperty().name() != "data"
|
||||
&& modelNode.parentProperty().name() != "children") {
|
||||
return modelNode.parentProperty().name();
|
||||
} else {
|
||||
return modelNode.simplifiedTypeName();
|
||||
}
|
||||
} else {
|
||||
return modelNode.id();
|
||||
}
|
||||
}
|
||||
|
||||
static CrumbleBarInfo createCrumbleBarInfoFromModelNode(const ModelNode &modelNode)
|
||||
{
|
||||
CrumbleBarInfo crumbleBarInfo;
|
||||
crumbleBarInfo.componentId = componentIdForModelNode(modelNode);
|
||||
crumbleBarInfo.fileName = currentDesignDocument()->textEditor()->document()->filePath();
|
||||
crumbleBarInfo.modelNode = modelNode;
|
||||
|
||||
return crumbleBarInfo;
|
||||
}
|
||||
|
||||
CrumbleBar::CrumbleBar(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_isInternalCalled(false),
|
||||
@@ -45,6 +77,8 @@ CrumbleBar::CrumbleBar(QObject *parent) :
|
||||
SIGNAL(elementClicked(QVariant)),
|
||||
this,
|
||||
SLOT(onCrumblePathElementClicked(QVariant)));
|
||||
|
||||
updateVisibility();
|
||||
}
|
||||
|
||||
void CrumbleBar::pushFile(const QString &fileName)
|
||||
@@ -65,27 +99,24 @@ void CrumbleBar::pushFile(const QString &fileName)
|
||||
crumblePath()->pushElement(fileName.split("/").last(), QVariant::fromValue(crumbleBarInfo));
|
||||
|
||||
m_isInternalCalled = false;
|
||||
|
||||
updateVisibility();
|
||||
}
|
||||
|
||||
static DesignDocument *currentDesignDocument()
|
||||
void CrumbleBar::pushInFileComponent(const ModelNode &modelNode)
|
||||
{
|
||||
return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument();
|
||||
}
|
||||
|
||||
void CrumbleBar::pushInFileComponent(const QString &componentId)
|
||||
{
|
||||
CrumbleBarInfo crumbleBarInfo;
|
||||
crumbleBarInfo.componentId = componentId;
|
||||
crumbleBarInfo.fileName = currentDesignDocument()->textEditor()->document()->filePath();
|
||||
|
||||
CrumbleBarInfo crumbleBarInfo = createCrumbleBarInfoFromModelNode(modelNode);
|
||||
CrumbleBarInfo lastElementCrumbleBarInfo = crumblePath()->dataForLastIndex().value<CrumbleBarInfo>();
|
||||
|
||||
if (!lastElementCrumbleBarInfo.componentId.isEmpty())
|
||||
crumblePath()->popElement();
|
||||
|
||||
crumblePath()->pushElement(componentId, QVariant::fromValue(crumbleBarInfo));
|
||||
crumblePath()->pushElement(crumbleBarInfo.componentId, QVariant::fromValue(crumbleBarInfo));
|
||||
|
||||
m_isInternalCalled = false;
|
||||
|
||||
updateVisibility();
|
||||
}
|
||||
|
||||
void CrumbleBar::nextFileIsCalledInternally()
|
||||
@@ -111,7 +142,6 @@ void CrumbleBar::onCrumblePathElementClicked(const QVariant &data)
|
||||
if (!crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().componentId.isEmpty())
|
||||
crumblePath()->popElement();
|
||||
|
||||
|
||||
m_isInternalCalled = true;
|
||||
if (clickedCrumbleBarInfo.componentId.isEmpty()
|
||||
&& clickedCrumbleBarInfo.fileName == currentDesignDocument()->fileName()) {
|
||||
@@ -125,9 +155,15 @@ void CrumbleBar::onCrumblePathElementClicked(const QVariant &data)
|
||||
if (!clickedCrumbleBarInfo.componentId.isEmpty()) {
|
||||
currentDesignDocument()->changeToSubComponent(
|
||||
currentDesignDocument()->rewriterView()->modelNodeForId(clickedCrumbleBarInfo.componentId));
|
||||
pushInFileComponent(clickedCrumbleBarInfo.componentId);
|
||||
//pushInFileComponent(clickedCrumbleBarInfo.componentId);
|
||||
}
|
||||
}
|
||||
updateVisibility();
|
||||
}
|
||||
|
||||
void CrumbleBar::updateVisibility()
|
||||
{
|
||||
crumblePath()->setVisible(crumblePath()->length() > 1);
|
||||
}
|
||||
|
||||
bool operator ==(const CrumbleBarInfo &first, const CrumbleBarInfo &second)
|
||||
|
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <utils/crumblepath.h>
|
||||
#include <modelnode.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -42,7 +43,7 @@ public:
|
||||
explicit CrumbleBar(QObject *parent = 0);
|
||||
|
||||
void pushFile(const QString &fileName);
|
||||
void pushInFileComponent(const QString &componentId);
|
||||
void pushInFileComponent(const ModelNode &modelNode);
|
||||
|
||||
void nextFileIsCalledInternally();
|
||||
|
||||
@@ -51,6 +52,9 @@ public:
|
||||
private slots:
|
||||
void onCrumblePathElementClicked(const QVariant &data);
|
||||
|
||||
private:
|
||||
void updateVisibility();
|
||||
|
||||
private:
|
||||
bool m_isInternalCalled;
|
||||
Utils::CrumblePath *m_crumblePath;
|
||||
@@ -60,6 +64,7 @@ class CrumbleBarInfo {
|
||||
public:
|
||||
QString fileName;
|
||||
QString componentId;
|
||||
ModelNode modelNode;
|
||||
};
|
||||
|
||||
bool operator ==(const CrumbleBarInfo &first, const CrumbleBarInfo &second);
|
||||
|
@@ -285,18 +285,11 @@ void DesignDocument::changeToInFileComponentModel(ComponentTextModifier *textMod
|
||||
viewManager().attachViewsExceptRewriterAndComponetView();
|
||||
}
|
||||
|
||||
void DesignDocument::changeToSubComponentAndPushOnCrumblePath(const ModelNode &componentNode)
|
||||
void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
||||
{
|
||||
if (QmlDesignerPlugin::instance()->currentDesignDocument() != this)
|
||||
return;
|
||||
|
||||
changeToSubComponent(componentNode);
|
||||
|
||||
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrambleBar(componentNode.id());
|
||||
}
|
||||
|
||||
void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
||||
{
|
||||
if (m_inFileComponentModel)
|
||||
changeToDocumentModel();
|
||||
|
||||
@@ -304,6 +297,8 @@ void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
||||
|
||||
if (subComponentLoaded)
|
||||
attachRewriterToModel();
|
||||
|
||||
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrumbleBar(componentNode);
|
||||
}
|
||||
|
||||
void DesignDocument::attachRewriterToModel()
|
||||
|
@@ -117,7 +117,6 @@ public slots:
|
||||
void undo();
|
||||
void redo();
|
||||
void updateActiveQtVersion();
|
||||
void changeToSubComponentAndPushOnCrumblePath(const ModelNode &componentNode);
|
||||
void changeToSubComponent(const ModelNode &componentNode);
|
||||
|
||||
private slots:
|
||||
|
@@ -81,8 +81,7 @@ public:
|
||||
void enableWidgets();
|
||||
|
||||
void pushFileOnCrumbleBar(const QString &fileName);
|
||||
void pushInFileComponentOnCrambleBar(const QString &componentId);
|
||||
|
||||
void pushInFileComponentOnCrumbleBar(const ModelNode &modelNode);
|
||||
void nextFileIsCalledInternally();
|
||||
|
||||
NodeInstanceView *nodeInstanceView();
|
||||
|
@@ -213,10 +213,9 @@ void ViewManager::pushFileOnCrumbleBar(const QString &fileName)
|
||||
crumbleBar()->pushFile(fileName);
|
||||
}
|
||||
|
||||
void ViewManager::pushInFileComponentOnCrambleBar(const QString &componentId)
|
||||
|
||||
void ViewManager::pushInFileComponentOnCrumbleBar(const ModelNode &modelNode)
|
||||
{
|
||||
crumbleBar()->pushInFileComponent(componentId);
|
||||
crumbleBar()->pushInFileComponent(modelNode);
|
||||
}
|
||||
|
||||
void ViewManager::nextFileIsCalledInternally()
|
||||
|
Reference in New Issue
Block a user