File: quickopenmodel.h

package info (click to toggle)
kdevelop 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 73,508 kB
  • sloc: cpp: 291,803; python: 4,322; javascript: 3,518; sh: 1,316; ansic: 703; xml: 414; php: 95; lisp: 66; makefile: 31; sed: 12
file content (121 lines) | stat: -rw-r--r-- 3,837 bytes parent folder | download | duplicates (3)
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
/*
    SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de>

    SPDX-License-Identifier: LGPL-2.0-only
*/

#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