From 435de838922fe9594aa46afd24f9e207126f24ee Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Mon, 23 Jun 2014 17:54:46 +0200 Subject: [PATCH] QmlDesigner: Cleanup item library Change-Id: I863ae9a3e84ee6af7be56fa8ebf5a350f8e2db34 Reviewed-by: Tim Jenssen --- .../itemlibrary/itemlibrarymodel.cpp | 68 +++---------------- .../components/itemlibrary/itemlibrarymodel.h | 6 +- .../itemlibrary/itemlibrarysection.cpp | 2 - .../itemlibrary/itemlibrarysectionmodel.cpp | 25 ------- .../itemlibrary/itemlibrarysectionmodel.h | 2 - 5 files changed, 11 insertions(+), 92 deletions(-) diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp index 3d9e0538995..ad09b001860 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp @@ -63,8 +63,7 @@ void ItemLibraryModel::setExpanded(bool expanded, const QString §ion) } ItemLibraryModel::ItemLibraryModel(QObject *parent) - : QAbstractListModel(parent), - m_nextLibId(0) + : QAbstractListModel(parent) { addRoleNames(); } @@ -76,17 +75,17 @@ ItemLibraryModel::~ItemLibraryModel() int ItemLibraryModel::rowCount(const QModelIndex & /*parent*/) const { - return m_sectionModels.count(); + return m_sections.count(); } QVariant ItemLibraryModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || index.row() +1 > m_sectionModels.count()) + if (!index.isValid() || index.row() +1 > m_sections.count()) return QVariant(); if (m_roleNames.contains(role)) { - QVariant value = m_sectionModels.at(index.row())->property(m_roleNames.value(role)); + QVariant value = m_sections.at(index.row())->property(m_roleNames.value(role)); ItemLibrarySectionModel* model = qobject_cast(value.value()); if (model) @@ -140,7 +139,6 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model) QMap sections; clearSections(); - m_nextLibId = 0; QStringList imports; foreach (const Import &import, model->imports()) @@ -161,7 +159,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model) if (sectionModel == 0) { sectionModel = new ItemLibrarySection(itemSectionName, this); - m_sectionModels.append(sectionModel); + m_sections.append(sectionModel); } itemModel = new ItemLibraryItem(sectionModel); @@ -190,14 +188,14 @@ QMimeData *ItemLibraryModel::getMimeData(const ItemLibraryEntry &itemLibraryEntr QList ItemLibraryModel::sections() const { - return m_sectionModels; + return m_sections; } void ItemLibraryModel::clearSections() { beginResetModel(); - qDeleteAll(m_sectionModels); - m_sectionModels.clear(); + qDeleteAll(m_sections); + m_sections.clear(); endResetModel(); } @@ -207,33 +205,9 @@ void ItemLibraryModel::registerQmlTypes() qmlRegisterType(); } -int ItemLibraryModel::visibleSectionCount() const -{ - int visibleCount = 0; - - foreach (ItemLibrarySection *section, m_sectionModels) { - if (section->isVisible()) - ++visibleCount; - } - - return visibleCount; -} - -QList ItemLibraryModel::visibleSections() const -{ - QList visibleSectionList; - - foreach (ItemLibrarySection *section, m_sectionModels) { - if (section->isVisible()) - visibleSectionList.append(section); - } - - return visibleSectionList; -} - ItemLibrarySection *ItemLibraryModel::sectionByName(const QString §ionName) { - foreach (ItemLibrarySection *itemLibrarySection, m_sectionModels) { + foreach (ItemLibrarySection *itemLibrarySection, m_sections) { if (itemLibrarySection->sectionName() == sectionName) return itemLibrarySection; } @@ -245,7 +219,7 @@ void ItemLibraryModel::updateVisibility() { bool changed = false; - foreach (ItemLibrarySection *itemLibrarySection, m_sectionModels) { + foreach (ItemLibrarySection *itemLibrarySection, m_sections) { QString sectionSearchText = m_searchText; if (itemLibrarySection->sectionName().toLower().contains(m_searchText)) @@ -280,28 +254,6 @@ void ItemLibraryModel::resetModel() endResetModel(); } -int ItemLibraryModel::getWidth(const ItemLibraryEntry &itemLibraryEntry) -{ - foreach (const ItemLibraryEntry::Property &property, itemLibraryEntry.properties()) - { - if (property.name() == "width") - return property.value().toInt(); - } - - return 64; -} - -int ItemLibraryModel::getHeight(const ItemLibraryEntry &itemLibraryEntry) -{ - foreach (const ItemLibraryEntry::Property &property, itemLibraryEntry.properties()) - { - if (property.name() == "height") - return property.value().toInt(); - } - - return 64; -} - void registerQmlTypes() { registerItemLibrarySortedModel(); diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h index 009c3bd9974..9a86453d9cd 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h @@ -87,16 +87,12 @@ private: // functions void addRoleNames(); void resetModel(); - int getWidth(const ItemLibraryEntry &entry); - int getHeight(const ItemLibraryEntry &entry); private: // variables - QList m_sectionModels; + QList m_sections; QHash m_roleNames; QString m_searchText; - QSize m_itemIconSize; - int m_nextLibId; }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.cpp index a3170258384..513fd0f117e 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.cpp @@ -40,8 +40,6 @@ ItemLibrarySection::ItemLibrarySection(const QString §ionName, QObject *pare m_sectionExpanded(true), m_isVisible(true) { -// if (collapsedStateHash.contains(sectionName)) -// m_sectionExpanded= collapsedStateHash.value(sectionName); } diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp index 27cc4584241..b43632d95c0 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp @@ -92,7 +92,6 @@ void ItemLibrarySectionModel::resetModel() { beginResetModel(); endResetModel(); - emit dataChanged(QModelIndex(), QModelIndex()); } void ItemLibrarySectionModel::addRoleNames() @@ -107,28 +106,4 @@ void ItemLibrarySectionModel::addRoleNames() setRoleNames(m_roleNames); } -int ItemLibrarySectionModel::visibleItemCount() const -{ - int visibleItemCount = 0; - - foreach (ItemLibraryItem *itemLibraryItem, m_itemList) { - if (itemLibraryItem->isVisible()) - visibleItemCount += 1; - } - - return visibleItemCount; -} - -const QList ItemLibrarySectionModel::visibleItems() const -{ - QList visibleItemList; - - foreach (ItemLibraryItem *itemLibraryItem, m_itemList) { - if (itemLibraryItem->isVisible()) - visibleItemList.append(itemLibraryItem); - } - - return visibleItemList; -} - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h index e61d93293c3..f47d75183a4 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h @@ -59,8 +59,6 @@ public: private: // functions void addRoleNames(); - int visibleItemCount() const; - const QList visibleItems() const; private: // variables QList m_itemList;