Commit 2e06f98a authored by Tim Jenssen's avatar Tim Jenssen
Browse files

QmlDesigner: convert itemIds to real entries



Change-Id: I421d20a33f8f30fe796f72e4500a2756b97c7983
Reviewed-by: default avatarMarco Bubke <marco.bubke@digia.com>
parent 1da0d018
......@@ -83,8 +83,8 @@ void ItemLibraryItem::setItemLibraryEntry(const ItemLibraryEntry &itemLibraryEnt
m_itemLibraryEntry = itemLibraryEntry;
}
ItemLibraryEntry ItemLibraryItem::itemLibraryEntry() const
QVariant ItemLibraryItem::itemLibraryEntry() const
{
return m_itemLibraryEntry;
return QVariant::fromValue(m_itemLibraryEntry);
}
} // namespace QmlDesigner
......@@ -44,7 +44,7 @@ class ItemLibraryItem: public QObject {
Q_OBJECT
Q_PROPERTY(int itemLibId READ itemLibId FINAL)
Q_PROPERTY(ItemLibraryEntry itemLibraryEntry READ itemLibraryEntry FINAL)
Q_PROPERTY(QVariant itemLibraryEntry READ itemLibraryEntry FINAL)
Q_PROPERTY(QString itemName READ itemName FINAL)
Q_PROPERTY(QString itemLibraryIconPath READ itemLibraryIconPath FINAL)
Q_PROPERTY(QVariant sortingRole READ sortingRole FINAL)
......@@ -62,7 +62,7 @@ public:
bool isVisible() const;
void setItemLibraryEntry(const ItemLibraryEntry &itemLibraryEntry);
ItemLibraryEntry itemLibraryEntry() const;
QVariant itemLibraryEntry() const;
private:
ItemLibraryEntry m_itemLibraryEntry;
......
......@@ -196,13 +196,13 @@ QString ItemLibraryModel::getTypeName(int libId)
}
QMimeData *ItemLibraryModel::getMimeData(int libId)
QMimeData *ItemLibraryModel::getMimeData(const ItemLibraryEntry &itemLibraryEntry)
{
QMimeData *mimeData = new QMimeData();
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly);
stream << m_itemInfos.value(libId);
stream << itemLibraryEntry;
mimeData->setData(QStringLiteral("application/vnd.bauhaus.itemlibraryinfo"), data);
mimeData->removeFormat(QStringLiteral("text/plain"));
......
......@@ -61,7 +61,7 @@ public:
void update(ItemLibraryInfo *itemLibraryInfo, Model *model);
QString getTypeName(int libId);
QMimeData *getMimeData(int libId);
QMimeData *getMimeData(const ItemLibraryEntry &itemLibraryEntry);
QPixmap getLibraryEntryIcon(int libId);
ItemLibrarySection* section(int libraryId);
......
......@@ -64,8 +64,7 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
m_iconProvider(m_resIconSize),
m_itemsView(new QQuickView()),
m_resourcesView(new ItemLibraryTreeView(this)),
m_filterFlag(QtBasic),
m_itemLibraryId(-1)
m_filterFlag(QtBasic)
{
ItemLibraryModel::registerQmlTypes();
......@@ -79,6 +78,7 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
rootContext->setContextProperty(QStringLiteral("itemLibraryModel"), m_itemLibraryModel.data());
rootContext->setContextProperty(QStringLiteral("itemLibraryIconWidth"), m_itemIconSize.width());
rootContext->setContextProperty(QStringLiteral("itemLibraryIconHeight"), m_itemIconSize.height());
rootContext->setContextProperty(QStringLiteral("rootView"), this);
m_itemsView->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
......@@ -297,10 +297,6 @@ void ItemLibraryWidget::reloadQmlSource()
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)));
}
void ItemLibraryWidget::setImportFilter(FilterChangeFlag flag)
......@@ -373,28 +369,23 @@ void ItemLibraryWidget::setResourcePath(const QString &resourcePath)
updateSearch();
}
void ItemLibraryWidget::startDragAndDropDelayed(int itemLibraryId)
void ItemLibraryWidget::startDragAndDropDelayed(QVariant itemLibraryId)
{
m_itemLibraryId = itemLibraryId;
m_currentitemLibraryEntry = itemLibraryId.value<ItemLibraryEntry>();
QTimer::singleShot(0, this, SLOT(startDragAndDrop()));
}
void ItemLibraryWidget::startDragAndDrop()
{
QMimeData *mimeData = m_itemLibraryModel->getMimeData(m_itemLibraryId);
QMimeData *mimeData = m_itemLibraryModel->getMimeData(m_currentitemLibraryEntry);
QDrag *drag = new QDrag(this);
drag->setPixmap(m_itemLibraryModel->getLibraryEntryIcon(m_itemLibraryId));
drag->setPixmap(m_currentitemLibraryEntry.libraryEntryIconPath());
drag->setMimeData(mimeData);
drag->exec();
}
void ItemLibraryWidget::showItemInfo(int /*itemLibId*/)
{
// qDebug() << "showing item info about id" << itemLibId;
}
void ItemLibraryWidget::removeImport(const QString &name)
{
if (!m_model)
......
......@@ -96,9 +96,8 @@ public slots:
void setResourcePath(const QString &resourcePath);
void startDragAndDropDelayed(int itemLibId);
void startDragAndDropDelayed(QVariant itemLibId);
void startDragAndDrop();
void showItemInfo(int itemLibId);
void setModel(Model *model);
......@@ -140,7 +139,7 @@ private:
QPointer<Model> m_model;
FilterChangeFlag m_filterFlag;
int m_itemLibraryId;
ItemLibraryEntry m_currentitemLibraryEntry;
};
}
......
......@@ -124,5 +124,6 @@ private: // variables
} // namespace QmlDesigner
QML_DECLARE_TYPE(QmlDesigner::ItemLibraryEntry)
Q_DECLARE_METATYPE(QmlDesigner::ItemLibraryEntry)
#endif // ITEMLIBRARYINFO_H
Supports Markdown
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