-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewsessiondialog.cpp
More file actions
131 lines (117 loc) · 3 KB
/
Copy pathnewsessiondialog.cpp
File metadata and controls
131 lines (117 loc) · 3 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
#include <QMessageBox>
#include <QFileDialog>
#include <QDebug>
#include "newsessiondialog.h"
#include "ui_newsessiondialog.h"
NewSessionDialog::NewSessionDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewSessionDialog)
{
ui->setupUi(this);
setWindowTitle("QImageViewer | New Session");
QObject::connect(ui->imgPathButton, SIGNAL(clicked()), this, SLOT(ButtonImgPathPushed()));
QObject::connect(ui->txtPathButton, SIGNAL(clicked()), this, SLOT(ButtonTxtPathPushed()));
QObject::connect(ui->addSessionButton, SIGNAL(clicked()), this, SLOT(ButtonAddPushed()));
QObject::connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(ButtonCancelPushed()));
}
NewSessionDialog::~NewSessionDialog()
{
delete ui;
}
QString NewSessionDialog::GetSessionDescriptor()
{
QString name = ui->nameLineEdit->text();
QString imgPath = ui->imgPathLineEdit->text();
QString txtPath = ui->txtPathLineEdit->text();
QString descriptor = name + ";" + imgPath + ";" + txtPath;
return descriptor;
}
void NewSessionDialog::ButtonImgPathPushed()
{
QFileDialog dialog;
dialog.setFileMode(QFileDialog::ExistingFile);
if (dialog.exec())
{
QString filename = dialog.selectedFiles().at(0);
ui->imgPathLineEdit->setText(filename);
}
}
void NewSessionDialog::ButtonTxtPathPushed()
{
QFileDialog dialog;
dialog.setFileMode(QFileDialog::Directory);
if (dialog.exec())
{
QString filename = dialog.selectedFiles().at(0);
ui->txtPathLineEdit->setText(filename);
}
}
void NewSessionDialog::ButtonAddPushed()
{
if (!NameIsValid() || !ImgPathIsValid() || !TxtPathIsValid())
{
return;
}
accept();
}
void NewSessionDialog::ButtonCancelPushed()
{
reject();
}
bool NewSessionDialog::NameIsValid()
{
QString name = ui->nameLineEdit->text();
if (name.isEmpty())
{
QMessageBox m;
m.setText("Name is required");
m.exec();
return false;
}
if (name.contains(';'))
{
QMessageBox m;
m.setText("Name cannot contain ;");
m.exec();
return false;
}
return true;
}
bool NewSessionDialog::ImgPathIsValid()
{
QString imgPath = ui->imgPathLineEdit->text();
if (imgPath.isEmpty())
{
QMessageBox m;
m.setText("Image Path is required");
m.exec();
return false;
}
QFileInfo info(imgPath);
if (!(info.exists() && info.isFile()))
{
QMessageBox m;
m.setText("Image Path must be an existing file");
m.exec();
return false;
}
return true;
}
bool NewSessionDialog::TxtPathIsValid()
{
QString txtPath = ui->txtPathLineEdit->text();
if (txtPath.isEmpty())
{
// txtPath is not required
return true;
}
QFileInfo info(txtPath);
if (!(info.exists() && info.isDir()))
{
QMessageBox m;
m.setText("Text Path must be an existing directory");
m.exec();
return false;
}
return true;
}