Commit 5dfde6e0 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Show the imports in a view port



Change-Id: I3a69662c97931155cc589ca86f61e5deb67ffd12
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 1882a770
......@@ -29,7 +29,16 @@
#include "importlabel.h"
namespace QmlDesigner {
ImportLabel::ImportLabel(QWidget *parent) :
QWidget(parent)
QLabel(parent)
{
}
void ImportLabel::setImport(const Import &import)
{
setText(import.toString());
}
} // namespace QmlDesigner
......@@ -30,18 +30,21 @@
#ifndef IMPORTLABEL_H
#define IMPORTLABEL_H
#include <QWidget>
#include <QLabel>
class ImportLabel : public QWidget
#include <import.h>
namespace QmlDesigner {
class ImportLabel : public QLabel
{
Q_OBJECT
public:
explicit ImportLabel(QWidget *parent = 0);
signals:
public slots:
void setImport(const Import &import);
};
}
#endif // IMPORTLABEL_H
......@@ -45,22 +45,36 @@ ImportManagerView::~ImportManagerView()
}
bool ImportManagerView::hasWidget() const
{
return true;
}
WidgetInfo ImportManagerView::widgetInfo()
{
if (m_importsWidget == 0)
if (m_importsWidget == 0) {
m_importsWidget = new ImportsWidget;
if (model())
m_importsWidget->setImports(model()->imports());
}
return createWidgetInfo(m_importsWidget, 0, "ImportManager", WidgetInfo::LeftPane, 1);
}
void ImportManagerView::modelAttached(Model *model)
{
AbstractView::modelAttached(model);
if (m_importsWidget)
m_importsWidget->setImports(model->imports());
}
void ImportManagerView::modelAboutToBeDetached(Model *model)
{
if (m_importsWidget)
m_importsWidget->removeAllImports();
AbstractView::modelAboutToBeDetached(model);
}
void ImportManagerView::nodeCreated(const ModelNode &createdNode)
......@@ -193,9 +207,10 @@ void ImportManagerView::nodeOrderChanged(const NodeListProperty &/*listProperty*
}
void ImportManagerView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
void ImportManagerView::importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
{
if (m_importsWidget)
m_importsWidget->setImports(model()->imports());
}
void ImportManagerView::auxiliaryDataChanged(const ModelNode &/*node*/, const PropertyName &/*name*/, const QVariant &/*data*/)
......
......@@ -44,6 +44,7 @@ public:
explicit ImportManagerView(QObject *parent = 0);
~ImportManagerView();
bool hasWidget() const;
WidgetInfo widgetInfo();
void modelAttached(Model *model);
......
......@@ -29,6 +29,10 @@
#include "importswidget.h"
#include <QVBoxLayout>
#include "importlabel.h"
namespace QmlDesigner {
ImportsWidget::ImportsWidget(QWidget *parent) :
......@@ -36,4 +40,37 @@ ImportsWidget::ImportsWidget(QWidget *parent) :
{
}
void ImportsWidget::removeAllImports()
{
qDeleteAll(m_importLabels);
m_importLabels.clear();
updateLayout();
}
void ImportsWidget::setImports(const QList<Import> &imports)
{
qDeleteAll(m_importLabels);
m_importLabels.clear();
foreach (const Import &import, imports) {
ImportLabel *importLabel = new ImportLabel(this);
importLabel->setImport(import);
m_importLabels.append(importLabel);
}
updateLayout();
}
void ImportsWidget::updateLayout()
{
delete layout();
QVBoxLayout *layout = new QVBoxLayout(this);
foreach (ImportLabel *importLabel, m_importLabels)
layout->addWidget(importLabel);
layout->addStretch();
}
} // namespace QmlDesigner
......@@ -30,20 +30,28 @@
#ifndef QMLDESIGNER_IMPORTSWIDGET_H
#define QMLDESIGNER_IMPORTSWIDGET_H
#include <import.h>
#include <QWidget>
namespace QmlDesigner {
class ImportLabel;
class ImportsWidget : public QWidget
{
Q_OBJECT
public:
explicit ImportsWidget(QWidget *parent = 0);
signals:
void setImports(const QList<Import> &imports);
void removeAllImports();
public slots:
protected:
void updateLayout();
private:
QList<ImportLabel*> m_importLabels;
};
} // namespace QmlDesigner
......
......@@ -184,6 +184,7 @@ QList<WidgetInfo> ViewManager::widgetInfos()
QList<WidgetInfo> widgetInfoList;
widgetInfoList.append(m_formEditorView.widgetInfo());
widgetInfoList.append(m_importManagerView.widgetInfo());
widgetInfoList.append(m_itemLibraryView.widgetInfo());
widgetInfoList.append(m_navigatorView.widgetInfo());
widgetInfoList.append(m_propertyEditorView.widgetInfo());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment