source: SMSSender/src/ui/completers/bettercompleter.h @ 67:578192d6fe64

3.0
Last change on this file since 67:578192d6fe64 was 43:10dd65d71f7f, checked in by Sämy Zehnder <saemy.zehnder@…>, 13 years ago
  • Did a lot of work...
File size: 1.5 KB
Line 
1/*
2 * BetterCompleter.h
3 *
4 *  Created on: Jan 16, 2010
5 *      Author: saemy
6 */
7
8#ifndef BETTERCOMPLETER_H_
9#define BETTERCOMPLETER_H_
10
11#include <QCompleter>
12#include <QSortFilterProxyModel>
13#include <QTimer>
14#include <QStringList>
15
16class BetterCompletionModel: public QSortFilterProxyModel {
17    Q_OBJECT
18    Q_PROPERTY(QString searchString READ searchString WRITE setSearchString)
19
20public:
21    BetterCompletionModel(QObject* parent = 0);
22
23    enum Roles {
24        BetterCompletionRole = Qt::UserRole + 1,
25        MaxRole = BetterCompletionRole
26    };
27
28    QString searchString() const;
29    void setSearchString(const QString& str);
30
31    bool isValid() const;
32    void setValid(bool b);
33
34    virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
35
36public slots:
37    void setFilterFixedString (const QString& pattern);
38
39protected:
40    QRegExp searchMatcher() const;
41    virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
42
43private:
44    bool    isValid_;
45    QString searchString_;
46    QRegExp searchMatcher_;
47};
48
49
50
51class BetterCompleter: public QCompleter {
52    Q_OBJECT
53
54public:
55    BetterCompleter(QObject* parent = 0);
56    BetterCompleter(QAbstractItemModel* model, QObject* parent = 0);
57
58    virtual QString pathFromIndex(const QModelIndex& index) const;
59    virtual QStringList splitPath(const QString& path) const;
60
61private slots:
62    void updateFilter();
63
64private:
65    void init();
66    mutable QString searchString_;
67    mutable QTimer filterTimer_;
68};
69
70
71#endif /* BETTERCOMPLETER_H_ */
Note: See TracBrowser for help on using the repository browser.