From c35612e34a3834505a0ec123acba1af469786601 Mon Sep 17 00:00:00 2001
From: Yousef Hamza <jo.adama.93@gmail.com>
Date: Thu, 3 Apr 2014 19:08:58 +0200
Subject: [PATCH] Edit bookmark name

Add the option to edit the name of the bookmark to
be more meaningful for the user if wishes.
It works just as simple bookmarks can be removed and
hid.
It won't accept longer than 22 character cause longer
will display as garbge text.
And changed from displaying flag by depending on event
name, to depend of event type.

Signed-off-by: Yousef Hamza <jo.adama.93@gmail.com>
---
 qt-ui/profile/diveeventitem.cpp  |  2 +-
 qt-ui/profile/profilewidget2.cpp | 31 +++++++++++++++++++++++++++++++
 qt-ui/profile/profilewidget2.h   |  1 +
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/qt-ui/profile/diveeventitem.cpp b/qt-ui/profile/diveeventitem.cpp
index 3f75ab1..54e3e4c 100644
--- a/qt-ui/profile/diveeventitem.cpp
+++ b/qt-ui/profile/diveeventitem.cpp
@@ -59,7 +59,7 @@ void DiveEventItem::setupPixmap()
 #define EVENT_PIXMAP(PIX) QPixmap(QString(PIX)).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)
 	if (!internalEvent->name) {
 		setPixmap(EVENT_PIXMAP(":warning"));
-	} else if ((strcmp(internalEvent->name, "bookmark") == 0)) {
+	} else if (internalEvent->type == SAMPLE_EVENT_BOOKMARK) {
 		setPixmap(EVENT_PIXMAP(":flag"));
 	} else if (strcmp(internalEvent->name, "heading") == 0) {
 		setPixmap(EVENT_PIXMAP(":flag"));
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index ef52e28..a32ff87 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -23,6 +23,7 @@
 #include <QScrollBar>
 #include <QtCore/qmath.h>
 #include <QMessageBox>
+#include <QInputDialog>
 
 #ifndef QT_NO_DEBUG
 #include <QTableView>
@@ -705,6 +706,12 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
 		action->setData(QVariant::fromValue<void *>(item));
 		connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents()));
 		m.addAction(action);
+                if(item->getEvent()->type == SAMPLE_EVENT_BOOKMARK){
+                        action->setText(tr("Edit name"));
+                        action->setData(QVariant::fromValue<void *>(item));
+                        connect(action, SIGNAL(triggered(bool)), this, SLOT(editName()));
+                        m.addAction(action);
+                }
 	}
 	bool some_hidden = false;
 	for (int i = 0; i < evn_used; i++) {
@@ -806,3 +813,27 @@ void ProfileWidget2::setPrintMode(bool mode, bool grayscale)
 	printMode = mode;
 	isGrayscale = mode ? grayscale : false;
 }
+
+void ProfileWidget2::editName()
+{
+        QAction *action = qobject_cast<QAction *>(sender());
+        DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>());
+        struct event *event = item->getEvent();
+        bool ok;
+        QString newName = QInputDialog::getText(MainWindow::instance(), tr("QInputDialog::getText()"),
+                                                tr("Custom name:"), QLineEdit::Normal,
+                                                event->name, &ok);
+        if(ok && !newName.isEmpty()){
+                if(newName.length() > 22){//longer names will display as garbage.
+                        QMessageBox lengthWarning;
+                        lengthWarning.setText("Name is too long!");
+                        lengthWarning.exec();
+                        return;
+                }
+                const char* temp;
+                temp = newName.toStdString().c_str();
+                strcpy(event->name, temp);
+                remember_event(temp);
+        }
+        replot();
+}
\ No newline at end of file
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index eb7486e..29c9153 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -79,6 +79,7 @@ slots: // Necessary to call from QAction's signals.
 	void hideEvents();
 	void unhideEvents();
 	void removeEvent();
+        void editName();
 
 protected:
 	virtual void resizeEvent(QResizeEvent *event);
-- 
1.8.3.4 (Apple Git-47)

