Edit name option for bookmarks

Add the option to edit the name of a bookmark to be more meaningful for
the user they prefer.
It works just as simple bookmarks and can be removed and hidden.
It won't accept names longer than 22 characters because longer names will
display as garbage text.
Also changed the code from displaying flag depending on event name to
depending on event type.

Signed-off-by: Yousef Hamza <jo.adama.93@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Yosef Hamza 2014-04-03 21:16:15 +02:00 committed by Dirk Hohndel
parent c268b757df
commit 0f5664e584
3 changed files with 34 additions and 1 deletions

View file

@ -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"));

View file

@ -23,6 +23,7 @@
#include <QScrollBar>
#include <QtCore/qmath.h>
#include <QMessageBox>
#include <QInputDialog>
#ifndef QT_NO_DEBUG
#include <QTableView>
@ -709,6 +710,13 @@ 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 = new QAction(&m);
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++) {
@ -810,3 +818,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("Edit name of bookmark"),
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();
}

View file

@ -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);