SipAddressesProxyModel.hpp 1.66 KB
Newer Older
1
/*
2
 * SipAddressesProxyModel.hpp
3
 * Copyright (C) 2017-2018  Belledonne Communications, Grenoble, France
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *  Created on: February 2, 2017
 *      Author: Ronan Abhamon
 */

23 24
#ifndef SIP_ADDRESSES_PROXY_MODEL_H_
#define SIP_ADDRESSES_PROXY_MODEL_H_
25

Ghislain MARY's avatar
Ghislain MARY committed
26 27
#include <QSortFilterProxyModel>

28 29
// =============================================================================

30
class SipAddressesProxyModel : public QSortFilterProxyModel {
31 32 33
  Q_OBJECT;

public:
34
  SipAddressesProxyModel (QObject *parent = Q_NULLPTR);
Ronan's avatar
Ronan committed
35

36
  Q_INVOKABLE void setFilter (const QString &pattern);
37

38
protected:
39
  bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
Ronan's avatar
Ronan committed
40 41 42
  bool lessThan (const QModelIndex &left, const QModelIndex &right) const override;

private:
43
  int computeEntryWeight (const QVariantMap &entry) const;
Ronan's avatar
Ronan committed
44 45
  int computeStringWeight (const QString &string) const;

46
  QString mFilter;
47

48
  static const QRegExp SearchSeparators;
49 50
};

51
#endif // SIP_ADDRESSES_PROXY_MODEL_H_