-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathprojecttreemodel.cpp
More file actions
144 lines (109 loc) · 3.83 KB
/
projecttreemodel.cpp
File metadata and controls
144 lines (109 loc) · 3.83 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
Ted, a simple text editor/IDE.
Copyright 2012, Blitz Research Ltd.
See LICENSE.TXT for licensing terms.
*/
#include "projecttreemodel.h"
ProjectTreeModel::ProjectTreeModel( QObject *parent ):QFileSystemModel( parent ),_current(-1){
}
bool ProjectTreeModel::addProject( const QString &dir ){
if( dir.isEmpty() ) return false;
QString sdir=dir.endsWith( '/' ) ? dir : dir+'/';
for( int i=0;i<_dirs.size();++i ){
if( _dirs[i].startsWith( sdir ) ) return false;
QString idir=_dirs[i].endsWith( '/' ) ? _dirs[i] : _dirs[i]+'/';
if( dir.startsWith( idir ) ) return false;
}
QFileSystemModel::setRootPath( "" );
QModelIndex index=QFileSystemModel::index( dir );
if( !index.isValid() ) return false;
QFileSystemModel::beginInsertRows( QModelIndex(),_projs.size(),_projs.size() );
_dirs.push_back( dir );
_projs.push_back( index );
QFileSystemModel::endInsertRows();
// _current=_projs.size()-1;
return true;
}
void ProjectTreeModel::removeProject( const QString &dir ){
for( int i=0;i<_dirs.size();++i ){
if( dir==_dirs[i] ){
QFileSystemModel::beginRemoveRows( QModelIndex(),_dirs.size()-1,_dirs.size()-1 );
_dirs.remove( i );
_projs.remove( i );
QFileSystemModel::endRemoveRows();
return;
}
}
}
bool ProjectTreeModel::isProject( const QModelIndex &index ){
for( int i=0;i<_projs.size();++i ){
if( index==_projs[i] ) return true;
}
return false;
}
bool ProjectTreeModel::hasChildren ( const QModelIndex &parent ) const{
if( !parent.isValid() ) return _projs.size()>0;
return QFileSystemModel::hasChildren( parent );
}
int ProjectTreeModel::rowCount( const QModelIndex &parent )const{
if( !parent.isValid() ) return _projs.size();
return QFileSystemModel::rowCount( parent );
}
QModelIndex ProjectTreeModel::index ( int row,int column,const QModelIndex &parent ) const{
if( !parent.isValid() ){
if( row>=0 && row<_projs.size() ) return _projs[row];
return QModelIndex();
}
return QFileSystemModel::index( row,column,parent );
}
QVariant ProjectTreeModel::data( const QModelIndex &index,int role)const{
if( role==Qt::FontRole && _current!=-1 && index==_projs[_current]){
QFont font=QFileSystemModel::data( index,role ).value<QFont>();
font.setBold( true );
return font;
}
if (role == Qt::DecorationRole)
{
QString txtfilename = fileName(index);
txtfilename = txtfilename.right(5);
//qDebug() << txtfilename;
//qDebug() << type(index);
if(type(index).endsWith("Folder") && !txtfilename.endsWith(".data"))
{
return QPixmap(":/icons/circle/tree/folder.png");
}
if(type(index).endsWith("monkey File"))
{
return QPixmap(":/icons/circle/tree/monkey.png");
}
if(type(index).endsWith("png File"))
{
return QPixmap(":/icons/circle/tree/image.png");
}
if(type(index).endsWith("jpg File"))
{
return QPixmap(":/icons/circle/tree/image.png");
}
if(type(index).endsWith("gif File"))
{
return QPixmap(":/icons/circle/tree/image.png");
}
if(type(index).endsWith("ico File"))
{
return QPixmap(":/icons/circle/tree/image.png");
}
if(type(index).endsWith("fnt File"))
{
return QPixmap(":/icons/circle/tree/font.png");
}
if(type(index).endsWith("txt File"))
{
return QPixmap(":/icons/circle/tree/text.png");
}
if(txtfilename.endsWith(".data") && !type(index).endsWith("data File"))
{
return QPixmap(":/icons/circle/tree/data.png");
}
}
return QFileSystemModel::data( index,role );
}