-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappfilesysmodel.cpp
More file actions
54 lines (40 loc) · 1.37 KB
/
appfilesysmodel.cpp
File metadata and controls
54 lines (40 loc) · 1.37 KB
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
#include "appfilesysmodel.h"
#include <QUrl>
#include <QMimeData>
AppFileSysModel::AppFileSysModel(QObject *parent)
: QFileSystemModel{parent}
{
}
Qt::ItemFlags AppFileSysModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QFileSystemModel::flags(index);
if (!index.isValid()) {
return defaultFlags;
}
const QFileInfo &fileInfo = this->fileInfo(index);
if (fileInfo.isDir()) { // The target
// allowed drop
return Qt::ItemIsDropEnabled | defaultFlags;
} else if (fileInfo.isFile()) { // The source: should be directory (in that case)
// allowed drag
return Qt::ItemIsDragEnabled | defaultFlags;
}
return defaultFlags;
}
bool AppFileSysModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
const QFileInfo &dropTo = this->fileInfo(parent);
QString fromPath{};
if (data->hasUrls()) {
foreach (QUrl url, data->urls())
{
fromPath = url.toLocalFile();
emit moveFile(url.toLocalFile(), dropTo.filePath());
}
}
std::filesystem::path destDirPath = dropTo.filePath().toStdString(),
fromDirPath = fromPath.toStdString();
destDirPath = destDirPath / fromDirPath.filename();
emit moveFinished(QString::fromStdString(destDirPath.u8string()));
return true;
}