Changeset View
Changeset View
Standalone View
Standalone View
src/mainwindow.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 57 | if (m_instances->count() == 1) { | |||
---|---|---|---|---|---|
58 | m_instances->setTabsClosable(false); | 58 | m_instances->setTabsClosable(false); | ||
59 | m_instances->setMovable(false); | 59 | m_instances->setMovable(false); | ||
60 | } | 60 | } | ||
61 | }); | 61 | }); | ||
62 | } | 62 | } | ||
63 | 63 | | |||
64 | void MainWindow::closeEvent(QCloseEvent *event) | 64 | void MainWindow::closeEvent(QCloseEvent *event) | ||
65 | { | 65 | { | ||
66 | if (!askToSave(m_gcodeEditor->modifiedFiles())) { | ||||
67 | event->ignore(); | ||||
68 | } | ||||
69 | | ||||
66 | bool closePrompt = false; | 70 | bool closePrompt = false; | ||
67 | for (int i = 0; i < m_instances->count(); i++) { | 71 | for (int i = 0; i < m_instances->count(); i++) { | ||
68 | AtCoreInstanceWidget *instance = qobject_cast<AtCoreInstanceWidget *>(m_instances->widget(i)); | 72 | AtCoreInstanceWidget *instance = qobject_cast<AtCoreInstanceWidget *>(m_instances->widget(i)); | ||
69 | if (instance->isPrinting()) { | 73 | if (instance->isPrinting()) { | ||
70 | closePrompt = true; | 74 | closePrompt = true; | ||
71 | break; | 75 | break; | ||
72 | } | 76 | } | ||
73 | } | 77 | } | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 141 | { | |||
142 | connect(this, &MainWindow::profilesChanged, newInstanceWidget, &AtCoreInstanceWidget::updateProfileData); | 146 | connect(this, &MainWindow::profilesChanged, newInstanceWidget, &AtCoreInstanceWidget::updateProfileData); | ||
143 | connect(newInstanceWidget, &AtCoreInstanceWidget::requestProfileDialog, this, [this] { | 147 | connect(newInstanceWidget, &AtCoreInstanceWidget::requestProfileDialog, this, [this] { | ||
144 | std::unique_ptr<ProfilesDialog> pd(new ProfilesDialog); | 148 | std::unique_ptr<ProfilesDialog> pd(new ProfilesDialog); | ||
145 | pd->exec(); | 149 | pd->exec(); | ||
146 | emit(profilesChanged()); | 150 | emit(profilesChanged()); | ||
147 | }); | 151 | }); | ||
148 | 152 | | |||
149 | connect(newInstanceWidget, &AtCoreInstanceWidget::requestFileChooser, this, [newInstanceWidget, this] { | 153 | connect(newInstanceWidget, &AtCoreInstanceWidget::requestFileChooser, this, [newInstanceWidget, this] { | ||
154 | QUrl file; | ||||
150 | switch (m_openFiles.size()) | 155 | switch (m_openFiles.size()) | ||
151 | { | 156 | { | ||
152 | case 0: | 157 | case 0: | ||
153 | QMessageBox::warning(this, i18n("Error"), | 158 | QMessageBox::warning(this, i18n("Error"), | ||
154 | i18n("There's no GCode File open. \n Please select a file and try again."), | 159 | i18n("There's no GCode File open. \n Please select a file and try again."), | ||
155 | QMessageBox::Ok); | 160 | QMessageBox::Ok); | ||
156 | break; | 161 | break; | ||
157 | case 1: | 162 | case 1: | ||
158 | newInstanceWidget->printFile(m_openFiles.at(0)); | 163 | file = m_openFiles.at(0); | ||
159 | break; | 164 | break; | ||
160 | default: | 165 | default: | ||
161 | ChooseFileDialog dialog(this, m_openFiles); | 166 | ChooseFileDialog dialog(this, m_openFiles); | ||
162 | if (dialog.exec() == QDialog::Accepted) { | 167 | if (dialog.exec() == QDialog::Accepted) { | ||
163 | newInstanceWidget->printFile(dialog.choosenFile()); | 168 | file = dialog.choosenFile(); | ||
169 | } | ||||
170 | break; | ||||
171 | } | ||||
172 | if (m_gcodeEditor->modifiedFiles().contains(file)) | ||||
173 | { | ||||
patrickelectric: This breaks the code style. | |||||
There are no other larger function to follow style of in this project MessageBox:: info( this, "TITLE" , "TEXT" , ... ); is the style of the others . Should i put the title and parent on the first line or am i just missing the previous "style " here ? rizzitello: There are no other larger function to follow style of in this project
```
MessageBox:: info… | |||||
174 | int result = QMessageBox::question( | ||||
175 | this | ||||
176 | , i18n("Document Modified") | ||||
177 | , i18n("%1 \n Contains Unsaved Changes That will not be in the print.\n Would you like to Save before printing?", file.toLocalFile()) | ||||
178 | , QMessageBox::Save | ||||
179 | , QMessageBox::Cancel | ||||
180 | , QMessageBox::Ignore | ||||
181 | ); | ||||
182 | if (result == QMessageBox::Cancel) { | ||||
183 | return; | ||||
184 | } else if (result == QMessageBox::Save) { | ||||
patrickelectric: else after return is not necessary. | |||||
I personally find if / else if to be an easier logic to follow Then a collection of "if" when checking the same variable. rizzitello: I personally find if / else if to be an easier logic to follow Then a collection of "if" when… | |||||
185 | m_gcodeEditor->saveFile(file); | ||||
164 | } | 186 | } | ||
165 | } | 187 | } | ||
188 | newInstanceWidget->printFile(file); | ||||
166 | }); | 189 | }); | ||
167 | 190 | | |||
168 | connect(newInstanceWidget, &AtCoreInstanceWidget::connectionChanged, this, &MainWindow::atCoreInstanceNameChange); | 191 | connect(newInstanceWidget, &AtCoreInstanceWidget::connectionChanged, this, &MainWindow::atCoreInstanceNameChange); | ||
169 | 192 | | |||
170 | if (m_instances->count() > 1) { | 193 | if (m_instances->count() > 1) { | ||
171 | m_instances->setTabsClosable(true); | 194 | m_instances->setTabsClosable(true); | ||
172 | m_instances->setMovable(true); | 195 | m_instances->setMovable(true); | ||
173 | m_instances->setCurrentIndex(m_instances->count() - 1); | 196 | m_instances->setCurrentIndex(m_instances->count() - 1); | ||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Line(s) | 387 | if (m_currEditorView) { | |||
365 | guiFactory()->removeClient(m_currEditorView); | 388 | guiFactory()->removeClient(m_currEditorView); | ||
366 | } | 389 | } | ||
367 | if (view) { | 390 | if (view) { | ||
368 | guiFactory()->addClient(view); | 391 | guiFactory()->addClient(view); | ||
369 | } | 392 | } | ||
370 | } | 393 | } | ||
371 | m_currEditorView = view; | 394 | m_currEditorView = view; | ||
372 | } | 395 | } | ||
396 | | ||||
397 | bool MainWindow::askToSave(const QVector<QUrl> &fileList) | ||||
398 | { | ||||
399 | | ||||
400 | if (fileList.isEmpty()) { | ||||
401 | return true; | ||||
402 | } | ||||
403 | QSize iconSize = QSize(fontMetrics().lineSpacing(), fontMetrics().lineSpacing()); | ||||
404 | auto dialog = new QDialog(); | ||||
405 | const int padding = 30; | ||||
406 | auto listWidget = new QListWidget(); | ||||
407 | listWidget->setMinimumWidth(fontMetrics().height() / 2 * padding); | ||||
408 | for (const auto &url : fileList) { | ||||
409 | listWidget->addItem(url.toLocalFile() + " [*]"); | ||||
410 | } | ||||
411 | | ||||
412 | auto hLayout = new QHBoxLayout(); | ||||
413 | auto saveBtn = new QPushButton(QIcon::fromTheme("document-save", QIcon(QStringLiteral(":/%1/save").arg(m_theme))), i18n("Save Selected")); | ||||
414 | saveBtn->setIconSize(iconSize); | ||||
415 | connect(saveBtn, &QPushButton::clicked, this, [this, &listWidget, &fileList, &dialog] { | ||||
416 | if (!m_gcodeEditor->saveFile(fileList.at(listWidget->currentRow()))) | ||||
417 | { | ||||
418 | QMessageBox::information(this, i18n("Save Failed"), i18n("Failed to save file: %1").arg(fileList.at(listWidget->currentRow()).toLocalFile())); | ||||
419 | } else | ||||
420 | { | ||||
421 | QString txt = listWidget->item(listWidget->currentRow())->text(); | ||||
422 | txt.remove(" [*]"); | ||||
423 | listWidget->item(listWidget->currentRow())->setText(txt); | ||||
424 | for (int i = 0; i < listWidget->count(); i++) { | ||||
patrickelectric: for(const auto& item: listWidget->selectedItems()) | |||||
Selected Items != Count IIrc i had to use this style if. I will check again when I can get back to the code. rizzitello: Selected Items != Count
IIrc i had to use this style if. I will check again when I can get… | |||||
425 | QString string = listWidget->item(i)->text(); | ||||
426 | if (string.endsWith(" [*]")) { | ||||
427 | return; | ||||
428 | } | ||||
429 | } | ||||
430 | dialog->accept(); | ||||
431 | } | ||||
432 | }); | ||||
433 | hLayout->addWidget(saveBtn); | ||||
434 | | ||||
435 | auto saveAllBtn = new QPushButton(QIcon::fromTheme("document-save-all", QIcon(QStringLiteral(":/%1/saveAll").arg(m_theme))), i18n("Save All")); | ||||
436 | saveAllBtn->setIconSize(iconSize); | ||||
437 | connect(saveAllBtn, &QPushButton::clicked, this, [this, &listWidget, &fileList, &dialog] { | ||||
438 | for (int i = 0; i < listWidget->count(); i++) | ||||
patrickelectric: Same thing. | |||||
439 | { | ||||
440 | if (!m_gcodeEditor->saveFile(fileList.at(i))) { | ||||
441 | QMessageBox::information(this, i18n("Save Failed"), i18n("Failed to save file: %1").arg(fileList.at(i).toLocalFile())); | ||||
442 | dialog->reject(); | ||||
443 | } else { | ||||
444 | QString txt = listWidget->item(listWidget->currentRow())->text(); | ||||
445 | txt.remove(" [*]"); | ||||
446 | listWidget->item(listWidget->currentRow())->setText(txt); | ||||
447 | } | ||||
448 | } | ||||
449 | dialog->accept(); | ||||
450 | }); | ||||
451 | hLayout->addWidget(saveAllBtn); | ||||
452 | | ||||
453 | auto cancelBtn = new QPushButton(QIcon::fromTheme("dialog-cancel", QIcon(QStringLiteral(":/%1/cancel").arg(m_theme))), i18n("Cancel")); | ||||
454 | cancelBtn->setIconSize(iconSize); | ||||
455 | connect(cancelBtn, &QPushButton::clicked, this, [&dialog] { | ||||
456 | dialog->reject(); | ||||
457 | }); | ||||
458 | hLayout->addWidget(cancelBtn); | ||||
459 | | ||||
460 | auto ignoreBtn = new QPushButton(QIcon::fromTheme("window-close", QIcon(QStringLiteral(":/icon/close"))), i18n("Ignore")); | ||||
461 | ignoreBtn->setIconSize(iconSize); | ||||
462 | connect(ignoreBtn, &QPushButton::clicked, this, [&dialog] { | ||||
463 | dialog->accept(); | ||||
464 | }); | ||||
465 | hLayout->addWidget(ignoreBtn); | ||||
466 | | ||||
467 | auto layout = new QVBoxLayout; | ||||
468 | auto label = new QLabel(i18n("Files with Unsaved Changes.")); | ||||
469 | layout->addWidget(label); | ||||
470 | layout->addWidget(listWidget); | ||||
471 | layout->addItem(hLayout); | ||||
472 | dialog->setLayout(layout); | ||||
473 | | ||||
474 | return dialog->exec(); | ||||
Why not use a QFileDialog to save the file instead of manually mounting one? tcanabrava: Why not use a QFileDialog to save the file instead of manually mounting one? | |||||
This is a list based dialog of all the files we have open not a normal picker. rizzitello: This is a list based dialog of all the files we have open not a normal picker. | |||||
475 | } |
This breaks the code style.