CppTools: Fix builtin overview model

5e872c0fcd changed the base class to TreeModel which
needs to have TreeItem inserted to fully work as intended.

This patch makes the overview model work without running
into countless soft asserts when using the builtin code model.

Change-Id: I875529bef03ea2cd9a226b05410fd05e247eded1
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Nikita Baryshnikov <nib952051@gmail.com>
This commit is contained in:
Christian Stenger
2018-02-27 12:25:05 +01:00
parent 4523e57943
commit 33f2c24049
2 changed files with 145 additions and 182 deletions

View File

@@ -32,18 +32,22 @@
namespace CppTools {
struct SymbolItem : public Utils::TreeItem
{
SymbolItem() = default;
SymbolItem(CPlusPlus::Symbol *symbol) : symbol(symbol) {}
QVariant data(int column, int role) const override;
CPlusPlus::Symbol *symbol = nullptr; // not owned
};
class CPPTOOLS_EXPORT OverviewModel : public AbstractOverviewModel
{
Q_OBJECT
public:
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
void rebuild(CPlusPlus::Document::Ptr doc) override;
bool isGenerated(const QModelIndex &sourceIndex) const override;
@@ -55,10 +59,12 @@ private:
bool hasDocument() const;
unsigned globalSymbolCount() const;
CPlusPlus::Symbol *globalSymbolAt(unsigned index) const;
void buildTree(SymbolItem *root, bool isRoot);
private:
CPlusPlus::Document::Ptr _cppDocument;
CPlusPlus::Overview _overview;
friend class SymbolItem;
};
} // namespace CppTools