1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "filesourceview.h"
6#include "filesourcedelegate.h"
7
8#include <QHeaderView>
9#include <QFileSystemModel>
10#include <QGridLayout>
11
12class FileSourceViewPrivate
13{
14 friend class FileSourceView;
15 QFileSystemModel *model{nullptr};
16 FileSourceDelegate *delegate{nullptr};
17};
18
19FileSourceView::FileSourceView(QWidget *parent)
20 : QTreeView(parent)
21 , d (new FileSourceViewPrivate)
22{
23 d->model = new QFileSystemModel;
24 d->delegate = new FileSourceDelegate;
25 d->model->setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden);
26 setModel(d->model);
27 header()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
28 setItemDelegate(d->delegate);
29}
30
31void FileSourceView::setRootPath(const QString &filePath)
32{
33 d->model->setRootPath(filePath);
34 setRootIndex(d->model->index(filePath));
35}
36