-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenamefilemodel.cpp
More file actions
83 lines (76 loc) · 2.2 KB
/
renamefilemodel.cpp
File metadata and controls
83 lines (76 loc) · 2.2 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "renamefilemodel.h"
QFileInfo RenameFileModel::fileInfo(const QModelIndex &index) const
{
QFileInfo fInfo = QFileSystemModel::fileInfo(index);
return fInfo;
}
QVariant RenameFileModel::headerData(int section, Qt::Orientation orientation, int role) const
{
// horizontal Header
if ((role == Qt::DisplayRole) && (orientation == Qt::Horizontal)) {
switch(section){
case 0:
return tr("Name");
case 4:
return tr("New Name");
}
}
return QFileSystemModel::headerData(section, orientation, role);
}
int RenameFileModel::columnCount(const QModelIndex &parent) const
{
return QFileSystemModel::columnCount()+2;
}
QVariant RenameFileModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid()){return QFileSystemModel::data(index,role);}
if(index.column()==columnCount()-2)
{
switch(role)
{
/* return data for last column for given index */
case(Qt::DisplayRole):
{
QString newName = Renamer::preview(index.row());
return newName;
//return QString("YourText");
}
case(Qt::ForegroundRole):
{
return QVariant(QColor::fromRgb(10, 110, 40, 255));
}
case(Qt::TextAlignmentRole):
{
return Qt::AlignLeft;
}
default:{}
}
}
if(index.column()==columnCount()-1)
{
switch(role)
{
/* return data for last column for given index */
case(Qt::DisplayRole):
{
QFileInfo fInfo = QFileSystemModel::fileInfo(index);
return fInfo.absolutePath();
//return QString("YourText");
}
case(Qt::TextAlignmentRole):
{
return Qt::AlignLeft;
}
default:{}
}
}
return QFileSystemModel::data(index,role);
}
/*int rowCount(const QModelIndex& parent = QModelIndex()) const
{
return QFileSystemModel::rowCount();
}*/
/*bool setData(const QModelIndex &index, const QVariant &value, int role) override {
emit dataChanged(index,index, QVector<int>( Qt::ItemDataRole::DisplayRole ));
return QFileSystemModel::setData(index, value, role);
}*/