-
Notifications
You must be signed in to change notification settings - Fork 0
/
openfile.cpp
39 lines (33 loc) · 1.09 KB
/
openfile.cpp
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
#include "openfile.h"
#include "ui_openfile.h"
#include <QFileSystemModel>
OpenFile::OpenFile(QWidget *parent) :
QDialog(parent),
ui(new Ui::OpenFile), path("")
{
ui->setupUi(this);
dirmodel = new QFileSystemModel(this);
dirmodel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
ui->treeView->setModel(dirmodel);
ui->treeView->setRootIndex(dirmodel->setRootPath(QApplication::applicationFilePath()));
filemodel = new QFileSystemModel(this);
filemodel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
QStringList filters;
filters << "*.txt";
filemodel->setNameFilters(filters);
filemodel->setNameFilterDisables(false);
ui->listView->setModel(filemodel);
}
OpenFile::~OpenFile()
{
delete ui;
}
void OpenFile::on_treeView_clicked(const QModelIndex &index)
{
QString tempPath = dirmodel->fileInfo(index).absoluteFilePath();
ui->listView->setRootIndex(filemodel->setRootPath(tempPath));
}
void OpenFile::on_listView_clicked(const QModelIndex &index)
{
path = filemodel->fileInfo(index).absoluteFilePath();
}