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 "ldapattributeproxymodel.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 LdapAttributeProxyModel::LdapAttributeProxyModelPrivate |
31 | { |
32 | public: |
33 | LdapAttributeProxyModelPrivate(); |
34 | |
35 | }; |
36 | |
37 | LdapAttributeProxyModel::LdapAttributeProxyModelPrivate::LdapAttributeProxyModelPrivate() |
38 | { |
39 | |
40 | } |
41 | |
42 | LdapAttributeProxyModel::LdapAttributeProxyModel( QObject *parent ) |
43 | : QSortFilterProxyModel( parent ), |
44 | m_d( new LdapAttributeProxyModelPrivate() ) |
45 | { |
46 | |
47 | } |
48 | |
49 | LdapAttributeProxyModel::~LdapAttributeProxyModel() |
50 | { |
51 | delete m_d; |
52 | } |
53 | |
54 | QVariant LdapAttributeProxyModel::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 LdapAttributeProxyModel::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 LdapAttributeProxyModel::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::Attr; |
80 | } |
81 | |
82 | QVariant LdapAttributeProxyModel::( int section, |
83 | Qt::Orientation orientation, |
84 | int role ) const |
85 | { |
86 | if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) { |
87 | if ( section == 0 ) { |
88 | return QVariant( i18n( "Attribute" ) ); |
89 | } else if ( section == 1 ) { |
90 | return QVariant( i18n( "Value" ) ); |
91 | } |
92 | } |
93 | |
94 | return QVariant(); |
95 | } |
96 | |
97 | int LdapAttributeProxyModel::columnCount( const QModelIndex &/*parent*/ ) const |
98 | { |
99 | return 2; |
100 | } |
101 | |
102 | Qt::ItemFlags LdapAttributeProxyModel::flags( const QModelIndex &index ) const |
103 | { |
104 | // Included so as not to break BC in case we wish to use this later in 4.x |
105 | return sourceModel()->flags( mapToSource( index ) ); |
106 | } |
107 | |
108 | bool LdapAttributeProxyModel::hasChildren( const QModelIndex &parent ) const |
109 | { |
110 | // We need to handle this carefully bacause of the filtering out of attributes |
111 | // and the lazy population approach. |
112 | LdapModel *model = static_cast<LdapModel*>( sourceModel() ); |
113 | return model->hasChildrenOfType( mapToSource( parent ), LdapModel::Attribute ); |
114 | } |
115 | |
116 | QModelIndex LdapAttributeProxyModel::mapFromSource( const QModelIndex &sourceIndex ) const |
117 | { |
118 | return QSortFilterProxyModel::mapFromSource( sourceIndex ); |
119 | } |
120 | |
121 | QModelIndex LdapAttributeProxyModel::mapToSource( const QModelIndex &proxyIndex ) const |
122 | { |
123 | return QSortFilterProxyModel::mapToSource( proxyIndex ); |
124 | } |
125 | |
126 | bool LdapAttributeProxyModel::insertRows( int row, int count, |
127 | const QModelIndex &parent ) |
128 | { |
129 | Q_UNUSED( row ); |
130 | Q_UNUSED( count ); |
131 | Q_UNUSED( parent ); |
132 | return false; |
133 | } |
134 | |
135 | bool LdapAttributeProxyModel::removeRows( int row, int count, |
136 | const QModelIndex &parent ) |
137 | { |
138 | Q_UNUSED( row ); |
139 | Q_UNUSED( count ); |
140 | Q_UNUSED( parent ); |
141 | return false; |
142 | } |
143 | |
144 | void LdapAttributeProxyModel::sort( int column, Qt::SortOrder order ) |
145 | { |
146 | Q_UNUSED( column ); |
147 | Q_UNUSED( order ); |
148 | } |
149 | |
150 | Qt::DropActions LdapAttributeProxyModel::supportedDropActions() const |
151 | { |
152 | return Qt::MoveAction; |
153 | } |
154 | |
155 | QMimeData *LdapAttributeProxyModel::mimeData( const QModelIndexList &indexes ) const |
156 | { |
157 | Q_UNUSED( indexes ); |
158 | return 0; |
159 | } |
160 | |
161 | bool LdapAttributeProxyModel::dropMimeData( const QMimeData *data, Qt::DropAction action, |
162 | int row, int column, const QModelIndex &parent ) |
163 | { |
164 | /** \todo Implement drag and drop for LdapModel */ |
165 | Q_UNUSED( data ); |
166 | Q_UNUSED( action ); |
167 | Q_UNUSED( row ); |
168 | Q_UNUSED( column ); |
169 | Q_UNUSED( parent ); |
170 | return false; |
171 | } |
172 | |
173 | |