Commit 7df5ce2d authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.itemLibrary: turn the item library into a full view.

This is more consistent with the whole architecture and allows
the item library to listen to imports.
parent d3619e80
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
#include "model/viewlogger.h" #include "model/viewlogger.h"
#include <allpropertiesbox.h> #include <allpropertiesbox.h>
#include <itemlibrary.h> #include <itemlibraryview.h>
#include <itemlibrarywidget.h>
#include <navigatorview.h> #include <navigatorview.h>
#include <stateseditorview.h> #include <stateseditorview.h>
#include <formeditorview.h> #include <formeditorview.h>
...@@ -84,7 +85,7 @@ class DesignDocumentControllerPrivate { ...@@ -84,7 +85,7 @@ class DesignDocumentControllerPrivate {
public: public:
QWeakPointer<FormEditorView> formEditorView; QWeakPointer<FormEditorView> formEditorView;
QWeakPointer<ItemLibrary> itemLibrary; QWeakPointer<ItemLibraryView> itemLibraryView;
QWeakPointer<NavigatorView> navigator; QWeakPointer<NavigatorView> navigator;
QWeakPointer<AllPropertiesBox> allPropertiesBox; QWeakPointer<AllPropertiesBox> allPropertiesBox;
QWeakPointer<StatesEditorView> statesEditorView; QWeakPointer<StatesEditorView> statesEditorView;
...@@ -190,9 +191,9 @@ QList<RewriterView::Error> DesignDocumentController::qmlErrors() const ...@@ -190,9 +191,9 @@ QList<RewriterView::Error> DesignDocumentController::qmlErrors() const
return m_d->rewriterView->errors(); return m_d->rewriterView->errors();
} }
void DesignDocumentController::setItemLibrary(ItemLibrary* itemLibrary) void DesignDocumentController::setItemLibraryView(ItemLibraryView* itemLibraryView)
{ {
m_d->itemLibrary = itemLibrary; m_d->itemLibraryView = itemLibraryView;
} }
void DesignDocumentController::setNavigator(NavigatorView* navigatorView) void DesignDocumentController::setNavigator(NavigatorView* navigatorView)
...@@ -246,8 +247,8 @@ void DesignDocumentController::setFileName(const QString &fileName) ...@@ -246,8 +247,8 @@ void DesignDocumentController::setFileName(const QString &fileName)
if (m_d->model) if (m_d->model)
m_d->model->setFileUrl(m_d->searchPath); m_d->model->setFileUrl(m_d->searchPath);
if (m_d->itemLibrary) if (m_d->itemLibraryView)
m_d->itemLibrary->setResourcePath(QFileInfo(fileName).absolutePath()); m_d->itemLibraryView->widget()->setResourcePath(QFileInfo(fileName).absolutePath());
emit displayNameChanged(displayName()); emit displayNameChanged(displayName());
} }
...@@ -354,8 +355,8 @@ void DesignDocumentController::loadCurrentModel() ...@@ -354,8 +355,8 @@ void DesignDocumentController::loadCurrentModel()
m_d->model->attachView(m_d->nodeInstanceView.data()); m_d->model->attachView(m_d->nodeInstanceView.data());
m_d->model->attachView(m_d->navigator.data()); m_d->model->attachView(m_d->navigator.data());
m_d->itemLibrary->setItemLibraryInfo(m_d->model->metaInfo().itemLibraryInfo()); m_d->itemLibraryView->widget()->setItemLibraryInfo(m_d->model->metaInfo().itemLibraryInfo());
m_d->itemLibrary->setResourcePath(QFileInfo(m_d->fileName).absolutePath()); m_d->itemLibraryView->widget()->setResourcePath(QFileInfo(m_d->fileName).absolutePath());
if (!m_d->componentAction) { if (!m_d->componentAction) {
m_d->componentAction = new ComponentAction(m_d->formEditorView->widget()); m_d->componentAction = new ComponentAction(m_d->formEditorView->widget());
...@@ -366,9 +367,10 @@ void DesignDocumentController::loadCurrentModel() ...@@ -366,9 +367,10 @@ void DesignDocumentController::loadCurrentModel()
// Disable switching between in file components for the time being // Disable switching between in file components for the time being
m_d->componentAction->setVisible(false); m_d->componentAction->setVisible(false);
connect(m_d->itemLibrary.data(), SIGNAL(itemActivated(const QString&)), m_d->formEditorView.data(), SLOT(activateItemCreator(const QString&))); connect(m_d->itemLibraryView->widget(), SIGNAL(itemActivated(const QString&)), m_d->formEditorView.data(), SLOT(activateItemCreator(const QString&)));
m_d->model->attachView(m_d->formEditorView.data()); m_d->model->attachView(m_d->formEditorView.data());
m_d->model->attachView(m_d->itemLibraryView.data());
if (!m_d->textEdit->parent()) // hack to prevent changing owner of external text edit if (!m_d->textEdit->parent()) // hack to prevent changing owner of external text edit
......
...@@ -51,7 +51,7 @@ class ModelNode; ...@@ -51,7 +51,7 @@ class ModelNode;
class TextModifier; class TextModifier;
class QmlObjectNode; class QmlObjectNode;
class RewriterView; class RewriterView;
class ItemLibrary; class ItemLibraryView;
class NavigatorView; class NavigatorView;
class AllPropertiesBox; class AllPropertiesBox;
class StatesEditorView; class StatesEditorView;
...@@ -89,7 +89,7 @@ public: ...@@ -89,7 +89,7 @@ public:
QString contextHelpId() const; QString contextHelpId() const;
QList<RewriterView::Error> qmlErrors() const; QList<RewriterView::Error> qmlErrors() const;
void setItemLibrary(ItemLibrary* itemLibrary); void setItemLibraryView(ItemLibraryView* itemLibraryView);
void setNavigator(NavigatorView* navigatorView); void setNavigator(NavigatorView* navigatorView);
void setAllPropertiesBox(AllPropertiesBox* allPropertiesBox); void setAllPropertiesBox(AllPropertiesBox* allPropertiesBox);
void setStatesEditorView(StatesEditorView* statesEditorView); void setStatesEditorView(StatesEditorView* statesEditorView);
......
...@@ -39,7 +39,7 @@ QT_END_NAMESPACE ...@@ -39,7 +39,7 @@ QT_END_NAMESPACE
namespace QmlDesigner { namespace QmlDesigner {
class ItemLibrary; class ItemLibraryWidget;
class FormWindowManager; class FormWindowManager;
class PluginManager; class PluginManager;
class CorePrivate; class CorePrivate;
......
...@@ -6,8 +6,8 @@ VPATH += $$PWD ...@@ -6,8 +6,8 @@ VPATH += $$PWD
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
# Input # Input
HEADERS += itemlibrary.h customdraganddrop.h itemlibrarymodel.h itemlibrarywidgets.h itemlibraryimageprovider.h HEADERS += itemlibraryview.h itemlibrarywidget.h customdraganddrop.h itemlibrarymodel.h itemlibrarycomponents.h itemlibraryimageprovider.h
SOURCES += itemlibrary.cpp customdraganddrop.cpp itemlibrarymodel.cpp itemlibrarywidgets.cpp itemlibraryimageprovider.cpp SOURCES += itemlibraryview.cpp itemlibrarywidget.cpp customdraganddrop.cpp itemlibrarymodel.cpp itemlibrarycomponents.cpp itemlibraryimageprovider.cpp
RESOURCES += itemlibrary.qrc RESOURCES += itemlibrary.qrc
OTHER_FILES += \ OTHER_FILES += \
......
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
** **
**************************************************************************/ **************************************************************************/
#include "itemlibrarywidgets.h" #include "itemlibrarycomponents.h"
#include "itemlibrary.h"
#include "customdraganddrop.h" #include "customdraganddrop.h"
#include <QtCore/QMimeData> #include <QtCore/QMimeData>
......
#include "itemlibraryview.h"
#include "itemlibrarywidget.h"
namespace QmlDesigner {
ItemLibraryView::ItemLibraryView(QObject* parent) : AbstractView(parent), m_widget(new ItemLibraryWidget)
{
}
ItemLibraryView::~ItemLibraryView()
{
}
ItemLibraryWidget *ItemLibraryView::widget()
{
return m_widget.data();
}
void ItemLibraryView::modelAttached(Model *model)
{
AbstractView::modelAttached(model);
}
void ItemLibraryView::modelAboutToBeDetached(Model *model)
{
AbstractView::modelAboutToBeDetached(model);
}
void ItemLibraryView::importAdded(const Import &import)
{
}
void ItemLibraryView::importRemoved(const Import &import)
{
}
void ItemLibraryView::nodeCreated(const ModelNode &)
{
}
void ItemLibraryView::nodeRemoved(const ModelNode &, const NodeAbstractProperty &, PropertyChangeFlags)
{
}
void ItemLibraryView::propertiesRemoved(const QList<AbstractProperty> &)
{
}
void ItemLibraryView::variantPropertiesChanged(const QList<VariantProperty> &, PropertyChangeFlags)
{
}
void ItemLibraryView::bindingPropertiesChanged(const QList<BindingProperty> &, PropertyChangeFlags)
{
}
void ItemLibraryView::nodeAboutToBeRemoved(const ModelNode &)
{
}
void ItemLibraryView::nodeOrderChanged(const NodeListProperty &, const ModelNode &, int)
{
}
void ItemLibraryView::nodeAboutToBeReparented(const ModelNode &, const NodeAbstractProperty &, const NodeAbstractProperty &, AbstractView::PropertyChangeFlags)
{
}
void ItemLibraryView::nodeReparented(const ModelNode &, const NodeAbstractProperty &, const NodeAbstractProperty &, AbstractView::PropertyChangeFlags)
{
}
void ItemLibraryView::rootNodeTypeChanged(const QString &, int , int )
{
}
void ItemLibraryView::nodeIdChanged(const ModelNode &, const QString &, const QString& )
{
}
void ItemLibraryView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& )
{
}
void ItemLibraryView::selectedNodesChanged(const QList<ModelNode> &,
const QList<ModelNode> &)
{
}
void ItemLibraryView::auxiliaryDataChanged(const ModelNode &, const QString &, const QVariant &)
{
}
void ItemLibraryView::scriptFunctionsChanged(const ModelNode &, const QStringList &)
{
}
void ItemLibraryView::instancePropertyChange(const QList<QPair<ModelNode, QString> > &)
{
}
void ItemLibraryView::instancesCompleted(const QVector<ModelNode> &)
{
}
} //QmlDesigner
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef ITEMLIBRARYVIEW_H
#define ITEMLIBRARYVIEW_H
#include <abstractview.h>
#include <QWeakPointer>
namespace QmlDesigner {
class ItemLibraryWidget;
class ItemLibraryView : public AbstractView
{
Q_OBJECT
public:
ItemLibraryView(QObject* parent = 0);
~ItemLibraryView();
ItemLibraryWidget *widget();
// AbstractView
void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model);
void importAdded(const Import &import);
void importRemoved(const Import &import);
void nodeCreated(const ModelNode &createdNode);
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
void propertiesRemoved(const QList<AbstractProperty> &propertyList);
void variantPropertiesChanged(const QList<VariantProperty> &propertyList, PropertyChangeFlags propertyChange);
void bindingPropertiesChanged(const QList<BindingProperty> &propertyList, PropertyChangeFlags propertyChange);
void nodeAboutToBeRemoved(const ModelNode &removedNode);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void nodeAboutToBeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
void propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList);
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
private:
QWeakPointer<ItemLibraryWidget> m_widget;
};
}
#endif // ITEMLIBRARYVIEW_H
...@@ -27,10 +27,10 @@ ...@@ -27,10 +27,10 @@
** **
**************************************************************************/ **************************************************************************/
#include "itemlibrary.h" #include "itemlibrarywidget.h"
#include <utils/filterlineedit.h> #include <utils/filterlineedit.h>
#include "itemlibrarywidgets.h" #include "itemlibrarycomponents.h"
#include "itemlibrarymodel.h" #include "itemlibrarymodel.h"
#include "itemlibraryimageprovider.h" #include "itemlibraryimageprovider.h"
#include "customdraganddrop.h" #include "customdraganddrop.h"
...@@ -92,9 +92,9 @@ private: ...@@ -92,9 +92,9 @@ private:
// ---------- ItemLibraryPrivate // ---------- ItemLibraryPrivate
class ItemLibraryPrivate { class ItemLibraryWidgetPrivate {
public: public:
ItemLibraryPrivate(QObject *object); ItemLibraryWidgetPrivate(QObject *object);
Internal::ItemLibraryModel *m_itemLibraryModel; Internal::ItemLibraryModel *m_itemLibraryModel;
QDirModel *m_resourcesDirModel; QDirModel *m_resourcesDirModel;
...@@ -109,7 +109,7 @@ public: ...@@ -109,7 +109,7 @@ public:
MyFileIconProvider m_iconProvider; MyFileIconProvider m_iconProvider;
}; };
ItemLibraryPrivate::ItemLibraryPrivate(QObject *object) : ItemLibraryWidgetPrivate::ItemLibraryWidgetPrivate(QObject *object) :
m_itemLibraryModel(0), m_itemLibraryModel(0),
m_resourcesDirModel(0), m_resourcesDirModel(0),
m_stackedWidget(0), m_stackedWidget(0),
...@@ -123,9 +123,9 @@ ItemLibraryPrivate::ItemLibraryPrivate(QObject *object) : ...@@ -123,9 +123,9 @@ ItemLibraryPrivate::ItemLibraryPrivate(QObject *object) :
Q_UNUSED(object); Q_UNUSED(object);
} }
ItemLibrary::ItemLibrary(QWidget *parent) : ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
QFrame(parent), QFrame(parent),
m_d(new ItemLibraryPrivate(this)) m_d(new ItemLibraryWidgetPrivate(this))
{ {
setWindowTitle(tr("Library", "Title of library view")); setWindowTitle(tr("Library", "Title of library view"));
...@@ -230,7 +230,7 @@ ItemLibrary::ItemLibrary(QWidget *parent) : ...@@ -230,7 +230,7 @@ ItemLibrary::ItemLibrary(QWidget *parent) :
} }
} }
ItemLibrary::~ItemLibrary() ItemLibraryWidget::~ItemLibraryWidget()
{ {
/* workaround: delete the items view before the model is deleted. /* workaround: delete the items view before the model is deleted.
This prevents qml warnings when the item library is destructed. */ This prevents qml warnings when the item library is destructed. */
...@@ -239,7 +239,7 @@ ItemLibrary::~ItemLibrary() ...@@ -239,7 +239,7 @@ ItemLibrary::~ItemLibrary()
delete m_d; delete m_d;
} }
void ItemLibrary::setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo) void ItemLibraryWidget::setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo)
{ {
if (m_d->m_itemLibraryInfo.data() == itemLibraryInfo) if (m_d->m_itemLibraryInfo.data() == itemLibraryInfo)
return; return;
...@@ -256,7 +256,7 @@ void ItemLibrary::setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo) ...@@ -256,7 +256,7 @@ void ItemLibrary::setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo)
updateSearch(); updateSearch();
} }
void ItemLibrary::setSearchFilter(const QString &searchFilter) void ItemLibraryWidget::setSearchFilter(const QString &searchFilter)
{ {
if (m_d->m_stackedWidget->currentIndex() == 0) { if (m_d->m_stackedWidget->currentIndex() == 0) {
m_d->m_itemLibraryModel->setSearchText(searchFilter); m_d->m_itemLibraryModel->setSearchText(searchFilter);
...@@ -279,25 +279,25 @@ void ItemLibrary::setSearchFilter(const QString &searchFilter) ...@@ -279,25 +279,25 @@ void ItemLibrary::setSearchFilter(const QString &searchFilter)
} }
} }
void ItemLibrary::updateModel() void ItemLibraryWidget::updateModel()
{ {
m_d->m_itemLibraryModel->update(m_d->m_itemLibraryInfo.data()); m_d->m_itemLibraryModel->update(m_d->m_itemLibraryInfo.data());
updateSearch(); updateSearch();
} }
void ItemLibrary::updateSearch() void ItemLibraryWidget::updateSearch()
{ {
setSearchFilter(m_d->m_lineEdit->text()); setSearchFilter(m_d->m_lineEdit->text());
} }
void ItemLibrary::setResourcePath(const QString &resourcePath) void ItemLibraryWidget::setResourcePath(const QString &resourcePath)
{ {
if (m_d->m_resourcesView->model() == m_d->m_resourcesDirModel) if (m_d->m_resourcesView->model() == m_d->m_resourcesDirModel)
m_d->m_resourcesView->setRootIndex(m_d->m_resourcesDirModel->index(resourcePath)); m_d->m_resourcesView->setRootIndex(m_d->m_resourcesDirModel->index(resourcePath));
updateSearch(); updateSearch();
} }
void ItemLibrary::startDragAndDrop(int itemLibId) void ItemLibraryWidget::startDragAndDrop(int itemLibId)
{ {
QMimeData *mimeData = m_d->m_itemLibraryModel->getMimeData(itemLibId); QMimeData *mimeData = m_d->m_itemLibraryModel->getMimeData(itemLibId);
CustomItemLibraryDrag *drag = new CustomItemLibraryDrag(this); CustomItemLibraryDrag *drag = new CustomItemLibraryDrag(this);
...@@ -313,12 +313,12 @@ void ItemLibrary::startDragAndDrop(int itemLibId) ...@@ -313,12 +313,12 @@ void ItemLibrary::startDragAndDrop(int itemLibId)
drag->exec(); drag->exec();
} }
void ItemLibrary::showItemInfo(int /*itemLibId*/) void ItemLibraryWidget::showItemInfo(int /*itemLibId*/)
{ {
// qDebug() << "showing item info about id" << itemLibId; // qDebug() << "showing item info about id" << itemLibId;
} }
void ItemLibrary::wheelEvent(QWheelEvent *event) void ItemLibraryWidget::wheelEvent(QWheelEvent *event)
{ {
if (m_d->m_stackedWidget->currentIndex() == 0 && if (m_d->m_stackedWidget->currentIndex() == 0 &&
m_d->m_itemsView->rect().contains(event->pos())) { m_d->m_itemsView->rect().contains(event->pos())) {
......
...@@ -27,26 +27,26 @@ ...@@ -27,26 +27,26 @@
** **
**************************************************************************/ **************************************************************************/
#ifndef ITEMLIBRARY_H #ifndef ITEMLIBRARYWIDGET_H
#define ITEMLIBRARY_H #define ITEMLIBRARYWIDGET_H
#include "itemlibraryinfo.h" #include "itemlibraryinfo.h"
#include <QtGui/QFrame> #include <QtGui/QFrame>
namespace QmlDesigner { namespace QmlDesigner {
class ItemLibraryPrivate; class ItemLibraryWidgetPrivate;
class MetaInfo; class MetaInfo;
class ItemLibraryEntry; class ItemLibraryEntry;
class ItemLibrary : public QFrame class ItemLibraryWidget : public QFrame