Эх сурвалжийг харах

-while saving filedialog sets the directory of the last edited image
-fixed unnecessary question about "unsaved" data

gapchich 13 жил өмнө
parent
commit
d7db7c537e
4 өөрчлөгдсөн 44 нэмэгдсэн , 3 устгасан
  1. 30 3
      ImageLabeler.cpp
  2. 1 0
      ImageLabeler.h
  3. 10 0
      functions.cpp
  4. 3 0
      functions.h

+ 30 - 3
ImageLabeler.cpp

@@ -51,6 +51,7 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 
 	/* flags */
 	interrupt_search_ = 0;
+	unsaved_data_ = 0;
 
 	/*
 	 * menu bar part begins
@@ -712,6 +713,8 @@ ImageLabeler::addLabel()
 
 	list_label_->addItem(newItem);
 	list_label_->setItemSelected(newItem, true);
+
+	unsaved_data_ = 1;
 }
 
 void
@@ -758,6 +761,8 @@ ImageLabeler::addLabel(
 	newItem->setFlags(newItem->flags() | Qt::ItemIsEditable);
 	list_label_->addItem(newItem);
 	list_label_->setItemSelected(newItem, true);
+
+	unsaved_data_ = 1;
 }
 
 void
@@ -781,6 +786,8 @@ ImageLabeler::editLabel(QListWidgetItem *anItem)
 	list_label_->blockSignals(true);
 	anItem->setText(label);
 	list_label_->blockSignals(false);
+
+	unsaved_data_ = 1;
 }
 
 void
@@ -805,6 +812,8 @@ ImageLabeler::removeLabel()
 	}
 	list_label_->takeItem(label_ID_);
 	list_label_colors_.takeAt(label_ID_);
+
+	unsaved_data_ = 1;
 }
 
 void
@@ -884,7 +893,6 @@ ImageLabeler::addPolyArea(
 	list_areas_->setItemSelected(newItem, true);
 }
 
-/* TODO: finish area editing */
 void
 ImageLabeler::editArea()
 {
@@ -939,6 +947,8 @@ ImageLabeler::onAreaItemChange(QListWidgetItem *anItem)
 	anItem->setFlags(anItem->flags() ^ Qt::ItemIsEditable);
 	list_areas_->blockSignals(false);
 	image_holder_->update();
+
+	unsaved_data_ = 1;
 }
 
 
@@ -975,6 +985,8 @@ ImageLabeler::onAreaEdit()
 			}
 		}
 	}
+
+	unsaved_data_ = 1;
 }
 
 void
@@ -1044,6 +1056,8 @@ ImageLabeler::deleteArea()
 		list_polygon_.removeAt(areaNum);
 
 	image_holder_->update();
+
+	unsaved_data_ = 1;
 }
 
 void
@@ -1091,6 +1105,8 @@ ImageLabeler::toggleLabelPriority()
 	list_label_->blockSignals(false);
 
 	image_holder_->update();
+
+	unsaved_data_ = 1;
 }
 
 void
@@ -1255,12 +1271,15 @@ ImageLabeler::saveAllInfo()
 	fileDialog.setAcceptMode(QFileDialog::AcceptSave);
 	fileDialog.setDefaultSuffix("dat");
 	fileDialog.setFileMode(QFileDialog::AnyFile);
+	QString dir = getDirFromPath(&(*current_image_));
 
 	/* altering the name of a new file */
 	QString newFileName = alterFileName(*current_image_, "_labeled");
 
 	fileDialog.selectFile(newFileName);
 
+	fileDialog.setDirectory(dir);
+
 	QString filename;
 	if (fileDialog.exec()) {
 		filename = fileDialog.selectedFiles().last();
@@ -1285,6 +1304,8 @@ ImageLabeler::saveAllInfo()
 
 	file.write(xml.toLocal8Bit());
 	file.close();
+
+	unsaved_data_ = 0;
 }
 
 void
@@ -1305,12 +1326,15 @@ ImageLabeler::saveSegmentedPicture()
 	fileDialog.setAcceptMode(QFileDialog::AcceptSave);
 	fileDialog.setDefaultSuffix("png");
 	fileDialog.setFileMode(QFileDialog::AnyFile);
+	QString dir = getDirFromPath(&(*current_image_));
 
 	/* altering the name of a new file */
 	QString newFileName = alterFileName(*current_image_, "_segmented");
 
 	fileDialog.selectFile(newFileName);
 
+	fileDialog.setDirectory(dir);
+
 	QString filename;
 	if (fileDialog.exec()) {
 		filename = fileDialog.selectedFiles().last();
@@ -2184,8 +2208,9 @@ ImageLabeler::showWarning(
 bool
 ImageLabeler::askForUnsavedData()
 {
-	if (!list_bounding_box_.isEmpty() ||
-		!list_polygon_.isEmpty())
+	if ((!list_bounding_box_.isEmpty() ||
+		!list_polygon_.isEmpty()) &&
+		unsaved_data_)
 	{
 		QMessageBox msgBox;
 		msgBox.setText(tr("There is some unsaved data"));
@@ -2274,6 +2299,8 @@ ImageLabeler::confirmSelection()
 		break;
 	}
 	button_confirm_selection_->setEnabled(false);
+
+	unsaved_data_ = 1;
 }
 
 void

+ 1 - 0
ImageLabeler.h

@@ -236,6 +236,7 @@ private:
 
 	/* flags */
 	bool interrupt_search_;
+	bool unsaved_data_;
 };
 
 #endif /* __IMAGELABELER_H__ */

+ 10 - 0
functions.cpp

@@ -87,6 +87,16 @@ QString alterFileName(const QString &aFilename, const QString &aSuffix)
 	return newFileName;
 }
 
+QString
+getDirFromPath(QString *aPath)
+{
+	int lastSlash = aPath->lastIndexOf("/");
+	int symbolsToCut = aPath->size() - (aPath->size() - lastSlash);
+
+	QString dir = aPath->mid(0, symbolsToCut);
+	return dir;
+}
+
 /*
  *
  */

+ 3 - 0
functions.h

@@ -12,6 +12,9 @@ class QString;
 class QChar;
 class QDomDocument;
 
+QString getDirFromPath(
+	QString *aPath
+	);
 int getNumFromString(
 	QString *aString,
 	const QString &aFirstStr,