Commit 00a63db6 authored by Simon Depiets's avatar Simon Depiets

Set the proper entry index in catalog after a filter is applied

BUG: 400208
parent 88e55189
......@@ -154,13 +154,22 @@ void CatalogView::slotNewEntryDisplayed(const DocPosition& pos)
QModelIndex item = m_proxyModel->mapFromSource(m_model->index(pos.entry, 0));
m_browser->setCurrentIndex(item);
m_browser->scrollTo(item/*,QAbstractItemView::PositionAtCenter*/);
m_lastKnownDocPosition = pos.entry;
}
void CatalogView::setFilterRegExp()
{
QString expr = m_lineEdit->text();
if (m_proxyModel->filterRegExp().pattern() != expr)
m_proxyModel->setFilterRegExp(m_proxyModel->filerOptions()&CatalogTreeFilterModel::IgnoreAccel ? expr.remove(Project::instance()->accel()) : expr);
m_proxyModel->setFilterRegExp(m_proxyModel->filterOptions()&CatalogTreeFilterModel::IgnoreAccel ? expr.remove(Project::instance()->accel()) : expr);
refreshCurrentIndex();
}
void CatalogView::refreshCurrentIndex()
{
QModelIndex newPositionOfSelectedItem = m_proxyModel->mapFromSource(m_model->index(m_lastKnownDocPosition, 0));
m_browser->setCurrentIndex(newPositionOfSelectedItem);
m_browser->scrollTo(newPositionOfSelectedItem);
}
void CatalogView::slotItemActivated(const QModelIndex& idx)
......@@ -175,12 +184,13 @@ void CatalogView::filterOptionToggled(QAction* action)
int opt = action->data().toInt();
if (opt > 0)
m_proxyModel->setFilerOptions(m_proxyModel->filerOptions()^opt);
m_proxyModel->setFilterOptions(m_proxyModel->filterOptions()^opt);
else {
if (opt != -1) opt = -opt - 2;
m_proxyModel->setFilterKeyColumn(opt);
}
m_filterOptionsMenu->clear();
refreshCurrentIndex();
}
void CatalogView::fillFilterOptionsMenu()
{
......@@ -226,7 +236,7 @@ void CatalogView::fillFilterOptionsMenu()
txt = allmenus[ext]->addAction(i18n(alltitles[ext][i - ext * FIRSTSTATEPOSITION]));
txt->setData(1 << i);
txt->setCheckable(true);
txt->setChecked(m_proxyModel->filerOptions() & (1 << i));
txt->setChecked(m_proxyModel->filterOptions() & (1 << i));
if ((1 << i) == CatalogTreeFilterModel::IgnoreAccel)
basicMenu->addSeparator();
}
......@@ -240,13 +250,15 @@ void CatalogView::fillFilterOptionsMenu()
txt->setCheckable(true);
txt->setChecked(m_proxyModel->filterKeyColumn() == i);
}
refreshCurrentIndex();
}
void CatalogView::reset()
{
m_proxyModel->setFilterKeyColumn(-1);
m_proxyModel->setFilerOptions(CatalogTreeFilterModel::AllStates);
m_proxyModel->setFilterOptions(CatalogTreeFilterModel::AllStates);
m_lineEdit->clear();
refreshCurrentIndex();
//emit gotoEntry(DocPosition(m_proxyModel->mapToSource(m_browser->currentIndex()).row()),0);
slotItemActivated(m_browser->currentIndex());
}
......@@ -305,11 +317,13 @@ int CatalogView::lastEntryNumber()
void CatalogView::setEntryFilteredOut(int entry, bool filteredOut)
{
m_proxyModel->setEntryFilteredOut(entry, filteredOut);
refreshCurrentIndex();
}
void CatalogView::setEntriesFilteredOut(bool filteredOut)
{
show();
m_proxyModel->setEntriesFilteredOut(filteredOut);
refreshCurrentIndex();
}
......@@ -54,6 +54,7 @@ public:
int lastEntryNumber();
private:
int siblingEntryNumber(int step);
void refreshCurrentIndex();
public slots:
void slotNewEntryDisplayed(const DocPosition&);
......@@ -78,6 +79,7 @@ private:
QMenu* m_filterOptionsMenu;
CatalogTreeModel* m_model;
CatalogTreeFilterModel* m_proxyModel;
int m_lastKnownDocPosition;
};
#endif
......@@ -196,7 +196,7 @@ QVariant CatalogTreeModel::data(const QModelIndex& index, int role) const
CatalogTreeFilterModel::CatalogTreeFilterModel(QObject* parent)
: QSortFilterProxyModel(parent)
, m_filerOptions(AllStates)
, m_filterOptions(AllStates)
, m_individualRejectFilterEnable(false)
, m_mergeCatalog(NULL)
{
......@@ -233,9 +233,9 @@ void CatalogTreeFilterModel::setEntryFilteredOut(int entry, bool filteredOut)
invalidateFilter();
}
void CatalogTreeFilterModel::setFilerOptions(int o)
void CatalogTreeFilterModel::setFilterOptions(int o)
{
m_filerOptions = o;
m_filterOptions = o;
setFilterCaseSensitivity(o & CaseInsensitive ? Qt::CaseInsensitive : Qt::CaseSensitive);
static_cast<CatalogTreeModel*>(sourceModel())->setIgnoreAccel(o & IgnoreAccel);
invalidateFilter();
......@@ -243,7 +243,7 @@ void CatalogTreeFilterModel::setFilerOptions(int o)
bool CatalogTreeFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
int filerOptions = m_filerOptions;
int filerOptions = m_filterOptions;
bool accepts = true;
if (bool(filerOptions & Ready) != bool(filerOptions & NotReady)) {
bool ready = sourceModel()->index(source_row, CatalogTreeModel::TranslationStatus, source_parent).data(Qt::UserRole).toBool();
......
......@@ -145,10 +145,10 @@ public:
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
void setFilerOptions(int o);
int filerOptions()const
void setFilterOptions(int o);
int filterOptions()const
{
return m_filerOptions;
return m_filterOptions;
}
void setSourceModel(QAbstractItemModel* sourceModel) override;
......@@ -170,7 +170,7 @@ public slots:
}
private:
int m_filerOptions;
int m_filterOptions;
bool m_individualRejectFilterEnable;
QVector<bool> m_individualRejectFilter; //used from kross scripts
MergeCatalog* m_mergeCatalog;
......
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