39 : QWidget(parent), options_(options), prev_selected_(false) {
40 setWindowFlags(Qt::Dialog);
41 setWindowModality(Qt::ApplicationModal);
42 setWindowTitle(
"Project");
45 QPushButton* databse_path_new =
new QPushButton(tr(
"New"),
this);
46 connect(databse_path_new, &QPushButton::released,
this,
47 &ProjectWidget::SelectNewDatabasePath);
48 QPushButton* databse_path_open =
new QPushButton(tr(
"Open"),
this);
49 connect(databse_path_open, &QPushButton::released,
this,
50 &ProjectWidget::SelectExistingDatabasePath);
51 database_path_text_ =
new QLineEdit(
this);
52 database_path_text_->setText(
56 QPushButton* image_path_select =
new QPushButton(tr(
"Select"),
this);
57 connect(image_path_select, &QPushButton::released,
this,
58 &ProjectWidget::SelectImagePath);
59 image_path_text_ =
new QLineEdit(
this);
60 image_path_text_->setText(QString::fromStdString(*options_->
image_path));
63 QPushButton* create_button =
new QPushButton(tr(
"Save"),
this);
64 connect(create_button, &QPushButton::released,
this, &ProjectWidget::Save);
66 QGridLayout* grid =
new QGridLayout(
this);
68 grid->addWidget(
new QLabel(tr(
"Database"),
this), 0, 0);
69 grid->addWidget(database_path_text_, 0, 1);
70 grid->addWidget(databse_path_new, 0, 2);
71 grid->addWidget(databse_path_open, 0, 3);
73 grid->addWidget(
new QLabel(tr(
"Images"),
this), 1, 0);
74 grid->addWidget(image_path_text_, 1, 1);
75 grid->addWidget(image_path_select, 1, 2);
77 grid->addWidget(create_button, 2, 2);
86 database_path_text_->clear();
87 image_path_text_->clear();
91 return database_path_text_->text().toUtf8().constData();
95 return image_path_text_->text().toUtf8().constData();
99 database_path_text_->setText(QString::fromStdString(
path));
103 image_path_text_->setText(QString::fromStdString(
path));
106 void ProjectWidget::Save() {
116 QMessageBox::critical(
this,
"", tr(
"Invalid paths"));
120 void ProjectWidget::SelectNewDatabasePath() {
121 QString database_path = QFileDialog::getSaveFileName(
122 this, tr(
"Select database file"), DefaultDirectory(),
123 tr(
"SQLite3 database (*.db)"));
124 if (database_path !=
"") {
126 database_path +=
".db";
128 database_path_text_->setText(database_path);
132 void ProjectWidget::SelectExistingDatabasePath() {
133 const auto database_path = QFileDialog::getOpenFileName(
134 this, tr(
"Select database file"), DefaultDirectory(),
135 tr(
"SQLite3 database (*.db)"));
136 if (database_path !=
"") {
137 database_path_text_->setText(database_path);
141 void ProjectWidget::SelectImagePath() {
142 const auto image_path = QFileDialog::getExistingDirectory(
143 this, tr(
"Select image path..."), DefaultDirectory(),
144 QFileDialog::ShowDirsOnly);
145 if (image_path !=
"") {
146 image_path_text_->setText(image_path);
150 QString ProjectWidget::DefaultDirectory() {
151 if (prev_selected_) {
155 prev_selected_ =
true;
160 return QString::fromStdString(parent_path);
164 if (!database_path_text_->text().isEmpty()) {
165 const auto parent_path =
166 GetParentDir(database_path_text_->text().toUtf8().constData());
168 return QString::fromStdString(parent_path);
172 if (!image_path_text_->text().isEmpty()) {
173 return image_path_text_->text();
std::shared_ptr< std::string > database_path
std::shared_ptr< std::string > project_path
std::shared_ptr< std::string > image_path
static const std::string path
bool HasFileExtension(const std::string &file_name, const std::string &ext)
bool ExistsDir(const std::string &path)
std::string GetParentDir(const std::string &path)