浏览代码

added possibility for keeping annotation when changing images

Sven Sickert 8 年之前
父节点
当前提交
ebfacc79ac
共有 2 个文件被更改,包括 45 次插入20 次删除
  1. 44 20
      ImageLabeler.cpp
  2. 1 0
      ImageLabeler.h

+ 44 - 20
ImageLabeler.cpp

@@ -1243,13 +1243,10 @@ ImageLabeler::nextImage(int iImageStep)
 		return;
 	}
 
-	list_bounding_box_.clear();
-	list_polygon_.clear();
-	list_areas_->clear();
-	image_holder_->clearAll();
-	segmented_image_.clear();
-	//clearLabelColorList();
-	
+    if (!askForKeepingAnnotations()) {
+        return;
+    }
+
 	if (list_images_widget_->count() - iImageStep == image_ID_) {
 		image_ID_ = 0;
 	}
@@ -1297,14 +1294,10 @@ ImageLabeler::prevImage(int iImageStep)
 		return;
 	}
 
-	list_bounding_box_.clear();
-	list_polygon_.clear();
-	list_areas_->clear();
-	image_holder_->clearAll();
-	segmented_image_.clear();
-	//clearLabelColorList();
+    if (!askForKeepingAnnotations()) {
+        return;
+    }
 
-	
 	if (image_ID_ < iImageStep) {
 		image_ID_ = list_images_widget_->count() - 1;
 	}
@@ -3129,12 +3122,37 @@ ImageLabeler::askForUnsavedData()
 
 		if (QMessageBox::Save == ret)
 			saveAllInfo();
+        else if (QMessageBox::Discard == ret)
+            return true;
 		else if (QMessageBox::Cancel == ret)
-			return true;
+            return false;
 	}
 	return true;
 }
 
+bool
+ImageLabeler::askForKeepingAnnotations()
+{
+    if ((!list_bounding_box_.isEmpty() ||
+        !list_polygon_.isEmpty()) )
+    {
+        QMessageBox msgBox;
+        msgBox.setText(tr("There are some annotations"));
+        msgBox.setInformativeText(tr("Do you want to keep them?"));
+        msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+        msgBox.setDefaultButton(QMessageBox::Yes);
+        msgBox.setIcon(QMessageBox::Question);
+        int ret = msgBox.exec();
+
+        if (QMessageBox::Yes == ret)
+            return true;
+        else if (QMessageBox::No == ret)
+            clearAllTool();
+    }
+
+    return true;
+}
+
 //! A slot member setting bbox tool active
 /*!
  * \param[in] aButtonPressed is a bool flag which is needed for toggled buttons
@@ -3631,13 +3649,19 @@ ImageLabeler::selectImage(QListWidgetItem *anItem)
 		return;
 		/* NOTREACHED */
 	}
-	clearAllTool();
-	//clearLabelList();
-	//clearLabelColorList();
 
-	image_ID_ = list_images_widget_->row(anItem);
+    if (!askForUnsavedData()) {
+        return;
+    }
+
+    if (!askForKeepingAnnotations()) {
+        return;
+    }
+
+    image_ID_ = list_images_widget_->row(anItem);
+
+    selectImage(image_ID_);
 
-	selectImage(image_ID_);
 }
 
 //! A protected member loading image from list_images_

+ 1 - 0
ImageLabeler.h

@@ -73,6 +73,7 @@ protected:
 	void getImagesFromDir(const QDir &dir);
 	void showWarning(const QString &text);
 	bool askForUnsavedData();
+    bool askForKeepingAnnotations();
 	void loadLegendFromNode(QDomElement *anElement);
 	void addLabel(
 		int aLabelID,