Commit e5104799 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmkDesigner: Refactor ItemLibraryItem



Change-Id: I0876f3b94df6ea0cf457e67306c89a798f0c8bfd
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent 9c8fa496
......@@ -31,11 +31,9 @@
namespace QmlDesigner {
ItemLibraryItem::ItemLibraryItem(int itemLibId, const QString &itemName, QObject *parent)
ItemLibraryItem::ItemLibraryItem(int itemLibId, QObject *parent)
: QObject(parent),
m_libId(itemLibId),
m_name(itemName),
m_iconSize(64, 64)
m_libId(itemLibId)
{
}
......@@ -51,13 +49,13 @@ int ItemLibraryItem::itemLibId() const
QString ItemLibraryItem::itemName() const
{
return m_name;
return m_itemLibraryEntry.name();
}
QString ItemLibraryItem::itemLibraryIconPath() const
{
//Prepend image provider prefix
return QStringLiteral("image://qmldesigner_itemlibrary/") + m_iconPath;
return QStringLiteral("image://qmldesigner_itemlibrary/") + m_itemLibraryEntry.libraryEntryIconPath();
}
QVariant ItemLibraryItem::sortingRole() const
......@@ -65,17 +63,6 @@ QVariant ItemLibraryItem::sortingRole() const
return itemName();
}
void ItemLibraryItem::setItemIconPath(const QString &iconPath)
{
m_iconPath = iconPath;
}
void ItemLibraryItem::setItemIconSize(const QSize &itemIconSize)
{
m_iconSize = itemIconSize;
setItemIconPath(m_iconPath);
}
bool ItemLibraryItem::setVisible(bool isVisible)
{
if (isVisible != m_isVisible) {
......
......@@ -50,7 +50,7 @@ class ItemLibraryItem: public QObject {
Q_PROPERTY(QVariant sortingRole READ sortingRole FINAL)
public:
ItemLibraryItem(int itemLibId, const QString &itemName, QObject *parent);
ItemLibraryItem(int itemLibId, QObject *parent);
~ItemLibraryItem();
int itemLibId() const;
......@@ -58,9 +58,6 @@ public:
QString itemLibraryIconPath() const;
QVariant sortingRole() const;
void setItemIconPath(const QString &iconPath);
void setItemIconSize(const QSize &itemIconSize);
bool setVisible(bool isVisible);
bool isVisible() const;
......@@ -71,9 +68,6 @@ private:
ItemLibraryEntry m_itemLibraryEntry;
int m_libId;
bool m_isVisible;
QString m_name;
QString m_iconPath;
QSize m_iconSize;
};
} // namespace QmlDesigner
......
......@@ -64,7 +64,6 @@ void ItemLibraryModel::setExpanded(bool expanded, const QString &section)
ItemLibraryModel::ItemLibraryModel(QObject *parent)
: QAbstractListModel(parent),
m_itemIconSize(64, 64),
m_nextLibId(0)
{
addRoleNames();
......@@ -123,16 +122,6 @@ void ItemLibraryModel::setSearchText(const QString &searchText)
}
}
void ItemLibraryModel::setItemIconSize(const QSize &itemIconSize)
{
m_itemIconSize = itemIconSize;
foreach (ItemLibrarySection* itemLibrarySectionModel, sections()) {
itemLibrarySectionModel->updateItemIconSize(itemIconSize);
}
}
int ItemLibraryModel::getSectionLibId(int itemLibId)
{
return m_sections.value(itemLibId);
......@@ -190,10 +179,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
m_itemInfos.insert(itemId, entry);
itemModel = new ItemLibraryItem(itemId, entry.name(), sectionModel);
itemModel->setItemIconPath(entry.libraryEntryIconPath());
itemModel->setItemIconSize(m_itemIconSize);
itemModel = new ItemLibraryItem(itemId, sectionModel);
itemModel->setItemLibraryEntry(entry);
sectionModel->addSectionEntry(itemModel);
m_sections.insert(itemId, sectionId);
......
......@@ -77,7 +77,6 @@ public:
public slots:
void setSearchText(const QString &searchText);
void setItemIconSize(const QSize &itemIconSize);
int getSectionLibId(int itemLibId);
void setExpanded(bool, const QString &section);
......
......@@ -106,12 +106,6 @@ bool ItemLibrarySection::updateSectionVisibility(const QString &searchText, bool
}
void ItemLibrarySection::updateItemIconSize(const QSize &itemIconSize)
{
foreach (ItemLibraryItem* itemLibraryItemModel, m_sectionEntries.items())
itemLibraryItemModel->setItemIconSize(itemIconSize);
}
bool ItemLibrarySection::setVisible(bool isVisible)
{
if (isVisible != m_isVisible) {
......
......@@ -55,7 +55,6 @@ public:
QObject *sectionEntries();
bool updateSectionVisibility(const QString &searchText, bool *changed);
void updateItemIconSize(const QSize &itemIconSize);
bool setVisible(bool isVisible);
bool isVisible() const;
......
......@@ -74,7 +74,6 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
/* create Items view and its model */
m_itemsView->setResizeMode(QQuickView::SizeRootObjectToView);
m_itemLibraryModel = new ItemLibraryModel(this);
m_itemLibraryModel->setItemIconSize(m_itemIconSize);
QQmlContext *rootContext = m_itemsView->rootContext();
rootContext->setContextProperty(QStringLiteral("itemLibraryModel"), m_itemLibraryModel.data());
......
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