QmlDesigner: Fix crumble bar

Change-Id: I8eefba1b5b9839b28be5dbae379366714f40ed27
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
Thomas Hartmann
2013-02-06 13:12:55 +01:00
parent 66ddcb54c2
commit a17f96d42a
8 changed files with 50 additions and 48 deletions

View File

@@ -49,8 +49,15 @@ FormEditorCrumbleBar::FormEditorCrumbleBar(QObject *parent) :
void FormEditorCrumbleBar::pushFile(const QString &fileName) void FormEditorCrumbleBar::pushFile(const QString &fileName)
{ {
if (m_isInternalCalled == false) if (m_isInternalCalled == false) {
crumblePath()->clear(); crumblePath()->clear();
} else {
CrumbleBarInfo lastElementCrumbleBarInfo = crumblePath()->dataForLastIndex().value<CrumbleBarInfo>();
if (!lastElementCrumbleBarInfo.componentId.isEmpty()
&& lastElementCrumbleBarInfo.fileName == fileName)
crumblePath()->popElement();
}
CrumbleBarInfo crumbleBarInfo; CrumbleBarInfo crumbleBarInfo;
crumbleBarInfo.fileName = fileName; crumbleBarInfo.fileName = fileName;
@@ -77,6 +84,8 @@ void FormEditorCrumbleBar::pushInFileComponent(const QString &componentId)
crumblePath()->popElement(); crumblePath()->popElement();
crumblePath()->pushElement(componentId, QVariant::fromValue(crumbleBarInfo)); crumblePath()->pushElement(componentId, QVariant::fromValue(crumbleBarInfo));
m_isInternalCalled = false;
} }
void FormEditorCrumbleBar::nextFileIsCalledInternally() void FormEditorCrumbleBar::nextFileIsCalledInternally()
@@ -91,23 +100,33 @@ Utils::CrumblePath *FormEditorCrumbleBar::crumblePath()
void FormEditorCrumbleBar::onCrumblePathElementClicked(const QVariant &data) void FormEditorCrumbleBar::onCrumblePathElementClicked(const QVariant &data)
{ {
CrumbleBarInfo crumbleBarInfo = data.value<CrumbleBarInfo>(); CrumbleBarInfo clickedCrumbleBarInfo = data.value<CrumbleBarInfo>();
if (crumbleBarInfo == crumblePath()->dataForLastIndex().value<CrumbleBarInfo>()) if (clickedCrumbleBarInfo == crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
return; return;
while (crumbleBarInfo != crumblePath()->dataForLastIndex().value<CrumbleBarInfo>()) while (clickedCrumbleBarInfo != crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
crumblePath()->popElement(); crumblePath()->popElement();
if (!crumbleBarInfo.componentId.isEmpty()) if (!crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().componentId.isEmpty())
crumblePath()->popElement(); crumblePath()->popElement();
crumblePath()->popElement();
m_isInternalCalled = true; m_isInternalCalled = true;
Core::EditorManager::openEditor(crumbleBarInfo.fileName); if (clickedCrumbleBarInfo.componentId.isEmpty()
if (!crumbleBarInfo.componentId.isEmpty()) && clickedCrumbleBarInfo.fileName == currentDesignDocument()->fileName()) {
currentDesignDocument()->changeToSubComponent(currentDesignDocument()->rewriterView()->modelNodeForId(crumbleBarInfo.componentId)); nextFileIsCalledInternally();
currentDesignDocument()->changeToDocumentModel();
} else {
crumblePath()->popElement();
nextFileIsCalledInternally();
Core::EditorManager::openEditor(clickedCrumbleBarInfo.fileName);
if (!clickedCrumbleBarInfo.componentId.isEmpty()) {
currentDesignDocument()->changeToSubComponent(
currentDesignDocument()->rewriterView()->modelNodeForId(clickedCrumbleBarInfo.componentId));
pushInFileComponent(clickedCrumbleBarInfo.componentId);
}
}
} }
bool operator ==(const CrumbleBarInfo &first, const CrumbleBarInfo &second) bool operator ==(const CrumbleBarInfo &first, const CrumbleBarInfo &second)

View File

@@ -39,13 +39,16 @@ namespace QmlDesigner {
ComponentAction::ComponentAction(ComponentView *componentView) ComponentAction::ComponentAction(ComponentView *componentView)
: QWidgetAction(componentView), : QWidgetAction(componentView),
m_componentView(componentView) m_componentView(componentView),
dontEmitCurrentComponentChanged(false)
{ {
} }
void ComponentAction::setCurrentIndex(int index) void ComponentAction::setCurrentIndex(int index)
{ {
dontEmitCurrentComponentChanged = true;
emit currentIndexChanged(index); emit currentIndexChanged(index);
dontEmitCurrentComponentChanged = false;
} }
QWidget *ComponentAction::createWidget(QWidget *parent) QWidget *ComponentAction::createWidget(QWidget *parent)
@@ -54,25 +57,19 @@ QWidget *ComponentAction::createWidget(QWidget *parent)
comboBox->setMinimumWidth(120); comboBox->setMinimumWidth(120);
comboBox->setToolTip(tr("Edit sub components defined in this file")); comboBox->setToolTip(tr("Edit sub components defined in this file"));
comboBox->setModel(m_componentView->standardItemModel()); comboBox->setModel(m_componentView->standardItemModel());
connect(comboBox, SIGNAL(currentIndexChanged(int)), SLOT(emitCurrentComponentChanged(int))); comboBox->setCurrentIndex(-1);
connect(comboBox, SIGNAL(activated(int)), SLOT(emitCurrentComponentChanged(int)));
connect(this, SIGNAL(currentIndexChanged(int)), comboBox, SLOT(setCurrentIndex(int))); connect(this, SIGNAL(currentIndexChanged(int)), comboBox, SLOT(setCurrentIndex(int)));
return comboBox; return comboBox;
} }
static const QString fileNameOfCurrentDocument()
{
return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()->textEditor()->document()->fileName();
}
void ComponentAction::emitCurrentComponentChanged(int index) void ComponentAction::emitCurrentComponentChanged(int index)
{ {
ModelNode componentNode = m_componentView->modelNode(index); if (dontEmitCurrentComponentChanged)
return;
if ( index > 0) ModelNode componentNode = m_componentView->modelNode(index);
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrambleBar(componentNode.id());
else
QmlDesignerPlugin::instance()->viewManager().pushFileOnCrambleBar(fileNameOfCurrentDocument());
emit currentComponentChanged(componentNode); emit currentComponentChanged(componentNode);
} }

View File

@@ -63,6 +63,7 @@ public slots:
private: private:
QWeakPointer<ComponentView> m_componentView; QWeakPointer<ComponentView> m_componentView;
bool dontEmitCurrentComponentChanged;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -78,14 +78,6 @@ QWidget *ComponentView::widget()
return 0; return 0;
} }
void ComponentView::appendWholeDocumentAsComponent()
{
QStandardItem *item = new QStandardItem(tr("whole document"));
item->setData(QVariant::fromValue(rootModelNode()), ModelNodeRole);
item->setEditable(false);
m_standardItemModel->appendRow(item);
}
void ComponentView::removeSingleNodeFromList(const ModelNode &node) void ComponentView::removeSingleNodeFromList(const ModelNode &node)
{ {
for (int row = 0; row < m_standardItemModel->rowCount(); row++) { for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
@@ -114,7 +106,6 @@ void ComponentView::modelAttached(Model *model)
AbstractView::modelAttached(model); AbstractView::modelAttached(model);
appendWholeDocumentAsComponent();
searchForComponentAndAddToList(rootModelNode()); searchForComponentAndAddToList(rootModelNode());
m_componentAction->blockSignals(block); m_componentAction->blockSignals(block);

View File

@@ -116,7 +116,6 @@ private: //functions
void updateModel(); void updateModel();
void searchForComponentAndAddToList(const ModelNode &node); void searchForComponentAndAddToList(const ModelNode &node);
void searchForComponentAndRemoveFromList(const ModelNode &node); void searchForComponentAndRemoveFromList(const ModelNode &node);
void appendWholeDocumentAsComponent();
void removeSingleNodeFromList(const ModelNode &node); void removeSingleNodeFromList(const ModelNode &node);
int indexForNode(const ModelNode &node); int indexForNode(const ModelNode &node);

View File

@@ -236,7 +236,7 @@ QList<RewriterView::Error> DesignDocument::qmlSyntaxErrors() const
bool DesignDocument::hasQmlSyntaxErrors() const bool DesignDocument::hasQmlSyntaxErrors() const
{ {
return !m_currentModel->rewriterView()->errors().isEmpty(); return m_currentModel->rewriterView() && !m_currentModel->rewriterView()->errors().isEmpty();
} }
QString DesignDocument::displayName() const QString DesignDocument::displayName() const
@@ -314,26 +314,18 @@ void DesignDocument::loadDocument(QPlainTextEdit *edit)
m_documentLoaded = true; m_documentLoaded = true;
} }
static const QString fileNameOfCurrentDocument()
{
return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()->textEditor()->document()->fileName();
}
void DesignDocument::changeCurrentModelTo(const ModelNode &node) void DesignDocument::changeCurrentModelTo(const ModelNode &node)
{ {
if (QmlDesignerPlugin::instance()->currentDesignDocument() != this) if (QmlDesignerPlugin::instance()->currentDesignDocument() != this)
return; return;
if (rootModelNode() == node) {
changeToDocumentModel();
} else {
changeToSubComponent(node);
}
changeToSubComponent(node);
// s_clearCrumblePath = false;
// while (m_formEditorView->crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().modelNode.isValid() &&
// !m_formEditorView->crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().modelNode.isRootNode())
// m_formEditorView->crumblePath()->popElement();
// if (node.isRootNode() && m_formEditorView->crumblePath()->dataForLastIndex().isValid())
// m_formEditorView->crumblePath()->popElement();
// s_clearCrumblePath = true;
} }
void DesignDocument::changeToSubComponent(const ModelNode &componentNode) void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
@@ -354,6 +346,8 @@ void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
activateCurrentModel(m_inFileComponentTextModifier.data()); activateCurrentModel(m_inFileComponentTextModifier.data());
} }
if (!componentNode.id().isEmpty())
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrambleBar(componentNode.id());
} }
void DesignDocument::changeToExternalSubComponent(const QString &fileName) void DesignDocument::changeToExternalSubComponent(const QString &fileName)

View File

@@ -101,6 +101,8 @@ public:
void goIntoComponent(); void goIntoComponent();
void changeToDocumentModel();
signals: signals:
void displayNameChanged(const QString &newFileName); void displayNameChanged(const QString &newFileName);
void dirtyStateChanged(bool newState); void dirtyStateChanged(bool newState);
@@ -127,7 +129,6 @@ private slots:
void updateFileName(const QString &oldFileName, const QString &newFileName); void updateFileName(const QString &oldFileName, const QString &newFileName);
private: // functions private: // functions
void changeToDocumentModel();
void changeToInFileComponentModel(); void changeToInFileComponentModel();
QWidget *centralWidget() const; QWidget *centralWidget() const;

View File

@@ -242,8 +242,8 @@ void QmlDesignerPlugin::changeEditor()
m_shortCutManager.connectUndoActions(currentDesignDocument()); m_shortCutManager.connectUndoActions(currentDesignDocument());
if (m_documentManager.hasCurrentDesignDocument()) { if (m_documentManager.hasCurrentDesignDocument()) {
m_viewManager.pushFileOnCrambleBar(m_documentManager.currentDesignDocument()->fileName());
activateAutoSynchronization(); activateAutoSynchronization();
m_viewManager.pushFileOnCrambleBar(m_documentManager.currentDesignDocument()->fileName());
} }
m_shortCutManager.updateUndoActions(currentDesignDocument()); m_shortCutManager.updateUndoActions(currentDesignDocument());