-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatedbwizardpage.cpp
More file actions
84 lines (69 loc) · 2.32 KB
/
Copy pathcreatedbwizardpage.cpp
File metadata and controls
84 lines (69 loc) · 2.32 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
#include "createdbwizardpage.h"
CreateDbWizardPage::CreateDbWizardPage(QWidget *parent) :
QWizardPage(parent)
{
setupLayout();
connect(changeToolButton, SIGNAL(clicked()), this, SLOT(showOpenFile()));
connect(createDbCheckBox, SIGNAL(clicked(bool)), this, SLOT(onCreateCheckBoxClicked(bool)));
setupRegisterFields();
}
void CreateDbWizardPage::setupLayout()
{
fileNameFileEdit = new QLineEdit;
fileNameLabel = new QLabel(tr("&File Name: "));
fileNameLabel->setBuddy(fileNameFileEdit);
fileNameFileEdit->setText(QCoreApplication::applicationDirPath() + "/" + "production.db");
createDbCheckBox = new QCheckBox(tr("database exist?"));
changeToolButton = new QToolButton;
changeToolButton->setText(tr("..."));
changeToolButton->setToolTip(tr("Change file name or path"));
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(fileNameLabel, 0, 0);
mainLayout->addWidget(fileNameFileEdit, 0, 1);
mainLayout->addWidget(changeToolButton, 0, 2);
mainLayout->addWidget(createDbCheckBox, 1, 1);
setLayout(mainLayout);
setTitle(tr("Setup Database"));
setSubTitle(tr("Create a database or set the path of an exisiting database. "
"Make sure the database exist if you are setting its path."));
}
void CreateDbWizardPage::showOpenFile()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Database file"),
".", tr("Database File (*.db)"));
if(!fileName.isEmpty())
{
fileNameFileEdit->setText(fileName);
}
}
void CreateDbWizardPage::setupRegisterFields()
{
registerField("fileName", fileNameFileEdit);
registerField("cbCreateDb", createDbCheckBox);
}
void CreateDbWizardPage::onCreateCheckBoxClicked(bool final)
{
setFinalPage(final);
}
int CreateDbWizardPage::nextId() const
{
if(createDbCheckBox->isChecked())
{
return -1;
}
else
{
return 2;
}
}
bool CreateDbWizardPage::validatePage()
{
bool fileExists = QFile::exists(fileNameFileEdit->text());
if(!fileExists && createDbCheckBox->isChecked())
{
QMessageBox::information(this, tr("File validation"),
tr("File: %1 don't not exist.").arg(fileNameFileEdit->text()));
return false;
}
return true;
}