SelectSegmentDialog.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * This file is part of the Carpe Diem Active Learning Software,
  3. * Copyright (C) 2017 Clemens-Alexander Brust (ikosa dot de at gmail dot com).
  4. *
  5. * For licensing information, see the LICENSE file included with this project.
  6. */
  7. #include "SelectSegmentDialog.h"
  8. #include "ui_SelectSegmentDialog.h"
  9. #include <QPushButton>
  10. #include <QMessageBox>
  11. SelectSegmentDialog::SelectSegmentDialog(QWidget *parent, Conv::SegmentSet* set, Project* project):
  12. QDialog(parent), project(project), set(set),
  13. ui(new Ui::SelectSegmentDialog)
  14. {
  15. ui->setupUi(this);
  16. ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Review");
  17. if(set != nullptr && project != nullptr) {
  18. UpdateSegments();
  19. } else {
  20. reject();
  21. }
  22. }
  23. SelectSegmentDialog::~SelectSegmentDialog()
  24. {
  25. delete ui;
  26. }
  27. void SelectSegmentDialog::UpdateSegments() {
  28. ui->segmentListWidget->clear();
  29. for(unsigned int s = 0; s < set->GetSegmentCount(); s++) {
  30. Conv::Segment* segment = set->GetSegment(s);
  31. ui->segmentListWidget->addItem(QString::fromStdString(segment->name));
  32. }
  33. if(set->GetSegmentCount() > 0) {
  34. segment = set->GetSegment(0);
  35. ui->segmentListWidget->setCurrentRow(0);
  36. ui->segmentListWidget->item(0)->setSelected(true);
  37. ui->removeButton->setEnabled(true);
  38. } else {
  39. ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
  40. ui->removeButton->setEnabled(false);
  41. }
  42. }
  43. void SelectSegmentDialog::on_segmentListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
  44. {
  45. if(current != nullptr) {
  46. segment = set->GetSegment(ui->segmentListWidget->row(current));
  47. }
  48. }
  49. void SelectSegmentDialog::on_removeButton_clicked()
  50. {
  51. if(segment != nullptr) {
  52. set->RemoveSegment(ui->segmentListWidget->currentRow());
  53. UpdateSegments();
  54. }
  55. }
  56. void SelectSegmentDialog::on_moveToNewButton_clicked()
  57. {
  58. if(segment != nullptr) {
  59. set->RemoveSegment(ui->segmentListWidget->currentRow());
  60. for(unsigned int sample = 0; sample < segment->GetSampleCount(); sample++) {
  61. Conv::JSON& sample_json = segment->GetSample(sample);
  62. std::string filename = sample_json["image_rpath"];
  63. if(!(project->AddSample(filename))) {
  64. QMessageBox::critical(this, tr("Error"), tr("Could not import unlabeled sample! See log for details."), QMessageBox::Ok);
  65. }
  66. }
  67. UpdateSegments();
  68. }
  69. }