У меня есть вложенная структура данных, которую я хотел бы отобразить с помощью QTreeView.
Допустим, у меня есть что-то вроде этого:
class Image
{
public:
...
std::vector<Filter> filter_;
};
typedef std::vector<Image> Gallery;
typedef std::vector<Gallery> Galleries;
QTreeView должен отображать MultiGallery следующим образом:
Gallery1
|_____Image1
|_____Image2
|_____Image3
Gallery2
|_____Image1
| |_____Filter1
| |_____Filter2
|_____Image2
Я прочитал примеры Qt Model View, я знаю, что мне нужно наследовать от QAbstractItemModel, чтобы создать древовидную модель и реализовать функции-члены:
QVariant data(const QModelIndex &index, int role) const;
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int columnCount(const QModelIndex &parent=QModelIndex()) const;
int rowCount(const QModelIndex &parent=QModelIndex()) const;
Я просто не знаю, как лучше всего реализовать их, особенно функцию индекса.