File indexing completed on 2024-05-12 05:44:27
0001 /*************************************************************************** 0002 * Copyright (C) 2008 by Rajko Albrecht ral@alwins-world.de * 0003 * https://kde.org/applications/development/org.kde.kdesvn * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 0021 #include "svnsortfilter.h" 0022 #include "settings/kdesvnsettings.h" 0023 #include "svnitemmodel.h" 0024 #include "svnitemnode.h" 0025 0026 void SvnSortFilterProxy::setSourceModel(QAbstractItemModel *sourceModel) 0027 { 0028 m_sourceModel = qobject_cast<SvnItemModel *>(sourceModel); 0029 QSortFilterProxyModel::setSourceModel(sourceModel); 0030 } 0031 0032 bool SvnSortFilterProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const 0033 { 0034 if (!(left.isValid() && right.isValid())) { 0035 return QSortFilterProxyModel::lessThan(left, right); 0036 } 0037 0038 SvnItemModelNode *n1 = static_cast<SvnItemModelNode *>(left.internalPointer()); 0039 SvnItemModelNode *n2 = static_cast<SvnItemModelNode *>(right.internalPointer()); 0040 /* 0041 * when having valid model indexes the internal pointer MUST be valid, too. 0042 * so we may skip if for this. 0043 */ 0044 Q_ASSERT(n1 && n2); 0045 if (n1->sortChar() == n2->sortChar()) { 0046 if (sortColumn() == SvnItemModel::LastRevision) { 0047 return n1->cmtRev() < n2->cmtRev(); 0048 } 0049 return QSortFilterProxyModel::lessThan(left, right); 0050 } 0051 // we want folders always @first 0052 if (sortOrder() == Qt::AscendingOrder) { 0053 return n1->sortChar() < n2->sortChar(); 0054 } else { 0055 return n1->sortChar() > n2->sortChar(); 0056 } 0057 } 0058 0059 bool SvnSortFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const 0060 { 0061 if (m_sourceModel->filterIndex(source_parent, source_row, m_ShowFilter)) { 0062 return false; 0063 } 0064 return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); 0065 } 0066 0067 void SvnSortFilterProxy::setShowFilter(svnmodel::ItemTypeFlag fl) 0068 { 0069 m_ShowFilter = fl; 0070 invalidateFilter(); 0071 } 0072 0073 #include "moc_svnsortfilter.cpp"