1 | /* |
2 | This file is part of libkldap. |
3 | Copyright (c) 2006 Sean Harmer <sh@theharmers.co.uk> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #include "ldapstructureproxymodel.h" |
22 | #include "ldapmodel.h" |
23 | #include "ldapmodelnode_p.h" |
24 | |
25 | #include <kdebug.h> |
26 | #include <klocalizedstring.h> |
27 | |
28 | using namespace KLDAP; |
29 | |
30 | class LdapStructureProxyModel::LdapStructureProxyModelPrivate |
31 | { |
32 | public: |
33 | LdapStructureProxyModelPrivate(); |
34 | |
35 | }; |
36 | |
37 | LdapStructureProxyModel::LdapStructureProxyModelPrivate::LdapStructureProxyModelPrivate() |
38 | { |
39 | |
40 | } |
41 | |
42 | LdapStructureProxyModel::LdapStructureProxyModel( QObject *parent ) |
43 | : QSortFilterProxyModel( parent ), |
44 | m_d( new LdapStructureProxyModelPrivate() ) |
45 | { |
46 | |
47 | } |
48 | |
49 | LdapStructureProxyModel::~LdapStructureProxyModel() |
50 | { |
51 | delete m_d; |
52 | } |
53 | |
54 | QVariant LdapStructureProxyModel::data( const QModelIndex &index, |
55 | int role ) const |
56 | { |
57 | // Included just in case we decide to do any special presentation of the data |
58 | // at some other point throughout the 4.x series. |
59 | return sourceModel()->data( mapToSource( index ), role ); |
60 | } |
61 | |
62 | bool LdapStructureProxyModel::setData( const QModelIndex &index, |
63 | const QVariant &value, |
64 | int role ) |
65 | { |
66 | Q_UNUSED( index ); |
67 | Q_UNUSED( value ); |
68 | Q_UNUSED( role ); |
69 | return false; |
70 | } |
71 | |
72 | bool LdapStructureProxyModel::filterAcceptsRow( int sourceRow, |
73 | const QModelIndex &sourceParent ) const |
74 | { |
75 | QModelIndex idx = sourceModel()->index( sourceRow, 0, sourceParent ); |
76 | LdapModelNode::NodeType nodeType = |
77 | static_cast<LdapModelNode::NodeType>( |
78 | sourceModel()->data( idx, LdapModel::NodeTypeRole ).toUInt() ); |
79 | return nodeType == LdapModelNode::DN; |
80 | } |
81 | |
82 | QVariant LdapStructureProxyModel::( int section, |
83 | Qt::Orientation orientation, |
84 | int role ) const |
85 | { |
86 | Q_UNUSED( section ); |
87 | if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) { |
88 | return i18n( "Distinguished Name" ); |
89 | } |
90 | |
91 | return QVariant(); |
92 | } |
93 | |
94 | int LdapStructureProxyModel::columnCount( const QModelIndex &/*parent*/ ) const |
95 | { |
96 | // No need for more than one column just to show the structure |
97 | return 1; |
98 | } |
99 | |
100 | Qt::ItemFlags LdapStructureProxyModel::flags( const QModelIndex &index ) const |
101 | { |
102 | // Included so as not to break BC in case we wish to use this later in 4.x |
103 | return sourceModel()->flags( mapToSource( index ) ); |
104 | } |
105 | |
106 | bool LdapStructureProxyModel::hasChildren( const QModelIndex &parent ) const |
107 | { |
108 | // We need to handle this carefully bacause of the filtering out of attributes |
109 | // and the lazy population approach. |
110 | LdapModel *model = static_cast<LdapModel*>( sourceModel() ); |
111 | return model->hasChildrenOfType( mapToSource( parent ), LdapModel::DistinguishedName ); |
112 | } |
113 | |
114 | QModelIndex LdapStructureProxyModel::mapFromSource( const QModelIndex &sourceIndex ) const |
115 | { |
116 | return QSortFilterProxyModel::mapFromSource( sourceIndex ); |
117 | } |
118 | |
119 | QModelIndex LdapStructureProxyModel::mapToSource( const QModelIndex &proxyIndex ) const |
120 | { |
121 | return QSortFilterProxyModel::mapToSource( proxyIndex ); |
122 | } |
123 | |
124 | bool LdapStructureProxyModel::insertRows( int row, int count, |
125 | const QModelIndex &parent ) |
126 | { |
127 | Q_UNUSED( row ); |
128 | Q_UNUSED( count ); |
129 | Q_UNUSED( parent ); |
130 | return false; |
131 | } |
132 | |
133 | bool LdapStructureProxyModel::removeRows( int row, int count, |
134 | const QModelIndex &parent ) |
135 | { |
136 | Q_UNUSED( row ); |
137 | Q_UNUSED( count ); |
138 | Q_UNUSED( parent ); |
139 | return false; |
140 | } |
141 | |
142 | void LdapStructureProxyModel::sort( int column, Qt::SortOrder order ) |
143 | { |
144 | Q_UNUSED( column ); |
145 | Q_UNUSED( order ); |
146 | } |
147 | |
148 | Qt::DropActions LdapStructureProxyModel::supportedDropActions() const |
149 | { |
150 | return Qt::MoveAction; |
151 | } |
152 | |
153 | QMimeData *LdapStructureProxyModel::mimeData( const QModelIndexList &indexes ) const |
154 | { |
155 | Q_UNUSED( indexes ); |
156 | return 0; |
157 | } |
158 | |
159 | bool LdapStructureProxyModel::dropMimeData( const QMimeData *data, Qt::DropAction action, |
160 | int row, int column, const QModelIndex &parent ) |
161 | { |
162 | /** \todo Implement drag and drop for LdapModel */ |
163 | Q_UNUSED( data ); |
164 | Q_UNUSED( action ); |
165 | Q_UNUSED( row ); |
166 | Q_UNUSED( column ); |
167 | Q_UNUSED( parent ); |
168 | return false; |
169 | } |
170 | |
171 | |