Commit ef87889b authored by Tim Jenssen's avatar Tim Jenssen

QmlDesigner: add reload feature to item library view

Change-Id: Ib71dc235abd059056063c5d9b9072c8bdc932762
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 94887ce5
......@@ -22,11 +22,3 @@ SOURCES += itemlibraryview.cpp \
itemlibrarysection.cpp
RESOURCES += itemlibrary.qrc
OTHER_FILES += \
qml/Selector.qml \
qml/SectionView.qml \
qml/Scrollbar.qml \
qml/ItemView.qml \
qml/ItemsViewStyle.qml \
qml/ItemsView.qml
<RCC>
<qresource prefix="/ItemLibrary" >
<file>qml/ItemsView.qml</file>
<file>qml/ItemsViewStyle.qml</file>
<file>qml/SectionView.qml</file>
<file>qml/SingleItemView.qml</file>
<file>qml/Selector.qml</file>
<file>images/item-default-icon.png</file>
<file>images/item-invalid-icon.png</file>
</qresource>
......
......@@ -30,7 +30,9 @@
#include "itemlibrarywidget.h"
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include "itemlibrarymodel.h"
#include "itemlibraryimageprovider.h"
#include <model.h>
......@@ -48,7 +50,7 @@
#include <QMenu>
#include <QApplication>
#include <QTimer>
#include <QShortcut>
#include <QQuickItem>
enum {
......@@ -87,14 +89,6 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
m_itemsView->rootContext()->setContextProperty(QStringLiteral("highlightColor"), highlightColor);
// loading the qml has to come after all needed context properties are set
m_itemsView->setSource(QUrl("qrc:/ItemLibrary/qml/ItemsView.qml"));
QQuickItem *rootItem = qobject_cast<QQuickItem*>(m_itemsView->rootObject());
connect(rootItem, SIGNAL(itemSelected(int)), this, SLOT(showItemInfo(int)));
connect(rootItem, SIGNAL(itemDragged(int)), this, SLOT(startDragAndDropDelayed(int)));
connect(this, SIGNAL(scrollItemsView(QVariant)), rootItem, SLOT(scrollView(QVariant)));
connect(this, SIGNAL(resetItemsView()), rootItem, SLOT(resetView()));
/* create Resources view and its model */
m_resourcesFileSystemModel = new QFileSystemModel(this);
......@@ -155,6 +149,12 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
/* style sheets */
setStyleSheet(QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css")));
m_resourcesView->setStyleSheet(QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css")));
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F5), this);
connect(m_qmlSourceUpdateShortcut, SIGNAL(activated()), this, SLOT(reloadQmlSource()));
// init the first load of the QML UI elements
reloadQmlSource();
}
void ItemLibraryWidget::setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo)
......@@ -295,6 +295,26 @@ void ItemLibraryWidget::setCurrentIndexOfStackedWidget(int index)
m_stackedWidget->setCurrentIndex(index);
}
QString ItemLibraryWidget::qmlSourcesPath()
{
return Core::ICore::resourcePath() + QStringLiteral("/qmldesigner/itemLibraryQmlSources");
}
void ItemLibraryWidget::reloadQmlSource()
{
QString itemLibraryQmlFilePath = qmlSourcesPath() + QStringLiteral("/ItemsView.qml");
QTC_ASSERT(QFileInfo::exists(itemLibraryQmlFilePath), return);
m_itemsView->engine()->clearComponentCache();
m_itemsView->setSource(QUrl::fromLocalFile(itemLibraryQmlFilePath));
QQuickItem *rootItem = qobject_cast<QQuickItem*>(m_itemsView->rootObject());
connect(rootItem, SIGNAL(itemSelected(int)), this, SLOT(showItemInfo(int)));
connect(rootItem, SIGNAL(itemDragged(int)), this, SLOT(startDragAndDropDelayed(int)));
connect(this, SIGNAL(scrollItemsView(QVariant)), rootItem, SLOT(scrollView(QVariant)));
connect(this, SIGNAL(resetItemsView()), rootItem, SLOT(resetView()));
}
void ItemLibraryWidget::setImportFilter(FilterChangeFlag flag)
{
return;
......
......@@ -43,6 +43,7 @@
QT_BEGIN_NAMESPACE
class QFileSystemModel;
class QStackedWidget;
class QShortcut;
QT_END_NAMESPACE
namespace QmlDesigner {
......@@ -87,6 +88,7 @@ public:
void setImportsWidget(QWidget *importsWidget);
static QString qmlSourcesPath();
public slots:
void setSearchFilter(const QString &searchFilter);
void updateModel();
......@@ -119,6 +121,7 @@ signals:
private slots:
void setCurrentIndexOfStackedWidget(int index);
void reloadQmlSource();
private:
QSize m_itemIconSize;
......@@ -135,6 +138,7 @@ private:
QPointer<Utils::FancyLineEdit> m_filterLineEdit;
QScopedPointer<QQuickView> m_itemsView;
QScopedPointer<ItemLibraryTreeView> m_resourcesView;
QShortcut *m_qmlSourceUpdateShortcut;
QPointer<Model> m_model;
FilterChangeFlag m_filterFlag;
......
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