Commit fd4e68ac authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.ItemLibrary: remove declarative private dependecy

We derived from QDeclarativeListModel which is private.
This patch uses QAbstractListModel instead.

Change-Id: Ib567433f5fbb38780b32e5a9291d2cb87730e624
Reviewed-by: default avatarKai Koehne <kai.koehne@digia.com>
Reviewed-by: default avatarMarco Bubke <marco.bubke@digia.com>
parent 9385c9f9
......@@ -32,8 +32,8 @@
#include <QMap>
#include <QIcon>
#include <QScriptEngine>
#include <private/qdeclarativelistmodel_p.h>
#include <QAbstractListModel>
#include <QtDeclarative>
QT_FORWARD_DECLARE_CLASS(QMimeData)
......@@ -45,52 +45,82 @@ class Model;
namespace Internal {
template <class T>
class ItemLibrarySortedModel: public QDeclarativeListModel {
void registerQmlTypes();
class ItemLibrarySortedModel: public QAbstractListModel {
Q_OBJECT
public:
ItemLibrarySortedModel(QObject *parent = 0);
~ItemLibrarySortedModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
void clearElements();
void addElement(T *element, int libId);
void addElement(QObject *element, int libId);
void removeElement(int libId);
bool elementVisible(int libId) const;
bool setElementVisible(int libId, bool visible);
const QMap<int, T *> &elements() const;
void privateInsert(int pos, QObject *element);
void privateRemove(int pos);
const QMap<int, QObject *> &elements() const;
template<typename T>
const QList<T> elementsByType() const;
QObject *element(int libId);
template<typename T>
T elementByType(int libId);
T *elementModel(int libId);
int findElement(int libId) const;
int visibleElementPosition(int libId) const;
void resetModel();
private:
void addRoleName(const QByteArray &roleName);
struct order_struct {
int libId;
bool visible;
};
QMap<int, T *> m_elementModels;
QMap<int, QObject *> m_elementModels;
QList<struct order_struct> m_elementOrder;
QList<QObject *> m_privList;
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)
class ItemLibraryItemModel: public QScriptValue {
public:
ItemLibraryItemModel(QScriptEngine *scriptEngine, int itemLibId, const QString &itemName);
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);
bool operator<(const ItemLibraryItemModel &other) const;
private:
QWeakPointer<QScriptEngine> m_scriptEngine;
int m_libId;
QString m_name;
QString m_iconPath;
......@@ -98,14 +128,27 @@ private:
};
class ItemLibrarySectionModel: public QScriptValue {
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(QScriptEngine *scriptEngine, int sectionLibId, const QString &sectionName, QObject *parent = 0);
ItemLibrarySectionModel(int sectionLibId, const QString &sectionName, 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);
......@@ -113,20 +156,24 @@ public:
bool updateSectionVisibility(const QString &searchText, bool *changed);
void updateItemIconSize(const QSize &itemIconSize);
bool operator<(const ItemLibrarySectionModel &other) const;
signals:
void sectionEntriesChanged();
private:
QString m_name;
ItemLibrarySortedModel<ItemLibraryItemModel> m_sectionEntries;
int m_sectionLibId;
bool m_sectionExpanded;
ItemLibrarySortedModel m_sectionEntries;
};
class ItemLibraryModel: public ItemLibrarySortedModel<ItemLibrarySectionModel> {
class ItemLibraryModel: public ItemLibrarySortedModel {
Q_OBJECT
Q_PROPERTY(QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged)
public:
explicit ItemLibraryModel(QScriptEngine *scriptEngine, QObject *parent = 0);
explicit ItemLibraryModel(QObject *parent = 0);
~ItemLibraryModel();
QString searchText() const;
......@@ -137,6 +184,9 @@ public:
QMimeData *getMimeData(int libId);
QIcon getIcon(int libId);
ItemLibrarySectionModel* section(int libId);
QList<ItemLibrarySectionModel*> sections() const;
public slots:
void setSearchText(const QString &searchText);
void setItemIconSize(const QSize &itemIconSize);
......@@ -159,7 +209,6 @@ private:
int getHeight(const ItemLibraryEntry &entry);
QPixmap createDragPixmap(int width, int height);
QWeakPointer<QScriptEngine> m_scriptEngine;
QMap<int, ItemLibraryEntry> m_itemInfos;
QMap<int, int> m_sections;
......@@ -171,5 +220,7 @@ private:
} // namespace Internal
} // namespace QmlDesigner
QML_DECLARE_TYPE(QmlDesigner::Internal::ItemLibrarySortedModel)
#endif // ITEMLIBRARYMODEL_H
......@@ -67,6 +67,8 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
m_resourcesView(new Internal::ItemLibraryTreeView(this)),
m_filterFlag(QtBasic)
{
Internal::registerQmlTypes();
setWindowTitle(tr("Library", "Title of library view"));
/* create Items view and its model */
......@@ -75,7 +77,7 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
m_itemsView->setAcceptDrops(false);
m_itemsView->setFocusPolicy(Qt::ClickFocus);
m_itemsView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
m_itemLibraryModel = new Internal::ItemLibraryModel(QDeclarativeEnginePrivate::getScriptEngine(m_itemsView->engine()), this);
m_itemLibraryModel = new Internal::ItemLibraryModel(this);
m_itemLibraryModel->setItemIconSize(m_itemIconSize);
QDeclarativeContext *rootContext = m_itemsView->rootContext();
......
......@@ -77,18 +77,18 @@ Column {
var currentItemX = sectionView.x + gridFrame.x + gridView.x + gridView.currentItem.x;
var currentItemY = sectionView.y + gridFrame.y + gridView.y + gridView.currentItem.y
- gridView.contentY; // workaround: GridView reports wrong contentY
- gridView.contentY; // workaround: GridView reports wrong contentY
if (currentItemY < flickable.contentY)
pos = Math.max(0, currentItemY)
else if ((currentItemY + gridView.currentItem.height) >
(flickable.contentY + flickable.height - 1))
pos = Math.min(Math.max(0, flickable.contentHeight - flickable.height),
currentItemY + gridView.currentItem.height - flickable.height + 1)
else if ((currentItemY + gridView.currentItem.height) >
(flickable.contentY + flickable.height - 1))
pos = Math.min(Math.max(0, flickable.contentHeight - flickable.height),
currentItemY + gridView.currentItem.height - flickable.height + 1)
if (pos >= 0)
flickable.contentY = pos
if (pos >= 0)
flickable.contentY = pos
}
// internal
......@@ -168,7 +168,8 @@ Column {
clip: true
width: entriesPerRow * cellWidth + 1
height: Math.ceil(sectionEntries.count / entriesPerRow) * cellHeight + 1
height: gridView.model !== undefined ? Math.ceil(gridView.count / sectionView.entriesPerRow) * cellHeight + 1 : 0
anchors.horizontalCenter: parent.horizontalCenter
GridView {
......@@ -198,18 +199,18 @@ updated properly under all conditions */
}
states: [
State {
name: "shrunk"
PropertyChanges {
target: gridFrame
height: 0
opacity: 0
}
PropertyChanges {
target: arrow
rotation: -90
State {
name: "shrunk"
PropertyChanges {
target: gridFrame
height: 0
opacity: 0
}
PropertyChanges {
target: arrow
rotation: -90
}
}
}
]
}
......
Markdown is supported
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