forked from qt-creator/qt-creator
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:
@@ -103,6 +103,7 @@ ScrollView {
|
||||
delegate: Section {
|
||||
width: itemsView.viewport.width
|
||||
caption: sectionName // to be set by model
|
||||
visible: sectionVisible
|
||||
Grid {
|
||||
id: itemGrid
|
||||
|
||||
|
@@ -76,17 +76,17 @@ ItemLibraryModel::~ItemLibraryModel()
|
||||
|
||||
int ItemLibraryModel::rowCount(const QModelIndex & /*parent*/) const
|
||||
{
|
||||
return visibleSectionCount();
|
||||
return m_sectionModels.count();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
||||
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*>());
|
||||
if (model)
|
||||
@@ -170,6 +170,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
||||
}
|
||||
}
|
||||
|
||||
resetModel();
|
||||
updateVisibility();
|
||||
}
|
||||
|
||||
@@ -250,14 +251,15 @@ void ItemLibraryModel::updateVisibility()
|
||||
if (itemLibrarySection->sectionName().toLower().contains(m_searchText))
|
||||
sectionSearchText.clear();
|
||||
|
||||
bool sectionChanged = false,
|
||||
sectionVisibility = itemLibrarySection->updateSectionVisibility(sectionSearchText,
|
||||
§ionChanged);
|
||||
if (sectionChanged)
|
||||
changed = true;
|
||||
|
||||
bool sectionChanged = false;
|
||||
bool sectionVisibility = itemLibrarySection->updateSectionVisibility(sectionSearchText,
|
||||
§ionChanged);
|
||||
changed |= sectionChanged;
|
||||
changed |= itemLibrarySection->setVisible(sectionVisibility);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
resetModel();
|
||||
}
|
||||
|
||||
void ItemLibraryModel::addRoleNames()
|
||||
@@ -272,6 +274,12 @@ void ItemLibraryModel::addRoleNames()
|
||||
setRoleNames(m_roleNames);
|
||||
}
|
||||
|
||||
void ItemLibraryModel::resetModel()
|
||||
{
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int ItemLibraryModel::getWidth(const ItemLibraryEntry &itemLibraryEntry)
|
||||
{
|
||||
foreach (const ItemLibraryEntry::Property &property, itemLibraryEntry.properties())
|
||||
|
@@ -85,6 +85,7 @@ signals:
|
||||
private: // functions
|
||||
void updateVisibility();
|
||||
void addRoleNames();
|
||||
void resetModel();
|
||||
|
||||
int getWidth(const ItemLibraryEntry &entry);
|
||||
int getHeight(const ItemLibraryEntry &entry);
|
||||
|
@@ -83,19 +83,17 @@ bool ItemLibrarySection::updateSectionVisibility(const QString &searchText, bool
|
||||
foreach(ItemLibraryItem *itemLibraryItem, m_sectionEntries.items()) {
|
||||
bool itemVisible = itemLibraryItem->itemName().toLower().contains(searchText);
|
||||
|
||||
bool itemChanged = false;
|
||||
itemChanged = itemLibraryItem->setVisible(itemVisible);
|
||||
bool itemChanged = itemLibraryItem->setVisible(itemVisible);
|
||||
|
||||
*changed |= itemChanged;
|
||||
|
||||
if (itemVisible)
|
||||
haveVisibleItems = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
m_sectionEntries.resetModel();
|
||||
|
||||
emit sectionEntriesChanged();
|
||||
|
||||
return haveVisibleItems;
|
||||
}
|
||||
|
||||
|
@@ -90,6 +90,8 @@ const QList<ItemLibraryItem *> &ItemLibrarySectionModel::items() const
|
||||
|
||||
void ItemLibrarySectionModel::resetModel()
|
||||
{
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
emit dataChanged(QModelIndex(), QModelIndex());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user