| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_QTGUI_SORTFILTERTREEPROXYMODEL_H |
| 7 |
#define AVOGADRO_QTGUI_SORTFILTERTREEPROXYMODEL_H |
| 8 |
|
| 9 |
#include "avogadroqtguiexport.h" |
| 10 |
|
| 11 |
#include <QSortFilterProxyModel> |
| 12 |
|
| 13 |
namespace Avogadro::QtGui { |
| 14 |
|
| 15 |
class AVOGADROQTGUI_EXPORT SortFilterTreeProxyModel |
| 16 |
: public QSortFilterProxyModel |
| 17 |
{ |
| 18 |
Q_OBJECT |
| 19 |
public: |
| 20 |
SortFilterTreeProxyModel(QObject* parent = nullptr) |
| 21 |
: QSortFilterProxyModel(parent), m_sourceRoot() |
| 22 |
{ |
| 23 |
} |
| 24 |
// From http://kodeclutz.blogspot.com/2008/12/filtering-qtreeview.html |
| 25 |
bool filterAcceptsRow(int sourceRow, |
| 26 |
const QModelIndex& sourceParent) const override; |
| 27 |
|
| 28 |
// This is a hack to prevent us from becoming root-less |
| 29 |
// See |
| 30 |
// http://stackoverflow.com/questions/3212392/qtreeview-qfilesystemmodel-setrootpath-and-qsortfilterproxymodel-with-regexp-fo |
| 31 |
void setSourceRoot(const QModelIndex& sourceRoot) |
| 32 |
{ |
| 33 |
m_sourceRoot = sourceRoot; |
| 34 |
} |
| 35 |
|
| 36 |
private: |
| 37 |
QModelIndex m_sourceRoot; |
| 38 |
}; |
| 39 |
|
| 40 |
} // namespace Avogadro::QtGui |
| 41 |
|
| 42 |
#endif |