File: quickopenmodel.h

package info (click to toggle)
kdevplatform 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 19,868 kB
  • sloc: cpp: 128,247; sh: 697; python: 365; php: 83; makefile: 4
file content (130 lines) | stat: -rw-r--r-- 4,462 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* This file is part of the KDE libraries
   Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef QUICKOPENMODEL_H
#define QUICKOPENMODEL_H

#include <QMultiMap>
#include <QString>
#include <QAbstractItemModel>
#include <QSet>

#include <language/duchain/indexedstring.h>

#include <language/interfaces/quickopendataprovider.h>
#include "expandingtree/expandingwidgetmodel.h"

class QuickOpenModel : public ExpandingWidgetModel {
  Q_OBJECT
  public:
    QuickOpenModel( QWidget* parent );
    
    void registerProvider( const QStringList& scopes, const QStringList& type, KDevelop::QuickOpenDataProviderBase* provider );

    /**
     * Remove provider.
     * @param provider The provider to remove
     * @return Whether a provider was removed. If false, the provider was not attached.
     * */
    bool removeProvider( KDevelop::QuickOpenDataProviderBase* provider );

    ///Returns a list of all scopes that a registered through some providers
    QStringList allScopes() const;
    ///Returns a list of all types that a registered through some providers
    QStringList allTypes() const;

    /**
     * @param items The list of items that should be used.
     * @param scopesThe list of scopes that should be used.
     
    * When this is called, the state is restart()ed.
     * */
    void enableProviders( const QStringList& items, const QStringList& scopes );
    
    ///Reset all providers, unexpand everything, empty caches.
    void restart(bool keepFilterText = false);

    QModelIndex index( int, int, const QModelIndex& parent ) const;
    QModelIndex parent( const QModelIndex& ) const;
    int rowCount( const QModelIndex& ) const;
    int columnCount() const;
    int columnCount( const QModelIndex& ) const;
    QVariant data( const QModelIndex&, int ) const;

    /**
     * Tries to execute the item currently selected.
     * Returns true if the quickopen-dialog should be closed.
     * @param filterText Should be the current content of the filter line-edit.
     *
     * If this returns false, and filterText was changed, the change must be put
     * into the line-edit. That way items may execute by changing the content
     * of the line-edit.
     * */
    bool execute( const QModelIndex& index, QString& filterText );

    //The expandingwidgetmodel needs access to the tree-view
    void setTreeView( QTreeView* view );
    
    virtual QTreeView* treeView() const;

    virtual QSet<KDevelop::IndexedString> fileSet() const;

    ///This value will be added to the height of all created expanding-widgets
    void setExpandingWidgetHeightIncrease(int pixels);
  public slots:
    void textChanged( const QString& str );
  private slots:
    void destroyed( QObject* obj );
    void resetTimer();
    void restart_internal( bool keepFilterText );
  
  private:
    virtual bool indexIsItem(const QModelIndex& index) const;
    
    virtual int contextMatchQuality(const QModelIndex & index) const;

    KDevelop::QuickOpenDataPointer getItem( int row, bool noReset = false ) const;
    
    typedef QHash<int, KDevelop::QuickOpenDataPointer> DataList;
    mutable DataList m_cachedData;

    QTreeView* m_treeView;
    QTimer* m_resetTimer;

    struct ProviderEntry {
      ProviderEntry() : enabled(false) {
      }
      bool enabled;
      QSet<QString> scopes;
      QSet<QString> types;
      KDevelop::QuickOpenDataProviderBase* provider;
    };
    
  //typedef QMultiMap< QString, ProviderEntry > ProviderMap;
    typedef QList<ProviderEntry> ProviderList;
    QList<ProviderEntry> m_providers;
    QString m_filterText;
    int m_expandingWidgetHeightIncrease;
    mutable int m_resetBehindRow;

    QSet<QString> m_enabledItems;
    QSet<QString> m_enabledScopes;
};

#endif