Isis 3 Programmer Reference
SortFilterProxyModel.cpp
1#include "SortFilterProxyModel.h"
2
3#include <QAbstractItemModel>
4#include <QIdentityProxyModel>
5#include <QModelIndex>
6#include <QObject>
7#include <QPersistentModelIndex>
8#include <QSortFilterProxyModel>
9#include <QStandardItem>
10#include <QVariant>
11
12#include "ProjectItem.h"
13#include "ProjectItemModel.h"
14
15namespace Isis {
16
17 SortFilterProxyModel::SortFilterProxyModel(QObject *parent) :
18 QSortFilterProxyModel(parent) {
19 }
20
21
22 void SortFilterProxyModel::setSelectedItems(QList<ProjectItem *> selected){
23
24 QList<QModelIndex> selIx;
25 foreach(ProjectItem * item,selected) {
26 selIx.append(item->index() );
27
28 }
29
30 foreach(QModelIndex ix,selIx) {
31 selectedIndexRows.append(ix.row() );
32 }
33
34 selectedIndices=selIx;
35
36 }
37
38 void SortFilterProxyModel::setSourceModel(ProjectItemModel *newSourceModel) {
39
40 QPersistentModelIndex persistentIndex(newSourceModel->index(0,0,QModelIndex()));
41
42
43
44 if (persistentIndex.isValid()) {
45 //qDebug() << "persistent index is valid: " << persistentIndex;
46 m_root = persistentIndex;
47 }
48 else {
49 //qDebug() << "persistent index NOT valid.";
50 m_root = QPersistentModelIndex(QModelIndex());
51 }
52
53 baseModel = newSourceModel;
54 QSortFilterProxyModel::setSourceModel(newSourceModel);
55 }
56
57
58 bool SortFilterProxyModel::setRoot(const QStandardItem *item) {
59
60 m_root = QPersistentModelIndex(item->index());
61 return true;
62
63
64 }
65
66
67 bool SortFilterProxyModel::filterAcceptsRow(int sourceRow,
68 const QModelIndex &sourceParent) const {
69 bool accept(false);
70
71 if (selectedIndices.count() == 0) {
72 accept = true;
73 }
74
75 if (this->sourceModel()!=nullptr) {
76 QModelIndex ix = this->sourceModel()->index( sourceRow, 0, sourceParent );
77 if (ix.isValid() ) {
78 ProjectItem * item = baseModel->itemFromIndex(ix);
79 if (selectedIndices.contains(ix) ) {
80 accept = true;
81 }
82 if (item->text() == "Images" ) {
83 accept = true;
84 }
85 }//end if (ix.isValid() )
86
87 }
88 return accept;
89
90 }
91
92
93
94
95}//end namespace
96
97
Represents an item of a ProjectItemModel in Qt's model-view framework.
Provides access to data stored in a Project through Qt's model-view framework.
ProjectItem * itemFromIndex(const QModelIndex &index)
Returns the ProjectItem corresponding to a given QModelIndex.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16