Commit 81341a86 authored by Marco Bubke's avatar Marco Bubke Committed by Thomas Hartmann
Browse files

QmlDesigner: Add registration of additional views.



Change-Id: I48aff6a1a94ca3c0bcd8b0689333b6acad7d35cd
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 479b22ec
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include "formeditoritem.h" #include "formeditoritem.h"
#include "formeditorscene.h" #include "formeditorscene.h"
#include "toolbox.h" #include "toolbox.h"
#include <designmodecontext.h>
#include <rewritertransaction.h> #include <rewritertransaction.h>
#include <modelnode.h> #include <modelnode.h>
#include <itemlibraryinfo.h> #include <itemlibraryinfo.h>
...@@ -54,6 +56,7 @@ ...@@ -54,6 +56,7 @@
#include <nodelistproperty.h> #include <nodelistproperty.h>
#include <commondefines.h> #include <commondefines.h>
#include <coreplugin/icore.h>
namespace QmlDesigner { namespace QmlDesigner {
...@@ -68,6 +71,9 @@ FormEditorView::FormEditorView(QObject *parent) ...@@ -68,6 +71,9 @@ FormEditorView::FormEditorView(QObject *parent)
m_currentTool(m_selectionTool), m_currentTool(m_selectionTool),
m_transactionCounter(0) m_transactionCounter(0)
{ {
Internal::FormEditorContext *formEditorContext = new Internal::FormEditorContext(m_formEditorWidget.data());
Core::ICore::addContextObject(formEditorContext);
connect(formEditorWidget()->zoomAction(), SIGNAL(zoomLevelChanged(double)), SLOT(updateGraphicsIndicators())); connect(formEditorWidget()->zoomAction(), SIGNAL(zoomLevelChanged(double)), SLOT(updateGraphicsIndicators()));
connect(formEditorWidget()->showBoundingRectAction(), SIGNAL(toggled(bool)), scene(), SLOT(setShowBoundingRects(bool))); connect(formEditorWidget()->showBoundingRectAction(), SIGNAL(toggled(bool)), scene(), SLOT(setShowBoundingRects(bool)));
connect(formEditorWidget()->selectOnlyContentItemsAction(), SIGNAL(toggled(bool)), this, SLOT(setSelectOnlyContentItemsAction(bool))); connect(formEditorWidget()->selectOnlyContentItemsAction(), SIGNAL(toggled(bool)), this, SLOT(setSelectOnlyContentItemsAction(bool)));
...@@ -273,6 +279,11 @@ QWidget *FormEditorView::widget() ...@@ -273,6 +279,11 @@ QWidget *FormEditorView::widget()
return m_formEditorWidget.data(); return m_formEditorWidget.data();
} }
WidgetInfo FormEditorView::widgetInfo()
{
return createWidgetInfo(m_formEditorWidget.data(), "FormEditor", WidgetInfo::CentralPane, 0, tr("Form Editor"));
}
FormEditorWidget *FormEditorView::formEditorWidget() FormEditorWidget *FormEditorView::formEditorWidget()
{ {
return m_formEditorWidget.data(); return m_formEditorWidget.data();
......
...@@ -86,6 +86,8 @@ public: ...@@ -86,6 +86,8 @@ public:
// FormEditorView // FormEditorView
QWidget *widget(); QWidget *widget();
WidgetInfo widgetInfo();
FormEditorWidget *formEditorWidget(); FormEditorWidget *formEditorWidget();
AbstractFormEditorTool *currentTool() const; AbstractFormEditorTool *currentTool() const;
FormEditorScene *scene() const; FormEditorScene *scene() const;
......
...@@ -51,6 +51,16 @@ QWidget *ItemLibraryView::widget() ...@@ -51,6 +51,16 @@ QWidget *ItemLibraryView::widget()
return m_widget.data(); return m_widget.data();
} }
bool ItemLibraryView::hasWidget() const
{
return true;
}
WidgetInfo ItemLibraryView::widgetInfo()
{
return createWidgetInfo(widget(), QLatin1String("Library"), WidgetInfo::LeftPane, 0);
}
void ItemLibraryView::modelAttached(Model *model) void ItemLibraryView::modelAttached(Model *model)
{ {
AbstractView::modelAttached(model); AbstractView::modelAttached(model);
......
...@@ -49,6 +49,8 @@ public: ...@@ -49,6 +49,8 @@ public:
~ItemLibraryView(); ~ItemLibraryView();
QWidget *widget(); QWidget *widget();
bool hasWidget() const;
WidgetInfo widgetInfo();
// AbstractView // AbstractView
void modelAttached(Model *model); void modelAttached(Model *model);
......
...@@ -33,7 +33,9 @@ ...@@ -33,7 +33,9 @@
#include "modelnodecontextmenu.h" #include "modelnodecontextmenu.h"
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <designmodecontext.h>
#include <nodeproperty.h> #include <nodeproperty.h>
#include <nodelistproperty.h> #include <nodelistproperty.h>
#include <variantproperty.h> #include <variantproperty.h>
...@@ -57,6 +59,9 @@ NavigatorView::NavigatorView(QObject* parent) : ...@@ -57,6 +59,9 @@ NavigatorView::NavigatorView(QObject* parent) :
m_widget(new NavigatorWidget(this)), m_widget(new NavigatorWidget(this)),
m_treeModel(new NavigatorTreeModel(this)) m_treeModel(new NavigatorTreeModel(this))
{ {
Internal::NavigatorContext *navigatorContext = new Internal::NavigatorContext(m_widget.data());
Core::ICore::addContextObject(navigatorContext);
m_widget->setTreeModel(m_treeModel.data()); m_widget->setTreeModel(m_treeModel.data());
connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection))); connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection)));
...@@ -99,6 +104,16 @@ QWidget *NavigatorView::widget() ...@@ -99,6 +104,16 @@ QWidget *NavigatorView::widget()
return m_widget.data(); return m_widget.data();
} }
bool NavigatorView::hasWidget() const
{
return true;
}
WidgetInfo NavigatorView::widgetInfo()
{
return createWidgetInfo(m_widget.data(), QLatin1String("Navigator"), WidgetInfo::LeftPane, 0);
}
void NavigatorView::modelAttached(Model *model) void NavigatorView::modelAttached(Model *model)
{ {
QmlModelView::modelAttached(model); QmlModelView::modelAttached(model);
......
...@@ -57,6 +57,8 @@ public: ...@@ -57,6 +57,8 @@ public:
~NavigatorView(); ~NavigatorView();
QWidget *widget(); QWidget *widget();
bool hasWidget() const;
WidgetInfo widgetInfo();
// AbstractView // AbstractView
void modelAttached(Model *model); void modelAttached(Model *model);
......
...@@ -966,6 +966,15 @@ QWidget *PropertyEditor::widget() ...@@ -966,6 +966,15 @@ QWidget *PropertyEditor::widget()
return m_stackedWidget; return m_stackedWidget;
} }
bool PropertyEditor::hasWidget() const
{
return true;
}
WidgetInfo PropertyEditor::widgetInfo()
{
return createWidgetInfo(m_stackedWidget, QLatin1String("Properties"), WidgetInfo::RightPane, 0);
}
void PropertyEditor::actualStateChanged(const ModelNode &node) void PropertyEditor::actualStateChanged(const ModelNode &node)
{ {
......
...@@ -84,6 +84,8 @@ public: ...@@ -84,6 +84,8 @@ public:
void setQmlDir(const QString &qmlDirPath); void setQmlDir(const QString &qmlDirPath);
QWidget *widget(); QWidget *widget();
bool hasWidget() const;
WidgetInfo widgetInfo();
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList); const QList<ModelNode> &lastSelectedNodeList);
......
...@@ -65,6 +65,11 @@ QWidget *StatesEditorView::widget() ...@@ -65,6 +65,11 @@ QWidget *StatesEditorView::widget()
return m_statesEditorWidget.data(); return m_statesEditorWidget.data();
} }
WidgetInfo StatesEditorView::widgetInfo()
{
return createWidgetInfo(m_statesEditorWidget.data(), "StatesEditor", WidgetInfo::TopPane, 0, tr("States Editor"));
}
void StatesEditorView::removeState(int nodeId) void StatesEditorView::removeState(int nodeId)
{ {
try { try {
......
...@@ -75,6 +75,8 @@ public: ...@@ -75,6 +75,8 @@ public:
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList); void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
QWidget *widget(); QWidget *widget();
WidgetInfo widgetInfo();
public slots: public slots:
void synchonizeCurrentStateFromWidget(); void synchonizeCurrentStateFromWidget();
......
...@@ -58,6 +58,24 @@ class QmlModelView; ...@@ -58,6 +58,24 @@ class QmlModelView;
class NodeInstanceView; class NodeInstanceView;
class RewriterView; class RewriterView;
struct WidgetInfo {
enum PlacementHint {
NoPane,
LeftPane,
RightPane,
TopPane, // not used
BottomPane, // not used
CentralPane // not used
};
QString uniqueId;
QString tabName;
QWidget *widget;
int placementPriority;
PlacementHint placementHint;
};
class QMLDESIGNERCORE_EXPORT AbstractView : public QObject class QMLDESIGNERCORE_EXPORT AbstractView : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -180,11 +198,18 @@ public: ...@@ -180,11 +198,18 @@ public:
void resetView(); void resetView();
virtual bool hasWidget() const;
virtual QWidget *widget() = 0; virtual QWidget *widget() = 0;
virtual WidgetInfo widgetInfo();
protected: protected:
void setModel(Model * model); void setModel(Model * model);
void removeModel(); void removeModel();
static WidgetInfo createWidgetInfo(QWidget *widget = 0,
const QString &uniqueId = QString(),
WidgetInfo::PlacementHint placementHint = WidgetInfo::NoPane,
int placementPriority = 0,
const QString &tabName = QString());
private: //functions private: //functions
QList<ModelNode> toModelNodeList(const QList<Internal::InternalNodePointer> &nodeList) const; QList<ModelNode> toModelNodeList(const QList<Internal::InternalNodePointer> &nodeList) const;
......
...@@ -54,6 +54,7 @@ class ViewManager ...@@ -54,6 +54,7 @@ class ViewManager
{ {
public: public:
ViewManager(); ViewManager();
~ViewManager();
void attachRewriterView(TextModifier *textModifier); void attachRewriterView(TextModifier *textModifier);
void detachRewriterView(); void detachRewriterView();
...@@ -69,13 +70,14 @@ public: ...@@ -69,13 +70,14 @@ public:
void setNodeInstanceViewQtPath(const QString & qtPath); void setNodeInstanceViewQtPath(const QString & qtPath);
void resetPropertyEditorView(); void resetPropertyEditorView();
void resisterFormEditorTool(AbstractFormEditorTool *tool); // takes ownership void resisterFormEditorTool(AbstractFormEditorTool *tool); // takes ownership
void registerView(AbstractView *view);
QList<WidgetInfo> widgetInfos();
QWidget *formEditorWidget(); void disableWidgets();
QWidget *propertyEditorWidget(); void enableWidgets();
QWidget *itemLibraryWidget();
QWidget *navigatorWidget();
QWidget *statesEditorWidget();
void pushFileOnCrambleBar(const QString &fileName); void pushFileOnCrambleBar(const QString &fileName);
void pushInFileComponentOnCrambleBar(const QString &componentId); void pushInFileComponentOnCrambleBar(const QString &componentId);
...@@ -89,8 +91,8 @@ private: // functions ...@@ -89,8 +91,8 @@ private: // functions
void attachNodeInstanceView(); void attachNodeInstanceView();
void attachItemLibraryView(); void attachItemLibraryView();
void attachAdditionalViews();
void detachAdditionalViews();
Model *currentModel() const; Model *currentModel() const;
Model *documentModel() const; Model *documentModel() const;
......
...@@ -118,6 +118,23 @@ void AbstractView::removeModel() ...@@ -118,6 +118,23 @@ void AbstractView::removeModel()
m_model.clear(); m_model.clear();
} }
WidgetInfo AbstractView::createWidgetInfo(QWidget *widget,
const QString &uniqueId,
WidgetInfo::PlacementHint placementHint,
int placementPriority,
const QString &tabName)
{
WidgetInfo widgetInfo;
widgetInfo.widget = widget;
widgetInfo.uniqueId = uniqueId;
widgetInfo.placementHint = placementHint;
widgetInfo.placementPriority = placementPriority;
widgetInfo.tabName = tabName;
return widgetInfo;
}
/*! /*!
\name Model related functions \name Model related functions
\{ \{
...@@ -367,6 +384,16 @@ void AbstractView::resetView() ...@@ -367,6 +384,16 @@ void AbstractView::resetView()
currentModel->attachView(this); currentModel->attachView(this);
} }
bool AbstractView::hasWidget() const
{
return false;
}
WidgetInfo AbstractView::widgetInfo()
{
return createWidgetInfo();
}
QList<ModelNode> AbstractView::allModelNodes() const QList<ModelNode> AbstractView::allModelNodes() const
{ {
return toModelNodeList(model()->d->allNodes()); return toModelNodeList(model()->d->allNodes());
......
...@@ -24,6 +24,12 @@ ViewManager::ViewManager() ...@@ -24,6 +24,12 @@ ViewManager::ViewManager()
m_formEditorView.formEditorWidget()->toolBox()->addLeftSideAction(m_componentView.action()); // ugly hack m_formEditorView.formEditorWidget()->toolBox()->addLeftSideAction(m_componentView.action()); // ugly hack
} }
ViewManager::~ViewManager()
{
foreach (const QWeakPointer<AbstractView> &view, m_additionalViews)
delete view.data();
}
DesignDocument *ViewManager::currentDesignDocument() const DesignDocument *ViewManager::currentDesignDocument() const
{ {
return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument(); return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument();
...@@ -87,9 +93,15 @@ void ViewManager::resisterFormEditorTool(AbstractFormEditorTool *tool) ...@@ -87,9 +93,15 @@ void ViewManager::resisterFormEditorTool(AbstractFormEditorTool *tool)
m_formEditorView.registerTool(tool); m_formEditorView.registerTool(tool);
} }
void ViewManager::registerView(AbstractView *view)
{
m_additionalViews.append(view);
}
void ViewManager::detachViewsExceptRewriterAndComponetView() void ViewManager::detachViewsExceptRewriterAndComponetView()
{ {
switchStateEditorViewToBaseState(); switchStateEditorViewToBaseState();
detachAdditionalViews();
currentModel()->detachView(DesignerActionManager::view()); currentModel()->detachView(DesignerActionManager::view());
currentModel()->detachView(&m_formEditorView); currentModel()->detachView(&m_formEditorView);
currentModel()->detachView(&m_navigatorView); currentModel()->detachView(&m_navigatorView);
...@@ -109,6 +121,18 @@ void ViewManager::attachItemLibraryView() ...@@ -109,6 +121,18 @@ void ViewManager::attachItemLibraryView()
currentModel()->attachView(&m_itemLibraryView); currentModel()->attachView(&m_itemLibraryView);
} }
void ViewManager::attachAdditionalViews()
{
foreach (const QWeakPointer<AbstractView> &view, m_additionalViews)
currentModel()->attachView(view.data());
}
void ViewManager::detachAdditionalViews()
{
foreach (const QWeakPointer<AbstractView> &view, m_additionalViews)
currentModel()->detachView(view.data());
}
void ViewManager::attachComponentView() void ViewManager::attachComponentView()
{ {
documentModel()->attachView(&m_componentView); documentModel()->attachView(&m_componentView);
...@@ -134,6 +158,7 @@ void ViewManager::attachViewsExceptRewriterAndComponetView() ...@@ -134,6 +158,7 @@ void ViewManager::attachViewsExceptRewriterAndComponetView()
currentModel()->attachView(&m_statesEditorView); currentModel()->attachView(&m_statesEditorView);
currentModel()->attachView(&m_propertyEditorView); currentModel()->attachView(&m_propertyEditorView);
currentModel()->attachView(DesignerActionManager::view()); currentModel()->attachView(DesignerActionManager::view());
attachAdditionalViews();
switchStateEditorViewToSavedState(); switchStateEditorViewToSavedState();
} }
...@@ -152,29 +177,41 @@ void ViewManager::setNodeInstanceViewQtPath(const QString &qtPath) ...@@ -152,29 +177,41 @@ void ViewManager::setNodeInstanceViewQtPath(const QString &qtPath)
m_nodeInstanceView.setPathToQt(qtPath); m_nodeInstanceView.setPathToQt(qtPath);
} }
QWidget *ViewManager::formEditorWidget() static bool widgetInfoLessThan(const WidgetInfo &firstWidgetInfo, const WidgetInfo &secondWidgetInfo)
{ {
return m_formEditorView.widget(); return firstWidgetInfo.placementPriority < secondWidgetInfo.placementPriority;
} }
QWidget *ViewManager::propertyEditorWidget() QList<WidgetInfo> ViewManager::widgetInfos()
{ {
return m_propertyEditorView.widget(); QList<WidgetInfo> widgetInfoList;
}
QWidget *ViewManager::itemLibraryWidget() widgetInfoList.append(m_formEditorView.widgetInfo());
{ widgetInfoList.append(m_itemLibraryView.widgetInfo());
return m_itemLibraryView.widget(); widgetInfoList.append(m_navigatorView.widgetInfo());
widgetInfoList.append(m_propertyEditorView.widgetInfo());
widgetInfoList.append(m_statesEditorView.widgetInfo());
foreach (const QWeakPointer<AbstractView> &abstractView, m_additionalViews) {
if (abstractView && abstractView->hasWidget())
widgetInfoList.append(abstractView->widgetInfo());
}
qSort(widgetInfoList.begin(), widgetInfoList.end(), widgetInfoLessThan);
return widgetInfoList;
} }
QWidget *ViewManager::navigatorWidget() void ViewManager::disableWidgets()
{ {
return m_navigatorView.widget(); foreach (const WidgetInfo &widgetInfo, widgetInfos())
widgetInfo.widget->setEnabled(false);
} }
QWidget *ViewManager::statesEditorWidget() void ViewManager::enableWidgets()
{ {
return m_statesEditorView.widget(); foreach (const WidgetInfo &widgetInfo, widgetInfos())
widgetInfo.widget->setEnabled(true);
} }
void ViewManager::pushFileOnCrambleBar(const QString &fileName) void ViewManager::pushFileOnCrambleBar(const QString &fileName)
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "designmodewidget.h" #include "designmodewidget.h"
#include "qmldesignerconstants.h" #include "qmldesignerconstants.h"
#include "styledoutputpaneplaceholder.h" #include "styledoutputpaneplaceholder.h"
#include "designmodecontext.h"
#include "qmldesignerplugin.h" #include "qmldesignerplugin.h"
#include <model.h> #include <model.h>
...@@ -71,6 +70,7 @@ ...@@ -71,6 +70,7 @@
#include <QClipboard> #include <QClipboard>
#include <QLabel> #include <QLabel>
#include <QProgressDialog> #include <QProgressDialog>
#include <QTabWidget>
using Core::MiniSplitter; using Core::MiniSplitter;
using Core::IEditor; using Core::IEditor;
...@@ -82,9 +82,6 @@ enum { ...@@ -82,9 +82,6 @@ enum {
debug = false debug = false
}; };
const char SB_NAVIGATOR[] = "Navigator";
const char SB_LIBRARY[] = "Library";
const char SB_PROPERTIES[] = "Properties";
const char SB_PROJECTS[] = "Projects"; const char SB_PROJECTS[] = "Projects";
const char SB_FILESYSTEM[] = "FileSystem";