-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbpathdialog.cpp
executable file
·78 lines (61 loc) · 2.16 KB
/
dbpathdialog.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
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
#include "dbpathdialog.h"
#include "ui_dbpathdialog.h"
#include <QStandardPaths>
DbPathDialog::DbPathDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::DbPathDialog)
{
ui->setupUi(this);
dir_model = new QFileSystemModel(this);
qDebug() << dir_model;
dir_model->setRootPath("/");
dir_model->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
QModelIndex index_to_show = dir_model->index(QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory));
ui->dir_tree->setModel(dir_model);
ui->dir_tree->setRootIndex(index_to_show);
ui->dir_tree->resizeColumnToContents(0);
ui->dir_tree->setColumnHidden(1, true);
ui->dir_tree->setColumnHidden(2, true);
ui->dir_tree->setColumnHidden(3, true);
ui->dir_tree->setHeaderHidden(true);
file_model = new QFileSystemModel(this);
file_model->setRootPath("/");
file_model->setFilter(QDir::NoDotAndDotDot | QDir::Files);
ui->file_tree->setModel(file_model);
ui->file_tree->setRootIndex(index_to_show);
ui->file_tree->resizeColumnToContents(0);
ui->file_tree->setColumnHidden(1, true);
ui->file_tree->setColumnHidden(2, true);
ui->file_tree->setColumnHidden(3, true);
ui->file_tree->setHeaderHidden(true);
file_model->setReadOnly(false);
}
DbPathDialog::~DbPathDialog()
{
delete ui;
}
void DbPathDialog::on_dir_tree_clicked(const QModelIndex &index)
{
current_dir_model_item_path = dir_model->fileInfo(index).absoluteFilePath();
ui->file_tree->setRootIndex(file_model->setRootPath(current_dir_model_item_path));
}
void DbPathDialog::on_Cancella_button_clicked()
{
close();
}
void DbPathDialog::on_Conferma_button_clicked()
{
QString filepath = file_model->fileInfo(ui->file_tree->currentIndex()).absoluteFilePath();
SetDbPath_SIGNAL(filepath);
close();
}
void DbPathDialog::on_Crea_db_button_clicked()
{
//create a new database in the current folder and let the user edit the title.
ModelManager * model = new ModelManager();
model->setPath(current_dir_model_item_path);
if(model->createNewDatabase()) {
qDebug() << "new database created";
}
delete model;
}