This is an attempt to solve ticket #300
(http://trac.hohndel.org/ticket/300).
Nicu Badescu
>From cda5e8320cceeb1ddd967e3de3203f275591df16 Mon Sep 17 00:00:00 2001
From: Nicu Badescu <[email protected]>
Date: Sat, 1 Mar 2014 03:25:46 +0200
Subject: [PATCH 1/3] Add name to bookmarks
Implement the feature to give name to bookmarks. Also, modify the EventItem
constructor to show the flag icon for newly created bookmarks.
Signed-off-by: Nicu Badescu <[email protected]>
---
qt-ui/profilegraphics.cpp | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index f94a27c..6635d4f 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -8,10 +8,12 @@
#include <QScrollBar>
#include <QPen>
#include <QBrush>
+#include <QByteArray>
#include <QDebug>
#include <QLineF>
#include <QSettings>
#include <QIcon>
+#include <QInputDialog>
#include <QPropertyAnimation>
#include <QGraphicsSceneHoverEvent>
#include <QMouseEvent>
@@ -181,7 +183,20 @@ void ProfileGraphicsView::addBookmark()
QPoint viewPos = mapFromGlobal(globalPos);
QPointF scenePos = mapToScene(viewPos);
int seconds = scenePos.x() / gc.maxx * (gc.rightx - gc.leftx) + gc.leftx;
- add_event(current_dc, seconds, SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark");
+ bool ok;
+ QString bookmarkName = QInputDialog::getText(this, "Set Bookmark Name", "Bookmark Name:",
+ QLineEdit::Normal, "", &ok);
+ if (ok) {
+ if (!bookmarkName.isEmpty()) {
+ bookmarkName = "bookmark: " + bookmarkName;
+ QByteArray bookmarkNameCStr = bookmarkName.toLocal8Bit();
+ add_event(current_dc, seconds, SAMPLE_EVENT_BOOKMARK, 0, 0, bookmarkNameCStr.data());
+ } else {
+ add_event(current_dc, seconds, SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark");
+ }
+ } else {
+ return;
+ }
mark_divelist_changed(true);
plot(current_dive, true);
}
@@ -1475,7 +1490,7 @@ QColor EventItem::getColor(const color_indice_t i)
EventItem::EventItem(struct event *ev, QGraphicsItem *parent, bool grayscale) : QGraphicsPixmapItem(parent), ev(ev), isGrayscale(grayscale)
{
- if (ev->name && (strcmp(ev->name, "bookmark") == 0 || strcmp(ev->name, "heading") == 0)) {
+ if (ev->name && (strstr(ev->name, "bookmark") != NULL || strcmp(ev->name, "heading") == 0)) {
setPixmap(QPixmap(QString(":flag")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
} else {
setPixmap(QPixmap(QString(":warning")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
--
1.7.9.5
>From 246182ed329427445f906a220758bb23b23001fc Mon Sep 17 00:00:00 2001
From: Nicu Badescu <[email protected]>
Date: Sat, 1 Mar 2014 03:59:15 +0200
Subject: [PATCH 2/3] Put a suggestive message in the text area
Signed-off-by: Nicu Badescu <[email protected]>
---
qt-ui/profilegraphics.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index 6635d4f..e3bba3b 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -185,7 +185,7 @@ void ProfileGraphicsView::addBookmark()
int seconds = scenePos.x() / gc.maxx * (gc.rightx - gc.leftx) + gc.leftx;
bool ok;
QString bookmarkName = QInputDialog::getText(this, "Set Bookmark Name", "Bookmark Name:",
- QLineEdit::Normal, "", &ok);
+ QLineEdit::Normal, "Leave blank for default", &ok);
if (ok) {
if (!bookmarkName.isEmpty()) {
bookmarkName = "bookmark: " + bookmarkName;
--
1.7.9.5
>From 2a8230746d5f202c4cad4d42a841efa3d627004d Mon Sep 17 00:00:00 2001
From: Nicu Badescu <[email protected]>
Date: Sat, 1 Mar 2014 04:00:25 +0200
Subject: [PATCH 3/3] Check for occurrences of word "bookmark" instead of
exact match
This is needed because the bookmarks can any name from now on.
Signed-off-by: Nicu Badescu <[email protected]>
---
dive.c | 2 +-
qt-ui/profile/diveeventitem.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/dive.c b/dive.c
index 4058122..e3763ea 100644
--- a/dive.c
+++ b/dive.c
@@ -571,7 +571,7 @@ static bool is_potentially_redundant(struct event *event)
{
if (!strcmp(event->name, "gaschange"))
return false;
- if (!strcmp(event->name, "bookmark"))
+ if (!strstr(event->name, "bookmark"))
return false;
if (!strcmp(event->name, "heading"))
return false;
diff --git a/qt-ui/profile/diveeventitem.cpp b/qt-ui/profile/diveeventitem.cpp
index 40d9e72..1b7e75c 100644
--- a/qt-ui/profile/diveeventitem.cpp
+++ b/qt-ui/profile/diveeventitem.cpp
@@ -55,7 +55,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 ((strstr(internalEvent->name, "bookmark") != NULL)) {
setPixmap(EVENT_PIXMAP(":flag"));
} else if (strcmp(internalEvent->name, "heading") == 0) {
setPixmap(EVENT_PIXMAP(":flag"));
--
1.7.9.5
_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface