File: quickopenmodel.h

package info (click to toggle)
kdevelop 4%3A5.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 57,892 kB
  • sloc: cpp: 278,773; javascript: 3,558; python: 3,385; sh: 1,317; ansic: 689; xml: 273; php: 95; makefile: 40; lisp: 13; sed: 12
file content (133 lines) | stat: -rw-r--r-- 4,526 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
131
132
133
/* 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 KDEVPLATFORM_PLUGIN_QUICKOPENMODEL_H
#define KDEVPLATFORM_PLUGIN_QUICKOPENMODEL_H

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

#include <serialization/indexedstring.h>

#include <language/interfaces/quickopendataprovider.h>
#include "expandingtree/expandingwidgetmodel.h"
class QTimer;
class QuickOpenModel
    : public ExpandingWidgetModel
{
    Q_OBJECT
public:
    explicit 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 scopes The 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 override;
    QModelIndex parent(const QModelIndex&) const override;
    int rowCount(const QModelIndex&) const override;
    int unfilteredRowCount() const;
    int columnCount() const;
    int columnCount(const QModelIndex&) const override;
    QVariant data(const QModelIndex&, int) const override;

    /**
     * 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);

    QTreeView* treeView() const override;

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

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

    int contextMatchQuality(const QModelIndex& index) const override;

    KDevelop::QuickOpenDataPointer getItem(int row, bool noReset = false) const;

    using DataList = QHash<int, KDevelop::QuickOpenDataPointer>;
    mutable DataList m_cachedData;

    QTreeView* m_treeView;
    QTimer* m_resetTimer;

    struct ProviderEntry
    {
        ProviderEntry()
        {
        }
        bool enabled = false;
        QSet<QString> scopes;
        QSet<QString> types;
        KDevelop::QuickOpenDataProviderBase* provider;
    };

    //using ProviderMap = QMultiMap<QString, ProviderEntry>;
    using ProviderList = QVector<ProviderEntry>;
    ProviderList m_providers;
    QString m_filterText;
    int m_expandingWidgetHeightIncrease;
    mutable int m_resetBehindRow;

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

#endif