11 #include "util/option_manager.h"
21 : QWidget(parent), options_(options), prev_selected_(false) {
22 setWindowFlags(Qt::Dialog);
23 setWindowModality(Qt::ApplicationModal);
24 setWindowTitle(
"Project");
27 QPushButton* databse_path_new =
new QPushButton(tr(
"New"),
this);
28 connect(databse_path_new, &QPushButton::released,
this,
29 &ProjectWidget::SelectNewDatabasePath);
30 QPushButton* databse_path_open =
new QPushButton(tr(
"Open"),
this);
31 connect(databse_path_open, &QPushButton::released,
this,
32 &ProjectWidget::SelectExistingDatabasePath);
33 database_path_text_ =
new QLineEdit(
this);
34 database_path_text_->setText(
35 QString::fromStdString(*options_->database_path));
38 QPushButton* image_path_select =
new QPushButton(tr(
"Select"),
this);
39 connect(image_path_select, &QPushButton::released,
this,
40 &ProjectWidget::SelectImagePath);
41 image_path_text_ =
new QLineEdit(
this);
42 image_path_text_->setText(QString::fromStdString(*options_->image_path));
45 QPushButton* create_button =
new QPushButton(tr(
"Save"),
this);
46 connect(create_button, &QPushButton::released,
this, &ProjectWidget::Save);
48 QGridLayout* grid =
new QGridLayout(
this);
50 grid->addWidget(
new QLabel(tr(
"Database"),
this), 0, 0);
51 grid->addWidget(database_path_text_, 0, 1);
52 grid->addWidget(databse_path_new, 0, 2);
53 grid->addWidget(databse_path_open, 0, 3);
55 grid->addWidget(
new QLabel(tr(
"Images"),
this), 1, 0);
56 grid->addWidget(image_path_text_, 1, 1);
57 grid->addWidget(image_path_select, 1, 2);
59 grid->addWidget(create_button, 2, 2);
68 database_path_text_->clear();
69 image_path_text_->clear();
73 const std::string& database_path,
74 const std::string& image_path) {
76 settings.beginGroup(
"Reconstruction");
84 return database_path_text_->text().toUtf8().constData();
88 return image_path_text_->text().toUtf8().constData();
92 database_path_text_->setText(QString::fromStdString(
path));
96 image_path_text_->setText(QString::fromStdString(
path));
99 void ProjectWidget::Save() {
105 Database database(*options_->database_path);
106 persistSave(*options_->project_path, *options_->database_path,
107 *options_->image_path);
111 QMessageBox::critical(
this,
"", tr(
"Invalid paths"));
115 void ProjectWidget::SelectNewDatabasePath() {
116 QString database_path = QFileDialog::getSaveFileName(
117 this, tr(
"Select database file"), DefaultDirectory(),
118 tr(
"SQLite3 database (*.db)"));
119 if (database_path !=
"") {
121 database_path +=
".db";
123 database_path_text_->setText(database_path);
127 void ProjectWidget::SelectExistingDatabasePath() {
128 const auto database_path = QFileDialog::getOpenFileName(
129 this, tr(
"Select database file"), DefaultDirectory(),
130 tr(
"SQLite3 database (*.db)"));
131 if (database_path !=
"") {
132 database_path_text_->setText(database_path);
136 void ProjectWidget::SelectImagePath() {
137 const auto image_path = QFileDialog::getExistingDirectory(
138 this, tr(
"Select image path..."), DefaultDirectory(),
139 QFileDialog::ShowDirsOnly);
140 if (image_path !=
"") {
141 image_path_text_->setText(image_path);
145 QString ProjectWidget::DefaultDirectory() {
146 if (prev_selected_) {
150 prev_selected_ =
true;
152 if (!options_->project_path->empty()) {
153 const auto parent_path = GetParentDir(*options_->project_path);
154 if (ExistsDir(parent_path)) {
155 return QString::fromStdString(parent_path);
159 if (!database_path_text_->text().isEmpty()) {
160 const auto parent_path =
161 GetParentDir(database_path_text_->text().toUtf8().constData());
162 if (ExistsDir(parent_path)) {
163 return QString::fromStdString(parent_path);
167 if (!image_path_text_->text().isEmpty()) {
168 return image_path_text_->text();
static const std::string path
bool HasFileExtension(const std::string &file_name, const std::string &ext)
Generic file read and write utility for python interface.
colmap::OptionManager OptionManager