SVN_SILENT made messages (.desktop file)
[kdepim.git] / kjots / kjotsbookshelfentryvalidator.cpp
blob870b3021a33fd4a91a0b177e84cea27b91185612
1 /*
2 This file is part of KJots.
4 Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
23 #include "kjotsbookshelfentryvalidator.h"
25 KJotsBookshelfEntryValidator::KJotsBookshelfEntryValidator( QAbstractItemModel* model, QObject* parent )
26 : QValidator( parent )
28 m_model = model;
31 KJotsBookshelfEntryValidator::~KJotsBookshelfEntryValidator()
36 QValidator::State KJotsBookshelfEntryValidator::validate( QString& input, int& pos ) const
38 Q_UNUSED(pos);
39 if (!m_model)
40 return Invalid;
41 if (input.isEmpty())
42 return Intermediate;
44 QModelIndexList list = m_model->match(
45 m_model->index(0,0),
46 Qt::DisplayRole,
47 input,
48 Qt::MatchStartsWith | Qt::MatchFixedString | Qt::MatchWrap );
50 if (list.empty())
52 return Invalid;
54 else
56 foreach (const QModelIndex& index, list)
58 if ( 0 == QString::compare(m_model->data(index).toString(), input, Qt::CaseInsensitive ) )
60 return Acceptable;
62 return Intermediate;
65 return Invalid;