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 "qmldesignerplugin.h"
|
||||||
|
|
||||||
|
#include <nodeabstractproperty.h>
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
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) :
|
CrumbleBar::CrumbleBar(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_isInternalCalled(false),
|
m_isInternalCalled(false),
|
||||||
@@ -45,6 +77,8 @@ CrumbleBar::CrumbleBar(QObject *parent) :
|
|||||||
SIGNAL(elementClicked(QVariant)),
|
SIGNAL(elementClicked(QVariant)),
|
||||||
this,
|
this,
|
||||||
SLOT(onCrumblePathElementClicked(QVariant)));
|
SLOT(onCrumblePathElementClicked(QVariant)));
|
||||||
|
|
||||||
|
updateVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrumbleBar::pushFile(const QString &fileName)
|
void CrumbleBar::pushFile(const QString &fileName)
|
||||||
@@ -65,27 +99,24 @@ void CrumbleBar::pushFile(const QString &fileName)
|
|||||||
crumblePath()->pushElement(fileName.split("/").last(), QVariant::fromValue(crumbleBarInfo));
|
crumblePath()->pushElement(fileName.split("/").last(), QVariant::fromValue(crumbleBarInfo));
|
||||||
|
|
||||||
m_isInternalCalled = false;
|
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>();
|
CrumbleBarInfo lastElementCrumbleBarInfo = crumblePath()->dataForLastIndex().value<CrumbleBarInfo>();
|
||||||
|
|
||||||
if (!lastElementCrumbleBarInfo.componentId.isEmpty())
|
if (!lastElementCrumbleBarInfo.componentId.isEmpty())
|
||||||
crumblePath()->popElement();
|
crumblePath()->popElement();
|
||||||
|
|
||||||
crumblePath()->pushElement(componentId, QVariant::fromValue(crumbleBarInfo));
|
crumblePath()->pushElement(crumbleBarInfo.componentId, QVariant::fromValue(crumbleBarInfo));
|
||||||
|
|
||||||
m_isInternalCalled = false;
|
m_isInternalCalled = false;
|
||||||
|
|
||||||
|
updateVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrumbleBar::nextFileIsCalledInternally()
|
void CrumbleBar::nextFileIsCalledInternally()
|
||||||
@@ -111,7 +142,6 @@ void CrumbleBar::onCrumblePathElementClicked(const QVariant &data)
|
|||||||
if (!crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().componentId.isEmpty())
|
if (!crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().componentId.isEmpty())
|
||||||
crumblePath()->popElement();
|
crumblePath()->popElement();
|
||||||
|
|
||||||
|
|
||||||
m_isInternalCalled = true;
|
m_isInternalCalled = true;
|
||||||
if (clickedCrumbleBarInfo.componentId.isEmpty()
|
if (clickedCrumbleBarInfo.componentId.isEmpty()
|
||||||
&& clickedCrumbleBarInfo.fileName == currentDesignDocument()->fileName()) {
|
&& clickedCrumbleBarInfo.fileName == currentDesignDocument()->fileName()) {
|
||||||
@@ -125,9 +155,15 @@ void CrumbleBar::onCrumblePathElementClicked(const QVariant &data)
|
|||||||
if (!clickedCrumbleBarInfo.componentId.isEmpty()) {
|
if (!clickedCrumbleBarInfo.componentId.isEmpty()) {
|
||||||
currentDesignDocument()->changeToSubComponent(
|
currentDesignDocument()->changeToSubComponent(
|
||||||
currentDesignDocument()->rewriterView()->modelNodeForId(clickedCrumbleBarInfo.componentId));
|
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)
|
bool operator ==(const CrumbleBarInfo &first, const CrumbleBarInfo &second)
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <utils/crumblepath.h>
|
#include <utils/crumblepath.h>
|
||||||
|
#include <modelnode.h>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ public:
|
|||||||
explicit CrumbleBar(QObject *parent = 0);
|
explicit CrumbleBar(QObject *parent = 0);
|
||||||
|
|
||||||
void pushFile(const QString &fileName);
|
void pushFile(const QString &fileName);
|
||||||
void pushInFileComponent(const QString &componentId);
|
void pushInFileComponent(const ModelNode &modelNode);
|
||||||
|
|
||||||
void nextFileIsCalledInternally();
|
void nextFileIsCalledInternally();
|
||||||
|
|
||||||
@@ -51,6 +52,9 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void onCrumblePathElementClicked(const QVariant &data);
|
void onCrumblePathElementClicked(const QVariant &data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateVisibility();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isInternalCalled;
|
bool m_isInternalCalled;
|
||||||
Utils::CrumblePath *m_crumblePath;
|
Utils::CrumblePath *m_crumblePath;
|
||||||
@@ -60,6 +64,7 @@ class CrumbleBarInfo {
|
|||||||
public:
|
public:
|
||||||
QString fileName;
|
QString fileName;
|
||||||
QString componentId;
|
QString componentId;
|
||||||
|
ModelNode modelNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator ==(const CrumbleBarInfo &first, const CrumbleBarInfo &second);
|
bool operator ==(const CrumbleBarInfo &first, const CrumbleBarInfo &second);
|
||||||
|
@@ -285,18 +285,11 @@ void DesignDocument::changeToInFileComponentModel(ComponentTextModifier *textMod
|
|||||||
viewManager().attachViewsExceptRewriterAndComponetView();
|
viewManager().attachViewsExceptRewriterAndComponetView();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignDocument::changeToSubComponentAndPushOnCrumblePath(const ModelNode &componentNode)
|
void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
||||||
{
|
{
|
||||||
if (QmlDesignerPlugin::instance()->currentDesignDocument() != this)
|
if (QmlDesignerPlugin::instance()->currentDesignDocument() != this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
changeToSubComponent(componentNode);
|
|
||||||
|
|
||||||
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrambleBar(componentNode.id());
|
|
||||||
}
|
|
||||||
|
|
||||||
void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
|
||||||
{
|
|
||||||
if (m_inFileComponentModel)
|
if (m_inFileComponentModel)
|
||||||
changeToDocumentModel();
|
changeToDocumentModel();
|
||||||
|
|
||||||
@@ -304,6 +297,8 @@ void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
|||||||
|
|
||||||
if (subComponentLoaded)
|
if (subComponentLoaded)
|
||||||
attachRewriterToModel();
|
attachRewriterToModel();
|
||||||
|
|
||||||
|
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrumbleBar(componentNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesignDocument::attachRewriterToModel()
|
void DesignDocument::attachRewriterToModel()
|
||||||
|
@@ -117,7 +117,6 @@ public slots:
|
|||||||
void undo();
|
void undo();
|
||||||
void redo();
|
void redo();
|
||||||
void updateActiveQtVersion();
|
void updateActiveQtVersion();
|
||||||
void changeToSubComponentAndPushOnCrumblePath(const ModelNode &componentNode);
|
|
||||||
void changeToSubComponent(const ModelNode &componentNode);
|
void changeToSubComponent(const ModelNode &componentNode);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@@ -81,8 +81,7 @@ public:
|
|||||||
void enableWidgets();
|
void enableWidgets();
|
||||||
|
|
||||||
void pushFileOnCrumbleBar(const QString &fileName);
|
void pushFileOnCrumbleBar(const QString &fileName);
|
||||||
void pushInFileComponentOnCrambleBar(const QString &componentId);
|
void pushInFileComponentOnCrumbleBar(const ModelNode &modelNode);
|
||||||
|
|
||||||
void nextFileIsCalledInternally();
|
void nextFileIsCalledInternally();
|
||||||
|
|
||||||
NodeInstanceView *nodeInstanceView();
|
NodeInstanceView *nodeInstanceView();
|
||||||
|
@@ -213,10 +213,9 @@ void ViewManager::pushFileOnCrumbleBar(const QString &fileName)
|
|||||||
crumbleBar()->pushFile(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()
|
void ViewManager::nextFileIsCalledInternally()
|
||||||
|
Reference in New Issue
Block a user