Changeset View
Changeset View
Standalone View
Standalone View
src/project/projectwidget.cpp
Show First 20 Lines • Show All 137 Lines • ▼ Show 20 Line(s) | |||||
138 | { | 138 | { | ||
139 | public: | 139 | public: | ||
140 | SortFilterProxyModel(QObject* parent=0) | 140 | SortFilterProxyModel(QObject* parent=0) | ||
141 | : KDirSortFilterProxyModel(parent) | 141 | : KDirSortFilterProxyModel(parent) | ||
142 | { | 142 | { | ||
143 | connect(Project::instance()->model(),SIGNAL(totalsChanged(int,int,int,bool)),this,SLOT(invalidate())); | 143 | connect(Project::instance()->model(),SIGNAL(totalsChanged(int,int,int,bool)),this,SLOT(invalidate())); | ||
144 | } | 144 | } | ||
145 | ~SortFilterProxyModel(){} | 145 | ~SortFilterProxyModel(){} | ||
146 | void toggleTranslatedFiles(); | ||||
146 | protected: | 147 | protected: | ||
147 | bool lessThan(const QModelIndex& left, | 148 | bool lessThan(const QModelIndex& left, | ||
148 | const QModelIndex& right) const; | 149 | const QModelIndex& right) const; | ||
149 | bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; | 150 | bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; | ||
151 | private: | ||||
152 | bool m_hideTranslatedFiles = false; | ||||
150 | }; | 153 | }; | ||
151 | 154 | | |||
155 | void SortFilterProxyModel::toggleTranslatedFiles() | ||||
mlaurent: coding style:
::foo()
{
...
}
| |||||
aacid: You still need to move the { down. | |||||
156 | { | ||||
157 | m_hideTranslatedFiles = !m_hideTranslatedFiles; | ||||
158 | invalidateFilter(); | ||||
159 | } | ||||
152 | 160 | | |||
153 | bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const | 161 | bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const | ||
154 | { | 162 | { | ||
155 | bool result=false; | 163 | bool result=false; | ||
156 | const QAbstractItemModel* model=sourceModel(); | 164 | const QAbstractItemModel* model=sourceModel(); | ||
157 | QModelIndex item=model->index(source_row,0,source_parent); | 165 | QModelIndex item=model->index(source_row,0,source_parent); | ||
158 | /* | 166 | /* | ||
159 | if (model->hasChildren(item)) | 167 | if (model->hasChildren(item)) | ||
160 | model->fetchMore(item); | 168 | model->fetchMore(item); | ||
161 | */ | 169 | */ | ||
162 | if (item.data(ProjectModel::TotalRole) == 0) | 170 | if (item.data(ProjectModel::TotalRole) == 0) | ||
163 | return false; // Hide rows with no translations | 171 | return false; // Hide rows with no translations | ||
164 | 172 | | |||
173 | if (item.data(ProjectModel::FuzzyUntrCountAllRole) == 0 && m_hideTranslatedFiles) | ||||
174 | return false; // Hide rows with no untranslated items if the filter is enabled | ||||
175 | | ||||
165 | int i=model->rowCount(item); | 176 | int i=model->rowCount(item); | ||
166 | while(--i>=0 && !result) | 177 | while(--i>=0 && !result) | ||
167 | result=filterAcceptsRow(i,item); | 178 | result=filterAcceptsRow(i,item); | ||
168 | 179 | | |||
169 | return result || QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); | 180 | return result || QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); | ||
170 | } | 181 | } | ||
171 | 182 | | |||
172 | bool SortFilterProxyModel::lessThan(const QModelIndex& left, | 183 | bool SortFilterProxyModel::lessThan(const QModelIndex& left, | ||
▲ Show 20 Lines • Show All 323 Lines • ▼ Show 20 Line(s) | |||||
496 | void ProjectWidget::gotoPrevFuzzy() {gotoIndex(currentIndex(), ProjectModel::FuzzyCountRole, -1);} | 507 | void ProjectWidget::gotoPrevFuzzy() {gotoIndex(currentIndex(), ProjectModel::FuzzyCountRole, -1);} | ||
497 | void ProjectWidget::gotoNextFuzzy() {gotoIndex(currentIndex(), ProjectModel::FuzzyCountRole, +1);} | 508 | void ProjectWidget::gotoNextFuzzy() {gotoIndex(currentIndex(), ProjectModel::FuzzyCountRole, +1);} | ||
498 | void ProjectWidget::gotoPrevUntranslated() {gotoIndex(currentIndex(), ProjectModel::UntransCountRole, -1);} | 509 | void ProjectWidget::gotoPrevUntranslated() {gotoIndex(currentIndex(), ProjectModel::UntransCountRole, -1);} | ||
499 | void ProjectWidget::gotoNextUntranslated() {gotoIndex(currentIndex(), ProjectModel::UntransCountRole, +1);} | 510 | void ProjectWidget::gotoNextUntranslated() {gotoIndex(currentIndex(), ProjectModel::UntransCountRole, +1);} | ||
500 | void ProjectWidget::gotoPrevTemplateOnly() {gotoIndex(currentIndex(), ProjectModel::TemplateOnlyRole, -1);} | 511 | void ProjectWidget::gotoPrevTemplateOnly() {gotoIndex(currentIndex(), ProjectModel::TemplateOnlyRole, -1);} | ||
501 | void ProjectWidget::gotoNextTemplateOnly() {gotoIndex(currentIndex(), ProjectModel::TemplateOnlyRole, +1);} | 512 | void ProjectWidget::gotoNextTemplateOnly() {gotoIndex(currentIndex(), ProjectModel::TemplateOnlyRole, +1);} | ||
502 | void ProjectWidget::gotoPrevTransOnly() {gotoIndex(currentIndex(), ProjectModel::TransOnlyRole, -1);} | 513 | void ProjectWidget::gotoPrevTransOnly() {gotoIndex(currentIndex(), ProjectModel::TransOnlyRole, -1);} | ||
503 | void ProjectWidget::gotoNextTransOnly() {gotoIndex(currentIndex(), ProjectModel::TransOnlyRole, +1);} | 514 | void ProjectWidget::gotoNextTransOnly() {gotoIndex(currentIndex(), ProjectModel::TransOnlyRole, +1);} | ||
515 | void ProjectWidget::toggleTranslatedFiles() | ||||
516 | { | ||||
517 | m_proxyModel->toggleTranslatedFiles(); | ||||
518 | } | ||||
Can you try with invalidateFilter ? Reading the documentation it seems it would make more sense. Also IMHO it makes more sense to call this inside toggletranslatedfiles than here. aacid: Can you try with invalidateFilter ? Reading the documentation it seems it would make more sense. | |||||
504 | 519 | | |||
505 | QSortFilterProxyModel* ProjectWidget::proxyModel(){return m_proxyModel;} | 520 | QSortFilterProxyModel* ProjectWidget::proxyModel(){return m_proxyModel;} | ||
506 | 521 | |
coding style:
::foo()
{
...
}