Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Fix effectlist filter causing display of corrupted list

parent 0dd2dae2
......@@ -30,6 +30,9 @@ AssetFilter::AssetFilter(QObject *parent)
: QSortFilterProxyModel(parent)
, m_name_enabled(false)
{
setFilterRole(Qt::DisplayRole);
setSortRole(Qt::DisplayRole);
setDynamicSortFilter(false);
}
void AssetFilter::setFilterName(bool enabled, const QString &pattern)
......@@ -37,7 +40,9 @@ void AssetFilter::setFilterName(bool enabled, const QString &pattern)
m_name_enabled = enabled;
m_name_value = pattern;
invalidateFilter();
sort(0);
if (rowCount() > 1) {
sort(0);
}
}
bool AssetFilter::filterName(const std::shared_ptr<TreeItem> &item) const
......@@ -61,6 +66,9 @@ bool AssetFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParen
if (item->dataColumn(AssetTreeModel::idCol) == QStringLiteral("root")) {
// In that case, we have a category. We hide it if it does not have children.
QModelIndex category = sourceModel()->index(sourceRow, 0, sourceParent);
if (!category.isValid()) {
return false;
}
bool accepted = false;
for (int i = 0; i < sourceModel()->rowCount(category) && !accepted; ++i) {
accepted = filterAcceptsRow(i, category);
......@@ -142,3 +150,15 @@ QModelIndex AssetFilter::getCategory(int catRow)
QModelIndex cat = index(catRow, 0, QModelIndex());
return cat;
}
QVariantList AssetFilter::getCategories()
{
QVariantList list;
for (int i = 0; i < sourceModel()->rowCount(); i++) {
QModelIndex cat = getCategory(i);
if (cat.isValid()) {
list << cat;
}
}
return list;
}
......@@ -45,6 +45,7 @@ public:
/** @brief Returns true if the ModelIndex in the source model is visible after filtering
*/
bool isVisible(const QModelIndex &sourceIndex);
QVariantList getCategories();
Q_INVOKABLE QModelIndex getNextChild(const QModelIndex &current);
Q_INVOKABLE QModelIndex getPreviousChild(const QModelIndex &current);
Q_INVOKABLE QModelIndex firstVisibleItem(const QModelIndex &current);
......
......@@ -90,13 +90,3 @@ QVariant AssetTreeModel::data(const QModelIndex &index, int role) const
return item->dataColumn(index.column());
}
QList<QModelIndex> AssetTreeModel::getChildrenIndexes()
{
QList<QModelIndex> indexes;
for (int i = 0; i != rootItem->childCount(); ++i) {
auto child = rootItem->child(i);
indexes << getIndexFromItem(child);
}
return indexes;
}
......@@ -41,7 +41,6 @@ public:
QString getDescription(const QModelIndex &index) const;
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role) const override;
QList<QModelIndex> getChildrenIndexes();
// for convenience, we store the column of each data field
static int nameCol, idCol, favCol, typeCol;
......
......@@ -64,11 +64,8 @@ void AssetListWidget::setFilterName(const QString &pattern)
{
m_proxyModel->setFilterName(!pattern.isEmpty(), pattern);
if (!pattern.isEmpty()) {
QVariantList mapped;
for (const QModelIndex &ix : m_model->getChildrenIndexes()) {
mapped << m_proxyModel->mapFromSource(ix);
}
QMetaObject::invokeMethod(rootObject(), "expandNodes", Qt::QueuedConnection, Q_ARG(QVariant, mapped));
QVariantList mapped = m_proxyModel->getCategories();
QMetaObject::invokeMethod(rootObject(), "expandNodes", Qt::DirectConnection, Q_ARG(QVariant, mapped));
}
}
......
......@@ -37,7 +37,9 @@ Rectangle {
function expandNodes(indexes) {
for(var i = 0; i < indexes.length; i++) {
treeView.expand(indexes[i]);
if (indexes[i].valid) {
treeView.expand(indexes[i]);
}
}
}
function rowPosition(model, index) {
......@@ -187,7 +189,10 @@ Rectangle {
onTextChanged: {
var current = sel.currentIndex
assetlist.setFilterName(text)
sel.setCurrentIndex(assetListModel.firstVisibleItem(current), ItemSelectionModel.ClearAndSelect)
if (text.length > 0) {
sel.clear
sel.setCurrentIndex(assetListModel.firstVisibleItem(current), ItemSelectionModel.Select)
}
treeView.__listView.positionViewAtIndex(rowPosition(assetListModel, sel.currentIndex), ListView.Visible)
}
onEditingFinished: {
......
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