diff --git a/src/ksvnwidgets/models/commitmodel.cpp b/src/ksvnwidgets/models/commitmodel.cpp index 1e00d172..0e27f610 100644 --- a/src/ksvnwidgets/models/commitmodel.cpp +++ b/src/ksvnwidgets/models/commitmodel.cpp @@ -1,325 +1,316 @@ /*************************************************************************** * Copyright (C) 2005-2009 by Rajko Albrecht * * ral@alwins-world.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "commitmodel.h" #include "commitmodelhelper.h" #include "svnqt/commititem.h" #include CommitModel::CommitModel(const svn::CommitItemList &aList, QObject *parent) : QAbstractItemModel(parent) { setCommitData(aList); } /********************* * Begin CommitModel * *********************/ CommitModel::CommitModel(const CommitActionEntries &_checked, const CommitActionEntries &_notchecked, QObject *parent) : QAbstractItemModel(parent) { setCommitData(_checked, _notchecked); } CommitModel::~CommitModel() { } void CommitModel::setCommitData(const svn::CommitItemList &aList) { if (!m_List.isEmpty()) { beginRemoveRows(QModelIndex(), 0, m_List.count() - 1); m_List.clear(); endRemoveRows(); } if (!aList.isEmpty()) { m_List.reserve(aList.size()); beginInsertRows(QModelIndex(), 0, aList.size() - 1); for (int j = 0; j < aList.size(); ++j) { m_List.append(CommitModelNodePtr(new CommitModelNode(aList[j]))); } endInsertRows(); } } void CommitModel::setCommitData(const CommitActionEntries &checked, const CommitActionEntries ¬checked) { if (!m_List.isEmpty()) { beginRemoveRows(QModelIndex(), 0, m_List.count() - 1); m_List.clear(); endRemoveRows(); } const int totalSize = checked.size() + notchecked.size(); if (totalSize > 0) { m_List.reserve(totalSize); beginInsertRows(QModelIndex(), 0, totalSize - 1); for (int j = 0; j < checked.size(); ++j) { m_List.append(CommitModelNodePtr(new CommitModelNode(checked[j], true))); } for (int j = 0; j < notchecked.size(); ++j) { m_List.append(CommitModelNodePtr(new CommitModelNode(notchecked[j], false))); } endInsertRows(); } } int CommitModel::ActionColumn()const { return 0; } int CommitModel::ItemColumn()const { return 1; } CommitModelNodePtr CommitModel::node(const QModelIndex &index) { if (!index.isValid() || index.row() >= m_List.count()) { return CommitModelNodePtr(); } return m_List.at(index.row()); } CommitActionEntries CommitModel::checkedEntries()const { CommitActionEntries res; for (int i = 0; i < m_List.count(); ++i) { if (m_List.at(i)->checked()) { res.append(m_List.at(i)->actionEntry()); } } return res; } void CommitModel::markItems(bool mark, CommitActionEntry::ACTION_TYPE _type) { QVariant v = mark ? int(2) : int(0); for (int i = 0; i < m_List.count(); ++i) { if (m_List.at(i)->actionEntry().type() & _type) { QModelIndex _index = index(i, 0, QModelIndex()); setData(_index, v, Qt::CheckStateRole); dataChanged(_index, _index); } } } /*! \fn CommitModel::removeEntries(const QStringList&) */ void CommitModel::removeEntries(const QStringList &_items) { QStringList items = _items; // items is normally much smaller than m_List, therefore // iterate over the items in the inner loop for (int j = m_List.count() - 1; j >= 0; --j) { const QString aeName = m_List.at(j)->actionEntry().name(); for (int i = items.size() - 1; i >= 0; --i) { if (aeName == items.at(i)) { beginRemoveRows(QModelIndex(), j, j); m_List.remove(j); endRemoveRows(); items.removeAt(i); break; // break inner loop } } if (items.isEmpty()) break; } } const CommitModelNodePtr CommitModel::dataForRow(int row) const { if (row < 0 || row >= m_List.size()) return CommitModelNodePtr(); return m_List.at(row); } /************************************ * begin overload of Model methods * ************************************/ QModelIndex CommitModel::index(int row, int column, const QModelIndex & /*parent*/)const { if (row < 0 || row >= m_List.count()) { return QModelIndex(); } const CommitModelNodePtr &n = m_List.at(row); return createIndex(row, column, n.data()); } QModelIndex CommitModel::parent(const QModelIndex &)const { // we have no tree... return QModelIndex(); } QVariant CommitModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() >= m_List.count() || role != Qt::DisplayRole) { return QVariant(); } const CommitModelNodePtr &n = m_List.at(index.row()); if (index.column() == ActionColumn()) { return n->actionEntry().action(); } if (index.column() == ItemColumn()) { return n->actionEntry().name(); } return QVariant(); } QVariant CommitModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == ActionColumn()) { return i18n("Action"); } if (section == ItemColumn()) { return i18n("Entry"); } } return QAbstractItemModel::headerData(section, orientation, role); } int CommitModel::rowCount(const QModelIndex &) const { return m_List.count(); } int CommitModel::columnCount(const QModelIndex &) const { return 2; } /************************************ * end overload of Model methods * ************************************/ /********************* * end CommitModel * *********************/ /************************************ * begin CommitModelCheckitem * ************************************/ CommitModelCheckitem::CommitModelCheckitem(const CommitActionEntries &_checked, const CommitActionEntries &_notchecked, QObject *parent) : CommitModel(_checked, _notchecked, parent) { } CommitModelCheckitem::~CommitModelCheckitem() { } int CommitModelCheckitem::ActionColumn()const { return 1; } int CommitModelCheckitem::ItemColumn()const { return 0; } Qt::ItemFlags CommitModelCheckitem::flags(const QModelIndex &index) const { if (index.isValid() && index.column() == ItemColumn()) { return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; } return CommitModel::flags(index); } QVariant CommitModelCheckitem::data(const QModelIndex &index, int role) const { if (index.column() != ItemColumn() || role != Qt::CheckStateRole || !index.isValid() || index.row() >= m_List.count()) { return CommitModel::data(index, role); } if (m_List.at(index.row())->checked()) { return Qt::Checked; } return Qt::Unchecked; } bool CommitModelCheckitem::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.column() != ItemColumn() || role != Qt::CheckStateRole || !index.isValid() || index.row() >= m_List.count()) { return CommitModel::setData(index, value, role); } if (value.type() == QVariant::Int) { CommitModelNodePtr _l = m_List.at(index.row()); bool old = _l->checked(); bool nv = value.toInt() > 0; _l->setChecked(nv); if (old != nv) { emit dataChanged(index, index); } return old != nv; } return false; } /************************************ * end CommitModelCheckitem * ************************************/ /*************************** * Begin CommitFilterModel * ***************************/ -CommitFilterModel::CommitFilterModel(QObject *parent) - : QSortFilterProxyModel(parent) - , m_sourceModel(nullptr) - , m_visibleTypes(CommitActionEntry::ALL) -{} - -CommitFilterModel::~CommitFilterModel() -{} - void CommitFilterModel::setSourceModel(QAbstractItemModel *sourceModel) { m_sourceModel = qobject_cast(sourceModel); QSortFilterProxyModel::setSourceModel(sourceModel); } bool CommitFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { if (!m_sourceModel || source_parent.isValid()) return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); const CommitModelNodePtr node = m_sourceModel->dataForRow(source_row); return ((node->actionEntry().type() & m_visibleTypes) != 0); } void CommitFilterModel::hideItems(bool bHide, CommitActionEntry::ACTION_TYPE aType) { const CommitActionEntry::ActionTypes curVisibleTypes = m_visibleTypes; if (bHide) { m_visibleTypes &= ~aType; } else { m_visibleTypes |= aType; } if (m_visibleTypes != curVisibleTypes) { invalidateFilter(); } } /************************* * end CommitFilterModel * *************************/ diff --git a/src/ksvnwidgets/models/commitmodel.h b/src/ksvnwidgets/models/commitmodel.h index 51bd5e2c..1102c848 100644 --- a/src/ksvnwidgets/models/commitmodel.h +++ b/src/ksvnwidgets/models/commitmodel.h @@ -1,98 +1,97 @@ /*************************************************************************** * Copyright (C) 2005-2009 by Rajko Albrecht * * ral@alwins-world.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef COMMITMODEL_H #define COMMITMODEL_H #include "commitmodelfwd.h" #include "commitmodelhelper.h" #include "svnqt/svnqttypes.h" #include #include #include class CommitModel: public QAbstractItemModel { Q_OBJECT protected: explicit CommitModel(const CommitActionEntries &, const CommitActionEntries &, QObject *parent = nullptr); void setCommitData(const CommitActionEntries &, const CommitActionEntries &); public: explicit CommitModel(const svn::CommitItemList &, QObject *parent = nullptr); void setCommitData(const svn::CommitItemList &); ~CommitModel(); QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex())const override; QModelIndex parent(const QModelIndex &)const override; QVariant data(const QModelIndex &index, int role) const override; int rowCount(const QModelIndex &) const override; int columnCount(const QModelIndex &) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; virtual int ActionColumn()const; virtual int ItemColumn()const; CommitModelNodePtr node(const QModelIndex &); CommitActionEntries checkedEntries()const; void markItems(bool mark, CommitActionEntry::ACTION_TYPE _type); void removeEntries(const QStringList &_items); const CommitModelNodePtr dataForRow(int row) const; protected: CommitModelNodeList m_List; }; class CommitModelCheckitem: public CommitModel { Q_OBJECT public: CommitModelCheckitem(const CommitActionEntries &, const CommitActionEntries &, QObject *parent = nullptr); ~CommitModelCheckitem(); Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant data(const QModelIndex &index, int role) const override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; int ActionColumn()const override; int ItemColumn()const override; }; -class CommitFilterModel : public QSortFilterProxyModel +class CommitFilterModel final : public QSortFilterProxyModel { Q_OBJECT public: - explicit CommitFilterModel(QObject *parent); - ~CommitFilterModel(); + using QSortFilterProxyModel::QSortFilterProxyModel; void setSourceModel(QAbstractItemModel *sourceModel) override; - bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; - void hideItems(bool bHide, CommitActionEntry::ACTION_TYPE aType); +protected: + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; private: - CommitModel *m_sourceModel; - CommitActionEntry::ActionTypes m_visibleTypes; + CommitModel *m_sourceModel = nullptr; + CommitActionEntry::ActionTypes m_visibleTypes = CommitActionEntry::ALL; }; #endif diff --git a/src/svnfrontend/models/logitemmodel.cpp b/src/svnfrontend/models/logitemmodel.cpp index d33c7d53..e2b59d19 100644 --- a/src/svnfrontend/models/logitemmodel.cpp +++ b/src/svnfrontend/models/logitemmodel.cpp @@ -1,279 +1,271 @@ /*************************************************************************** * Copyright (C) 2007 by Rajko Albrecht ral@alwins-world.de * * http://kdesvn.alwins-world.de/ * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "logitemmodel.h" #include "logmodelhelper.h" #include "svnqt/client.h" #include #include #include SvnLogModel::SvnLogModel(const svn::LogEntriesMapPtr &_log, const QString &m_name, QObject *parent) : QAbstractListModel(parent) , m_emptyString() , m_min(-1) , m_max(-1) , m_name() , m_left(-1) , m_right(-1) { setLogData(_log, m_name); } -SvnLogModel::~SvnLogModel() -{} - void SvnLogModel::setLogData(const svn::LogEntriesMapPtr &log, const QString &name) { beginResetModel(); m_data.clear(); endResetModel(); m_name = name; m_left = m_right = -1; QMap itemMap; m_min = m_max = -1; if (log->isEmpty()) { return; } m_data.reserve(log->count()); beginInsertRows(QModelIndex(), 0, log->count() - 1); svn::LogEntriesMap::const_iterator it = log->constBegin(); for (; it != log->constEnd(); ++it) { SvnLogModelNodePtr np(new SvnLogModelNode((*it))); m_data.append(np); if ((*it).revision > m_max) { m_max = (*it).revision; } if ((*it).revision < m_min || m_min == -1) { m_min = (*it).revision; } itemMap[(*it).revision] = np; } endInsertRows(); QString bef = m_name; qlonglong rev; // YES! I'd checked it: this is much faster than getting list of keys // and iterating over that list! for (long c = m_max; c > -1; --c) { if (!itemMap.contains(c)) { continue; } if (itemMap[c]->realName().isEmpty()) { itemMap[c]->setRealName(bef); } itemMap[c]->copiedFrom(bef, rev); } } qlonglong SvnLogModel::min() const { return m_min; } qlonglong SvnLogModel::max() const { return m_max; } int SvnLogModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return m_data.count(); } QVariant SvnLogModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() >= m_data.count()) { return QVariant(); } const SvnLogModelNodePtr &_l = m_data.at(index.row()); switch (role) { case Qt::DisplayRole: switch (index.column()) { case Revision: return _l->revision(); case Author: return _l->author(); case Date: return _l->date(); case Message: return _l->shortMessage(); } break; case Qt::DecorationRole: if (index.column() == 0) { if (index.row() == m_left) { return QIcon::fromTheme(QStringLiteral("kdesvnleft")); } if (index.row() == m_right) { return QIcon::fromTheme(QStringLiteral("kdesvnright")); } return QStringLiteral(" "); } break; } return QVariant(); } qlonglong SvnLogModel::toRevision(const QModelIndex &index)const { if (!index.isValid() || index.row() >= m_data.count()) { return -1; } return m_data[index.row()]->revision(); } const QString &SvnLogModel::fullMessage(const QModelIndex &index)const { if (!index.isValid() || index.row() >= m_data.count()) { return m_emptyString; } return m_data[index.row()]->message(); } const QString &SvnLogModel::realName(const QModelIndex &index) { if (!index.isValid() || index.row() >= m_data.count()) { return m_emptyString; } return m_data[index.row()]->realName(); } int SvnLogModel::columnCount(const QModelIndex &)const { return Count; } QVariant SvnLogModel::headerData(int section, Qt::Orientation orientation, int role) const { Q_UNUSED(orientation); switch (role) { case Qt::DisplayRole: switch (section) { case Revision: return i18n("Revision"); case Author: return i18n("Author"); case Date: return i18n("Date"); case Message: return i18n("Message"); } } return QVariant(); } SvnLogModelNodePtr SvnLogModel::indexNode(const QModelIndex &index)const { if (!index.isValid() || index.row() >= m_data.count()) { return SvnLogModelNodePtr(); } return m_data.at(index.row()); } void SvnLogModel::fillChangedPaths(const QModelIndex &index, QTreeWidget *where) { if (!where || !index.isValid() || index.row() >= m_data.count()) { return; } where->clear(); const SvnLogModelNodePtr &_l = m_data.at(index.row()); if (_l->changedPaths().isEmpty()) { return; } QList _list; for (int i = 0; i < _l->changedPaths().count(); ++i) { _list.append(new LogChangePathItem(_l->changedPaths()[i])); } where->addTopLevelItems(_list); where->resizeColumnToContents(0); where->resizeColumnToContents(1); where->resizeColumnToContents(2); where->sortByColumn(1, Qt::AscendingOrder); } int SvnLogModel::leftRow()const { return m_left; } int SvnLogModel::rightRow()const { return m_right; } void SvnLogModel::setLeftRow(int v) { if (m_right == v) { m_right = -1; } m_left = v; } void SvnLogModel::setRightRow(int v) { if (m_left == v) { m_left = -1; } m_right = v; } -SvnLogSortModel::SvnLogSortModel(QObject *parent) - : QSortFilterProxyModel(parent) - , m_sourceModel(nullptr) -{} - -SvnLogSortModel::~SvnLogSortModel() -{} - +// +// SvnLogSortModel +// void SvnLogSortModel::setSourceModel(QAbstractItemModel *sourceModel) { m_sourceModel = qobject_cast(sourceModel); QSortFilterProxyModel::setSourceModel(sourceModel); } bool SvnLogSortModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { if(source_left.column() != source_right.column() || !m_sourceModel) { return QSortFilterProxyModel::lessThan(source_left, source_right); } const SvnLogModelNodePtr &dataLeft = m_sourceModel->m_data.at(source_left.row()); const SvnLogModelNodePtr &dataRight = m_sourceModel->m_data.at(source_right.row()); switch (source_left.column()) { case SvnLogModel::Author: return dataLeft->author() < dataRight->author(); case SvnLogModel::Revision: return dataLeft->revision() < dataRight->revision(); case SvnLogModel::Date: return dataLeft->dateMSec() < dataRight->dateMSec(); case SvnLogModel::Message: return dataLeft->message() < dataRight->message(); default: break; } return QSortFilterProxyModel::lessThan(source_left, source_right); } diff --git a/src/svnfrontend/models/logitemmodel.h b/src/svnfrontend/models/logitemmodel.h index 61a59f77..dbe691b9 100644 --- a/src/svnfrontend/models/logitemmodel.h +++ b/src/svnfrontend/models/logitemmodel.h @@ -1,93 +1,91 @@ /*************************************************************************** * Copyright (C) 2007 by Rajko Albrecht ral@alwins-world.de * * http://kdesvn.alwins-world.de/ * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef LOG_ITEM_MODEL_H #define LOG_ITEM_MODEL_H #include #include #include "svnqt/svnqttypes.h" class SvnLogModelNode; class QTreeWidget; typedef QSharedPointer SvnLogModelNodePtr; class SvnLogModel: public QAbstractListModel { Q_OBJECT public: SvnLogModel(const svn::LogEntriesMapPtr &_log, const QString &_name, QObject *parent); - ~SvnLogModel(); void setLogData(const svn::LogEntriesMapPtr &log, const QString &name); qlonglong toRevision(const QModelIndex &)const; const QString &fullMessage(const QModelIndex &index)const; void fillChangedPaths(const QModelIndex &index, QTreeWidget *target); const QString &realName(const QModelIndex &index); enum Columns { Author = 0, Revision, Date, Message, Count }; QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &) const Q_DECL_OVERRIDE; SvnLogModelNodePtr indexNode(const QModelIndex &)const; - int leftRow()const; - int rightRow()const; + int leftRow() const; + int rightRow() const; void setLeftRow(int); void setRightRow(int); qlonglong min() const; qlonglong max() const; private: QVector m_data; QString m_emptyString; qlonglong m_min, m_max; QString m_name; int m_left, m_right; friend class SvnLogSortModel; }; -class SvnLogSortModel : public QSortFilterProxyModel +class SvnLogSortModel final : public QSortFilterProxyModel { Q_OBJECT public: - SvnLogSortModel(QObject *parent = nullptr); - ~SvnLogSortModel(); + using QSortFilterProxyModel::QSortFilterProxyModel; - void setSourceModel(QAbstractItemModel *sourceModel) final; + void setSourceModel(QAbstractItemModel *sourceModel) override final; protected: - bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const final; + bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override final; private: - SvnLogModel *m_sourceModel; + SvnLogModel *m_sourceModel = nullptr; }; #endif diff --git a/src/svnfrontend/models/svnsortfilter.cpp b/src/svnfrontend/models/svnsortfilter.cpp index 8e97d8d8..07ee5534 100644 --- a/src/svnfrontend/models/svnsortfilter.cpp +++ b/src/svnfrontend/models/svnsortfilter.cpp @@ -1,76 +1,71 @@ /*************************************************************************** * Copyright (C) 2008 by Rajko Albrecht ral@alwins-world.de * * http://kdesvn.alwins-world.de/ * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "svnsortfilter.h" #include "svnitemmodel.h" #include "svnitemnode.h" #include "settings/kdesvnsettings.h" -SvnSortFilterProxy::SvnSortFilterProxy(QObject *parent) - : QSortFilterProxyModel(parent), m_sourceModel(nullptr), m_ShowFilter(svnmodel::All) -{ -} - void SvnSortFilterProxy::setSourceModel(QAbstractItemModel *sourceModel) { m_sourceModel = qobject_cast(sourceModel); QSortFilterProxyModel::setSourceModel(sourceModel); } bool SvnSortFilterProxy::lessThan(const QModelIndex &left, const QModelIndex &right)const { if (!(left.isValid() && right.isValid())) { return QSortFilterProxyModel::lessThan(left, right); } SvnItemModelNode *n1 = static_cast(left.internalPointer()); SvnItemModelNode *n2 = static_cast(right.internalPointer()); /* * when having valid model indexes the internal pointer MUST be valid, too. * so we may skip if for this. */ Q_ASSERT(n1 && n2); if (n1->sortChar() == n2->sortChar()) { if (sortColumn() == SvnItemModel::LastRevision) { return n1->cmtRev() < n2->cmtRev(); } return QSortFilterProxyModel::lessThan(left, right); } // we want folders always @first if (sortOrder() == Qt::AscendingOrder) { return n1->sortChar() < n2->sortChar(); } else { return n1->sortChar() > n2->sortChar(); } } bool SvnSortFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent)const { if (m_sourceModel->filterIndex(source_parent, source_row, m_ShowFilter)) { return false; } return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); } void SvnSortFilterProxy::setShowFilter(svnmodel::ItemTypeFlag fl) { m_ShowFilter = fl; invalidateFilter(); } diff --git a/src/svnfrontend/models/svnsortfilter.h b/src/svnfrontend/models/svnsortfilter.h index 52a2508a..bacd4202 100644 --- a/src/svnfrontend/models/svnsortfilter.h +++ b/src/svnfrontend/models/svnsortfilter.h @@ -1,59 +1,59 @@ /*************************************************************************** * Copyright (C) 2008 by Rajko Albrecht ral@alwins-world.de * * http://kdesvn.alwins-world.de/ * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef SVNSORTFILTER_H #define SVNSORTFILTER_H #include #include "svnitemmodelfwd.h" -class SvnSortFilterProxy: public QSortFilterProxyModel +class SvnSortFilterProxy : public QSortFilterProxyModel { Q_OBJECT public: - explicit SvnSortFilterProxy(QObject *parent = nullptr); + using QSortFilterProxyModel::QSortFilterProxyModel; void setSourceModel(QAbstractItemModel *sourceModel) override; enum ShowType { None = 0x0, Dir = 1, File = 2, All = Dir | File }; Q_DECLARE_FLAGS(TypeFlag, ShowType) void setShowFilter(svnmodel::ItemTypeFlag); - svnmodel::ItemTypeFlag showFilter()const + svnmodel::ItemTypeFlag showFilter() const { return m_ShowFilter; } protected: bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; - SvnItemModel *m_sourceModel; - svnmodel::ItemTypeFlag m_ShowFilter; + SvnItemModel *m_sourceModel = nullptr; + svnmodel::ItemTypeFlag m_ShowFilter = svnmodel::All; }; #endif