QmlDesigner: Add item library section visibility

Search is working again

Change-Id: Ie6d52f476e2b9b5c3256bc289bcdd5dcadafea93
Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
This commit is contained in:
Marco Bubke
2014-06-23 17:48:15 +02:00
committed by Tim Jenssen
parent c77f533ddd
commit 826525f89f
5 changed files with 23 additions and 13 deletions

View File

@@ -103,6 +103,7 @@ ScrollView {
delegate: Section { delegate: Section {
width: itemsView.viewport.width width: itemsView.viewport.width
caption: sectionName // to be set by model caption: sectionName // to be set by model
visible: sectionVisible
Grid { Grid {
id: itemGrid id: itemGrid

View File

@@ -76,17 +76,17 @@ ItemLibraryModel::~ItemLibraryModel()
int ItemLibraryModel::rowCount(const QModelIndex & /*parent*/) const int ItemLibraryModel::rowCount(const QModelIndex & /*parent*/) const
{ {
return visibleSectionCount(); return m_sectionModels.count();
} }
QVariant ItemLibraryModel::data(const QModelIndex &index, int role) const QVariant ItemLibraryModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || index.row() +1 > visibleSectionCount()) if (!index.isValid() || index.row() +1 > m_sectionModels.count())
return QVariant(); return QVariant();
if (m_roleNames.contains(role)) { if (m_roleNames.contains(role)) {
QVariant value = visibleSections().at(index.row())->property(m_roleNames.value(role)); QVariant value = m_sectionModels.at(index.row())->property(m_roleNames.value(role));
ItemLibrarySectionModel* model = qobject_cast<ItemLibrarySectionModel *>(value.value<QObject*>()); ItemLibrarySectionModel* model = qobject_cast<ItemLibrarySectionModel *>(value.value<QObject*>());
if (model) if (model)
@@ -170,6 +170,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
} }
} }
resetModel();
updateVisibility(); updateVisibility();
} }
@@ -250,14 +251,15 @@ void ItemLibraryModel::updateVisibility()
if (itemLibrarySection->sectionName().toLower().contains(m_searchText)) if (itemLibrarySection->sectionName().toLower().contains(m_searchText))
sectionSearchText.clear(); sectionSearchText.clear();
bool sectionChanged = false, bool sectionChanged = false;
sectionVisibility = itemLibrarySection->updateSectionVisibility(sectionSearchText, bool sectionVisibility = itemLibrarySection->updateSectionVisibility(sectionSearchText,
&sectionChanged); &sectionChanged);
if (sectionChanged) changed |= sectionChanged;
changed = true;
changed |= itemLibrarySection->setVisible(sectionVisibility); changed |= itemLibrarySection->setVisible(sectionVisibility);
} }
if (changed)
resetModel();
} }
void ItemLibraryModel::addRoleNames() void ItemLibraryModel::addRoleNames()
@@ -272,6 +274,12 @@ void ItemLibraryModel::addRoleNames()
setRoleNames(m_roleNames); setRoleNames(m_roleNames);
} }
void ItemLibraryModel::resetModel()
{
beginResetModel();
endResetModel();
}
int ItemLibraryModel::getWidth(const ItemLibraryEntry &itemLibraryEntry) int ItemLibraryModel::getWidth(const ItemLibraryEntry &itemLibraryEntry)
{ {
foreach (const ItemLibraryEntry::Property &property, itemLibraryEntry.properties()) foreach (const ItemLibraryEntry::Property &property, itemLibraryEntry.properties())

View File

@@ -85,6 +85,7 @@ signals:
private: // functions private: // functions
void updateVisibility(); void updateVisibility();
void addRoleNames(); void addRoleNames();
void resetModel();
int getWidth(const ItemLibraryEntry &entry); int getWidth(const ItemLibraryEntry &entry);
int getHeight(const ItemLibraryEntry &entry); int getHeight(const ItemLibraryEntry &entry);

View File

@@ -83,19 +83,17 @@ bool ItemLibrarySection::updateSectionVisibility(const QString &searchText, bool
foreach(ItemLibraryItem *itemLibraryItem, m_sectionEntries.items()) { foreach(ItemLibraryItem *itemLibraryItem, m_sectionEntries.items()) {
bool itemVisible = itemLibraryItem->itemName().toLower().contains(searchText); bool itemVisible = itemLibraryItem->itemName().toLower().contains(searchText);
bool itemChanged = false; bool itemChanged = itemLibraryItem->setVisible(itemVisible);
itemChanged = itemLibraryItem->setVisible(itemVisible);
*changed |= itemChanged; *changed |= itemChanged;
if (itemVisible) if (itemVisible)
haveVisibleItems = true; haveVisibleItems = true;
} }
if (changed) if (changed)
m_sectionEntries.resetModel(); m_sectionEntries.resetModel();
emit sectionEntriesChanged();
return haveVisibleItems; return haveVisibleItems;
} }

View File

@@ -90,6 +90,8 @@ const QList<ItemLibraryItem *> &ItemLibrarySectionModel::items() const
void ItemLibrarySectionModel::resetModel() void ItemLibrarySectionModel::resetModel()
{ {
beginResetModel();
endResetModel();
emit dataChanged(QModelIndex(), QModelIndex()); emit dataChanged(QModelIndex(), QModelIndex());
} }