From 40e236046eaeb8af068b2d4f4773b16d726c5097 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 21 May 2014 12:34:36 +0200 Subject: [PATCH] QmlDesigner: Move ItemLibrarySectionModel in own file Change-Id: I1797e6df019d0a833e2b9b6eaeb72759432f9a64 Reviewed-by: Tim Jenssen --- .../components/itemlibrary/itemlibrary.pri | 16 ++- .../itemlibrary/itemlibrarymodel.cpp | 104 +------------- .../components/itemlibrary/itemlibrarymodel.h | 41 +----- .../itemlibrary/itemlibrarysectionmodel.cpp | 136 ++++++++++++++++++ .../itemlibrary/itemlibrarysectionmodel.h | 79 ++++++++++ 5 files changed, 232 insertions(+), 144 deletions(-) create mode 100644 src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp create mode 100644 src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.pri b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.pri index f1e654e0dbe..d9d9f2d446e 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.pri +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrary.pri @@ -1,8 +1,20 @@ VPATH += $$PWD # Input -HEADERS += itemlibraryview.h itemlibrarywidget.h itemlibrarymodel.h itemlibrarycomponents.h itemlibraryimageprovider.h -SOURCES += itemlibraryview.cpp itemlibrarywidget.cpp itemlibrarymodel.cpp itemlibrarycomponents.cpp itemlibraryimageprovider.cpp +HEADERS += itemlibraryview.h \ + itemlibrarywidget.h \ + itemlibrarymodel.h \ + itemlibrarycomponents.h \ + itemlibraryimageprovider.h \ + itemlibrarysectionmodel.h + +SOURCES += itemlibraryview.cpp \ + itemlibrarywidget.cpp \ + itemlibrarymodel.cpp \ + itemlibrarycomponents.cpp \ + itemlibraryimageprovider.cpp \ + itemlibrarysectionmodel.cpp + RESOURCES += itemlibrary.qrc OTHER_FILES += \ diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp index 85985b55f8a..81aacec346b 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp @@ -29,6 +29,8 @@ #include "itemlibrarymodel.h" #include "itemlibraryinfo.h" +#include "itemlibrarysectionmodel.h" + #include #include @@ -293,107 +295,6 @@ void ItemLibraryItemModel::setItemIconSize(const QSize &itemIconSize) setItemIconPath(m_iconPath); } -ItemLibrarySectionModel::ItemLibrarySectionModel(int sectionLibId, const QString §ionName, QObject *parent) - : QObject(parent), - m_name(sectionName), - m_sectionLibId(sectionLibId), - m_sectionExpanded(true), - m_sectionEntries(parent) -{ - if (collapsedStateHash.contains(sectionName)) - m_sectionExpanded= collapsedStateHash.value(sectionName); -} - - -QString ItemLibrarySectionModel::sectionName() const -{ - return m_name; -} - -int ItemLibrarySectionModel::sectionLibId() const -{ - return m_sectionLibId; -} - -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(ItemLibraryItemModel *sectionEntry) -{ - m_sectionEntries.addElement(sectionEntry, sectionEntry->itemLibId()); -} - - -void ItemLibrarySectionModel::removeSectionEntry(int itemLibId) -{ - m_sectionEntries.removeElement(itemLibId); -} - -QObject *ItemLibrarySectionModel::sectionEntries() -{ - return &m_sectionEntries; -} - -int ItemLibrarySectionModel::visibleItemIndex(int itemLibId) -{ - return m_sectionEntries.visibleElementPosition(itemLibId); -} - - -bool ItemLibrarySectionModel::isItemVisible(int itemLibId) -{ - return m_sectionEntries.elementVisible(itemLibId); -} - - -bool ItemLibrarySectionModel::updateSectionVisibility(const QString &searchText, bool *changed) -{ - bool haveVisibleItems = false; - - *changed = false; - - QMap::const_iterator itemIt = m_sectionEntries.elements().constBegin(); - while (itemIt != m_sectionEntries.elements().constEnd()) { - - bool itemVisible = m_sectionEntries.elementByType( - itemIt.key())->itemName().toLower().contains(searchText); - - bool itemChanged = false; - itemChanged = m_sectionEntries.setElementVisible(itemIt.key(), itemVisible); - - *changed |= itemChanged; - - if (itemVisible) - haveVisibleItems = true; - - ++itemIt; - } - - m_sectionEntries.resetModel(); - - emit sectionEntriesChanged(); - - return haveVisibleItems; -} - - -void ItemLibrarySectionModel::updateItemIconSize(const QSize &itemIconSize) -{ - foreach (ItemLibraryItemModel* itemLibraryItemModel, m_sectionEntries.elementsByType()) { - itemLibraryItemModel->setItemIconSize(itemIconSize); - } -} void ItemLibraryModel::setExpanded(bool expanded, const QString §ion) { @@ -412,7 +313,6 @@ ItemLibraryModel::ItemLibraryModel(QObject *parent) { } - ItemLibraryModel::~ItemLibraryModel() { } diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h index 91bcd3824da..8bed4531ef7 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h @@ -42,6 +42,7 @@ namespace QmlDesigner { class ItemLibraryInfo; class ItemLibraryEntry; class Model; +class ItemLibrarySectionModel; void registerQmlTypes(); @@ -125,46 +126,6 @@ private: QSize m_iconSize; }; - -class ItemLibrarySectionModel: public QObject { - - Q_OBJECT - - Q_PROPERTY(QObject* sectionEntries READ sectionEntries NOTIFY sectionEntriesChanged FINAL) - Q_PROPERTY(int sectionLibId READ sectionLibId 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 sectionLibId, const QString §ionName, QObject *parent = 0); - - QString sectionName() const; - int sectionLibId() const; - bool sectionExpanded() const; - QVariant sortingRole() const; - - void addSectionEntry(ItemLibraryItemModel *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); - -signals: - void sectionEntriesChanged(); - -private: - QString m_name; - int m_sectionLibId; - bool m_sectionExpanded; - ItemLibrarySortedModel m_sectionEntries; -}; - - class ItemLibraryModel: public ItemLibrarySortedModel { Q_OBJECT diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp new file mode 100644 index 00000000000..697b927379b --- /dev/null +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** 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 "itemlibrarysectionmodel.h" + +namespace QmlDesigner { + +ItemLibrarySectionModel::ItemLibrarySectionModel(int sectionLibId, const QString §ionName, QObject *parent) + : QObject(parent), + m_name(sectionName), + m_sectionLibId(sectionLibId), + m_sectionExpanded(true), + m_sectionEntries(parent) +{ +// if (collapsedStateHash.contains(sectionName)) +// m_sectionExpanded= collapsedStateHash.value(sectionName); +} + + +QString ItemLibrarySectionModel::sectionName() const +{ + return m_name; +} + +int ItemLibrarySectionModel::sectionLibId() const +{ + return m_sectionLibId; +} + +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(ItemLibraryItemModel *sectionEntry) +{ + m_sectionEntries.addElement(sectionEntry, sectionEntry->itemLibId()); +} + + +void ItemLibrarySectionModel::removeSectionEntry(int itemLibId) +{ + m_sectionEntries.removeElement(itemLibId); +} + +QObject *ItemLibrarySectionModel::sectionEntries() +{ + return &m_sectionEntries; +} + +int ItemLibrarySectionModel::visibleItemIndex(int itemLibId) +{ + return m_sectionEntries.visibleElementPosition(itemLibId); +} + + +bool ItemLibrarySectionModel::isItemVisible(int itemLibId) +{ + return m_sectionEntries.elementVisible(itemLibId); +} + + +bool ItemLibrarySectionModel::updateSectionVisibility(const QString &searchText, bool *changed) +{ + bool haveVisibleItems = false; + + *changed = false; + + QMap::const_iterator itemIt = m_sectionEntries.elements().constBegin(); + while (itemIt != m_sectionEntries.elements().constEnd()) { + +// bool itemVisible = m_sectionEntries.elementByType( +// itemIt.key())->itemName().toLower().contains(searchText); + + bool itemChanged = false; +// itemChanged = m_sectionEntries.setElementVisible(itemIt.key(), itemVisible); + + *changed |= itemChanged; + +// if (itemVisible) +// haveVisibleItems = true; + + ++itemIt; + } + + m_sectionEntries.resetModel(); + + emit sectionEntriesChanged(); + + return haveVisibleItems; +} + + +void ItemLibrarySectionModel::updateItemIconSize(const QSize &itemIconSize) +{ +// foreach (ItemLibraryItemModel* itemLibraryItemModel, m_sectionEntries.elementsByType()) { +// itemLibraryItemModel->setItemIconSize(itemIconSize); +// } +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h new file mode 100644 index 00000000000..d11645716da --- /dev/null +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarysectionmodel.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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_ITEMLIBRARYSECTIONMODEL_H +#define QMLDESIGNER_ITEMLIBRARYSECTIONMODEL_H + +#include "itemlibrarymodel.h" + +#include + +namespace QmlDesigner { + +class ItemLibrarySectionModel: public QObject { + + Q_OBJECT + + Q_PROPERTY(QObject* sectionEntries READ sectionEntries NOTIFY sectionEntriesChanged FINAL) + Q_PROPERTY(int sectionLibId READ sectionLibId 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 sectionLibId, const QString §ionName, QObject *parent = 0); + + QString sectionName() const; + int sectionLibId() const; + bool sectionExpanded() const; + QVariant sortingRole() const; + + void addSectionEntry(ItemLibraryItemModel *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); + +signals: + void sectionEntriesChanged(); + +private: + QString m_name; + int m_sectionLibId; + bool m_sectionExpanded; + ItemLibrarySortedModel m_sectionEntries; +}; + +} // namespace QmlDesigner + +#endif // QMLDESIGNER_ITEMLIBRARYSECTIONMODEL_H