-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdialogmain.cpp
71 lines (60 loc) · 2.36 KB
/
dialogmain.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
#include "dialogmain.h"
#include "ui_dialogmain.h"
#include <QPrinterInfo>
//#include <QtPrintSupport/QPrinterInfo>
#include <QSettings>
DialogMain::DialogMain(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogMain)
{
ui->setupUi(this);
m_firstDrawn = false;
m_directoryModel = new QFileSystemModel(this);
m_directoryModel->setFilter(QDir::NoDotAndDotDot|QDir::AllDirs);
//ui->treeViewDirectories->setRootIndex(rootIndex);
ui->treeViewDirectories->setModel(m_directoryModel);
ui->treeViewDirectories->hideColumn(1);
ui->treeViewDirectories->hideColumn(2);
ui->treeViewDirectories->hideColumn(3);
ui->treeViewDirectories->hideColumn(4);
m_fileModel = new QFileSystemModel(this);
m_fileModel->setFilter(QDir::NoDotAndDotDot|QDir::Files);
ui->treeViewSourceFiles->setModel(m_fileModel);
QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
foreach(QPrinterInfo printer, printers)
ui->comboBoxFilePrinters->addItem(printer.printerName());
ui->comboBoxFileTypes->addItem("*.tif");
// connect(&m_timer, SIGNAL(timeout()), this, SLOT(onTimer()));
// m_timer.start(2000);
connect(m_directoryModel, SIGNAL(rootPathChanged(QString)),this,SLOT(onDirectoryRootPathChanged()));
QModelIndex rootIndex = m_directoryModel->setRootPath("");
//QTimer::singleShot(0, this, SLOT(onTimer()));
}
DialogMain::~DialogMain()
{
delete ui;
}
void DialogMain::onDirectoryRootPathChanged()
{
// m_timer.stop();
QSettings settings;
QString path = settings.value("lastPath", QVariant("")).toString();
QModelIndex index = m_directoryModel->index(path,0);
ui->treeViewDirectories->setCurrentIndex(index);
ui->treeViewDirectories->scrollTo(index,QAbstractItemView::EnsureVisible);
ui->treeViewSourceFiles->setRootIndex(m_fileModel->setRootPath(path));
}
void DialogMain::onFileRootPathChanged()
{
ui->treeViewSourceFiles->setVisible(false);
ui->treeViewSourceFiles->resizeColumnToContents(0);
ui->treeViewSourceFiles->setVisible(true);
}
void DialogMain::on_treeViewDirectories_clicked(const QModelIndex &index)
{
QString path = m_directoryModel->fileInfo(index).absoluteFilePath();
ui->treeViewSourceFiles->setRootIndex(m_fileModel->setRootPath(path));
ui->treeViewSourceFiles->resizeColumnToContents(0);
QSettings settings;
settings.setValue("lastPath",path);
}