1 /****************************************************************************
2 **
3 ** Copyright (C) 2021 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 #include "assetimportupdatedialog.h"
26 #include "ui_assetimportupdatedialog.h"
27 #include "assetimportupdatetreeview.h"
28 #include "assetimportupdatetreemodel.h"
29 
30 #include <QDirIterator>
31 #include <QPushButton>
32 #include <QTreeView>
33 #include <QFileInfo>
34 #include <QModelIndex>
35 
36 namespace QmlDesigner {
37 namespace Internal {
38 
AssetImportUpdateDialog(const QString & importPath,const QSet<QString> & preSelectedFiles,const QSet<QString> & hiddenEntries,QWidget * parent)39 AssetImportUpdateDialog::AssetImportUpdateDialog(
40         const QString &importPath, const QSet<QString> &preSelectedFiles,
41         const QSet<QString> &hiddenEntries, QWidget *parent)
42     : QDialog(parent)
43     , ui(new Ui::AssetImportUpdateDialog)
44 {
45     setModal(true);
46     ui->setupUi(this);
47 
48     connect(ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked,
49             this, &AssetImportUpdateDialog::accept);
50     connect(ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
51             this, &AssetImportUpdateDialog::reject);
52     connect(ui->expandButton, &QPushButton::clicked,
53             this, &AssetImportUpdateDialog::expandAll);
54     connect(ui->collapseButton, &QPushButton::clicked,
55             this, &AssetImportUpdateDialog::collapseAll);
56     ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
57 
58     QList<QFileInfo> infos;
59     infos.append(QFileInfo{importPath});
60     QDirIterator it(importPath, {"*"}, QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot,
61                     QDirIterator::Subdirectories);
62     while (it.hasNext()) {
63         it.next();
64         const QString absFile = it.fileInfo().absoluteFilePath();
65         if (!hiddenEntries.contains(absFile))
66             infos.append(it.fileInfo());
67     }
68 
69     ui->treeView->model()->createItems(infos, preSelectedFiles);
70     ui->treeView->expandAll();
71 }
72 
~AssetImportUpdateDialog()73 AssetImportUpdateDialog::~AssetImportUpdateDialog()
74 {
75     delete ui;
76 }
77 
selectedFiles() const78 QStringList AssetImportUpdateDialog::selectedFiles() const
79 {
80     return ui->treeView->model()->checkedFiles();
81 }
82 
collapseAll()83 void AssetImportUpdateDialog::collapseAll()
84 {
85     ui->treeView->collapseAll();
86 }
87 
expandAll()88 void AssetImportUpdateDialog::expandAll()
89 {
90     ui->treeView->expandAll();
91 }
92 
93 } // namespace Internal
94 } // namespace QmlDesigner
95