Commit d17be7d4 authored by Marco Bubke's avatar Marco Bubke Committed by Tim Jenssen

QmlDesigner: Remove m_privList in ItemLibrarySectionModel

Change-Id: I7aaed4cc388d429e832ec79a283d381f1a60e907
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent a3a760d0
......@@ -46,23 +46,24 @@ ItemLibrarySectionModel::~ItemLibrarySectionModel()
int ItemLibrarySectionModel::rowCount(const QModelIndex &) const
{
return m_privList.count();
return visibleItemCount();
}
QVariant ItemLibrarySectionModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row()+1 > m_privList.count()) {
if (!index.isValid() || index.row() + 1 > visibleItemCount()) {
qDebug() << Q_FUNC_INFO << "invalid index requested";
return QVariant();
}
if (m_roleNames.contains(role)) {
QVariant value = m_privList.at(index.row())->property(m_roleNames.value(role));
QList<ItemLibraryItem *> visibleItemList = visibleItems();
QVariant value = visibleItemList.at(index.row())->property(m_roleNames.value(role));
if (ItemLibrarySectionModel* model = qobject_cast<ItemLibrarySectionModel *>(value.value<QObject*>()))
return QVariant::fromValue(model);
return m_privList.at(index.row())->property(m_roleNames.value(role));
return visibleItemList.at(index.row())->property(m_roleNames.value(role));
}
qWarning() << Q_FUNC_INFO << "invalid role requested";
......@@ -90,16 +91,6 @@ void ItemLibrarySectionModel::addItem(ItemLibraryItem *element)
element->setVisible(true);
}
void ItemLibrarySectionModel::privateInsert(int pos, QObject *element)
{
m_privList.insert(pos, element);
}
void ItemLibrarySectionModel::privateRemove(int pos)
{
m_privList.removeAt(pos);
}
const QList<ItemLibraryItem *> &ItemLibrarySectionModel::items() const
{
return m_itemList;
......@@ -123,4 +114,28 @@ 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<ItemLibraryItem *> ItemLibrarySectionModel::visibleItems() const
{
QList<ItemLibraryItem *> visibleItemList;
foreach (ItemLibraryItem *itemLibraryItem, m_itemList) {
if (itemLibraryItem->isVisible())
visibleItemList.append(itemLibraryItem);
}
return visibleItemList;
}
} // namespace QmlDesigner
......@@ -53,20 +53,17 @@ public:
void addItem(ItemLibraryItem *item);
void privateInsert(int pos, QObject *item);
void privateRemove(int pos);
const QList<ItemLibraryItem *> &items() const;
void resetModel();
private: // functions
void addRoleNames();
int visibleItemCount() const;
const QList<ItemLibraryItem *> visibleItems() const;
private: // variables
QList<ItemLibraryItem*> m_itemList;
QList<QObject *> m_privList;
QHash<int, QByteArray> m_roleNames;
};
......
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