diff options
author | Marco Bubke <marco.bubke@digia.com> | 2014-05-21 18:27:08 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@digia.com> | 2014-06-03 17:46:40 +0200 |
commit | b3ed42d8fb4709808a5363a314552cfea161f796 (patch) | |
tree | b44e8150fe32b8f096fe65db7af74e44e751ee35 | |
parent | b29fa169ab1fd6ed9b58afaad3b2be2d3051c6b8 (diff) | |
download | qt-creator-b3ed42d8fb4709808a5363a314552cfea161f796.tar.gz |
QmlDesigner: Move ItemLibrarySectionModel to ItemLibrarySection
Change-Id: Ic5410da35c67f5447a288299f40a0d4ab9f09d12
Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
7 files changed, 262 insertions, 184 deletions
diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.pri b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.pri index c7310aa88a..ce02c9c8de 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.pri +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.pri @@ -8,7 +8,8 @@ HEADERS += itemlibraryview.h \ itemlibraryimageprovider.h \ itemlibrarysectionmodel.h \ itemlibraryitem.h \ - resourceitemdelegate.h + resourceitemdelegate.h \ + itemlibrarysection.h SOURCES += itemlibraryview.cpp \ itemlibrarywidget.cpp \ @@ -17,7 +18,8 @@ SOURCES += itemlibraryview.cpp \ itemlibraryimageprovider.cpp \ itemlibrarysectionmodel.cpp \ itemlibraryitem.cpp \ - resourceitemdelegate.cpp + resourceitemdelegate.cpp \ + itemlibrarysection.cpp RESOURCES += itemlibrary.qrc diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp index 285ab15753..95e39ea954 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp @@ -31,6 +31,7 @@ #include "itemlibraryinfo.h" #include "itemlibrarysectionmodel.h" #include "itemlibraryitem.h" +#include "itemlibrarysection.h" #include <model.h> #include <nodemetainfo.h> @@ -127,7 +128,7 @@ void ItemLibraryModel::setItemIconSize(const QSize &itemIconSize) { m_itemIconSize = itemIconSize; - foreach (ItemLibrarySectionModel* itemLibrarySectionModel, sections()) { + foreach (ItemLibrarySection* itemLibrarySectionModel, sections()) { itemLibrarySectionModel->updateItemIconSize(itemIconSize); } } @@ -196,7 +197,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model) && (entry.requiredImport().isEmpty() || model->hasImport(entryToImport(entry), true, true))) { QString itemSectionName = entry.category(); - ItemLibrarySectionModel *sectionModel; + ItemLibrarySection *sectionModel; ItemLibraryItem *itemModel; int itemId = m_nextLibId++, sectionId; @@ -205,7 +206,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model) sectionModel = section(sectionId); } else { sectionId = m_nextLibId++; - sectionModel = new ItemLibrarySectionModel(sectionId, itemSectionName, this); + sectionModel = new ItemLibrarySection(sectionId, itemSectionName, this); addSection(sectionModel, sectionId); sections.insert(itemSectionName, sectionId); } @@ -264,17 +265,17 @@ QIcon ItemLibraryModel::getIcon(int libId) return m_itemInfos.value(libId).icon(); } -ItemLibrarySectionModel *ItemLibraryModel::section(int libraryId) +ItemLibrarySection *ItemLibraryModel::section(int libraryId) { return m_sectionModels.value(libraryId); } -QList<ItemLibrarySectionModel *> ItemLibraryModel::sections() const +QList<ItemLibrarySection *> ItemLibraryModel::sections() const { return m_sectionModels.values(); } -void ItemLibraryModel::addSection(ItemLibrarySectionModel *sectionModel, int sectionId) +void ItemLibraryModel::addSection(ItemLibrarySection *sectionModel, int sectionId) { m_sectionModels.insert(sectionId, sectionModel); sectionModel->setVisible(true); @@ -298,9 +299,9 @@ int ItemLibraryModel::visibleSectionCount() const { int visibleCount = 0; - QMap<int, ItemLibrarySectionModel*>::const_iterator sectionIterator = m_sectionModels.constBegin(); + QMap<int, ItemLibrarySection*>::const_iterator sectionIterator = m_sectionModels.constBegin(); while (sectionIterator != m_sectionModels.constEnd()) { - ItemLibrarySectionModel *sectionModel = sectionIterator.value(); + ItemLibrarySection *sectionModel = sectionIterator.value(); if (sectionModel->isVisible()) ++visibleCount; ++sectionIterator; @@ -310,13 +311,13 @@ int ItemLibraryModel::visibleSectionCount() const return visibleCount; } -QList<ItemLibrarySectionModel *> ItemLibraryModel::visibleSections() const +QList<ItemLibrarySection *> ItemLibraryModel::visibleSections() const { - QList<ItemLibrarySectionModel *> visibleSectionList; + QList<ItemLibrarySection *> visibleSectionList; - QMap<int, ItemLibrarySectionModel*>::const_iterator sectionIterator = m_sectionModels.constBegin(); + QMap<int, ItemLibrarySection*>::const_iterator sectionIterator = m_sectionModels.constBegin(); while (sectionIterator != m_sectionModels.constEnd()) { - ItemLibrarySectionModel *sectionModel = sectionIterator.value(); + ItemLibrarySection *sectionModel = sectionIterator.value(); if (sectionModel->isVisible()) visibleSectionList.append(sectionModel); ++sectionIterator; @@ -331,9 +332,9 @@ void ItemLibraryModel::updateVisibility() endResetModel(); bool changed = false; - QMap<int, ItemLibrarySectionModel*>::const_iterator sectionIterator = m_sectionModels.constBegin(); + QMap<int, ItemLibrarySection*>::const_iterator sectionIterator = m_sectionModels.constBegin(); while (sectionIterator != m_sectionModels.constEnd()) { - ItemLibrarySectionModel *sectionModel = sectionIterator.value(); + ItemLibrarySection *sectionModel = sectionIterator.value(); QString sectionSearchText = m_searchText; @@ -360,8 +361,8 @@ void ItemLibraryModel::updateVisibility() void ItemLibraryModel::addRoleNames() { int role = 0; - for (int propertyIndex = 0; propertyIndex < ItemLibrarySectionModel::staticMetaObject.propertyCount(); ++propertyIndex) { - QMetaProperty property = ItemLibrarySectionModel::staticMetaObject.property(propertyIndex); + for (int propertyIndex = 0; propertyIndex < ItemLibrarySection::staticMetaObject.propertyCount(); ++propertyIndex) { + QMetaProperty property = ItemLibrarySection::staticMetaObject.property(propertyIndex); m_roleNames.insert(role, property.name()); ++role; } diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h index 991b74e51b..e41eecb482 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h @@ -42,7 +42,7 @@ namespace QmlDesigner { class ItemLibraryInfo; class ItemLibraryEntry; class Model; -class ItemLibrarySectionModel; +class ItemLibrarySection; class ItemLibraryModel: public QAbstractListModel { @@ -64,16 +64,16 @@ public: QMimeData *getMimeData(int libId); QIcon getIcon(int libId); - ItemLibrarySectionModel* section(int libraryId); - QList<ItemLibrarySectionModel*> sections() const; - void addSection(ItemLibrarySectionModel *sectionModel, int sectionId); + ItemLibrarySection* section(int libraryId); + QList<ItemLibrarySection*> sections() const; + void addSection(ItemLibrarySection *sectionModel, int sectionId); void clearSections(); static void registerQmlTypes(); int visibleSectionCount() const; - QList<ItemLibrarySectionModel*> visibleSections() const; + QList<ItemLibrarySection*> visibleSections() const; public slots: void setSearchText(const QString &searchText); @@ -99,7 +99,7 @@ private: // functions QPixmap createDragPixmap(int width, int height); private: // variables - QMap<int, ItemLibrarySectionModel*> m_sectionModels; + QMap<int, ItemLibrarySection*> m_sectionModels; QMap<int, ItemLibraryEntry> m_itemInfos; QMap<int, int> m_sections; QHash<int, QByteArray> m_roleNames; diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.cpp new file mode 100644 index 0000000000..b551b404ac --- /dev/null +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.cpp @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "itemlibrarysection.h" + +#include "itemlibraryitem.h" + +namespace QmlDesigner { + +ItemLibrarySection::ItemLibrarySection(int sectionLibId, const QString §ionName, QObject *parent) + : QObject(parent), + m_name(sectionName), + m_sectionLibraryId(sectionLibId), + m_sectionExpanded(true), + m_sectionEntries(parent), + m_isVisible(false) +{ +// if (collapsedStateHash.contains(sectionName)) +// m_sectionExpanded= collapsedStateHash.value(sectionName); +} + + +QString ItemLibrarySection::sectionName() const +{ + return m_name; +} + +int ItemLibrarySection::sectionLibraryId() const +{ + return m_sectionLibraryId; +} + +bool ItemLibrarySection::sectionExpanded() const +{ + return m_sectionExpanded; +} + +QVariant ItemLibrarySection::sortingRole() const +{ + + if (sectionName() == QStringLiteral("QML Components")) //Qml Components always come first + return QVariant(QStringLiteral("AA.this_comes_first")); + + return sectionName(); +} + +void ItemLibrarySection::addSectionEntry(ItemLibraryItem *sectionEntry) +{ + m_sectionEntries.addItem(sectionEntry, sectionEntry->itemLibId()); +} + + +void ItemLibrarySection::removeSectionEntry(int itemLibId) +{ + m_sectionEntries.removeItem(itemLibId); +} + +QObject *ItemLibrarySection::sectionEntries() +{ + return &m_sectionEntries; +} + +int ItemLibrarySection::visibleItemIndex(int itemLibId) +{ + return m_sectionEntries.visibleItemPosition(itemLibId); +} + + +bool ItemLibrarySection::isItemVisible(int itemLibId) +{ + return m_sectionEntries.itemVisible(itemLibId); +} + + +bool ItemLibrarySection::updateSectionVisibility(const QString &searchText, bool *changed) +{ + bool haveVisibleItems = false; + + *changed = false; + + QMap<int, ItemLibraryItem*>::const_iterator itemIterator = m_sectionEntries.items().constBegin(); + while (itemIterator != m_sectionEntries.items().constEnd()) { + + bool itemVisible = m_sectionEntries.item(itemIterator.key())->itemName().toLower().contains(searchText); + + bool itemChanged = false; + itemChanged = m_sectionEntries.setItemVisible(itemIterator.key(), itemVisible); + + *changed |= itemChanged; + + if (itemVisible) + haveVisibleItems = true; + + ++itemIterator; + } + + m_sectionEntries.resetModel(); + + emit sectionEntriesChanged(); + + return haveVisibleItems; +} + + +void ItemLibrarySection::updateItemIconSize(const QSize &itemIconSize) +{ + foreach (ItemLibraryItem* itemLibraryItemModel, m_sectionEntries.itemList()) { + itemLibraryItemModel->setItemIconSize(itemIconSize); + } +} + +bool ItemLibrarySection::setVisible(bool isVisible) +{ + if (isVisible != m_isVisible) { + m_isVisible = isVisible; + return true; + } + + return false; +} + +bool ItemLibrarySection::isVisible() const +{ + return m_isVisible; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.h new file mode 100644 index 0000000000..f8b0d31c80 --- /dev/null +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysection.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QMLDESIGNER_ITEMLIBRARYSECTION_H +#define QMLDESIGNER_ITEMLIBRARYSECTION_H + +#include "itemlibrarysectionmodel.h" + +namespace QmlDesigner { + +class ItemLibrarySection: public QObject { + + Q_OBJECT + + Q_PROPERTY(QObject* sectionEntries READ sectionEntries NOTIFY sectionEntriesChanged FINAL) + Q_PROPERTY(QString sectionName READ sectionName FINAL) + Q_PROPERTY(bool sectionExpanded READ sectionExpanded FINAL) + Q_PROPERTY(QVariant sortingRole READ sortingRole FINAL) + +public: + ItemLibrarySection(int sectionLibraryId, const QString §ionName, QObject *parent = 0); + + QString sectionName() const; + int sectionLibraryId() const; + bool sectionExpanded() const; + QVariant sortingRole() const; + + void addSectionEntry(ItemLibraryItem *sectionEntry); + void removeSectionEntry(int itemLibId); + QObject *sectionEntries(); + + int visibleItemIndex(int itemLibId); + bool isItemVisible(int itemLibId); + + bool updateSectionVisibility(const QString &searchText, bool *changed); + void updateItemIconSize(const QSize &itemIconSize); + + bool setVisible(bool isVisible); + bool isVisible() const; + +signals: + void sectionEntriesChanged(); + +private: + ItemLibrarySortedModel m_sectionEntries; + QString m_name; + int m_sectionLibraryId; + bool m_sectionExpanded; + bool m_isVisible; +}; + +} // namespace QmlDesigner + +#endif // QMLDESIGNER_ITEMLIBRARYSECTION_H diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp index 4308e261c2..8be7f68515 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp @@ -158,7 +158,7 @@ const QMap<int, ItemLibraryItem*> &ItemLibrarySortedModel::items() const return m_itemModels; } -const QList<ItemLibraryItem *> &ItemLibrarySortedModel::itemList() const +const QList<ItemLibraryItem *> ItemLibrarySortedModel::itemList() const { return m_itemModels.values(); } @@ -214,121 +214,4 @@ void ItemLibrarySortedModel::addRoleName(const QByteArray &roleName) setRoleNames(m_roleNames); } -ItemLibrarySectionModel::ItemLibrarySectionModel(int sectionLibId, const QString §ionName, QObject *parent) - : QObject(parent), - m_name(sectionName), - m_sectionLibraryId(sectionLibId), - m_sectionExpanded(true), - m_sectionEntries(parent), - m_isVisible(false) -{ -// if (collapsedStateHash.contains(sectionName)) -// m_sectionExpanded= collapsedStateHash.value(sectionName); -} - - -QString ItemLibrarySectionModel::sectionName() const -{ - return m_name; -} - -int ItemLibrarySectionModel::sectionLibraryId() const -{ - return m_sectionLibraryId; -} - -bool ItemLibrarySectionModel::sectionExpanded() const -{ - return m_sectionExpanded; -} - -QVariant ItemLibrarySectionModel::sortingRole() const -{ - - if (sectionName() == QStringLiteral("QML Components")) //Qml Components always come first - return QVariant(QStringLiteral("AA.this_comes_first")); - - return sectionName(); -} - -void ItemLibrarySectionModel::addSectionEntry(ItemLibraryItem *sectionEntry) -{ - m_sectionEntries.addItem(sectionEntry, sectionEntry->itemLibId()); -} - - -void ItemLibrarySectionModel::removeSectionEntry(int itemLibId) -{ - m_sectionEntries.removeItem(itemLibId); -} - -QObject *ItemLibrarySectionModel::sectionEntries() -{ - return &m_sectionEntries; -} - -int ItemLibrarySectionModel::visibleItemIndex(int itemLibId) -{ - return m_sectionEntries.visibleItemPosition(itemLibId); -} - - -bool ItemLibrarySectionModel::isItemVisible(int itemLibId) -{ - return m_sectionEntries.itemVisible(itemLibId); -} - - -bool ItemLibrarySectionModel::updateSectionVisibility(const QString &searchText, bool *changed) -{ - bool haveVisibleItems = false; - - *changed = false; - - QMap<int, ItemLibraryItem*>::const_iterator itemIterator = m_sectionEntries.items().constBegin(); - while (itemIterator != m_sectionEntries.items().constEnd()) { - - bool itemVisible = m_sectionEntries.item(itemIterator.key())->itemName().toLower().contains(searchText); - - bool itemChanged = false; - itemChanged = m_sectionEntries.setItemVisible(itemIterator.key(), itemVisible); - - *changed |= itemChanged; - - if (itemVisible) - haveVisibleItems = true; - - ++itemIterator; - } - - m_sectionEntries.resetModel(); - - emit sectionEntriesChanged(); - - return haveVisibleItems; -} - - -void ItemLibrarySectionModel::updateItemIconSize(const QSize &itemIconSize) -{ - foreach (ItemLibraryItem* itemLibraryItemModel, m_sectionEntries.itemList()) { - itemLibraryItemModel->setItemIconSize(itemIconSize); - } -} - -bool ItemLibrarySectionModel::setVisible(bool isVisible) -{ - if (isVisible != m_isVisible) { - m_isVisible = isVisible; - return true; - } - - return false; -} - -bool ItemLibrarySectionModel::isVisible() const -{ - return m_isVisible; -} - } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h index bbec275fe9..ff76b28788 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h @@ -61,7 +61,7 @@ public: void privateRemove(int pos); const QMap<int, ItemLibraryItem*> &items() const; - const QList<ItemLibraryItem*> &itemList() const; + const QList<ItemLibraryItem *> itemList() const; ItemLibraryItem* item(int libId); @@ -85,47 +85,6 @@ private: QHash<int, QByteArray> m_roleNames; }; -class ItemLibrarySectionModel: public QObject { - - Q_OBJECT - - Q_PROPERTY(QObject* sectionEntries READ sectionEntries NOTIFY sectionEntriesChanged FINAL) - Q_PROPERTY(QString sectionName READ sectionName FINAL) - Q_PROPERTY(bool sectionExpanded READ sectionExpanded FINAL) - Q_PROPERTY(QVariant sortingRole READ sortingRole FINAL) - -public: - ItemLibrarySectionModel(int sectionLibraryId, const QString §ionName, QObject *parent = 0); - - QString sectionName() const; - int sectionLibraryId() const; - bool sectionExpanded() const; - QVariant sortingRole() const; - - void addSectionEntry(ItemLibraryItem *sectionEntry); - void removeSectionEntry(int itemLibId); - QObject *sectionEntries(); - - int visibleItemIndex(int itemLibId); - bool isItemVisible(int itemLibId); - - bool updateSectionVisibility(const QString &searchText, bool *changed); - void updateItemIconSize(const QSize &itemIconSize); - - bool setVisible(bool isVisible); - bool isVisible() const; - -signals: - void sectionEntriesChanged(); - -private: - ItemLibrarySortedModel m_sectionEntries; - QString m_name; - int m_sectionLibraryId; - bool m_sectionExpanded; - bool m_isVisible; -}; - } // namespace QmlDesigner QML_DECLARE_TYPE(QmlDesigner::ItemLibrarySortedModel) |