forked from qt-creator/qt-creator
QmlDesigner: Move ItemLibraryItemModel in own file
Change-Id: I4cb5ddf82ed677b653c23cae173a67f833241e65 Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
This commit is contained in:
@@ -6,14 +6,16 @@ HEADERS += itemlibraryview.h \
|
|||||||
itemlibrarymodel.h \
|
itemlibrarymodel.h \
|
||||||
itemlibrarycomponents.h \
|
itemlibrarycomponents.h \
|
||||||
itemlibraryimageprovider.h \
|
itemlibraryimageprovider.h \
|
||||||
itemlibrarysectionmodel.h
|
itemlibrarysectionmodel.h \
|
||||||
|
itemlibraryitemmodel.h
|
||||||
|
|
||||||
SOURCES += itemlibraryview.cpp \
|
SOURCES += itemlibraryview.cpp \
|
||||||
itemlibrarywidget.cpp \
|
itemlibrarywidget.cpp \
|
||||||
itemlibrarymodel.cpp \
|
itemlibrarymodel.cpp \
|
||||||
itemlibrarycomponents.cpp \
|
itemlibrarycomponents.cpp \
|
||||||
itemlibraryimageprovider.cpp \
|
itemlibraryimageprovider.cpp \
|
||||||
itemlibrarysectionmodel.cpp
|
itemlibrarysectionmodel.cpp \
|
||||||
|
itemlibraryitemmodel.cpp
|
||||||
|
|
||||||
RESOURCES += itemlibrary.qrc
|
RESOURCES += itemlibrary.qrc
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "itemlibraryitemmodel.h"
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
ItemLibraryItemModel::ItemLibraryItemModel(int itemLibId, const QString &itemName, QObject *parent)
|
||||||
|
: QObject(parent),
|
||||||
|
m_libId(itemLibId),
|
||||||
|
m_name(itemName),
|
||||||
|
m_iconSize(64, 64)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemLibraryItemModel::~ItemLibraryItemModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int ItemLibraryItemModel::itemLibId() const
|
||||||
|
{
|
||||||
|
return m_libId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString ItemLibraryItemModel::itemName() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ItemLibraryItemModel::itemLibraryIconPath() const
|
||||||
|
{
|
||||||
|
//Prepend image provider prefix
|
||||||
|
return QStringLiteral("image://qmldesigner_itemlibrary/") + m_iconPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ItemLibraryItemModel::sortingRole() const
|
||||||
|
{
|
||||||
|
return itemName();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemLibraryItemModel::setItemIconPath(const QString &iconPath)
|
||||||
|
{
|
||||||
|
m_iconPath = iconPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemLibraryItemModel::setItemIconSize(const QSize &itemIconSize)
|
||||||
|
{
|
||||||
|
m_iconSize = itemIconSize;
|
||||||
|
setItemIconPath(m_iconPath);
|
||||||
|
}
|
||||||
|
} // namespace QmlDesigner
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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_ITEMLIBRARYITEMMODEL_H
|
||||||
|
#define QMLDESIGNER_ITEMLIBRARYITEMMODEL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QSize>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class ItemLibraryItemModel: public QObject {
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(int itemLibId READ itemLibId FINAL)
|
||||||
|
Q_PROPERTY(QString itemName READ itemName FINAL)
|
||||||
|
Q_PROPERTY(QString itemLibraryIconPath READ itemLibraryIconPath FINAL)
|
||||||
|
Q_PROPERTY(QVariant sortingRole READ sortingRole FINAL)
|
||||||
|
|
||||||
|
public:
|
||||||
|
ItemLibraryItemModel(int itemLibId, const QString &itemName, QObject *parent);
|
||||||
|
~ItemLibraryItemModel();
|
||||||
|
|
||||||
|
int itemLibId() const;
|
||||||
|
QString itemName() const;
|
||||||
|
QString itemLibraryIconPath() const;
|
||||||
|
QVariant sortingRole() const;
|
||||||
|
|
||||||
|
void setItemIconPath(const QString &iconPath);
|
||||||
|
void setItemIconSize(const QSize &itemIconSize);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_libId;
|
||||||
|
QString m_name;
|
||||||
|
QString m_iconPath;
|
||||||
|
QSize m_iconSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QmlDesigner
|
||||||
|
|
||||||
|
#endif // QMLDESIGNER_ITEMLIBRARYITEMMODEL_H
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "itemlibrarymodel.h"
|
#include "itemlibrarymodel.h"
|
||||||
#include "itemlibraryinfo.h"
|
#include "itemlibraryinfo.h"
|
||||||
#include "itemlibrarysectionmodel.h"
|
#include "itemlibrarysectionmodel.h"
|
||||||
|
#include "itemlibraryitemmodel.h"
|
||||||
|
|
||||||
#include <model.h>
|
#include <model.h>
|
||||||
#include <nodemetainfo.h>
|
#include <nodemetainfo.h>
|
||||||
@@ -246,56 +247,6 @@ void ItemLibrarySortedModel::addRoleName(const QByteArray &roleName)
|
|||||||
setRoleNames(m_roleNames);
|
setRoleNames(m_roleNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemLibraryItemModel::ItemLibraryItemModel(int itemLibId, const QString &itemName, QObject *parent)
|
|
||||||
: QObject(parent),
|
|
||||||
m_libId(itemLibId),
|
|
||||||
m_name(itemName),
|
|
||||||
m_iconSize(64, 64)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ItemLibraryItemModel::~ItemLibraryItemModel()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ItemLibraryItemModel::itemLibId() const
|
|
||||||
{
|
|
||||||
return m_libId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString ItemLibraryItemModel::itemName() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ItemLibraryItemModel::itemLibraryIconPath() const
|
|
||||||
{
|
|
||||||
//Prepend image provider prefix
|
|
||||||
return QStringLiteral("image://qmldesigner_itemlibrary/")+ m_iconPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant ItemLibraryItemModel::sortingRole() const
|
|
||||||
{
|
|
||||||
return itemName();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ItemLibraryItemModel::setItemIconPath(const QString &iconPath)
|
|
||||||
{
|
|
||||||
m_iconPath = iconPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ItemLibraryItemModel::setItemIconSize(const QSize &itemIconSize)
|
|
||||||
{
|
|
||||||
m_iconSize = itemIconSize;
|
|
||||||
setItemIconPath(m_iconPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ItemLibraryModel::setExpanded(bool expanded, const QString §ion)
|
void ItemLibraryModel::setExpanded(bool expanded, const QString §ion)
|
||||||
{
|
{
|
||||||
if (collapsedStateHash.contains(section))
|
if (collapsedStateHash.contains(section))
|
||||||
|
|||||||
@@ -98,34 +98,6 @@ private:
|
|||||||
QHash<int, QByteArray> m_roleNames;
|
QHash<int, QByteArray> m_roleNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ItemLibraryItemModel: public QObject {
|
|
||||||
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_PROPERTY(int itemLibId READ itemLibId FINAL)
|
|
||||||
Q_PROPERTY(QString itemName READ itemName FINAL)
|
|
||||||
Q_PROPERTY(QString itemLibraryIconPath READ itemLibraryIconPath FINAL)
|
|
||||||
Q_PROPERTY(QVariant sortingRole READ sortingRole FINAL)
|
|
||||||
|
|
||||||
public:
|
|
||||||
ItemLibraryItemModel(int itemLibId, const QString &itemName, QObject *parent);
|
|
||||||
~ItemLibraryItemModel();
|
|
||||||
|
|
||||||
int itemLibId() const;
|
|
||||||
QString itemName() const;
|
|
||||||
QString itemLibraryIconPath() const;
|
|
||||||
QVariant sortingRole() const;
|
|
||||||
|
|
||||||
void setItemIconPath(const QString &iconPath);
|
|
||||||
void setItemIconSize(const QSize &itemIconSize);
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_libId;
|
|
||||||
QString m_name;
|
|
||||||
QString m_iconPath;
|
|
||||||
QSize m_iconSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ItemLibraryModel: public ItemLibrarySortedModel {
|
class ItemLibraryModel: public ItemLibrarySortedModel {
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#include "itemlibrarysectionmodel.h"
|
#include "itemlibrarysectionmodel.h"
|
||||||
|
|
||||||
|
#include "itemlibraryitemmodel.h"
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
ItemLibrarySectionModel::ItemLibrarySectionModel(int sectionLibId, const QString §ionName, QObject *parent)
|
ItemLibrarySectionModel::ItemLibrarySectionModel(int sectionLibId, const QString §ionName, QObject *parent)
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class ItemLibraryItemModel;
|
||||||
|
|
||||||
class ItemLibrarySectionModel: public QObject {
|
class ItemLibrarySectionModel: public QObject {
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
Reference in New Issue
Block a user